server/addons/db/functions/fnc_saveGameState.sqf
Jacob Schmidt 5b30efa3b0
All checks were successful
Build / Build (push) Successful in 26s
feat: Refactor database system for improved persistence and functionality
This commit refactors the database system to improve persistence, functionality, and code clarity. The key changes include:

-   **Removed direct store access:** Removed `createStore`, `getFromStore`, and `getStore` PREP macros.
-   **Centralized store management:** Introduced a central store registry (`FORGE_STORE_REG`) managed by the database interface.
-   **Namespace-based persistence:** Stores are now persisted in mission and profile namespaces instead of a global store.
-   **Simplified load/save functions:** `loadFromMission`, `loadFromProfile`, `saveToMission`, `saveToProfile`, and `saveToTemp` functions are updated to use the new namespace-based persistence. They now accept a `keyField` parameter for retrieving specific fields within a key's data.
-   **Refactored `processDBRequest`:** Updated to handle new request types and parameters, aligning with the refactored load/save functions.
-   **Improved error handling:** Added more robust error handling and logging, including checks for empty store names and missing keys.
-   **Removed client registration:** Removed client registration and cleanup logic as it's no longer needed with the new persistence model.
-   **Updated `verifyDB`:** Simplified to directly return the store registry.
-   **Updated `initDB`:** Refactored to use a HashMap object for the store interface and added more database functions.
-   **Added .gitignore entries:** Added entries for Visual Studio and other common build artifacts.
-   **Updated `loadGameState` and `saveGameState`:** Updated to support loading and saving game state to either mission or profile namespace.
2025-04-05 14:16:35 -05:00

74 lines
2.5 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Function: forge_server_db_fnc_saveGameState
* Author: J. Schmidt
*
* Description:
* Collects and saves the current game state to mission or profile namespace
*
* Arguments:
* 0: _nameSpace - Namespace to save to (mission, profile) <STRING> (default: mission)
*
* Return Value:
* Success <BOOL>
*/
params [["_nameSpace", "mission", [""]]];
if (isNil "companyFunds") then { companyFunds = 0 };
if (isNil "companyRating") then { companyRating = 0 };
if (isNil "companyGenerals") then { companyGenerals = [] };
if (isNil "companyGarageUnlocks") then { companyGarageUnlocks = [] };
private _default_armory_unlocks = [[],[],[],[]];
private _default_garage_unlocks = [[],[],[],[],[],[]];
private _companyState = createHashMapFromArray [
["key", "CompanyState"],
["funds", companyFunds],
["rating", companyRating],
["operations", companyGenerals],
["garage_unlocks", companyGarageUnlocks]
];
if (_nameSpace == "mission") then {
["companyStore", "CompanyState", _companyState] call FUNC(saveToMission);
} else {
["companyStore", "CompanyState", _companyState] call FUNC(saveToProfile);
};
{
if (alive _x) then {
private _playerState = createHashMapFromArray [
["key", getPlayerUID _x],
["armory_unlocks", GETVAR(_x,FORGE_Armory_Unlocks,_default_armory_unlocks)],
["garage_unlocks", GETVAR(_x,FORGE_Garage_Unlocks,_default_garage_unlocks)],
["locker", GETVAR(_x,FORGE_Locker,[])],
["garage", GETVAR(_x,FORGE_Garage,[])],
["cash", GETVAR(_x,FORGE_Cash,0)],
["bank", GETVAR(_x,FORGE_Bank,0)],
["number", GETVAR(_x,FORGE_Phone_Number,"unknown")],
["email", GETVAR(_x,FORGE_Email,"unknown@spearnet.mil")],
["paygrade", GETVAR(_x,FORGE_Paygrade,"E1")],
["reputation", rating _x],
["loadout", getUnitLoadout _x],
["holster", GETVAR(_x,FORGE_Holster_Weapon,true)],
["position", getPosASLVisual _x],
["direction", getDirVisual _x]
];
if (isNull objectParent _x) then {
_playerState set ["currentWeapon", currentMuzzle _x];
_playerState set ["stance", stance _x];
};
if (_nameSpace == "mission") then {
["playerStore", getPlayerUID _x, _playerState] call FUNC(saveToMission);
} else {
["playerStore", getPlayerUID _x, _playerState] call FUNC(saveToProfile);
};
};
} forEach playableUnits;
true