ACE3/addons/common/functions/fnc_getVehicleIcon.sqf
lambdatiger da73cf979d
Common - Make FUNC(getVehicleIcon) check for strings without the .paa extension (#10257)
* added fallback for icons without .paa post-fix

* Make sure it's at least a valid path before we spend time searching

* Revert "Make sure it's at least a valid path before we spend time searching"

This reverts commit 2d7a9454e3.

* Added checking for empty `_vehicleValue` strings

Update addons/common/functions/fnc_getVehicleIcon.sqf

Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>

---------

Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>
2024-08-26 11:31:25 -05:00

52 lines
1.5 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Author: AACO
* Function used to get the vehicle icon for provided object (cached for repeat use)
*
* Arguments:
* 0: Object to get icon of <OBJECT, STRING>
*
* Return Value:
* Icon of vehicle <STRING>
*
* Examples:
* ["B_Soldier_F"] call ace_common_fnc_getVehicleIcon;
*
* Public: Yes
*/
#define DEFAULT_TEXTURE "\A3\ui_f\data\Map\VehicleIcons\iconVehicle_ca.paa"
params [["_object", objNull, [objNull, ""]]];
if (_object isEqualTo objNull || {_object isEqualTo ""}) exitWith { DEFAULT_TEXTURE };
private _objectType = if (_object isEqualType objNull) then {
typeOf _object
} else {
_object
};
private _cachedValue = GVAR(vehicleIconCache) get _objectType;
if (isNil "_cachedValue") then {
private _vehicleValue = getText (configfile >> "CfgVehicles" >> _objectType >> "icon");
private _vehicleIconValue = getText (configfile >> "CfgVehicleIcons" >> _vehicleValue);
if (_vehicleIconValue == "") then {
if (_vehicleValue != "" && {((toLowerANSI _vehicleValue) find ".paa") > -1}) then {
_cachedValue = _vehicleValue;
} else {
if (_vehicleValue != "" && {fileExists (_vehicleValue + ".paa")}) then {
_cachedValue = _vehicleValue + ".paa";
} else {
_cachedValue = DEFAULT_TEXTURE;
};
};
} else {
_cachedValue = _vehicleIconValue;
};
GVAR(vehicleIconCache) set [_objectType, _cachedValue];
};
_cachedValue