Arsenal - Fix changing stats via script (#9312)

* fix addStat

* fix removeStat

* improve priority sorting

* change append to pushBack
This commit is contained in:
Grim 2023-08-19 23:45:07 -03:00 committed by GitHub
parent 007995612d
commit 8f3a1c5694
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 94 deletions

View File

@ -1,6 +1,6 @@
#include "script_component.hpp"
/*
* Author: Alganthe, johnb43
* Author: Alganthe, johnb43, LinkIsGrim
* Adds a stat to ACE Arsenal.
*
* Arguments:
@ -76,20 +76,13 @@ private _fnc_addToTabs = {
_currentTab = _tabsList select _x;
// Find if there is an entry with same ID
if (_currentTab findIf {_x findIf {_x select 0 == _statName} != -1} != -1) then {
if (_currentTab findIf {_x select 5 == _statName} != -1) then {
TRACE_1("A stat with this ID already exists", _statName);
} else {
_stat = +_finalArray;
_stat set [0, _statName];
_stat set [5, _statName];
private _index = _currentTab findIf {count _x < 5};
// Add to existing page if there's enough space, otherwise create a new page
if (_index != -1) then {
(_currentTab select _index) pushBack _stat;
} else {
_currentTab pushBack [_stat];
};
_currentTab pushBack _stat;
_return pushBack _statName;
@ -99,7 +92,7 @@ private _fnc_addToTabs = {
} forEach _tabsToAddTo;
};
private _finalArray = ["", _stats, _title, [_showBar, _showText], [_barStatement, _textStatement, _condition], _priority];
private _finalArray = [_priority, _stats, _title, [_showBar, _showText], [_barStatement, _textStatement, _condition], ""];
if (_leftTabs isNotEqualTo []) then {
[GVAR(statsListLeftPanel), _leftTabs, "L"] call _fnc_addToTabs;
@ -109,7 +102,6 @@ if (_rightTabs isNotEqualTo []) then {
[GVAR(statsListRightPanel), _rightTabs, "R"] call _fnc_addToTabs;
};
private _statsFlat = [];
private _stats = [];
private _tabToChange = [];
@ -123,34 +115,10 @@ private _tabToChange = [];
GVAR(statsListLeftPanel)
};
_statsFlat = [];
_stats = _tabToChange select _tab;
// Get all stats of a tab into a single array
{
_statsFlat append _x;
} forEach (_tabToChange select _tab);
// Put priority up front
{
reverse _x;
} forEach _statsFlat;
// Sort numerically
_statsFlat sort false;
// Put it back at the rear
{
reverse _x;
} forEach _statsFlat;
_stats = [];
// Group stats into groups of 5
for "_index" from 0 to count _statsFlat - 1 step 5 do {
_stats pushBack (_statsFlat select [_index, _index + 5]);
};
_tabToChange set [_tab, _stats];
// Sort by priority
_stats sort false;
} forEach _changes;
_return

View File

@ -23,7 +23,7 @@ private _fnc_addToTabs = {
{
// Make stat name
_stat = +_finalArray;
_stat set [0, [_class, _tabSide, [str _x, format ["0%1", _x]] select (_x < 10)] joinString ""];
_stat set [5, [_class, _tabSide, [str _x, format ["0%1", _x]] select (_x < 10)] joinString ""];
(_tabsList select _x) pushBack _stat;
} forEach _tabsToAddTo;
@ -31,22 +31,12 @@ private _fnc_addToTabs = {
// Sort by priority
private _fnc_sortLists = {
params ["_tabsList"];
params ["_tabs"];
{
// Put priority up front
{
reverse _x;
} forEach _x;
// Sort numerically
_x sort false;
// Put it back at the rear
{
reverse _x;
} forEach _x;
} forEach _tabsList;
} forEach _tabs;
};
private _statsListLeftPanel = [
@ -101,7 +91,7 @@ private _priority = 0;
_condition = compile _condition;
};
_finalArray = ["", _stats, _displayName, [_showBar, _showText], [{}, {}, _condition], _priority];
_finalArray = [_priority, _stats, _displayName, [_showBar, _showText], [{}, {}, _condition], ""];
if (_showBar) then {
(_finalArray select 4) set [0, compile (getText (_x >> "barStatement"))];

View File

@ -113,7 +113,7 @@ private _fnc_handleStats = {
private _textStatementResult = "";
{
_x params ["_ID", "_configEntry", "_title", "_bools", "_statements"];
_x params ["", "_configEntry", "_title", "_bools", "_statements"];
_bools params ["_showBar", "_showText"];
_statements params [["_barStatement", {}, [{}]], ["_textStatement", {}, [{}]], ["_condition", {true}, [{}]]];

View File

@ -25,7 +25,6 @@ private _stringCount = 0;
private _tabSide = "";
private _tab = "";
private _tabToChange = [];
private _changes = [];
{
// Get tab info
@ -44,41 +43,5 @@ private _changes = [];
};
// Delete stat
{
_x deleteAt (_x findIf {_x select 0 == _currentID});
} forEach _tabToChange;
// Store information, so that only tabs that were changed can be sorted again
_changes pushBackUnique [_tab, _tabSide];
_tabToChange deleteAt (_tabToChange findIf {_x select 5 == _currentID});
} forEach _IDList;
private _statsFlat = [];
private _stats = [];
// Fill empty spots
{
_x params ["_tab", "_tabSide"];
_tabToChange = if (_tabSide == "R") then {
GVAR(statsListRightPanel)
} else {
GVAR(statsListLeftPanel)
};
_statsFlat = [];
// Get all stats of a tab into a single array
{
_statsFlat append _x;
} forEach (_tabToChange select _tab);
// Priority has stayed intact, so no need to sort
_stats = [];
// Group stats into groups of 5
for "_index" from 0 to count _statsFlat - 1 step 5 do {
_stats pushBack (_statsFlat select [_index, _index + 5]);
};
_tabToChange set [_tab, _stats];
} forEach _changes;