xpdb/addons/save/functions/fnc_custom.sqf
Jacob Schmidt 3457f24161
Some checks failed
Build / Build (push) Failing after 7s
Update save and load functions to support scheduled/unscheduled execution
2025-02-22 09:07:27 -06:00

70 lines
2.6 KiB
Plaintext

#include "script_component.hpp"
/*
* Function: xpdb_save_fnc_custom
* Author: J.Schmidt
* Edit: 08.12.2024
* Copyright © 2024 NikolaiF90, J.Schmidt, All rights reserved
*
* Do not edit without permission!
*
* This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivative 4.0 International License.
* To view a copy of this license, vist https://creativecommons.org/licenses/by-nc-nd/4.0/ or send a letter to Creative Commons,
* PO Box 1866, Mountain View, CA 94042
*
* [Description]
* Executes an eXtended Persistent Database save based on user-defined configuration in XPDB_CfgXPDB (eXtended Persistent Database) within the mission config file.
*
* Arguments:
* 0: ID of Slot <SCALAR> (default: 0)
*
* Return Value:
* N/A
*
* Examples:
* [1] call xpdb_save_fnc_custom
*
* Public: Yes
*/
params [["_slot", nil, [0]]];
private _configPath = "missionConfigFile >> 'CfgXPDB' >> 'save'";
private _config = call compile _configPath;
if (isNull _config) exitWith {
[EGVAR(db,debug), "xpdb_save_fnc_custom", format ["Mission Config: eXtended Persistent Database config '%1' not found. eXtended Persistent Database save process skipped.", _configPath], true] call EFUNC(utils,debug);
};
[EGVAR(db,debug), "xpdb_save_fnc_custom", format ["Initializing eXtended Persistent Database save for slot '%1'...", _slot], false] call EFUNC(utils,debug);
private _saveEntries = "true" configClasses (_config);
{
private _entryName = configName _x;
private _functionName = getText (_x >> "function");
private _args = getArray (_x >> "args");
private _scheduled = getNumber (_x >> "scheduled") == 1;
if (_functionName != "") then {
private _function = call compile _functionName;
if (_scheduled) then {
private _result = _args spawn _function;
if (!isNil "_result") then {
[EGVAR(db,debug), "xpdb_save_fnc_custom", format ["Saving '%1.%2.%3'", EGVAR(db,prefix), _slot, _entryName], false] call EFUNC(utils,debug);
[_entryName, _result, _slot] call EFUNC(core,saveData);
};
} else {
private _result = _args call _function;
if (!isNil "_result") then {
[EGVAR(db,debug), "xpdb_save_fnc_custom", format ["Saving '%1.%2.%3'", EGVAR(db,prefix), _slot, _entryName], false] call EFUNC(utils,debug);
[_entryName, _result, _slot] call EFUNC(core,saveData);
};
};
};
} forEach _saveEntries;
[EGVAR(db,debug), "xpdb_save_fnc_custom", "eXtended Persistent Database save completed.", false] call EFUNC(utils,debug);