- Route bank sync payloads through the client bridge - Refresh account state without rebuilding the full session - Split CAD dispatcher UI into modular source files
245 lines
8.7 KiB
Plaintext
245 lines
8.7 KiB
Plaintext
#include "..\script_component.hpp"
|
|
|
|
/*
|
|
* File: fnc_initVGStore.sqf
|
|
* Author: IDSolutions
|
|
* Date: 2025-12-17
|
|
* Last Update: 2026-04-01
|
|
* Public: No
|
|
*
|
|
* Description:
|
|
* Initializes the Virtual Garage store for managing player vehicle unlocks.
|
|
* Virtual garage hot state is owned by the extension; SQF acts as a thin bridge.
|
|
*
|
|
* Arguments:
|
|
* None
|
|
*
|
|
* Return Value:
|
|
* VG store object [HASHMAP OBJECT]
|
|
*
|
|
* Example:
|
|
* call forge_server_garage_fnc_initVGStore
|
|
*/
|
|
|
|
#pragma hemtt ignore_variables ["_self"]
|
|
GVAR(VGarageModel) = compileFinal createHashMapObject [[
|
|
["#type", "VGarageModel"],
|
|
["defaults", compileFinal {
|
|
private _vGarage = createHashMap;
|
|
|
|
_vGarage set ["armor", []];
|
|
_vGarage set ["cars", ["B_Quadbike_01_F"]];
|
|
_vGarage set ["helis", []];
|
|
_vGarage set ["naval", []];
|
|
_vGarage set ["other", []];
|
|
_vGarage set ["planes", []];
|
|
|
|
_vGarage
|
|
}]
|
|
]];
|
|
|
|
GVAR(VGBaseStore) = compileFinal createHashMapFromArray [
|
|
["#base", EGVAR(common,BaseStore)],
|
|
["#type", "VGBaseStore"],
|
|
["#create", compileFinal {
|
|
["INFO", "VGarage Store Initialized!"] call EFUNC(common,log);
|
|
}],
|
|
["callHotVGarage", compileFinal {
|
|
params [["_function", "", [""]], ["_arguments", [], [[]]]];
|
|
|
|
if (_function isEqualTo "") exitWith { createHashMap };
|
|
|
|
[_function, _arguments] call EFUNC(extension,extCall) params ["_result", "_isSuccess"];
|
|
if !(_isSuccess) exitWith { createHashMap };
|
|
if !(_result isEqualType "") exitWith { createHashMap };
|
|
if ((_result find "Error:") == 0) exitWith {
|
|
["ERROR", format ["VGarage extension call '%1' failed: %2", _function, _result]] call EFUNC(common,log);
|
|
createHashMap
|
|
};
|
|
|
|
private _data = fromJSON _result;
|
|
if !(_data isEqualType createHashMap) exitWith { createHashMap };
|
|
_data
|
|
}],
|
|
["loadHotVGarage", compileFinal {
|
|
params [["_uid", "", [""]], ["_initialize", false, [false]]];
|
|
|
|
if (_uid isEqualTo "") exitWith { createHashMap };
|
|
|
|
private _command = ["owned:garage:hot:fetch", "owned:garage:hot:init"] select _initialize;
|
|
_self call ["callHotVGarage", [_command, [_uid]]]
|
|
}],
|
|
["init", compileFinal {
|
|
params [["_uid", "", [""]]];
|
|
|
|
private _player = [_uid] call EFUNC(common,getPlayer);
|
|
if (isNull _player) exitWith { createHashMap };
|
|
|
|
private _garage = _self call ["loadHotVGarage", [_uid, true]];
|
|
if (_garage isEqualTo createHashMap) then {
|
|
_garage = GVAR(VGarageModel) call ["defaults", []];
|
|
["ERROR", format ["Failed to initialize virtual garage for %1! Using fallback virtual garage.", _uid]] call EFUNC(common,log);
|
|
};
|
|
|
|
[CRPC(garage,responseInitVG), [_garage], _player] call CFUNC(targetEvent);
|
|
_garage
|
|
}],
|
|
["get", compileFinal {
|
|
params [["_uid", "", [""]], ["_field", "", [""]]];
|
|
|
|
private _garage = _self call ["loadHotVGarage", [_uid, false]];
|
|
if (_garage isEqualTo createHashMap) then {
|
|
_garage = _self call ["loadHotVGarage", [_uid, true]];
|
|
};
|
|
|
|
if (_field isEqualTo "") exitWith { _garage };
|
|
_garage getOrDefault [_field, []]
|
|
}],
|
|
["override", compileFinal {
|
|
params [
|
|
["_uid", "", [""]],
|
|
["_data", createHashMap, [createHashMap]],
|
|
["_save", false, [false]]
|
|
];
|
|
|
|
if (_uid isEqualTo "") exitWith { createHashMap };
|
|
if !(_data isEqualType createHashMap) exitWith { createHashMap };
|
|
|
|
private _garage = _self call ["callHotVGarage", ["owned:garage:hot:override", [_uid, toJSON _data]]];
|
|
if (_save && { _garage isNotEqualTo createHashMap }) then {
|
|
private _savedGarage = _self call ["callHotVGarage", ["owned:garage:hot:save", [_uid]]];
|
|
if (_savedGarage isNotEqualTo createHashMap) then {
|
|
_garage = _savedGarage;
|
|
} else {
|
|
_garage = createHashMap;
|
|
};
|
|
};
|
|
|
|
_garage
|
|
}],
|
|
["set", compileFinal {
|
|
params [
|
|
["_uid", "", [""]],
|
|
["_field", "", [""]],
|
|
["_value", nil, [[], "", 0, false, createHashMap]],
|
|
["_sync", false, [false]]
|
|
];
|
|
|
|
if (_uid isEqualTo "" || { _field isEqualTo "" }) exitWith { createHashMap };
|
|
|
|
private _garage = _self call ["loadHotVGarage", [_uid, false]];
|
|
if !(_garage isEqualType createHashMap) exitWith { createHashMap };
|
|
|
|
_garage set [_field, _value];
|
|
private _updatedGarage = _self call ["override", [_uid, _garage, _sync]];
|
|
if !(_updatedGarage isEqualType createHashMap) exitWith { createHashMap };
|
|
if (_updatedGarage isEqualTo createHashMap) exitWith { createHashMap };
|
|
|
|
createHashMapFromArray [[_field, _updatedGarage getOrDefault [_field, _value]]]
|
|
}],
|
|
["mset", compileFinal {
|
|
params [
|
|
["_uid", "", [""]],
|
|
["_fieldValuePairs", createHashMap, [createHashMap]],
|
|
["_sync", false, [false]]
|
|
];
|
|
|
|
if (_uid isEqualTo "") exitWith { createHashMap };
|
|
if !(_fieldValuePairs isEqualType createHashMap) exitWith { createHashMap };
|
|
|
|
private _garage = _self call ["loadHotVGarage", [_uid, false]];
|
|
if !(_garage isEqualType createHashMap) exitWith { createHashMap };
|
|
|
|
{ _garage set [_x, _y]; } forEach _fieldValuePairs;
|
|
private _updatedGarage = _self call ["override", [_uid, _garage, _sync]];
|
|
if !(_updatedGarage isEqualType createHashMap) exitWith { createHashMap };
|
|
if (_updatedGarage isEqualTo createHashMap) exitWith { createHashMap };
|
|
|
|
+_fieldValuePairs
|
|
}],
|
|
["save", compileFinal {
|
|
params [["_uid", "", [""]]];
|
|
|
|
if (_uid isEqualTo "") exitWith { createHashMap };
|
|
_self call ["callHotVGarage", ["owned:garage:hot:save", [_uid]]]
|
|
}],
|
|
["remove", compileFinal {
|
|
params [["_uid", "", [""]]];
|
|
|
|
if (_uid isEqualTo "") exitWith { false };
|
|
|
|
["owned:garage:hot:remove", [_uid]] call EFUNC(extension,extCall) params ["_result", "_isSuccess"];
|
|
_isSuccess && { _result isEqualTo "OK" }
|
|
}],
|
|
["grantVehicles", compileFinal {
|
|
params [["_uid", "", [""]], ["_vehicles", [], [[]]], ["_commit", false, [false]]];
|
|
|
|
private _result = createHashMapFromArray [
|
|
["success", false],
|
|
["message", "Virtual garage grant failed."],
|
|
["patch", createHashMap],
|
|
["granted", []],
|
|
["garage", createHashMap]
|
|
];
|
|
|
|
private _garage = +(_self call ["loadHotVGarage", [_uid, false]]);
|
|
if (_garage isEqualTo createHashMap) then {
|
|
_garage = GVAR(VGarageModel) call ["defaults", []];
|
|
};
|
|
|
|
private _patch = createHashMap;
|
|
private _granted = [];
|
|
private _categoriesToSync = [];
|
|
|
|
{
|
|
private _className = _x getOrDefault ["classname", ""];
|
|
private _category = toLowerANSI (_x getOrDefault ["category", ""]);
|
|
|
|
if (_className isEqualTo "") exitWith {
|
|
_result set ["message", "Vehicle checkout entry was missing a classname."];
|
|
};
|
|
|
|
if !(_category in ["cars", "armor", "helis", "planes", "naval", "other"]) exitWith {
|
|
_result set ["message", format ["Vehicle category '%1' is unsupported.", _category]];
|
|
};
|
|
|
|
private _categoryUnlocks = +(_garage getOrDefault [_category, []]);
|
|
_categoryUnlocks pushBackUnique _className;
|
|
_garage set [_category, _categoryUnlocks];
|
|
_categoriesToSync pushBackUnique _category;
|
|
_granted pushBack (createHashMapFromArray [
|
|
["classname", _className],
|
|
["category", _category]
|
|
]);
|
|
} forEach _vehicles;
|
|
|
|
{
|
|
private _category = _x;
|
|
_patch set [_category, _garage getOrDefault [_category, []]];
|
|
} forEach _categoriesToSync;
|
|
|
|
if (_commit) then {
|
|
private _savedGarage = _self call ["override", [_uid, _garage, false]];
|
|
if !(_savedGarage isEqualType createHashMap) exitWith {
|
|
_result set ["message", "Virtual garage cache update returned invalid data."];
|
|
_result
|
|
};
|
|
if (_savedGarage isEqualTo createHashMap) exitWith {
|
|
_result set ["message", "Failed to update virtual garage cache."];
|
|
_result
|
|
};
|
|
_garage = _savedGarage;
|
|
};
|
|
|
|
_result set ["success", true];
|
|
_result set ["message", ""];
|
|
_result set ["patch", _patch];
|
|
_result set ["granted", _granted];
|
|
_result set ["garage", _garage];
|
|
_result
|
|
}]
|
|
];
|
|
|
|
GVAR(VGarageStore) = createHashMapObject [GVAR(VGBaseStore)];
|
|
GVAR(VGarageStore)
|