feat: Implement store persistence and improve store interface
All checks were successful
Build / Build (push) Successful in 24s
All checks were successful
Build / Build (push) Successful in 24s
This commit introduces store persistence and refactors the store interface for improved functionality. The changes include: - Adding a `save` function to persist store data. - Refactoring `createStore` to `create` and `getStore` to `get`. - Adding `set` function to create store if not exist. - Refactoring `set` to `hset` and `get` to `hget` for hash set and get operations. - Refactoring `delete` to `hdel` for hash delete operations. - Implementing store saving after each modification.
This commit is contained in:
parent
767c95978e
commit
3bd5a4a9bf
24
.vscode/tasks.json
vendored
Normal file
24
.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "Start Arma 3 Server",
|
||||
"type": "process",
|
||||
"command": "wscript.exe",
|
||||
"args": [
|
||||
"D:\\SteamLibrary\\steamapps\\common\\Arma 3\\start_serverhub_hidden.vbs"
|
||||
],
|
||||
"presentation": {
|
||||
"reveal": "silent",
|
||||
"panel": "shared",
|
||||
"showReuseMessage": false,
|
||||
"clear": true
|
||||
},
|
||||
"problemMatcher": [],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -19,73 +19,98 @@ private _storeInterface = createHashMapObject [[
|
||||
["#create", {
|
||||
private _storeRegistry = GETVAR(profileNamespace,FORGE_STORE_REG,createHashMap);
|
||||
_self set ["stores", _storeRegistry];
|
||||
|
||||
true
|
||||
}],
|
||||
["createStore", {
|
||||
["save", {
|
||||
private _stores = _self get "stores";
|
||||
|
||||
SETVAR(profileNamespace,FORGE_STORE_REG,_stores);
|
||||
saveProfileNamespace;
|
||||
|
||||
true
|
||||
}],
|
||||
["create", {
|
||||
params [["_name", "", [""]]];
|
||||
|
||||
if (_name == "") exitWith { ERROR_MSG("Store name cannot be empty"); nil };
|
||||
|
||||
private _stores = _self get "stores";
|
||||
private _store = _stores getOrDefault [_name, nil];
|
||||
|
||||
if !(isNil "_store") exitWith { _store };
|
||||
|
||||
private _store = createHashMap;
|
||||
|
||||
_stores set [_name, _store];
|
||||
_self call ["save"];
|
||||
|
||||
_store
|
||||
}],
|
||||
["getStore", {
|
||||
["set", {
|
||||
params [["_name", "", [""]]];
|
||||
|
||||
if (_name == "") exitWith { ERROR_MSG("Store name cannot be empty"); nil };
|
||||
|
||||
private _stores = _self get "stores";
|
||||
_stores getOrDefault [_name, nil]
|
||||
private _store = _self call ["get", [_name]];
|
||||
|
||||
if (isNil "_store") then {
|
||||
_store = _self call ["create", [_name]];
|
||||
};
|
||||
|
||||
_store
|
||||
}],
|
||||
["deleteStore", {
|
||||
["get", {
|
||||
params [["_name", "", [""]]];
|
||||
|
||||
if (_name == "") exitWith { ERROR_MSG("Store name cannot be empty"); nil };
|
||||
|
||||
private _stores = _self get "stores";
|
||||
_stores get _name
|
||||
}],
|
||||
["delete", {
|
||||
params [["_name", "", [""]]];
|
||||
|
||||
if (_name == "") exitWith { ERROR_MSG("Store name cannot be empty"); false };
|
||||
|
||||
private _stores = _self get "stores";
|
||||
private _store = _stores getOrDefault [_name, nil];
|
||||
private _store = _self call ["get", [_name]];
|
||||
|
||||
if (isNil "_store") exitWith { ERROR_MSG_1("Store %1 not found", _name); false };
|
||||
|
||||
_stores deleteAt _name;
|
||||
true
|
||||
}],
|
||||
["set", {
|
||||
params [["_name", "", [""]], ["_key", "", [""]], ["_value", nil]];
|
||||
["hset", {
|
||||
params [["_name", "", [""]], ["_key", "", [""]], ["_value", "", ["", [], 0, false, createHashMap]]];
|
||||
|
||||
if (_name == "" || _key == "") exitWith { ERROR_MSG("Store name and, or key cannot be empty"); false };
|
||||
|
||||
private _stores = _self get "stores";
|
||||
private _store = _stores getOrDefault [_name, nil];
|
||||
private _store = _self call ["get", [_name]];
|
||||
|
||||
if (isNil "_store") exitWith { ERROR_MSG_1("Store %1 not found", _name); false };
|
||||
|
||||
_store set [_key, _value];
|
||||
_stores set [_name, _store];
|
||||
_self call ["save"];
|
||||
|
||||
true
|
||||
}],
|
||||
["get", {
|
||||
params [["_name", "", [""]], ["_key", "", [""]], ["_default", nil]];
|
||||
["hget", {
|
||||
params [["_name", "", [""]], ["_key", "", [""]]];
|
||||
|
||||
if (_name == "" || _key == "") exitWith { ERROR_MSG("Store name and, or key cannot be empty"); _default };
|
||||
|
||||
private _store = _self call ["getStore", [_name]];
|
||||
private _store = _self call ["get", [_name]];
|
||||
|
||||
if (isNil "_store") exitWith { ERROR_MSG_1("Store %1 not found", _name); _default };
|
||||
|
||||
_store getOrDefault [_key, _default]
|
||||
_store get _key
|
||||
}],
|
||||
["delete", {
|
||||
["hdel", {
|
||||
params [["_name", "", [""]], ["_key", "", [""]]];
|
||||
|
||||
if (_name == "" || _key == "") exitWith { ERROR_MSG("Store name and, or key cannot be empty"); false };
|
||||
|
||||
private _store = _self call ["getStore", [_name]];
|
||||
private _store = _self call ["get", [_name]];
|
||||
|
||||
if (isNil "_store") exitWith { ERROR_MSG_1("Store %1 not found", _name); false };
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user