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: <!ace_inventory_Grenades_ItemList isEqual>
  Error !: Type Array, expected Bool
```

* Add space
This commit is contained in:
Dedmen Miller 2019-02-17 18:41:48 +01:00 committed by PabstMirror
parent 7cce148513
commit 21fd4e5d16
2 changed files with 66 additions and 51 deletions

View File

@ -9,46 +9,23 @@ if (!hasInterface) exitWith {};
// luckily we don't need private items, so dummy and parent classes are out of the picture // luckily we don't need private items, so dummy and parent classes are out of the picture
GVAR(ItemKeyNamespace) = [] call CBA_fnc_createNamespace; GVAR(ItemKeyNamespace) = [] call CBA_fnc_createNamespace;
private _allItems = uiNamespace getVariable [QGVAR(ItemKeyCache), []]; //See XEH_preStart.sqf
private _fnc_addToCache = { // isEqualType is hacking protection as we cannot trust that the cache hasn't been manipulated
private _displayName = getText (_this >> "displayName"); {
private _picture = getText (_this >> "picture"); if (_x isEqualType [] && {_x isEqualTypeArray ["", configNull]}) then {
GVAR(ItemKeyNamespace) setVariable _x;
// list box seems to delete the leading backslash
if (_picture select [0,1] == "\") then {
_picture = _picture select [1];
}; };
} forEach ([[], _allItems] select (_allItems isEqualType []));
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;
GVAR(customFilters) = []; GVAR(customFilters) = [];
GVAR(selectedFilterIndex) = -1; GVAR(selectedFilterIndex) = -1;
// add custom filters // add custom filters
// generate list of grenades // get list of grenades
GVAR(Grenades_ItemList) = []; GVAR(Grenades_ItemList) = uiNamespace getVariable [QGVAR(Grenades_ItemList), []];
if (!(GVAR(Grenades_ItemList) isEqualType [])) then {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);
[localize LSTRING(Grenades), QFUNC(filterGrenades)] call FUNC(addCustomFilter); [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(Vests), QFUNC(filterVests)] call FUNC(addCustomFilter);
[localize LSTRING(Headgear), QFUNC(filterHeadgear)] call FUNC(addCustomFilter); [localize LSTRING(Headgear), QFUNC(filterHeadgear)] call FUNC(addCustomFilter);
// generate list of medical items // get list of medical items
GVAR(Medical_ItemList) = []; GVAR(Medical_ItemList) = uiNamespace getVariable [QGVAR(Medical_ItemList), []];
if (!(GVAR(Medical_ItemList) isEqualType [])) then {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);
[localize LSTRING(Medical), QFUNC(filterMedical)] call FUNC(addCustomFilter); [localize LSTRING(Medical), QFUNC(filterMedical)] call FUNC(addCustomFilter);

View File

@ -1,3 +1,57 @@
#include "script_component.hpp" #include "script_component.hpp"
#include "XEH_PREP.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];