client/addons/org/functions/fnc_handleOrgLoad.sqf
Jacob Schmidt 44625a8677
All checks were successful
Build / Build (push) Successful in 27s
feat: Refactor and document client-side functions
This commit refactors and adds documentation to several client-side functions across various addons, including:

- **Task Addon:** Added function headers and descriptions to task-related functions (fnc_destroy, fnc_attack, fnc_defuse, fnc_hostage, fnc_makeIED, fnc_hvt, fnc_heartBeat, fnc_makeTarget, fnc_makeHVT, fnc_makeHostage, fnc_makeObject, fnc_makeShooter, fnc_attackModule, fnc_destroyModule, fnc_hvtModule, fnc_hostageModule, fnc_defuseModule, fnc_protectedModule, fnc_hostagesModule, fnc_explosivesModule, fnc_shootersModule).
- **Org Addon:** Updated author and added function headers/descriptions to organization-related functions (fnc_initOrgStore, fnc_requestServerDB, fnc_addAsset, fnc_addReputation, fnc_create, fnc_removeAsset, fnc_addFunds, fnc_leave, fnc_addMember, fnc_disband, fnc_verifyOrgStore, fnc_handleOrgLoad).
- **Garage Addon:** Added function headers and descriptions to garage-related functions (fnc_openGarage, fnc_fetchNearby, fnc_initGarage, fnc_fetchGarage, fnc_storeVehicle).
- **Locker Addon:** Added function headers and descriptions to locker-related functions (fnc_openLocker, fnc_fetchPlayer, fnc_initLocker, fnc_fetchLocker).
- **Phone Addon:** Added function headers, descriptions, and examples to phone-related functions (fnc_initAction, fnc_showEmail, fnc_showMessage, fnc_delEmail, fnc_delMsg, fnc_showMessageInput, fnc_addContact, fnc_initPhone, fnc_addMsg, fnc_addEmail, fnc_newEmail, fnc_initVar, fnc_addOfflineEmail, fnc_addOfflineMsg, fnc_sendMsg, fnc_sendEmail, fnc_showContact, fnc_newMsg, fnc_dateToHhMm, fnc_initAddAction, fnc_openPhone, fnc_viewSettings, fnc_viewMessages, fnc_viewContacts, fnc_viewEmail, fnc_showDialpad, fnc_showSafari).
- **Admin Addon:** Added function headers and descriptions to admin-related functions (fnc_adminMessage, fnc_printAddonName, fnc_initAdmin, fnc_openAdmin, fnc_adminPromote).
- **Store Addon:** Added function headers and descriptions to store-related functions (fnc_openStore, fnc_initStore, fnc_selectProduct, fnc_changeFilter, fnc_changePayment, fnc_handlePurchase).
- **Medical Addon:** Added function headers, descriptions, and examples to medical-related functions (fnc_saveDroppedWeapons, fnc_moveInventory, fnc_onRespawn, fnc_onKilled, fnc_initMedical, fnc_deductMedicalCost, fnc_heartBeat).
- **Misc Addon:** Added function headers, descriptions, and examples to misc-related functions (fnc_formatNumber, fnc_isAssignableBinocular, fnc_isWeaponType, fnc_cargoToPairs, fnc_serializeString, fnc_deserializeString, fnc_getSystemTime).
- **Init Addon:** Updated author and removed unnecessary copyright information from init-related functions (fnc_initPlayer, fnc_playerDBSave, fnc_playerSaveLoop, fnc_playerDBLoad, fnc_handlePlayerLoad).
- **Money Addon:** Removed unnecessary copyright information from money-related functions (fnc_takeCash, fnc_giveCash, fnc_giveCashSubmit).
- **Interaction Addon:** Removed unnecessary copyright information from interaction-related functions (fnc_initInteraction, fnc_openInteraction, fnc_interactionAction).
- **Ambient Addon:** Removed unnecessary copyright information from ambient-related functions (fnc_ambientSound).
- **Arsenal Addon:** Added function headers, descriptions, and examples to arsenal-related functions (fnc_openArmory, fnc_saveUnlocks, fnc_updateUnlocks, fnc_openGarage, fnc_addGarageVehicle, fnc_addVirtualVehicles, fnc_addVirtualVehicles).
- **Dialogue Addon:** Added function headers and descriptions to dialogue-related functions (fnc_selectAI, fnc_selectDialogue).
- **Service Addon:** Added function headers and descriptions to service-related functions (fnc_initService).
- **Bank Addon:** Added function headers and descriptions to bank-related functions (fnc_initBank, fnc_refresh, fnc_openBank).

These changes improve code readability, maintainability, and provide better context for developers working with these functions. The author field was updated to `IDSolutions` where appropriate.
2025-04-05 16:12:32 -05:00

