Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inventory - Cache inventory postInit config lookups #6803

Merged
merged 7 commits into from
Feb 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 12 additions & 51 deletions addons/inventory/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 []));
dedmen marked this conversation as resolved.
Show resolved Hide resolved

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);

Expand All @@ -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);
54 changes: 54 additions & 0 deletions addons/inventory/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -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];