Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refuel - Cache refuel classes #6807

Merged
merged 3 commits into from
Feb 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 18 additions & 28 deletions addons/refuel/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -62,36 +62,26 @@ GVAR(actions) = [
];

// init menu for config refuel vehicles
private _sourceClasses = [];
private _cacheRefuelClasses = call (uiNamespace getVariable [QGVAR(cacheRefuelClasses), {[[],[]]}]);
_cacheRefuelClasses params [["_staticClasses", [], [[]]], ["_dynamicClasses", [], [[]]]];

{
private _fuelCargo = getNumber (_x >> QGVAR(fuelCargo));
if (_fuelCargo > 0 || {_fuelCargo == REFUEL_INFINITE_FUEL}) then {
private _sourceClass = configName _x;
// check if we can use actions with inheritance
if (
!isText (_x >> "EventHandlers" >> "CBA_Extended_EventHandlers" >> "init") // addActionToClass relies on XEH init
|| {configName _x isKindOf "Static"} // CBA_fnc_addClassEventHandler doesn't support "Static" class
) then {
if (2 == getNumber (_x >> "scope")) then {
[_sourceClass, 0, ["ACE_MainActions"], GVAR(mainAction)] call EFUNC(interact_menu,addActionToClass);
{
[_sourceClass, 0, ["ACE_MainActions", QGVAR(Refuel)], _x] call EFUNC(interact_menu,addActionToClass);
} forEach GVAR(actions);
TRACE_1("add menu to static",_sourceClass);
};
} else {
if (0 == {_sourceClass isKindOf _x} count _sourceClasses) then {
_sourceClasses pushBack _sourceClass;
[_sourceClass, 0, ["ACE_MainActions"], GVAR(mainAction), true] call EFUNC(interact_menu,addActionToClass);
{
[_sourceClass, 0, ["ACE_MainActions", QGVAR(Refuel)], _x, true] call EFUNC(interact_menu,addActionToClass);
} forEach GVAR(actions);
TRACE_1("add menu to dynamic",_sourceClass);
};
};
};
} forEach ('true' configClasses (configFile >> "CfgVehicles"));
private _className = _x;
[_className, 0, ["ACE_MainActions"], GVAR(mainAction)] call EFUNC(interact_menu,addActionToClass);
{
[_className, 0, ["ACE_MainActions", QGVAR(Refuel)], _x] call EFUNC(interact_menu,addActionToClass);
} forEach GVAR(actions);
TRACE_1("add menu to static",_x);
} forEach _staticClasses;

{
private _className = _x;
[_className, 0, ["ACE_MainActions"], GVAR(mainAction), true] call EFUNC(interact_menu,addActionToClass);
{
[_className, 0, ["ACE_MainActions", QGVAR(Refuel)], _x, true] call EFUNC(interact_menu,addActionToClass);
} forEach GVAR(actions);
TRACE_1("add menu to dynamic",_x);
} forEach _dynamicClasses;

#ifdef DRAW_HOOKS_POS
addMissionEventHandler ["Draw3D", {
Expand Down
27 changes: 27 additions & 0 deletions addons/refuel/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
#include "script_component.hpp"

#include "XEH_PREP.hpp"

// cache refuel vehicles, see XEH_postInit.sqf
private _staticClasses = [];
private _dynamicClasses = [];

{
private _fuelCargo = getNumber (_x >> QGVAR(fuelCargo));
if (_fuelCargo > 0 || {_fuelCargo == REFUEL_INFINITE_FUEL}) then {
private _sourceClass = configName _x;
// check if we can use actions with inheritance
if (
!isText (_x >> "EventHandlers" >> "CBA_Extended_EventHandlers" >> "init") // addActionToClass relies on XEH init
|| {configName _x isKindOf "Static"} // CBA_fnc_addClassEventHandler doesn't support "Static" class
) then {
if (2 == getNumber (_x >> "scope")) then {
_staticClasses pushBackUnique _sourceClass;
};
} else {
if (-1 == _dynamicClasses findIf {_sourceClass isKindOf _x}) then {
_dynamicClasses pushBackUnique _sourceClass;
};
};
};
} forEach ('true' configClasses (configFile >> "CfgVehicles"));

TRACE_2("compiled",count _staticClasses,count _dynamicClasses);
uiNamespace setVariable [QGVAR(cacheRefuelClasses), compileFinal str [_staticClasses, _dynamicClasses]];