248 lines
9.1 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Function: forge_client_org_fnc_handleOrgLoad
* Author: IDSolutions
*
* [Description]
* Processes and transforms raw organization data from a database into a structured hashMap.
* Handles data normalization, type conversion, and ensures all required organization fields are present.
* This function is called as a callback when organization data is loaded from the database.
*
* Arguments:
* 0: Raw Data <ARRAY> - DragonflyDB HGETALL result containing raw organization data
*
* Return Value:
* None
*
* Example:
* _orgData call forge_client_org_fnc_handleOrgLoad
*
* Public: No
*/
// Log the received data for debugging purposes
diag_log text format ["[FORGE Organization] Organization data received: '%1'", _this];
// Store the raw data and get player information
private _data = _this;
private _playerNetId = netId player;
private _store = call FUNC(verifyOrgStore);
// Validate the received data
if (isNil "_data" || {!(_data isEqualType [])} || {count _data < 2} || {_data isEqualTo [""]}) exitWith {
diag_log text "[FORGE Organization] Empty or invalid organization data received";
// Mark the store as loaded but with no organization
if !(isNil "_store") then {
_store set ["currentOrganization", nil];
_store set ["isLoaded", true];
};
["No organization data found", "info", 5, "right"] call forge_client_misc_fnc_notify;
};
// Create organization data hashMap to store the processed data
private _orgData = createHashMap;
// Process the data array - convert from flat key-value pairs to structured hashMap
for "_i" from 0 to (count _data - 1) step 2 do {
private _key = _data select _i;
private _value = _data select (_i + 1);
// Unwrap single-item arrays
if (_value isEqualType []) then {
switch (_key) do {
case "assets": {
// Convert to hashMap by assetType
private _flattenedAssets = [];
// Handle multi-level nesting and ensure it's flattened first
if (count _value > 0 && {_value select 0 isEqualType []}) then {
{
if (_x isEqualType []) then {
_flattenedAssets append _x;
} else {
_flattenedAssets pushBack _x;
};
} forEach _value;
} else {
_flattenedAssets = _value;
};
// Create hashMap from flattened assets
private _assetsMap = createHashMap;
{
if (_x isEqualType [] && count _x >= 2) then {
private _type = _x select 0;
private _class = _x select 1;
// Create a hashMap for this asset
private _assetMap = createHashMap;
// Try to get ID or generate one
private _assetId = "";
private _idIndex = _x findIf {_x == "id"};
if (_idIndex != -1 && _idIndex + 1 < count _x) then {
_assetId = _x select (_idIndex + 1);
} else {
_assetId = format ["%1_%2", _class, diag_tickTime];
};
// Add ID and class to asset map
_assetMap set ["id", _assetId];
_assetMap set ["className", _class];
// Add any extra properties (key-value pairs)
for "_j" from 2 to (count _x - 1) step 2 do {
if (_j + 1 < count _x) then {
private _propName = _x select _j;
private _propValue = _x select (_j + 1);
if (_propName != "className") then {
_assetMap set [_propName, _propValue];
};
};
};
// Add this asset to its type array
private _typeArray = _assetsMap getOrDefault [_type, []];
_typeArray pushBack _assetMap;
_assetsMap set [_type, _typeArray];
};
} forEach _flattenedAssets;
_value = _assetsMap;
};
case "members": {
// Convert to hashMap by playerUID
private _flattenedMembers = [];
// Handle multi-level nesting and ensure it's flattened first
if (count _value > 0 && {_value select 0 isEqualType []}) then {
{
if (_x isEqualType []) then {
_flattenedMembers append _x;
} else {
_flattenedMembers pushBack _x;
};
} forEach _value;
} else {
_flattenedMembers = _value;
};
// Create member hashMap
private _membersMap = createHashMap;
{
if (_x isEqualType [] && count _x >= 3) then {
private _uid = _x select 0;
private _name = _x select 1;
private _role = _x select 2;
private _joinDate = if (count _x > 3) then { _x select 3 } else { "" };
// Replace underscores with spaces in name
if (_name isEqualType "") then {
_name = [_name] call EFUNC(misc,deserializeString);
};
// Create member hashMap
private _memberMap = createHashMap;
_memberMap set ["uid", _uid];
_memberMap set ["name", _name];
_memberMap set ["role", _role];
_memberMap set ["joinDate", _joinDate];
// Add extra properties if any (for future expansion)
for "_j" from 4 to (count _x - 1) step 2 do {
if (_j + 1 < count _x) then {
private _propName = _x select _j;
private _propValue = _x select (_j + 1);
_memberMap set [_propName, _propValue];
};
};
_membersMap set [_uid, _memberMap];
};
} forEach _flattenedMembers;
_value = _membersMap;
};
case "logs": {
// Flatten arrays but don't process contents
private _flattenedArray = [];
// Handle multi-level nesting
if (count _value > 0 && {_value select 0 isEqualType []}) then {
{
if (_x isEqualType []) then {
_flattenedArray append _x;
} else {
_flattenedArray pushBack _x;
};
} forEach _value;
_value = _flattenedArray;
};
};
default {
if (count _value == 1) then {
_value = _value select 0;
};
};
};
};
// Process string values - deserialize names and owner
if (_value isEqualType "" && _key in ["name", "owner"]) then {
_value = [_value] call EFUNC(misc,deserializeString);
};
// Convert numeric values from strings to numbers
if (_key in ["funds", "reputation"] && _value isEqualType "") then {
_value = parseNumber _value;
};
// Store processed value in hashMap
_orgData set [_key, _value];
};
// Ensure we have all required fields in the hashMap
private _requiredFields = ["id", "name", "owner", "funds", "reputation", "assets", "members", "logs", "created", "lastModified"];
{
if (isNil {_orgData get _x}) then {
switch (_x) do {
case "funds";
case "reputation": {
_orgData set [_x, 0];
};
case "assets";
case "members": {
_orgData set [_x, createHashMap];
};
case "logs": {
_orgData set [_x, []];
};
case "created";
case "lastModified": {
_orgData set [_x, ""];
};
default {
_orgData set [_x, ""];
};
};
};
} forEach _requiredFields;
// Update the organization store with the complete hashMap
_store set ["currentOrganization", _orgData];
_store set ["isLoaded", true];
private _orgName = _orgData get "name";
// Log successful load and notify the user
if (!isNil "_orgName") then {
diag_log text format ["[FORGE Organization] Organization successfully loaded: %1", _orgName];
[format ["Organization '%1' loaded", _orgName], "success", 5, "right"] call forge_client_misc_fnc_notify;
};