Rearm - Optimise getting magazine names (#10052)

* Optimise getting rearm magazine names

* Replace using regex and localize CSW entries

* Added comments about prefix
This commit is contained in:
johnb432 2024-06-05 08:32:41 +02:00 committed by GitHub
parent 7c689bdff7
commit 29728352e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 42 additions and 25 deletions

View File

@ -1120,5 +1120,22 @@
<Russian>[CSW] Сумка с СПГ-9М орудием</Russian> <Russian>[CSW] Сумка с СПГ-9М орудием</Russian>
<Korean>[CSW] SPG-9M 발사기 가방</Korean> <Korean>[CSW] SPG-9M 발사기 가방</Korean>
</Key> </Key>
<!-- Used in rearm to remove the [CSW] prefix from magazine names, so adjust when necessary -->
<Key ID="STR_ACE_CSW_regex">
<English>^\[CSW\]</English>
<Spanish>^\[CSW\]</Spanish>
<German>^\[CSW\]</German>
<Portuguese>^\[CSW\]</Portuguese>
<French>^\[CSW\]</French>
<Japanese>^\[CSW\]</Japanese>
<Chinese>^\[CSW\]</Chinese>
<Chinesesimp>^\[班组\]</Chinesesimp>
<Italian>^\[CSW\]</Italian>
<Czech>^\[CSW\]</Czech>
<Turkish>^\[CSW\]</Turkish>
<Polish>^\[CSW\]</Polish>
<Russian>^\[CSW\]</Russian>
<Korean>^\[CSW\]</Korean>
</Key>
</Package> </Package>
</Project> </Project>

View File

@ -2,8 +2,8 @@
GVAR(hardpointGroupsCache) = [] call CBA_fnc_createNamespace; GVAR(hardpointGroupsCache) = [] call CBA_fnc_createNamespace;
GVAR(configTypesAdded) = []; GVAR(configTypesAdded) = [];
GVAR(magazineNameCache) = [] call CBA_fnc_createNamespace; GVAR(magazineNameCache) = createHashMap;
GVAR(originalMagazineNames) = []; GVAR(usedMagazineNames) = createHashMap;
[QGVAR(initSupplyVehicle), { [QGVAR(initSupplyVehicle), {
TRACE_1("initSupplyVehicle EH",_this); // Warning: this can run before settings are init TRACE_1("initSupplyVehicle EH",_this); // Warning: this can run before settings are init

View File

@ -1,7 +1,7 @@
#include "..\script_component.hpp" #include "..\script_component.hpp"
/* /*
* Author: PabstMirror * Author: PabstMirror, johnb43
* Gets a non-ambigious display name for a magazine using displayNameShort (AP/HE) * Gets a non-ambigious display name for a magazine using displayNameShort (AP/HE).
* *
* Arguments: * Arguments:
* 0: Magazine Classname <STRING> * 0: Magazine Classname <STRING>
@ -10,7 +10,7 @@
* Display Name <STRING> * Display Name <STRING>
* *
* Example: * Example:
* ["B_20mm_AP"] call ace_rearm_fnc_getMagazineName * "60Rnd_20mm_AP_shells" call ace_rearm_fnc_getMagazineName
* *
* Public: No * Public: No
*/ */
@ -18,31 +18,31 @@
params ["_className"]; params ["_className"];
TRACE_1("getMagazineName",_className); TRACE_1("getMagazineName",_className);
private _magName = GVAR(magazineNameCache) getVariable _className; GVAR(magazineNameCache) getOrDefaultCall [_className, {
if (isNil "_magName") then { private _cfgMagazines = configFile >> "CfgMagazines";
private _displayName = getText(configFile >> "CfgMagazines" >> _className >> "displayName"); private _displayName = getText (_cfgMagazines >> _className >> "displayName");
if (_displayName == "") then { if (_displayName == "") then {
_displayName = _className; _displayName = _className;
WARNING_1("Magazine is missing display name [%1]",_className); WARNING_1("Magazine is missing display name [%1]",_className);
}; };
if ((_displayName select [0,6]) == "[CSW] ") then { _displayName = _displayName select [6]; }; // [CSW] prefix is localised
if (["ace_csw"] call EFUNC(common,isModLoaded)) then {
_displayName = trim (_displayName regexReplace [LELSTRING(csw,regex), ""]);
};
GVAR(magazineNameCache) setVariable [_className, _displayName]; // If the display name exists already, add displayNameShort to the existing entry
GVAR(originalMagazineNames) pushBack _displayName; private _existingClassname = GVAR(usedMagazineNames) get _displayName;
if (!isNil "_existingClassname") then {
GVAR(magazineNameCache) set [_existingClassname, format ["%1: %2", _displayName, getText (_cfgMagazines >> _existingClassname >> "displayNameShort")]];
_displayName = format ["%1: %2", _displayName, getText (_cfgMagazines >> _className >> "displayNameShort")];
};
GVAR(usedMagazineNames) set [_displayName, _className];
TRACE_2("Adding to cache",_className,_displayName); TRACE_2("Adding to cache",_className,_displayName);
// go through all existing cache entries and update if there now are duplicates _displayName
{ }, true] // return
private _xMagName = GVAR(magazineNameCache) getVariable _x;
if ((_xMagName == _displayName) && {({_xMagName == _x} count GVAR(originalMagazineNames)) > 1}) then {
private _xMagName = format ["%1: %2", _displayName, getText(configFile >> "CfgMagazines" >> _x >> "displayNameShort")];
GVAR(magazineNameCache) setVariable [_x, _xMagName];
TRACE_2("Using unique name",_x,_xMagName);
};
} forEach (allVariables GVAR(magazineNameCache));
_magName = GVAR(magazineNameCache) getVariable _className;
};
_magName