Skip to content

Commit

Permalink
Use file exists for do callout (#397)
Browse files Browse the repository at this point in the history
* use fileExists and searching commonly used file extensions in doCallout

* Fix files not being searched correctly

prevent deeper search for files when they already have a file ending

* Lazy Eval condition

* fix edge case where invalid files where put into doCallout cache
  • Loading branch information
jokoho48 committed Jul 7, 2024
1 parent 7c38231 commit 25abd26
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions addons/main/functions/fnc_doCallout.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

if (GVAR(disableAICallouts)) exitWith {};

scopeName QGVAR(doCallout_main);
params [
["_unit", objNull, [objNull]],
["_behavior", "", [""]],
Expand Down Expand Up @@ -74,15 +73,33 @@ if (isNil "_cachedSounds") then {
_cachedSounds = getArray (_protocolConfig >> _callout);
private _deleted = false;
{
private _sound = _x;
private _sound = toLowerANSI _x;
if (_sound == "") then {
_sound = objNull;
_deleted = true;
} else {
if (_sound select [0, 1] != "\") then {
_sound = (getArray (configFile >> "CfgVoice" >> _speaker >> "directories") select 0) + _sound;
};
_cachedSounds set [_forEachIndex, objNull];
continue;
};

private _hasFileEnding = _sound regexMatch ".+?\.(?:ogg|wss|wav|mp3)$/io";

if (_sound select [0, 1] != "\") then {
_sound = (getArray (configFile >> "CfgVoice" >> _speaker >> "directories") select 0) + _sound;
};

if (!_hasFileEnding && {!fileExists _sound}) then {
{
if (fileExists (_sound + _x)) exitWith {
_sound = _sound + _x;
};
} forEach [".ogg", ".wss", ".wav", ".mp3"];
};

if (!_hasFileEnding || {!fileExists _sound}) then {
_deleted = true;
_cachedSounds set [_forEachIndex, objNull];
continue;
};

_cachedSounds set [_forEachIndex, _sound];
} forEach _cachedSounds;

Expand Down

0 comments on commit 25abd26

Please sign in to comment.