From 21fd4e5d16d81180718d81be22313632d44b9f63 Mon Sep 17 00:00:00 2001 From: Dedmen Miller Date: Sun, 17 Feb 2019 18:41:48 +0100 Subject: [PATCH] Inventory - Cache inventory postInit config lookups (#6803) * Cache inventory postInit config lookups * Safety * fix * More better * ugh * add parenthesii (not trolling) these are actually needed ``` Error in expression <_inventory_Grenades_ItemList", []]; if (!ace_inventory_Grenades_ItemList isEqual> Error position: Error !: Type Array, expected Bool ``` * Add space --- addons/inventory/XEH_postInit.sqf | 63 ++++++------------------------- addons/inventory/XEH_preStart.sqf | 54 ++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 51 deletions(-) diff --git a/addons/inventory/XEH_postInit.sqf b/addons/inventory/XEH_postInit.sqf index 7135383734..c5dc6c48f6 100644 --- a/addons/inventory/XEH_postInit.sqf +++ b/addons/inventory/XEH_postInit.sqf @@ -9,46 +9,23 @@ if (!hasInterface) exitWith {}; // luckily we don't need private items, so dummy and parent classes are out of the picture GVAR(ItemKeyNamespace) = [] call CBA_fnc_createNamespace; +private _allItems = uiNamespace getVariable [QGVAR(ItemKeyCache), []]; //See XEH_preStart.sqf -private _fnc_addToCache = { - private _displayName = getText (_this >> "displayName"); - private _picture = getText (_this >> "picture"); - - // list box seems to delete the leading backslash - if (_picture select [0,1] == "\") then { - _picture = _picture select [1]; +// isEqualType is hacking protection as we cannot trust that the cache hasn't been manipulated +{ + if (_x isEqualType [] && {_x isEqualTypeArray ["", configNull]}) then { + GVAR(ItemKeyNamespace) setVariable _x; }; - - GVAR(ItemKeyNamespace) setVariable [format ["%1:%2", _displayName, _picture], _this]; -}; - -private _allItems = []; - -_allItems append ("getNumber (_x >> 'scope') > 0" configClasses (configFile >> "CfgWeapons")); -_allItems append ("getNumber (_x >> 'scope') > 0" configClasses (configFile >> "CfgGlasses")); -_allItems append ("getNumber (_x >> 'scope') == 2" configClasses (configFile >> "CfgMagazines")); -_allItems append ("getNumber (_x >> 'scope') > 0 && {getNumber (_x >> 'isBackpack') == 1}" configClasses (configFile >> "CfgVehicles")); - -{_x call _fnc_addToCache; false} count _allItems; +} forEach ([[], _allItems] select (_allItems isEqualType [])); GVAR(customFilters) = []; GVAR(selectedFilterIndex) = -1; // add custom filters -// generate list of grenades -GVAR(Grenades_ItemList) = []; - -{ - GVAR(Grenades_ItemList) append getArray (configFile >> "CfgWeapons" >> "Throw" >> _x >> "magazines"); - false -} count getArray (configFile >> "CfgWeapons" >> "Throw" >> "muzzles"); - -// make list case insensitive -GVAR(Grenades_ItemList) = GVAR(Grenades_ItemList) apply {toLower _x}; - -// filter duplicates -GVAR(Grenades_ItemList) = GVAR(Grenades_ItemList) arrayIntersect GVAR(Grenades_ItemList); +// get list of grenades +GVAR(Grenades_ItemList) = uiNamespace getVariable [QGVAR(Grenades_ItemList), []]; +if (!(GVAR(Grenades_ItemList) isEqualType [])) then {GVAR(Grenades_ItemList) = []}; [localize LSTRING(Grenades), QFUNC(filterGrenades)] call FUNC(addCustomFilter); @@ -57,24 +34,8 @@ GVAR(Grenades_ItemList) = GVAR(Grenades_ItemList) arrayIntersect GVAR(Grenades_I [localize LSTRING(Vests), QFUNC(filterVests)] call FUNC(addCustomFilter); [localize LSTRING(Headgear), QFUNC(filterHeadgear)] call FUNC(addCustomFilter); -// generate list of medical items -GVAR(Medical_ItemList) = []; - -{ - GVAR(Medical_ItemList) append getArray (_x >> "items"); - false -} count ( - ("true" configClasses (configFile >> QEGVAR(Medical,Actions) >> "Basic")) + - ("true" configClasses (configFile >> QEGVAR(Medical,Actions) >> "Advanced")) -); - -// remove all numbers from list -GVAR(Medical_ItemList) = GVAR(Medical_ItemList) select {_x isEqualType ""}; - -// make list case insensitive -GVAR(Medical_ItemList) = GVAR(Medical_ItemList) apply {toLower _x}; - -// filter duplicates -GVAR(Medical_ItemList) = GVAR(Medical_ItemList) arrayIntersect GVAR(Medical_ItemList); +// get list of medical items +GVAR(Medical_ItemList) = uiNamespace getVariable [QGVAR(Medical_ItemList), []]; +if (!(GVAR(Medical_ItemList) isEqualType [])) then {GVAR(Medical_ItemList) = []}; [localize LSTRING(Medical), QFUNC(filterMedical)] call FUNC(addCustomFilter); diff --git a/addons/inventory/XEH_preStart.sqf b/addons/inventory/XEH_preStart.sqf index 022888575e..ae4ce6500c 100644 --- a/addons/inventory/XEH_preStart.sqf +++ b/addons/inventory/XEH_preStart.sqf @@ -1,3 +1,57 @@ #include "script_component.hpp" #include "XEH_PREP.hpp" + +//item cache, see XEH_postInit.sqf +private _allItems = ("getNumber (_x >> 'scope') > 0" configClasses (configFile >> "CfgWeapons")); +_allItems append ("getNumber (_x >> 'scope') > 0" configClasses (configFile >> "CfgGlasses")); +_allItems append ("getNumber (_x >> 'scope') == 2" configClasses (configFile >> "CfgMagazines")); +_allItems append ("getNumber (_x >> 'scope') > 0 && {getNumber (_x >> 'isBackpack') == 1}" configClasses (configFile >> "CfgVehicles")); + +uiNamespace setVariable [QGVAR(ItemKeyCache), _allItems apply { + private _displayName = getText (_x >> "displayName"); + private _picture = getText (_x >> "picture"); + + // list box seems to delete the leading backslash + if (_picture select [0,1] == "\") then { + _picture = _picture select [1]; + }; + + [format ["%1:%2", _displayName, _picture], _x]; +}]; + +// generate list of grenades +private _grenades_ItemList = []; + +{ + _grenades_ItemList append getArray (configFile >> "CfgWeapons" >> "Throw" >> _x >> "magazines"); +} forEach getArray (configFile >> "CfgWeapons" >> "Throw" >> "muzzles"); + +// make list case insensitive +_grenades_ItemList = _grenades_ItemList apply {toLower _x}; + +// filter duplicates +_grenades_ItemList = _grenades_ItemList arrayIntersect _grenades_ItemList; + +uiNamespace setVariable [QGVAR(Grenades_ItemList), _grenades_ItemList]; + +// generate list of medical items +private _medical_ItemList = []; + +{ + _medical_ItemList append getArray (_x >> "items"); +} forEach ( + ("true" configClasses (configFile >> QEGVAR(Medical,Actions) >> "Basic")) + + ("true" configClasses (configFile >> QEGVAR(Medical,Actions) >> "Advanced")) +); + +// remove all numbers from list +_medical_ItemList = _medical_ItemList select {_x isEqualType ""}; + +// make list case insensitive +_medical_ItemList = _medical_ItemList apply {toLower _x}; + +// filter duplicates +_medical_ItemList = _medical_ItemList arrayIntersect _medical_ItemList; + +uiNamespace setVariable [QGVAR(Medical_ItemList), _medical_ItemList];