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

Arsenal - Improve base backpack checking #10479

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions addons/arsenal/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ PREP(attributeLoad);
PREP(attributeMode);
PREP(attributeSelect);
PREP(baseAttachment);
PREP(baseBackpack);
PREP(baseOptic);
PREP(baseWeapon);
PREP(buttonActionsPage);
Expand Down
3 changes: 2 additions & 1 deletion addons/arsenal/XEH_preStart.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

#include "XEH_PREP.hpp"

// Cache for FUNC(baseWeapon)
// Caches for FUNC(baseX)
uiNamespace setVariable [QGVAR(baseWeaponNameCache), createHashMap];
uiNamespace setVariable [QGVAR(baseBackpackCache), createHashMap];

// Caches for names, pictures, mod icons
uiNamespace setVariable [QGVAR(addListBoxItemCache), createHashMap];
Expand Down
52 changes: 52 additions & 0 deletions addons/arsenal/functions/fnc_baseBackpack.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "..\script_component.hpp"
/*
* Author: LinkIsGrim
* Returns base backpack for a preset (loaded/AI) backpack variant
* Basically CBA_fnc_getNonPresetClass with model checking, as some backpacks don't have variants with no cargo (#10346)
*
* Arguments:
* 0: Backpack classname <STRING>
*
* Return Value:
* Most viable base backpack class, "" if not a backpack <STRING>
*
* Example:
* "B_Kitbag_rgr_Exp" call ace_arsenal_fnc_baseBackpack
*
* Public: Yes
*/

params [["_item", "", [""]]];

TRACE_1("looking up base backpack",_item);

(uiNamespace getVariable QGVAR(baseBackpackCache)) getOrDefaultCall [toLowerANSI _item, {
private _config = configFile >> "CfgVehicles" >> _item;
// TODO: handle file extension differences (implicit vs explicit .p3d)
// model could have missing file extension in a variant and present in parent, but that's stupid, bad config.
// It'll be inherited and match 99% of the time. Good enough until it burns, see texture checking below.
private _model = getText (_config >> "model");

// Texture checking is a can of worms: we'd have to create a hashmap nConfigs + 1 times and see if they match...
// ...and it wouldn't handle small things like custom patches or name tags
// If this ever comes up (it likely will), we'll burn that bridge when we get to it.
// private _textures = getArray (_config >> "hiddenSelectionsTextures");

while {
(isClass _config) &&
{getNumber (_config >> "scope") > 0} && // Some preset backpacks are scope = 1
{getText (_config >> "model") == _model}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably just need to move this around

// && {getArray (_config >> "hiddenSelectionsTextures") isEqualTo _textures}
} do {
if (
(count (_config >> "TransportItems") == 0) &&
{count (_config >> "TransportMagazines") == 0} &&
{count (_config >> "TransportWeapons") == 0}
) then {
break;
};
_config = inheritsFrom _config;
};

configName _config // return, will be "" if not a backpack
}, true]
4 changes: 2 additions & 2 deletions addons/arsenal/functions/fnc_replaceUniqueItemsLoadout.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private _cfgVehicles = configFile >> "CfgVehicles";
if (_containerClass != "") then {
if (_forEachIndex == IDX_LOADOUT_BACKPACK) then {
// Check for non-preset first
_uniqueBaseCfgText = [_containerClass, "CfgVehicles"] call CBA_fnc_getNonPresetClass;
_uniqueBaseCfgText = _containerClass call FUNC(baseBackpack);

if (_uniqueBaseCfgText != "") then {
_containerClass = _uniqueBaseCfgText;
Expand Down Expand Up @@ -102,7 +102,7 @@ private _cfgVehicles = configFile >> "CfgVehicles";
if (_containerClass != "") then {
if (_isBackpack) then {
// Check for non-preset first
_uniqueBaseCfgText = [_containerClass, "CfgVehicles"] call CBA_fnc_getNonPresetClass;
_uniqueBaseCfgText = _containerClass call FUNC(baseBackpack);

if (_uniqueBaseCfgText != "") then {
_containerClass = _uniqueBaseCfgText;
Expand Down
2 changes: 1 addition & 1 deletion addons/arsenal/functions/fnc_updateCurrentItemsList.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private _indexCurrentItems = -1;
case IDX_LOADOUT_BACKPACK: {
_x params [["_backpack", ""], ["_items", []]];
if (_backpack != "") then {
_backpack = [_backpack, "CfgVehicles"] call CBA_fnc_getNonPresetClass;
_backpack = _backpack call FUNC(baseBackpack);
};
GVAR(currentItems) set [IDX_CURR_BACKPACK, _backpack];
GVAR(currentItems) set [IDX_CURR_BACKPACK_ITEMS, _items];
Expand Down
2 changes: 1 addition & 1 deletion addons/arsenal/functions/fnc_updateUniqueItemsList.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private _fnc_uniqueEquipment = {

// Handle preset (loaded/AI) backpacks
if (_containerClass != "" && _forEachIndex == IDX_LOADOUT_BACKPACK) then {
_containerClass = [_containerClass, "CfgVehicles"] call CBA_fnc_getNonPresetClass;
_containerClass = _containerClass call FUNC(baseBackpack);
};

// Remove all unique equipment in tab; Add container as a unique equipment
Expand Down
2 changes: 1 addition & 1 deletion addons/arsenal/functions/fnc_verifyLoadout.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private _fnc_filterLoadout = {
_name = _name call FUNC(baseWeapon);
if NOT_IN_ARSENAL then {
// This could be a backpack
private _temp = [_name, "CfgVehicles"] call CBA_fnc_getNonPresetClass;
private _temp = _name call FUNC(baseBackpack);
if (_temp == "") then { // It's not
_unavailableItemsList pushBack _name;
_name = "";
Expand Down