Reliable settings framework

This commit is contained in:
esteldunedain 2015-05-14 20:45:53 -03:00
parent 032a2f3778
commit 5e3b6f389a
2 changed files with 28 additions and 7 deletions

View File

@ -1,12 +1,6 @@
// ACE - Common
#include "script_component.hpp"
// Load settings from profile
if (hasInterface) then {
call FUNC(loadSettingsFromProfile);
call FUNC(loadSettingsLocalizedText);
};
// Listens for global "SettingChanged" events, to update the force status locally
["SettingChanged", {
@ -249,3 +243,17 @@ if(isMultiplayer && { time > 0 || isNull player } ) then {
};
}, 0, []] call cba_fnc_addPerFrameHandler;
};
GVAR(commonPostInited) = true;
// Create a pfh to wait until all postinits are ready and settings are initialized
[{
// If post inits are not ready then wait
if !(SLX_XEH_MACHINE select 8) exitWith {};
// If settings are not initialized then wait
if !(GVAR(SettingsInitialized)) exitWith {};
diag_log text format["[ACE] Settings initialized"];
["SettingsInitialized", []] call FUNC(localEvent);
}, 0, []] call cba_fnc_addPerFrameHandler;

View File

@ -291,9 +291,22 @@ GVAR(syncedEvents) = HASH_CREATE;
//Debug
ACE_COUNTERS = [];
// Load settings
// Wait for server settings to arrive
GVAR(SettingsInitialized) = false;
["ServerSettingsReceived", {
// Load user settings from profile
if (hasInterface) then {
call FUNC(loadSettingsFromProfile);
call FUNC(loadSettingsLocalizedText);
};
GVAR(SettingsInitialized) = true;
}] call FUNC(addEventhandler);
// Load settings on the server and broadcast them
if (isServer) then {
call FUNC(loadSettingsOnServer);
// Raise a local event for other modules to listen too
["SettingsInitialized", []] call FUNC(localEvent);
};
ACE_player = player;