forge/arma/server/addons/garage/functions/fnc_initGarageStore.sqf

78 lines
2.7 KiB
Plaintext

#include "..\script_component.hpp"
/*
* File: fnc_initGarageStore.sqf
* Author: IDSolutions
* Date: 2025-12-17
* Last Update: 2026-02-13
* Public: No
*
* Description:
* Initializes the Garage store for managing player vehicles.
* Provides methods for syncing, saving, and applying vehicles to the player's garage.
*
* Arguments:
* None
*
* Return Value:
* Garage store object [HASHMAP OBJECT]
*
* Example:
* call forge_server_garage_fnc_initGarageStore
*/
#pragma hemtt ignore_variables ["_self"]
GVAR(GarageBaseStore) = compileFinal createHashMapFromArray [
["#base", EGVAR(common,BaseStore)],
["#type", "GarageBaseStore"],
["#create", compileFinal {
GVAR(Registry) = createHashMap;
["INFO", "Garage Store Initialized!"] call EFUNC(common,log);
}],
["init", compileFinal {
params [["_uid", "", [""]]];
private _player = [_uid] call EFUNC(common,getPlayer);
private _cached = GVAR(Registry) getOrDefault [_uid, nil];
if !(isNil { _cached }) exitWith { [CRPC(garage,responseInitGarage), [_cached], _player] call CFUNC(targetEvent); _cached };
["garage:exists", [_uid]] call EFUNC(extension,extCall) params ["_result", "_isSuccess"];
if !(_isSuccess) exitWith {
["ERROR", format ["Failed to check if garage %1 exists! Using fallback garage.", _uid]] call EFUNC(common,log);
private _fallbackGarage = createHashMap;
GVAR(Registry) set [_uid, _fallbackGarage];
[CRPC(garage,responseInitGarage), [_fallbackGarage], _player] call CFUNC(targetEvent);
_fallbackGarage
};
private _finalGarage = createHashMap;
if (_result == "true") then {
_finalGarage = _self call ["fetch", ["garage:get", _uid]];
["INFO", format ["Found garage for %1", _uid]] call EFUNC(common,log);
} else {
["garage:create", [_uid]] call EFUNC(extension,extCall) params ["_result", "_isSuccess"];
if !(_isSuccess) exitWith {
["ERROR", format ["Failed to create garage for %1! Using fallback garage.", _uid]] call EFUNC(common,log);
GVAR(Registry) set [_uid, _finalGarage];
[CRPC(garage,responseInitGarage), [_finalGarage], _player] call CFUNC(targetEvent);
_finalGarage
};
["INFO", format ["Created new garage for %1", _uid]] call EFUNC(common,log);
};
GVAR(Registry) set [_uid, _finalGarage];
[CRPC(garage,responseInitGarage), [_finalGarage], _player] call CFUNC(targetEvent);
_finalGarage
}]
];
GVAR(GarageStore) = createHashMapObject [GVAR(GarageBaseStore)];
GVAR(GarageStore)