mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
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:
parent
7c689bdff7
commit
29728352e2
@ -1120,5 +1120,22 @@
|
||||
<Russian>[CSW] Сумка с СПГ-9М орудием</Russian>
|
||||
<Korean>[CSW] SPG-9M 발사기 가방</Korean>
|
||||
</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>
|
||||
</Project>
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
GVAR(hardpointGroupsCache) = [] call CBA_fnc_createNamespace;
|
||||
GVAR(configTypesAdded) = [];
|
||||
GVAR(magazineNameCache) = [] call CBA_fnc_createNamespace;
|
||||
GVAR(originalMagazineNames) = [];
|
||||
GVAR(magazineNameCache) = createHashMap;
|
||||
GVAR(usedMagazineNames) = createHashMap;
|
||||
|
||||
[QGVAR(initSupplyVehicle), {
|
||||
TRACE_1("initSupplyVehicle EH",_this); // Warning: this can run before settings are init
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "..\script_component.hpp"
|
||||
/*
|
||||
* Author: PabstMirror
|
||||
* Gets a non-ambigious display name for a magazine using displayNameShort (AP/HE)
|
||||
* Author: PabstMirror, johnb43
|
||||
* Gets a non-ambigious display name for a magazine using displayNameShort (AP/HE).
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Magazine Classname <STRING>
|
||||
@ -10,7 +10,7 @@
|
||||
* Display Name <STRING>
|
||||
*
|
||||
* Example:
|
||||
* ["B_20mm_AP"] call ace_rearm_fnc_getMagazineName
|
||||
* "60Rnd_20mm_AP_shells" call ace_rearm_fnc_getMagazineName
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
@ -18,31 +18,31 @@
|
||||
params ["_className"];
|
||||
TRACE_1("getMagazineName",_className);
|
||||
|
||||
private _magName = GVAR(magazineNameCache) getVariable _className;
|
||||
if (isNil "_magName") then {
|
||||
private _displayName = getText(configFile >> "CfgMagazines" >> _className >> "displayName");
|
||||
GVAR(magazineNameCache) getOrDefaultCall [_className, {
|
||||
private _cfgMagazines = configFile >> "CfgMagazines";
|
||||
private _displayName = getText (_cfgMagazines >> _className >> "displayName");
|
||||
|
||||
if (_displayName == "") then {
|
||||
_displayName = _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];
|
||||
GVAR(originalMagazineNames) pushBack _displayName;
|
||||
// If the display name exists already, add displayNameShort to the existing entry
|
||||
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);
|
||||
|
||||
// go through all existing cache entries and update if there now are duplicates
|
||||
{
|
||||
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
|
||||
_displayName
|
||||
}, true] // return
|
||||
|
Loading…
Reference in New Issue
Block a user