From 1e1d1d63f2346399b96131c993ed23e2ccc46006 Mon Sep 17 00:00:00 2001 From: Grim <69561145+LinkIsGrim@users.noreply.github.com> Date: Sun, 11 Feb 2024 20:25:12 -0300 Subject: [PATCH] Arsenal - Add `ace_arsenal_loadoutVerified` event (#9792) Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com> --- .../arsenal/functions/fnc_verifyLoadout.sqf | 5 +++- addons/gunbag/XEH_preInit.sqf | 27 ++++++++++++++----- docs/wiki/framework/arsenal-framework.md | 1 + 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/addons/arsenal/functions/fnc_verifyLoadout.sqf b/addons/arsenal/functions/fnc_verifyLoadout.sqf index 697f65af58..03c5898579 100644 --- a/addons/arsenal/functions/fnc_verifyLoadout.sqf +++ b/addons/arsenal/functions/fnc_verifyLoadout.sqf @@ -19,7 +19,7 @@ private _extendedInfo = createHashMap; // Check if the provided loadout is a CBA extended loadout if (count _loadout == 2) then { - _extendedInfo = _loadout select 1; + _extendedInfo = +(_loadout select 1); // Copy the hashmap to prevent events from modifiyng the profileNamespace extendedInfo _loadout = _loadout select 0; }; @@ -70,4 +70,7 @@ private _fnc_filterLoadout = { // Loadout might come from a different modpack, which might have different config naming _loadout = _loadout call _fnc_filterLoadout; +// Raise event for 3rd party: mostly for handling extended info +[QGVAR(loadoutVerified), [_loadout, _extendedInfo]] call CBA_fnc_localEvent; + [[_loadout, _extendedInfo], _nullItemsList arrayIntersect _nullItemsList, _unavailableItemsList arrayIntersect _unavailableItemsList] diff --git a/addons/gunbag/XEH_preInit.sqf b/addons/gunbag/XEH_preInit.sqf index 2bb35513a2..f7a3cb23a6 100644 --- a/addons/gunbag/XEH_preInit.sqf +++ b/addons/gunbag/XEH_preInit.sqf @@ -26,17 +26,30 @@ PREP_RECOMPILE_END; }, _this] call CBA_fnc_execNextFrame; }] call CBA_fnc_addClassEventHandler; +[QEGVAR(arsenal,loadoutVerified), { + params ["_loadout", "_extendedInfo"]; + private _gunbagInfo = _extendedInfo getOrDefault [QGVAR(gunbagWeapon), []]; + if (_gunbagInfo isEqualTo []) exitWith {}; + + private _weapon = (_gunbagInfo select 0) call EFUNC(arsenal,baseWeapon); + if !(_weapon in EGVAR(arsenal,virtualItemsFlat)) exitWith { + INFO_1("removing [%1] from loadout",_gunbagInfo); + _extendedInfo deleteAt QGVAR(gunbagWeapon); + }; + { + private _class = _x param [0, ""]; + private _defaultValue = ["", []] select {_x isEqualType []}; + if (_class != "" && {!(_class in EGVAR(arsenal,virtualItemsFlat))}) then { + INFO_1("removing [%1] from loadout",_x); + _gunbagInfo set [_forEachIndex + 1, _defaultValue]; + }; + } forEach (_gunbagInfo select [1]); // weapon was verified above +}] call CBA_fnc_addEventHandler; + ["CBA_loadoutSet", { params ["_unit", "_loadout", "_extendedInfo"]; private _gunbagWeapon = _extendedInfo getOrDefault [QGVAR(gunbagWeapon), []]; if (_gunbagWeapon isNotEqualTo []) then { - if (!isNil QEGVAR(arsenal,virtualItemsFlatAll)) then { - private _weapon = (_gunbagWeapon select 0) call EFUNC(arsenal,baseWeapon); - if !(_weapon in EGVAR(arsenal,virtualItemsFlatAll)) then { - INFO_1("removing [%1] from loadout",_gunbagWeapon); - _gunbagWeapon = []; - }; - }; (backpackContainer _unit) setVariable [QGVAR(gunbagWeapon), _gunbagWeapon, true]; }; }] call CBA_fnc_addEventHandler; diff --git a/docs/wiki/framework/arsenal-framework.md b/docs/wiki/framework/arsenal-framework.md index 4baddf66ad..a586d779e2 100644 --- a/docs/wiki/framework/arsenal-framework.md +++ b/docs/wiki/framework/arsenal-framework.md @@ -511,6 +511,7 @@ All are local. | ace_arsenal_loadoutsDisplayClosed | None | 3.12.3 | | ace_arsenal_loadoutsTabChanged | loadouts screen display (DISPLAY), tab control (CONTROL) | 3.12.3 | | ace_arsenal_loadoutsListFilled | loadouts screen display (DISPLAY), tab control (CONTROL) | 3.12.3 | +| ace_arsenal_loadoutVerified | loadout data (ARRAY), loadout CBA extended data (HASHMAP) | 3.17.0 | | ace_arsenal_weaponItemChanged | weapon classname (STRING), item classname (STRING), item index (NUMBER, 0-5: muzzle, side, optic, bipod, magazine, underbarrel) | 3.16.0 | ## 9. Custom sub item categories