#include "..\script_component.hpp" /* * File: fnc_initUIBridge.sqf * Author: IDSolutions * Public: No * * Description: * Initializes the bank web UI bridge. */ #pragma hemtt ignore_variables ["_self"] private _webUIDeclarations = call EFUNC(common,initWebUIBridge); private _webUIBridgeDeclaration = _webUIDeclarations get "bridgeDeclaration"; GVAR(BankUIBridgeBaseClass) = compileFinal createHashMapFromArray [ ["#base", _webUIBridgeDeclaration], ["#type", "BankUIBridgeBaseClass"], ["#create", compileFinal { _self set ["mode", "bank"]; }], ["buildPayload", compileFinal { GVAR(BankSessionService) call ["buildPayload", [_self call ["getMode", []]]] }], ["getActiveBrowserControl", compileFinal { private _display = uiNamespace getVariable ["RscBank", displayNull]; if (isNull _display) exitWith { _self call ["setActiveBrowserControl", [controlNull]]; controlNull }; private _control = _display displayCtrl 1002; _self call ["setActiveBrowserControl", [_control]]; _control }], ["getMode", compileFinal { _self getOrDefault ["mode", "bank"] }], ["handleDepositEarningsRequest", compileFinal { params [["_data", createHashMap, [createHashMap]]]; private _amount = floor (_data getOrDefault ["amount", 0]); if (_amount <= 0) exitWith { _self call ["sendNotice", ["error", "No earnings are available to deposit."]]; }; [SRPC(bank,requestDepositEarnings), [getPlayerUID player, _amount]] call CFUNC(serverEvent); true }], ["handleDepositRequest", compileFinal { params [["_data", createHashMap, [createHashMap]]]; private _amount = floor (_data getOrDefault ["amount", 0]); if (_amount <= 0) exitWith { _self call ["sendNotice", ["error", "Enter a valid deposit amount."]]; }; [SRPC(bank,requestDeposit), [getPlayerUID player, _amount]] call CFUNC(serverEvent); true }], ["handleReady", compileFinal { params [["_control", controlNull, [controlNull]], ["_data", createHashMap, [createHashMap]]]; private _screen = _self call ["getScreen", []]; _screen call ["setControl", [_control]]; _screen call ["markReady", [true]]; _self call ["flushPendingEvents", []]; _self call ["sendEvent", ["bank::hydrate", _self call ["buildPayload", []], _control]]; }], ["handleTransferRequest", compileFinal { params [["_data", createHashMap, [createHashMap]]]; private _amount = floor (_data getOrDefault ["amount", 0]); private _target = _data getOrDefault ["target", ""]; private _from = toLowerANSI (_data getOrDefault ["from", "bank"]); if (_target isEqualTo "") exitWith { _self call ["sendNotice", ["error", "Select a transfer recipient."]]; }; if (_target isEqualTo getPlayerUID player) exitWith { _self call ["sendNotice", ["error", "You cannot transfer funds to yourself."]]; }; if (_amount <= 0) exitWith { _self call ["sendNotice", ["error", "Enter a valid transfer amount."]]; }; [SRPC(bank,requestTransfer), [getPlayerUID player, _target, _from, _amount]] call CFUNC(serverEvent); true }], ["handleWithdrawRequest", compileFinal { params [["_data", createHashMap, [createHashMap]]]; private _amount = floor (_data getOrDefault ["amount", 0]); if (_amount <= 0) exitWith { _self call ["sendNotice", ["error", "Enter a valid withdrawal amount."]]; }; [SRPC(bank,requestWithdraw), [getPlayerUID player, _amount]] call CFUNC(serverEvent); true }], ["refreshSession", compileFinal { private _control = _self call ["getActiveBrowserControl", []]; if (isNull _control) exitWith { false }; _self call ["sendEvent", ["bank::sync", _self call ["buildPayload", []], _control]] }], ["sendNotice", compileFinal { params [["_type", "error", [""]], ["_message", "", [""]], ["_control", controlNull, [controlNull]]]; if (_message isEqualTo "") exitWith { false }; _self call ["sendEvent", ["bank::notice", createHashMapFromArray [ ["message", _message], ["type", _type] ], _control]] }], ["setMode", compileFinal { params [["_mode", "bank", [""]]]; private _finalMode = toLowerANSI _mode; if !(_finalMode in ["bank", "atm"]) then { _finalMode = "bank"; }; _self set ["mode", _finalMode]; _finalMode }] ]; GVAR(BankUIBridge) = createHashMapObject [GVAR(BankUIBridgeBaseClass)]; GVAR(BankUIBridge)