ACE_Settings: store settings data on a list

This commit is contained in:
Nicolás Badano 2015-02-03 00:43:23 -03:00
parent 37199f2ba2
commit 67f7842722
5 changed files with 92 additions and 50 deletions

View File

@ -55,6 +55,7 @@ PREP(getMarkerType);
PREP(getName); PREP(getName);
PREP(getNumberFromMissionSQM); PREP(getNumberFromMissionSQM);
PREP(getPitchBankYaw); PREP(getPitchBankYaw);
PREP(getSettingData);
PREP(getStringFromMissionSQM); PREP(getStringFromMissionSQM);
PREP(getTargetAzimuthAndInclination); PREP(getTargetAzimuthAndInclination);
PREP(getTargetDistance); PREP(getTargetDistance);

View File

@ -0,0 +1,29 @@
/*
* Author: CAA-Picard
* Returns the metadata of a setting if it exists
*
* Arguments:
* 0: Name of the setting (String)
*
* Return Value:
* Setting Data (Array)
* 0: _name
* 1: _typeName
* 2: _isClientSetable
* 3: _localizedName
* 4: _localizedDescription
* 5: _possibleValues
* 6: _isForced
*
* Public: No
*/
#include "script_component.hpp"
EXPLODE_1_PVT(_this,_name);
_value = objNull;
{
if ((_x select 0) == _name) exitWith {_value = _x};
} forEach GVAR(settings);
_value

View File

