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

removeVirtualItems - Remove case sensitivity #8844

Closed
johnb432 opened this issue Mar 12, 2022 · 5 comments
Closed

removeVirtualItems - Remove case sensitivity #8844

johnb432 opened this issue Mar 12, 2022 · 5 comments
Labels
kind/enhancement Release Notes: **IMPROVED:**
Milestone

Comments

@johnb432
Copy link
Contributor

Is your enhancement related to a problem?
The ACE Arsenal doesn't return case sensitive naming for weapon attachments (which is another thing that could be remedied, but that's not the point of the issue).
If one wants to remove virtual items from the ACE Arsenal, they must give the case sensitive config name of the items to be removed.

E.g

[_this, ["optic_DMS"]] call ace_arsenal_fnc_removeVirtualItems does not work, whereas
[_this, ["optic_dms"]] call ace_arsenal_fnc_removeVirtualItems does.

This means the user has to look it up in the configs. Frankly it's not a big deal, but it would be nice if that could be avoided.

Solution you'd like:
I would like to see it case insensitive. It would be a quality of life improvement.

Proposed solution :

_items = _items select {_x isEqualType "" && {_x != ""}};

// Make sure all items are in string form
_items = _items select {_x isEqualType "" && {_x != ""}};

// Find the items that are to be removed using non-case sensitive means
private _item = "";

private _fnc_remove = {
    {
        _item = _x;
        _this deleteAt (_this findIf {_x == _item});
    } forEach _items;

    _this;
};

{
    if (_forEachIndex isEqualTo 0) then {
        _cargo set [_forEachIndex, [(_x select 0) call _fnc_remove, (_x select 1) call _fnc_remove, (_x select 2) call _fnc_remove]];
    } else {
        if (_forEachIndex isEqualTo 1) then {
            _cargo set [_forEachIndex, [(_x select 0) call _fnc_remove, (_x select 1) call _fnc_remove, (_x select 2) call _fnc_remove, (_x select 3) call _fnc_remove]];
        } else {
            _cargo set [_cargo find _x, _x call _fnc_remove];
        };
    };
} forEach _cargo;

This is what I have come up with as a working solution. However, it's noticeably slower for large arrays:
Testing with about 700 entries in the items parameter made the game freeze for an estimated time of 1-2s.

I'm hoping others can (help) implement this enhancement.

@johnb432 johnb432 added the kind/enhancement Release Notes: **IMPROVED:** label Mar 12, 2022
@rautamiekka
Copy link
Contributor

Since I can't test I'll have to speculate, but would it be faster, if less RAM-efficient, to return a copy that's been created by adding only the wanted stuff, instead of deleting from the original array ?

@commy2
Copy link
Contributor

commy2 commented Mar 13, 2022

Oof, this is terrible code.

Wouldn't it be enough to just lower case everything?

_items = _items apply {toLower _x};

in L56.

optic_DMS is the actual config case. If I were alganthe, I would've used that. Isn't that what is used here? In case you made a mistake, converting everything to config case is:

_items = _items apply {configName (_x call CBA_fnc_getItemConfig)};

@commy2
Copy link
Contributor

commy2 commented Mar 13, 2022

Should the case be random (I don't believe that), a much better way to write _fnc_remove is:

private _fnc_remove = {_this select {!(toLower _x in _items)}};

(which requires the first example I gave to sanitize _items).

Last resort would be inlining the filter via macro:

#define FILTER(from, what) ((from) select {!(toLower _x in (what))})

and then

(_x select 0) - _items

->

FILTER(_x select 0, _items)

@johnb432
Copy link
Contributor Author

_items = _items apply {configName (_x call CBA_fnc_getItemConfig)};

This is exactly what is needed, thanks!

@LinkIsGrim
Copy link
Contributor

Addressed in #9040.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Release Notes: **IMPROVED:**
Projects
None yet
Development

No branches or pull requests

4 participants