forge/arma/client/addons/store/functions/fnc_buildUIPayload.sqf
Jacob Schmidt bdc1e36e63 Implement interactive garage UI with service-based client bridge
- replace placeholder garage interaction with real UI open flow
- add catalog/session/UI bridge services for hydrate, sync, store, and retrieve actions
- migrate garage web UI bundle to new app shell/runtime structure
- align org/store function naming with shared init and UI bridge patterns
2026-03-14 03:06:18 -05:00

126 lines
4.1 KiB
Plaintext

#include "..\script_component.hpp"
/*
* File: fnc_buildUIPayload.sqf
* Author: IDSolutions
* Date: 2026-03-13
* Public: No
*
* Description:
* Builds the browser hydrate payload for the store UI from current client state.
*
* Arguments:
* None
*
* Return Value:
* Store UI payload [HASHMAP]
*/
private _storeState = createHashMap;
private _budget = 50000;
private _creditLine = 0;
private _cashBalance = 0;
private _bankBalance = 0;
private _orgFunds = 0;
private _orgId = "";
private _orgName = "";
private _orgOwnerUid = "";
private _orgCreditLines = createHashMap;
private _playerUid = getPlayerUID player;
private _playerVar = toLowerANSI (vehicleVarName player);
private _isOrgLeader = false;
private _isDefaultOrg = false;
private _isDefaultOrgCeo = false;
if !(isNil QGVAR(StoreClass)) then {
_storeState = GVAR(StoreClass) call ["getStoreState", []];
_budget = _storeState getOrDefault ["budget", _budget];
};
if !(isNil QEGVAR(bank,BankClass)) then {
_cashBalance = EGVAR(bank,BankClass) call ["get", ["cash", 0]];
_bankBalance = EGVAR(bank,BankClass) call ["get", ["bank", 0]];
};
if !(isNil QEGVAR(org,OrgClass)) then {
_orgId = EGVAR(org,OrgClass) call ["get", ["id", ""]];
_orgName = EGVAR(org,OrgClass) call ["get", ["name", ""]];
_orgOwnerUid = EGVAR(org,OrgClass) call ["get", ["owner", ""]];
_orgFunds = EGVAR(org,OrgClass) call ["get", ["funds", 0]];
_orgCreditLines = EGVAR(org,OrgClass) call ["get", ["credit_lines", createHashMap]];
_isDefaultOrg = (_orgId isEqualTo "default") || { toLowerANSI _orgOwnerUid isEqualTo "server" };
_isOrgLeader = _orgOwnerUid isEqualTo _playerUid;
_isDefaultOrgCeo = _isDefaultOrg && { _playerVar isEqualTo "ceo" };
};
if (_orgCreditLines isEqualType createHashMap) then {
private _playerCreditLine = _orgCreditLines getOrDefault [_playerUid, createHashMap];
if (_playerCreditLine isEqualType createHashMap) then {
_creditLine = _playerCreditLine getOrDefault ["amount", 0];
};
};
private _canUseOrgFunds = _isOrgLeader || _isDefaultOrgCeo;
private _orgFundsEnabled = _canUseOrgFunds && { _orgFunds > 0 };
private _paymentSources = [
createHashMapFromArray [
["id", "cash"],
["label", "Cash"],
["balance", _cashBalance],
["enabled", _cashBalance > 0],
["detail", "Use on-hand cash carried by the player."]
],
createHashMapFromArray [
["id", "bank"],
["label", "Bank"],
["balance", _bankBalance],
["enabled", _bankBalance > 0],
["detail", "Charge the player bank account."]
],
createHashMapFromArray [
["id", "org_funds"],
["label", "Org Funds"],
["balance", _orgFunds],
["enabled", _orgFundsEnabled],
["detail", [
"Only organization leaders or the default-org CEO can use treasury funds.",
[
"Charge organization treasury funds.",
"No organization funds are currently available."
] select _orgFundsEnabled
] select _canUseOrgFunds]
],
createHashMapFromArray [
["id", "credit_line"],
["label", "Credit Line"],
["balance", _creditLine],
["enabled", _creditLine > 0],
["detail", [
"No approved credit line is assigned to this member.",
"Use the approved procurement credit line."
] select (_creditLine > 0)]
]
];
createHashMapFromArray [
["session", createHashMapFromArray [
["actorName", name player],
["actorUid", _playerUid],
["approval", "Field Access"],
["orgId", _orgId],
["orgName", _orgName],
["orgLeader", _isOrgLeader],
["defaultOrgCeo", _isDefaultOrgCeo],
["canUseOrgFunds", _canUseOrgFunds]
]],
["storeConfig", createHashMapFromArray [
["budget", _budget],
["creditLine", _creditLine],
["availability", _storeState getOrDefault ["availability", "In-Stock"]],
["moduleState", _storeState getOrDefault ["moduleState", "Preview"]],
["paymentSources", _paymentSources],
["defaultPaymentSource", "cash"]
]],
["cartItems", []]
]