From 50f740f9be8bc23bed06333312143e3065421f16 Mon Sep 17 00:00:00 2001 From: Dystopian Date: Fri, 18 Dec 2020 00:28:54 +0400 Subject: [PATCH] Optimize interaction menu conditions (#8037) --- addons/interact_menu/functions/fnc_compileMenu.sqf | 11 +++++++---- .../functions/fnc_compileMenuSelfAction.sqf | 6 +++--- .../interact_menu/functions/fnc_compileMenuZeus.sqf | 7 +++++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/addons/interact_menu/functions/fnc_compileMenu.sqf b/addons/interact_menu/functions/fnc_compileMenu.sqf index 7f36247e22..1e1924d8fd 100644 --- a/addons/interact_menu/functions/fnc_compileMenu.sqf +++ b/addons/interact_menu/functions/fnc_compileMenu.sqf @@ -69,11 +69,14 @@ private _recurseFnc = { }; private _condition = getText (_entryCfg >> "condition"); - if (_condition == "") then {_condition = "true"}; - // Add canInteract (including exceptions) and canInteractWith to condition - if ((configName _entryCfg) != "ACE_MainActions") then { - _condition = _condition + format [QUOTE( && {[ARR_3(ACE_player, _target, %1)] call EFUNC(common,canInteractWith)} ), getArray (_entryCfg >> "exceptions")]; + if (configName _entryCfg == "ACE_MainActions") then { + if (_condition isEqualTo "") then {_condition = "true"}; + } else { + // Add canInteract (including exceptions) and canInteractWith to condition + private _canInteractCondition = format [QUOTE([ARR_3(ACE_player,_target,%1)] call EFUNC(common,canInteractWith)), getArray (_entryCfg >> "exceptions")]; + private _conditionFormatPattern = ["%1 && {%2}", "%2"] select (_condition isEqualTo "" || {_condition == "true"}); + _condition = format [_conditionFormatPattern, _condition, _canInteractCondition]; }; private _insertChildren = compile (getText (_entryCfg >> "insertChildren")); diff --git a/addons/interact_menu/functions/fnc_compileMenuSelfAction.sqf b/addons/interact_menu/functions/fnc_compileMenuSelfAction.sqf index 879ca7b138..c3ad9b35e7 100644 --- a/addons/interact_menu/functions/fnc_compileMenuSelfAction.sqf +++ b/addons/interact_menu/functions/fnc_compileMenuSelfAction.sqf @@ -45,10 +45,11 @@ private _recurseFnc = { private _statement = compile (getText (_entryCfg >> "statement")); private _condition = getText (_entryCfg >> "condition"); - if (_condition == "") then {_condition = "true"}; // Add canInteract (including exceptions) and canInteractWith to condition - _condition = _condition + format [QUOTE( && {[ARR_3(ACE_player, _target, %1)] call EFUNC(common,canInteractWith)} ), getArray (_entryCfg >> "exceptions")]; + private _canInteractCondition = format [QUOTE([ARR_3(ACE_player,_target,%1)] call EFUNC(common,canInteractWith)), getArray (_entryCfg >> "exceptions")]; + private _conditionFormatPattern = ["%1 && {%2}", "%2"] select (_condition isEqualTo "" || {_condition == "true"}); + _condition = compile format [_conditionFormatPattern, _condition, _canInteractCondition]; private _insertChildren = compile (getText (_entryCfg >> "insertChildren")); private _modifierFunction = compile (getText (_entryCfg >> "modifierFunction")); @@ -63,7 +64,6 @@ private _recurseFnc = { _runOnHover = (getNumber (_entryCfg >> "runOnHover")) > 0; }; - _condition = compile _condition; private _children = [_entryCfg] call _recurseFnc; private _entry = [ diff --git a/addons/interact_menu/functions/fnc_compileMenuZeus.sqf b/addons/interact_menu/functions/fnc_compileMenuZeus.sqf index c1f4dc0858..675cebe61f 100644 --- a/addons/interact_menu/functions/fnc_compileMenuZeus.sqf +++ b/addons/interact_menu/functions/fnc_compileMenuZeus.sqf @@ -35,7 +35,11 @@ private _recurseFnc = { private _statement = compile (getText (_entryCfg >> "statement")); private _condition = getText (_entryCfg >> "condition"); - if (_condition == "") then {_condition = "true"}; + if (_condition == "") then { + _condition = {true}; + } else { + _condition = compile _condition; + }; private _insertChildren = compile (getText (_entryCfg >> "insertChildren")); private _modifierFunction = compile (getText (_entryCfg >> "modifierFunction")); @@ -50,7 +54,6 @@ private _recurseFnc = { _runOnHover = (getNumber (_entryCfg >> "runOnHover")) > 0; }; - private _condition = compile _condition; private _children = [_entryCfg] call _recurseFnc; private _entry = [