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 - Make ACE_asItem and ACE_isUnique apply to CfgWeapons #10366

Merged
merged 26 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
046ae24
Add isMiscItem function
DartRuffian Oct 6, 2024
910ea12
Swap condition order
DartRuffian Oct 6, 2024
2f73da7
Update argument
DartRuffian Oct 6, 2024
48bcb6d
Update addons/arsenal/functions/fnc_isMiscItem.sqf
DartRuffian Oct 14, 2024
4f96bf9
Use toString instead of QUOTE
DartRuffian Oct 14, 2024
6fc8a78
Merge remote-tracking branch 'origin/master' into pr/DartRuffian/10366
LinkIsGrim Oct 14, 2024
4725005
Update addons/arsenal/functions/fnc_scanConfig.sqf
LinkIsGrim Oct 14, 2024
bf3f977
Update addons/arsenal/functions/fnc_scanConfig.sqf
DartRuffian Oct 15, 2024
5f3abd3
Fix magazine misc items not appearing
DartRuffian Oct 15, 2024
5450a56
add caching
LinkIsGrim Oct 15, 2024
a3a0c23
add cache, move all misc items check to function
LinkIsGrim Oct 15, 2024
09a78c7
Merge remote-tracking branch 'origin/release' into pr/10366/cache
LinkIsGrim Oct 15, 2024
acee077
missed ;
LinkIsGrim Oct 15, 2024
c908cea
clean it up
LinkIsGrim Oct 15, 2024
81468a9
Merge branch 'pr/10366/cache', remote-tracking branch 'origin' into p…
LinkIsGrim Oct 15, 2024
2d96e28
drop debug
LinkIsGrim Oct 15, 2024
ebd1375
add comment on uiNamespace
LinkIsGrim Oct 15, 2024
3e9a4e5
don't flood the cache while preventing cache misses in mission
LinkIsGrim Oct 15, 2024
99730a2
derp'd
LinkIsGrim Oct 15, 2024
0c2084e
Sort Chemical Detectors as tools
DartRuffian Oct 18, 2024
2860b7f
Update addons/arsenal/functions/fnc_scanConfig.sqf
DartRuffian Oct 19, 2024
c2417f5
Update fnc_addRightPanelButton.sqf
LinkIsGrim Oct 20, 2024
ac04b92
rename inPreStart, change config getter
LinkIsGrim Oct 30, 2024
8d3ad45
Update addons/arsenal/functions/fnc_isMiscItem.sqf
LinkIsGrim Nov 2, 2024
25cf666
Merge branch 'master' into pr/10366
johnb432 Nov 2, 2024
ede07d7
do the thing
LinkIsGrim Nov 2, 2024
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
6 changes: 6 additions & 0 deletions addons/arsenal/CfgWeapons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ class CfgWeapons {
class ToolKit: ItemCore {
ACE_isTool = 1; // sort in Tools Tab
};

class ChemicalDetector_01_base_F: ItemCore {
ACE_asItem = 1;
ACE_isTool = 1; // sort in Tools Tab
};

class DetectorCore;
class MineDetector: DetectorCore {
ACE_isTool = 1; // sort in Tools Tab
Expand Down
1 change: 1 addition & 0 deletions addons/arsenal/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ PREP(handleSearchInputChanged);
PREP(handleSearchModeToggle);
PREP(handleStats);
PREP(initBox);
PREP(isMiscItem);
PREP(itemInfo);
PREP(loadoutsChangeTab);
PREP(message);
Expand Down
1 change: 1 addition & 0 deletions addons/arsenal/XEH_preStart.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ uiNamespace setVariable [QGVAR(baseWeaponNameCache), createHashMap];
uiNamespace setVariable [QGVAR(addListBoxItemCache), createHashMap];
uiNamespace setVariable [QGVAR(rightPanelCache), createHashMap];
uiNamespace setVariable [QGVAR(sortCache), createHashMap];
uiNamespace setVariable [QGVAR(isMiscItemCache), createHashMap];

call FUNC(scanConfig);
17 changes: 3 additions & 14 deletions addons/arsenal/functions/fnc_addRightPanelButton.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,9 @@ if (!isNil "_currentButtonInPosition") then {
};

// If spot found, add items and return position
private _cfgWeapons = configFile >> "CfgWeapons";
private _cfgMagazines = configFile >> "CfgMagazines";
private _configItemInfo = "";
// Sanitize to configCase and drop anything that's not a misc item
_items = _items apply {_x call EFUNC(common,getConfigName)} select {_x call FUNC(isMiscItem)};

_items = _items select {
_configItemInfo = _cfgWeapons >> _x >> "ItemInfo";

_x isKindOf ["CBA_MiscItem", _cfgWeapons] && {getNumber (_configItemInfo >> "type") in [TYPE_MUZZLE, TYPE_OPTICS, TYPE_FLASHLIGHT, TYPE_BIPOD]} ||
{getNumber (_configItemInfo >> "type") in [TYPE_FIRST_AID_KIT, TYPE_MEDIKIT, TYPE_TOOLKIT]} ||
{getText (_cfgWeapons >> _x >> "simulation") == "ItemMineDetector"} ||
{getNumber (_cfgMagazines >> _x >> "ACE_isUnique") == 1} ||
{getNumber (_cfgMagazines >> _x >> "ACE_asItem") == 1}
};

GVAR(customRightPanelButtons) set [_position, [_items apply {_x call EFUNC(common,getConfigName)}, _picture, _tooltip, _moveOnOverwrite]];
GVAR(customRightPanelButtons) set [_position, [_items, _picture, _tooltip, _moveOnOverwrite]];

_position
54 changes: 54 additions & 0 deletions addons/arsenal/functions/fnc_isMiscItem.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "..\script_component.hpp"
/*
* Author: DartRuffian, LinkIsGrim
* Determines if a class is a miscellaneous item or not.
*
* Arguments:
* 0: Item or magazine <STRING>
* 1: Item config <CONFIG> (default: nil)
* 2: Whether item is a magazine <BOOL> (default: false)
* 3: Skip setting false keys in the cache, mostly used for building it during preStart <BOOL> (default: false)
*
* Return Value:
* True if class is a misc item, otherwise false <BOOL>
*
* Example:
* "ACE_CableTie" call ace_arsenal_fnc_isMiscItem
*
* Public: No
*/

params ["_item", "_config", ["_isMag", false], ["_skipFalseKeys", false]];
TRACE_4("",_item,_config,_isMag,_skipFalseKeys);

private _cache = uiNamespace getVariable QGVAR(isMiscItemCache);
private _return = _cache get _item;

// Don't replace with getOrDefaultCall, we want the key to only be set if return is true or _skipFalseKeys is false
if (isNil "_return") then {
private _fnc_hasProperty = {getNumber (_config >> "ACE_asItem") == 1 || {getNumber (_config >> "ACE_isUnique") == 1}};

_return = switch (true) do {
case (_item isKindOf ["CBA_MiscItem", configFile >> "CfgWeapons"]): {true}; // CBA misc item, easy

if (isNil "_config") then {
_config = _item call CBA_fnc_getItemConfig;
};

case (_isMag): _fnc_hasProperty; // Magazine misc item, also easy

private _itemType = getNumber (_config >> "ItemInfo" >> "type");

case (_itemType in [TYPE_FIRST_AID_KIT, TYPE_MEDIKIT, TYPE_TOOLKIT]): {true}; // Special items: Med/Toolkits
case (_itemType in [TYPE_MUZZLE, TYPE_OPTICS, TYPE_FLASHLIGHT, TYPE_BIPOD]): _fnc_hasProperty; // "Forced" misc items
case ((getText (configFile >> "CfgWeapons" >> _item >> "simulation")) == "ItemMineDetector"): {true}; // Special items: mine detectors

default {false}
};

if (_return || !_skipFalseKeys) then {
_cache set [_item, _return];
};
};

_return
16 changes: 7 additions & 9 deletions addons/arsenal/functions/fnc_scanConfig.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private _isTool = false;
_configItemInfo = _x >> "ItemInfo";
_hasItemInfo = isClass (_configItemInfo);
_itemInfoType = if (_hasItemInfo) then {getNumber (_configItemInfo >> "type")} else {0};
_isMiscItem = _className isKindOf ["CBA_MiscItem", _cfgWeapons];
_isMiscItem = [_className, _x, false, true] call FUNC(isMiscItem);
_isTool = getNumber (_x >> "ACE_isTool") isEqualTo 1;

switch (true) do {
Expand Down Expand Up @@ -127,13 +127,7 @@ private _isTool = false;
};
};
// Misc. items
case (
_hasItemInfo &&
{_isMiscItem &&
{_itemInfoType in [TYPE_OPTICS, TYPE_FLASHLIGHT, TYPE_MUZZLE, TYPE_BIPOD]}} ||
{_itemInfoType in [TYPE_FIRST_AID_KIT, TYPE_MEDIKIT, TYPE_TOOLKIT]} ||
{_simulationType == "ItemMineDetector"}
): {
case (_hasItemInfo && _isMiscItem): {
(_configItems get IDX_VIRT_MISC_ITEMS) set [_className, nil];
if (_isTool) then {_toolList set [_className, nil]};
};
Expand All @@ -160,7 +154,11 @@ private _magazineMiscItems = createHashMap;

{
_magazineMiscItems set [configName _x, nil];
} forEach ((toString {getNumber (_x >> "ACE_isUnique") == 1 || getNumber (_x >> "ACE_asItem") == 1}) configClasses _cfgMagazines);
} forEach ((toString {
with uiNamespace do { // configClasses runs in missionNamespace even if we're in preStart apparently
[configName _x, _x, true, true] call FUNC(isMiscItem);
};
}) configClasses _cfgMagazines);

// Remove invalid/non-existent entries
_grenadeList deleteAt "";
Expand Down
9 changes: 2 additions & 7 deletions addons/arsenal/functions/fnc_updateUniqueItemsList.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private _attachments = GVAR(virtualItems) get IDX_VIRT_ATTACHMENTS;
_configItemInfo = _config >> "ItemInfo";
_hasItemInfo = isClass (_configItemInfo);
_itemInfoType = if (_hasItemInfo) then {getNumber (_configItemInfo >> "type")} else {0};
_isMiscItem = _x isKindOf ["CBA_MiscItem", _cfgWeapons];
_isMiscItem = _x call FUNC(isMiscItem);

_baseWeapon = if (!_isMiscItem) then {
_x call FUNC(baseWeapon)
Expand Down Expand Up @@ -263,12 +263,7 @@ private _attachments = GVAR(virtualItems) get IDX_VIRT_ATTACHMENTS;
// Misc. items
case (
!(_x in (GVAR(virtualItems) get IDX_VIRT_MISC_ITEMS)) && // misc. items don't use 'baseWeapon'
{_x in (_configItems get IDX_VIRT_MISC_ITEMS) ||
{_hasItemInfo &&
{_isMiscItem &&
{_itemInfoType in [TYPE_OPTICS, TYPE_FLASHLIGHT, TYPE_MUZZLE, TYPE_BIPOD]}} ||
{_itemInfoType in [TYPE_FIRST_AID_KIT, TYPE_MEDIKIT, TYPE_TOOLKIT]} ||
{_simulationType == "ItemMineDetector"}}}
{_x in (_configItems get IDX_VIRT_MISC_ITEMS) || {_hasItemInfo && _isMiscItem}}
): {
(GVAR(virtualItems) get IDX_VIRT_UNIQUE_MISC_ITEMS) set [_x, nil];
};
Expand Down
4 changes: 2 additions & 2 deletions docs/wiki/framework/arsenal-framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ Examples:
ACE Arsenal uses 2 existing config entries to sort and display items.

- `baseWeapon`: Class name that is used to display an item in the arsenal, used for weapon/attachment variants that are not normally shown to the player (AI variants, PIP optics, and so on). This property can be applied to any weapon or weapon attachment in `CfgWeapons`. Items using CBA or RHS' Scripted Optics systems, or CBA Switchable Attachments do not need this property explictly set, and will automatically use their player-accessible class.
- `ACE_isUnique`: Classes in `CfgMagazines` with this property set to `1` will be treated and shown by the Arsenal as Misc. Items. Used for items with attached data that needs to be kept track of, such as Notepads or Spare Barrels.
- `ACE_asItem`: Classes in `CfgMagazines` with this property set to `1` will be treated and shown by the Arsenal as Items. Used for magazines that are not meant to be used in a weapon, such as Painkillers.
- `ACE_isUnique`: Classes in `CfgWeapons` or `CfgMagazines` with this property set to `1` will be treated and shown by the Arsenal as Misc. Items. Used for items with attached data that needs to be kept track of, such as Notepads or Spare Barrels.
- `ACE_asItem`: Classes in `CfgWeapons` or `CfgMagazines` with this property set to `1` will be treated and shown by the Arsenal as Items. Used for magazines that are not meant to be used in a weapon, such as Painkillers.

### 3.2 New config entries

Expand Down