@ -1,6 +1,6 @@
/* /*
* Author: CAA-Picard * Author: CAA-Picard
* Load the user setable setting from the user profile. * Load the user setable settings from the user profile.
* Config < Server UserConfig < Mission Config < Client settings * Config < Server UserConfig < Mission Config < Client settings
* *
* Arguments: * Arguments:
@ -13,36 +13,25 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
_fnc_setSettingFromProfile = { // Iterate through settings
EXPLODE_1_PVT(_this,_optionEntry); {
_name = _x select 0;
_isClientSetable = _x select 2;
_isForced = _x select 6;
_name = configName _optionEntry; // If setting is user setable
_valueEntry = _optionEntry >> "value"; if (_isClientSetable) then {
_isClientSetable = getNumber (_optionEntry >> "isClientSetable"); // If setting is not forced
if !(_isForced) then {
if (_isClientSetable > 0) then {
if !(missionNamespace getVariable format ["%1_forced", _name, false]) then {
_profileValue = profileNamespace getvariable _name; _profileValue = profileNamespace getvariable _name;
// If the setting is stored on the profile
if !(isNil _profileValue) then { if !(isNil _profileValue) then {
// If the profile variable has the correct type
if (typeName _profileValue == typeName (missionNamespace getvariable _name)) then { if (typeName _profileValue == typeName (missionNamespace getvariable _name)) then {
// Load the setting from the profile
missionNamespace setvariable [_name, _profileValue]; missionNamespace setvariable [_name, _profileValue];
}; };
}; };
}; };
}; };
}; } forEach GVAR(settings);
// Iterate through settings from main config
_countOptions = count (configFile >> "ACE_Settings");
for "_index" from 0 to (_countOptions - 1) do {
_optionEntry = (configFile >> "ACE_Settings") select _index;
[_optionEntry] call _fnc_setSettingFromProfile;
};
// Iterate through settings from mission config
_countOptions = count (missionConfigFile >> "ACE_Settings");
for "_index" from 0 to (_countOptions - 1) do {
_optionEntry = (missionConfigFile >> "ACE_Settings") select _index;
[_optionEntry] call _fnc_setSettingFromProfile;
};

View File

@ -13,7 +13,7 @@
*/ */
#include "script_component.hpp" #include "script_component.hpp"
GVAR(settingsList) = []; GVAR(settings) = [];
// Load settings from main config // Load settings from main config
_countOptions = count (configFile >> "ACE_Settings"); _countOptions = count (configFile >> "ACE_Settings");
@ -25,15 +25,13 @@ for "_index" from 0 to (_countOptions - 1) do {
// Check if all settings should be forced // Check if all settings should be forced
if (GVAR(forceAllSettings)) then { if (GVAR(forceAllSettings)) then {
{ {
if !(missionNamespace getVariable format ["%1_forced", _x]) then { _x set [6, true];
missionNamespace setVariable format ["%1_forced", _x, true]; } forEach GVAR(settings);
publicVariable format ["%1_forced", _name];
};
} forEach GVAR(settingsList);
}; };
// @todo
// Load settings from server userconfig only if the ACE_ServerSettings is loaded // Load settings from server userconfig only if the ACE_ServerSettings is loaded
if (isClass (configFile >> "CfgPatches" >> "ACE_ServerSettings")) then { /*if (isClass (configFile >> "CfgPatches" >> "ACE_ServerSettings")) then {
DFUNC(serverUserConfig) = compile preprocessFileLineNumbers "\userconfig\ACE\ACE_Settings.hpp"; DFUNC(serverUserConfig) = compile preprocessFileLineNumbers "\userconfig\ACE\ACE_Settings.hpp";
if !(isNil DFUNC(serverUserConfig)) then { if !(isNil DFUNC(serverUserConfig)) then {
[] call FUNC(serverUserConfig); [] call FUNC(serverUserConfig);
@ -47,7 +45,7 @@ if (isClass (configFile >> "CfgPatches" >> "ACE_ServerSettings")) then {
}; };
} forEach GVAR(settingsList); } forEach GVAR(settingsList);
}; };
}; };*/
// Load settings from mission config // Load settings from mission config
_countOptions = count (missionConfigFile >> "ACE_Settings"); _countOptions = count (missionConfigFile >> "ACE_Settings");
@ -59,9 +57,13 @@ for "_index" from 0 to (_countOptions - 1) do {
// Check if all settings should be forced // Check if all settings should be forced
if (GVAR(forceAllSettings)) then { if (GVAR(forceAllSettings)) then {
{ {
if !(missionNamespace getVariable format ["%1_forced", _x]) then { _x set [6, true];
missionNamespace setVariable format ["%1_forced", _x, true]; } forEach GVAR(settings);
publicVariable format ["%1_forced", _name];
};
} forEach GVAR(settingsList);
}; };
// Publish all settings data
publicVariable QGVAR(settings);
// Publish all setting values
{
publicVariable (_x select 0);
} forEach GVAR(settings);

View File

@ -28,6 +28,9 @@ _fnc_getValueWithType = {
if (_typeName == "ARRAY") exitWith { if (_typeName == "ARRAY") exitWith {
getArray (_optionEntry >> "value") getArray (_optionEntry >> "value")
}; };
if (_typeName == "COLOR") exitWith {
getArray (_optionEntry >> "value")
};
_value _value
}; };
@ -39,41 +42,59 @@ if (isNil _name) then {
// Get type from config // Get type from config
_typeName = getText (_optionEntry >> "typeName"); _typeName = getText (_optionEntry >> "typeName");
if (_typeName == "") then {
_typeName = "SCALAR";
};
// Read entry and cast it to the correct type // Read entry and cast it to the correct type
_value = [_optionEntry, _typeName] call _fnc_getValueWithType; _value = [_optionEntry, _typeName] call _fnc_getValueWithType;
// Init the variable and publish it // Init the variable and publish it
missionNamespace setVariable [_name, _value]; missionNamespace setVariable [_name, _value];
publicVariable _name;
// Set the variable to not forced
missionNamespace setVariable [format ["%1_forced", _name], false];
publicVariable format ["%1_forced", _name];
// Add the variable to a list on the server // Add the setting to a list on the server
GVAR(settingsList) pushBack _name; // Set the variable to not forced
/*_settingData = [
_name,
_typeName,
_isClientSetable,
_localizedName,
_localizedDescription,
_possibleValues,
_isForced
];*/
_settingData = [
_name,
_typeName,
(getNumber (_optionEntry >> "isClientSetable")) > 0,
getText (_optionEntry >> "displayName"),
getText (_optionEntry >> "description"),
getArray (_optionEntry >> "values"),
getNumber (_optionEntry >> "force") > 0
];
GVAR(settings) pushBack _settingData;
} else { } else {
// The setting already exists. // The setting already exists.
// Check if it's already forced and quit // Check if it's already forced and quit
if (missionNamespace getVariable format ["%1_forced", _name]) exitWith {}; _settingData = [_name] call FUNC(getSettingData);
if (_settingData select 6) exitWith {};
// The setting is not forced, so update the value // The setting is not forced, so update the value
// Get the type from the existing variable // Get the type from the existing variable
_typeName = typeName (missionNamespace getVariable _name); _typeName = _settingData select 1;
// Read entry and cast it to the correct type // Read entry and cast it to the correct type
_value = [_optionEntry, _typeName] call _fnc_getValueWithType; _value = [_optionEntry, _typeName] call _fnc_getValueWithType;
// Update the variable and publish it // Update the variable and publish it
missionNamespace setVariable [_name, _value]; missionNamespace setVariable [_name, _value];
publicVariable _name;
// Check if it needs forcing // Force the setting if requested
if (getNumber (_optionEntry >> "force") > 0) then { if (getNumber (_optionEntry >> "force") > 0) then {
missionNamespace setVariable [format ["%1_forced", _name], true]; _settingData set [6, true];
publicVariable format ["%1_forced", _name];
}; };
}; };