From dd5cf9b7df88e491d3d40b30965dc3b72da2bdc3 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Fri, 16 Sep 2022 15:45:10 +0200 Subject: [PATCH 1/9] Updated CBA_fnc_compatibleItems --- addons/jr/fnc_compatibleItems.sqf | 56 +++++++++---------------------- addons/main/script_mod.hpp | 2 +- 2 files changed, 17 insertions(+), 41 deletions(-) diff --git a/addons/jr/fnc_compatibleItems.sqf b/addons/jr/fnc_compatibleItems.sqf index c1c3ac47a3..bb8a560e46 100644 --- a/addons/jr/fnc_compatibleItems.sqf +++ b/addons/jr/fnc_compatibleItems.sqf @@ -19,7 +19,7 @@ Examples: (end) Author: - Original by Karel Moricky, Enhanced by Robalo, jokoho, commy2 + Original by Karel Moricky, Enhanced by Robalo, jokoho, commy2, johnb43 ---------------------------------------------------------------------------- */ SCRIPT(compatibleItems); @@ -27,51 +27,27 @@ params [["_weapon", "", [""]], ["_typefilter", nil, ["", 0]]]; if (_weapon == "") exitWith {[]}; -if (isNil QGVAR(namespace)) then { - GVAR(namespace) = call CBA_fnc_createNamespace; +if (isNil "_typefilter") exitWith { + compatibleItems _weapon }; -private _compatibleItems = GVAR(namespace) getVariable _weapon; +if (_typefilter isEqualType "") then { + _typefilter = [-1, 101, 201, 301, 302] param [["", "muzzle", "optic", "pointer", "bipod"] findIf {_x == _typefilter}, -1]; +}; -if (isNil "_compatibleItems") then { - _compatibleItems = []; - private _cfgWeapons = configFile >> "CfgWeapons"; - private _weaponConfig = _cfgWeapons >> _weapon; +if (_typefilter == -1) exitWith {[]}; - if (isClass _weaponConfig) then { - { - private _cfgCompatibleItems = _x >> "compatibleItems"; +if (isNil QGVAR(namespace)) then { + GVAR(namespace) = createHashMap; +}; - if (isArray _cfgCompatibleItems) then { - { - _compatibleItems pushBackUnique _x; - } forEach getArray _cfgCompatibleItems; - } else { - if (isClass _cfgCompatibleItems) then { - { - if (getNumber _x > 0) then { - _compatibleItems pushBackUnique configName _x; - }; - } forEach configProperties [_cfgCompatibleItems, "isNumber _x"]; - }; - }; - } forEach configProperties [_weaponConfig >> "WeaponSlotsInfo", "isClass _x"]; +_compatibleItems = GVAR(namespace) get (_weapon + "___" + str _typeFilter); - // Ensure item class names are in config case - _compatibleItems = _compatibleItems apply {configName (_cfgWeapons >> _x)}; +if (isNil "_compatibleItems") then { + private _cfgWeapons = configFile >> "CfgWeapons"; + _compatibleItems = (compatibleItems _weapon) select {_typefilter == getNumber (_cfgWeapons >> _x >> "itemInfo" >> "type")}; - GVAR(namespace) setVariable [_weapon, _compatibleItems]; // save entry in cache - } else { - ["'%1' not found in CfgWeapons", _weapon] call BIS_fnc_error; - }; + GVAR(namespace) set [_weapon + "___" + str _typeFilter, _compatibleItems]; }; -if (isNil "_typefilter") then { //return - + _compatibleItems -} else { - if (_typefilter isEqualType "") then { - _typefilter = [-1, 101, 201, 301, 302] param [["", "muzzle", "optic", "pointer", "bipod"] find _typefilter, -1]; - }; - - _compatibleItems select {_typefilter == getNumber (configFile >> "CfgWeapons" >> _x >> "itemInfo" >> "type")} -}; +_compatibleItems diff --git a/addons/main/script_mod.hpp b/addons/main/script_mod.hpp index f762ad855c..00c1466123 100644 --- a/addons/main/script_mod.hpp +++ b/addons/main/script_mod.hpp @@ -10,7 +10,7 @@ #define VERSION_AR MAJOR,MINOR,PATCHLVL,BUILD // MINIMAL required version for the Mod. Components can specify others.. -#define REQUIRED_VERSION 2.06 +#define REQUIRED_VERSION 2.10 /* // Defined DEBUG_MODE_NORMAL in a few CBA_fncs to prevent looped logging :) From b3d945cdffbbde9e6655c10a425d63471781bfe3 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Fri, 16 Sep 2022 15:53:43 +0200 Subject: [PATCH 2/9] Update fnc_compatibleItems.sqf --- addons/jr/fnc_compatibleItems.sqf | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/jr/fnc_compatibleItems.sqf b/addons/jr/fnc_compatibleItems.sqf index bb8a560e46..231b81bde3 100644 --- a/addons/jr/fnc_compatibleItems.sqf +++ b/addons/jr/fnc_compatibleItems.sqf @@ -41,13 +41,14 @@ if (isNil QGVAR(namespace)) then { GVAR(namespace) = createHashMap; }; -_compatibleItems = GVAR(namespace) get (_weapon + "___" + str _typeFilter); +private _cacheKey = format ["%1#%2", _weapon, _typeFilter]; +_compatibleItems = GVAR(namespace) get _cacheKey; if (isNil "_compatibleItems") then { private _cfgWeapons = configFile >> "CfgWeapons"; _compatibleItems = (compatibleItems _weapon) select {_typefilter == getNumber (_cfgWeapons >> _x >> "itemInfo" >> "type")}; - GVAR(namespace) set [_weapon + "___" + str _typeFilter, _compatibleItems]; + GVAR(namespace) set [_cacheKey, _compatibleItems]; }; _compatibleItems From e703926311740fb893d8b281d4edae82cb509bbd Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Sat, 8 Oct 2022 11:34:29 +0200 Subject: [PATCH 3/9] Addressed several issues --- addons/jr/fnc_compatibleItems.sqf | 68 +++++++++++++++++++++++++------ addons/main/script_mod.hpp | 2 +- 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/addons/jr/fnc_compatibleItems.sqf b/addons/jr/fnc_compatibleItems.sqf index 231b81bde3..0ecc90a327 100644 --- a/addons/jr/fnc_compatibleItems.sqf +++ b/addons/jr/fnc_compatibleItems.sqf @@ -19,7 +19,7 @@ Examples: (end) Author: - Original by Karel Moricky, Enhanced by Robalo, jokoho, commy2, johnb43 + Original by Karel Moricky, Enhanced by Robalo, jokoho, commy2 ---------------------------------------------------------------------------- */ SCRIPT(compatibleItems); @@ -27,28 +27,70 @@ params [["_weapon", "", [""]], ["_typefilter", nil, ["", 0]]]; if (_weapon == "") exitWith {[]}; -if (isNil "_typefilter") exitWith { - compatibleItems _weapon +private _cfgWeapons = configFile >> "CfgWeapons"; +private _weaponConfig = _cfgWeapons >> _weapon; + +// Check if weapon exists +if !(isClass _weaponConfig) exitWith { + ["'%1' not found in CfgWeapons", _weapon] call BIS_fnc_error; + + [] }; +// Convert filter into number (if string) if (_typefilter isEqualType "") then { - _typefilter = [-1, 101, 201, 301, 302] param [["", "muzzle", "optic", "pointer", "bipod"] findIf {_x == _typefilter}, -1]; + _typefilter = [-1, 101, 201, 301, 302] param [["", "muzzle", "optic", "pointer", "bipod"] find _typefilter, -1]; }; -if (_typefilter == -1) exitWith {[]}; +private _typeFilterExists = !isNil "_typefilter"; + +// Check if valid type filter +if (_typeFilterExists && {!(_typefilter in [101, 201, 301, 302])}) exitWith {[]}; if (isNil QGVAR(namespace)) then { - GVAR(namespace) = createHashMap; + GVAR(namespace) = createHashMap; +}; + +// Get cached result, if it exists +private _cachekey = format ["%1#%2", _weapon, ["all", _typefilter] select _typeFilterExists]; +private _compatibleItems = GVAR(namespace) get _cachekey; + +if (!isNil "_compatibleItems") exitWith { + +_compatibleItems }; -private _cacheKey = format ["%1#%2", _weapon, _typeFilter]; -_compatibleItems = GVAR(namespace) get _cacheKey; +if (_typeFilterExists) then { + // Get all compatible weapon attachments, then filter + _compatibleItems = _weapon call CBA_fnc_compatibleItems; + _compatibleItems = _compatibleItems select {_typefilter == getNumber (_cfgWeapons >> _x >> "itemInfo" >> "type")}; +} else { + _compatibleItems = []; -if (isNil "_compatibleItems") then { - private _cfgWeapons = configFile >> "CfgWeapons"; - _compatibleItems = (compatibleItems _weapon) select {_typefilter == getNumber (_cfgWeapons >> _x >> "itemInfo" >> "type")}; + { + private _cfgCompatibleItems = _x >> "compatibleItems"; - GVAR(namespace) set [_cacheKey, _compatibleItems]; + if (isArray _cfgCompatibleItems) then { + { + // Ensure item class name is in config case + _compatibleItems pushBackUnique configName (_cfgWeapons >> _x); + } forEach getArray _cfgCompatibleItems; + } else { + if (isClass _cfgCompatibleItems) then { + { + if (getNumber _x > 0) then { + // Ensure item class name is in config case + _compatibleItems pushBackUnique configName (_cfgWeapons >> configName _x); + }; + } forEach configProperties [_cfgCompatibleItems, "isNumber _x"]; + }; + }; + } forEach configProperties [_weaponConfig >> "WeaponSlotsInfo", "isClass _x"]; + + // Remove non-existent item(s) + _compatibleItems deleteAt (_compatibleItems find ""); }; -_compatibleItems +// Cache result +GVAR(namespace) set [_cachekey, _compatibleItems]; + ++_compatibleItems diff --git a/addons/main/script_mod.hpp b/addons/main/script_mod.hpp index 00c1466123..f762ad855c 100644 --- a/addons/main/script_mod.hpp +++ b/addons/main/script_mod.hpp @@ -10,7 +10,7 @@ #define VERSION_AR MAJOR,MINOR,PATCHLVL,BUILD // MINIMAL required version for the Mod. Components can specify others.. -#define REQUIRED_VERSION 2.10 +#define REQUIRED_VERSION 2.06 /* // Defined DEBUG_MODE_NORMAL in a few CBA_fncs to prevent looped logging :) From e35831cae8fedbf8d00755e688e7945d22a7dff3 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Mon, 10 Jul 2023 22:09:31 +0200 Subject: [PATCH 4/9] Update fnc_compatibleItems.sqf --- addons/jr/fnc_compatibleItems.sqf | 70 ++++++++++++++----------------- 1 file changed, 31 insertions(+), 39 deletions(-) diff --git a/addons/jr/fnc_compatibleItems.sqf b/addons/jr/fnc_compatibleItems.sqf index 0ecc90a327..04944020b3 100644 --- a/addons/jr/fnc_compatibleItems.sqf +++ b/addons/jr/fnc_compatibleItems.sqf @@ -51,46 +51,38 @@ if (isNil QGVAR(namespace)) then { GVAR(namespace) = createHashMap; }; -// Get cached result, if it exists -private _cachekey = format ["%1#%2", _weapon, ["all", _typefilter] select _typeFilterExists]; -private _compatibleItems = GVAR(namespace) get _cachekey; - -if (!isNil "_compatibleItems") exitWith { - +_compatibleItems -}; - -if (_typeFilterExists) then { - // Get all compatible weapon attachments, then filter - _compatibleItems = _weapon call CBA_fnc_compatibleItems; - _compatibleItems = _compatibleItems select {_typefilter == getNumber (_cfgWeapons >> _x >> "itemInfo" >> "type")}; -} else { - _compatibleItems = []; - - { - private _cfgCompatibleItems = _x >> "compatibleItems"; - - if (isArray _cfgCompatibleItems) then { - { - // Ensure item class name is in config case - _compatibleItems pushBackUnique configName (_cfgWeapons >> _x); - } forEach getArray _cfgCompatibleItems; - } else { - if (isClass _cfgCompatibleItems) then { +// Get cached result, if it exists, otherwise make it ++(GVAR(namespace) getOrDefaultCall [format ["%1#%2", _weapon, ["all", _typefilter] select _typeFilterExists], { + if (_typeFilterExists) then { + // Get all compatible weapon attachments, then filter + (_weapon call CBA_fnc_compatibleItems) select {_typefilter == getNumber (_cfgWeapons >> _x >> "itemInfo" >> "type")} + } else { + private _compatibleItems = createHashMap; + private _cfgCompatibleItems = configNull; + + { + _cfgCompatibleItems = _x >> "compatibleItems"; + + if (isArray _cfgCompatibleItems) then { { - if (getNumber _x > 0) then { - // Ensure item class name is in config case - _compatibleItems pushBackUnique configName (_cfgWeapons >> configName _x); - }; - } forEach configProperties [_cfgCompatibleItems, "isNumber _x"]; + // Ensure item class name is in config case + _compatibleItems set [configName (_cfgWeapons >> _x), nil]; + } forEach getArray _cfgCompatibleItems; + } else { + if (isClass _cfgCompatibleItems) then { + { + if (getNumber _x > 0) then { + // Ensure item class name is in config case + _compatibleItems set [configName (_cfgWeapons >> configName _x), nil]; + }; + } forEach configProperties [_cfgCompatibleItems, "isNumber _x"]; + }; }; - }; - } forEach configProperties [_weaponConfig >> "WeaponSlotsInfo", "isClass _x"]; - - // Remove non-existent item(s) - _compatibleItems deleteAt (_compatibleItems find ""); -}; + } forEach configProperties [_weaponConfig >> "WeaponSlotsInfo", "isClass _x"]; -// Cache result -GVAR(namespace) set [_cachekey, _compatibleItems]; + // Remove non-existent items + _compatibleItems deleteAt ""; -+_compatibleItems + keys _compatibleItems + }; +}, true]); From 8dd49233aeb5008d0727047ff7b17a6ce1773e62 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Mon, 10 Jul 2023 22:47:50 +0200 Subject: [PATCH 5/9] Added author --- addons/jr/fnc_compatibleItems.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/jr/fnc_compatibleItems.sqf b/addons/jr/fnc_compatibleItems.sqf index 04944020b3..53ab43ef3d 100644 --- a/addons/jr/fnc_compatibleItems.sqf +++ b/addons/jr/fnc_compatibleItems.sqf @@ -19,7 +19,7 @@ Examples: (end) Author: - Original by Karel Moricky, Enhanced by Robalo, jokoho, commy2 + Original by Karel Moricky, Enhanced by Robalo, jokoho, commy2, johnb43 ---------------------------------------------------------------------------- */ SCRIPT(compatibleItems); From 7151b966f1623b047598dc4f0962f31efdbf2b59 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Mon, 10 Jul 2023 22:51:36 +0200 Subject: [PATCH 6/9] Update fnc_compatibleItems.sqf --- addons/jr/fnc_compatibleItems.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/jr/fnc_compatibleItems.sqf b/addons/jr/fnc_compatibleItems.sqf index 53ab43ef3d..1f463275d1 100644 --- a/addons/jr/fnc_compatibleItems.sqf +++ b/addons/jr/fnc_compatibleItems.sqf @@ -85,4 +85,4 @@ if (isNil QGVAR(namespace)) then { keys _compatibleItems }; -}, true]); +}, true]) From 820424832ea870e12518fcf0461d7012274c060a Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Wed, 12 Jul 2023 17:19:09 +0200 Subject: [PATCH 7/9] Update fnc_execNextFrame.sqf --- addons/common/fnc_execNextFrame.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/common/fnc_execNextFrame.sqf b/addons/common/fnc_execNextFrame.sqf index c81cc92b9f..c9e53fda99 100644 --- a/addons/common/fnc_execNextFrame.sqf +++ b/addons/common/fnc_execNextFrame.sqf @@ -10,7 +10,7 @@ Parameters: _args - Parameters passed to the function executing. This will be the same array every execution. [optional] Returns: - Nothing + Nothing Useful Examples: (begin example) From 3ff5c07d9af0e63b17b6e2370fa479ae668a40df Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Wed, 12 Jul 2023 17:19:33 +0200 Subject: [PATCH 8/9] Revert "Update fnc_execNextFrame.sqf" This reverts commit 820424832ea870e12518fcf0461d7012274c060a. --- addons/common/fnc_execNextFrame.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/common/fnc_execNextFrame.sqf b/addons/common/fnc_execNextFrame.sqf index c9e53fda99..c81cc92b9f 100644 --- a/addons/common/fnc_execNextFrame.sqf +++ b/addons/common/fnc_execNextFrame.sqf @@ -10,7 +10,7 @@ Parameters: _args - Parameters passed to the function executing. This will be the same array every execution. [optional] Returns: - Nothing Useful + Nothing Examples: (begin example) From f00e681eaeffcdfc9171768bab8bb1d082a875cc Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Wed, 19 Jul 2023 18:11:10 +0200 Subject: [PATCH 9/9] Update fnc_compatibleItems.sqf --- addons/jr/fnc_compatibleItems.sqf | 70 +++++++++++++++++-------------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/addons/jr/fnc_compatibleItems.sqf b/addons/jr/fnc_compatibleItems.sqf index 1f463275d1..e618eefbde 100644 --- a/addons/jr/fnc_compatibleItems.sqf +++ b/addons/jr/fnc_compatibleItems.sqf @@ -51,38 +51,46 @@ if (isNil QGVAR(namespace)) then { GVAR(namespace) = createHashMap; }; -// Get cached result, if it exists, otherwise make it -+(GVAR(namespace) getOrDefaultCall [format ["%1#%2", _weapon, ["all", _typefilter] select _typeFilterExists], { - if (_typeFilterExists) then { - // Get all compatible weapon attachments, then filter - (_weapon call CBA_fnc_compatibleItems) select {_typefilter == getNumber (_cfgWeapons >> _x >> "itemInfo" >> "type")} - } else { - private _compatibleItems = createHashMap; - private _cfgCompatibleItems = configNull; - - { - _cfgCompatibleItems = _x >> "compatibleItems"; - - if (isArray _cfgCompatibleItems) then { +// Get cached result, if it exists +private _cachekey = format ["%1#%2", _weapon, ["all", _typefilter] select _typeFilterExists]; +private _compatibleItems = GVAR(namespace) get _cachekey; + +if (!isNil "_compatibleItems") exitWith { + +_compatibleItems +}; + +if (_typeFilterExists) then { + // Get all compatible weapon attachments, then filter + _compatibleItems = _weapon call CBA_fnc_compatibleItems; + _compatibleItems = _compatibleItems select {_typefilter == getNumber (_cfgWeapons >> _x >> "itemInfo" >> "type")}; +} else { + _compatibleItems = []; + + { + private _cfgCompatibleItems = _x >> "compatibleItems"; + + if (isArray _cfgCompatibleItems) then { + { + // Ensure item class name is in config case + _compatibleItems pushBackUnique configName (_cfgWeapons >> _x); + } forEach getArray _cfgCompatibleItems; + } else { + if (isClass _cfgCompatibleItems) then { { - // Ensure item class name is in config case - _compatibleItems set [configName (_cfgWeapons >> _x), nil]; - } forEach getArray _cfgCompatibleItems; - } else { - if (isClass _cfgCompatibleItems) then { - { - if (getNumber _x > 0) then { - // Ensure item class name is in config case - _compatibleItems set [configName (_cfgWeapons >> configName _x), nil]; - }; - } forEach configProperties [_cfgCompatibleItems, "isNumber _x"]; - }; + if (getNumber _x > 0) then { + // Ensure item class name is in config case + _compatibleItems pushBackUnique configName (_cfgWeapons >> configName _x); + }; + } forEach configProperties [_cfgCompatibleItems, "isNumber _x"]; }; - } forEach configProperties [_weaponConfig >> "WeaponSlotsInfo", "isClass _x"]; + }; + } forEach configProperties [_weaponConfig >> "WeaponSlotsInfo", "isClass _x"]; + + // Remove non-existent item(s) + _compatibleItems deleteAt (_compatibleItems find ""); +}; - // Remove non-existent items - _compatibleItems deleteAt ""; +// Cache result +GVAR(namespace) set [_cachekey, _compatibleItems]; - keys _compatibleItems - }; -}, true]) ++_compatibleItems