mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
ACE_Settings: store settings data on a list
This commit is contained in:
parent
37199f2ba2
commit
67f7842722
@ -55,6 +55,7 @@ PREP(getMarkerType);
|
||||
PREP(getName);
|
||||
PREP(getNumberFromMissionSQM);
|
||||
PREP(getPitchBankYaw);
|
||||
PREP(getSettingData);
|
||||
PREP(getStringFromMissionSQM);
|
||||
PREP(getTargetAzimuthAndInclination);
|
||||
PREP(getTargetDistance);
|
||||
|
29
addons/common/functions/fnc_getSettingData.sqf
Normal file
29
addons/common/functions/fnc_getSettingData.sqf
Normal 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
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* Arguments:
|
||||
@ -13,36 +13,25 @@
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
_fnc_setSettingFromProfile = {
|
||||
EXPLODE_1_PVT(_this,_optionEntry);
|
||||
// Iterate through settings
|
||||
{
|
||||
_name = _x select 0;
|
||||
_isClientSetable = _x select 2;
|
||||
_isForced = _x select 6;
|
||||
|
||||
_name = configName _optionEntry;
|
||||
_valueEntry = _optionEntry >> "value";
|
||||
_isClientSetable = getNumber (_optionEntry >> "isClientSetable");
|
||||
|
||||
if (_isClientSetable > 0) then {
|
||||
if !(missionNamespace getVariable format ["%1_forced", _name, false]) then {
|
||||
// If setting is user setable
|
||||
if (_isClientSetable) then {
|
||||
// If setting is not forced
|
||||
if !(_isForced) then {
|
||||
_profileValue = profileNamespace getvariable _name;
|
||||
// If the setting is stored on the profile
|
||||
if !(isNil _profileValue) then {
|
||||
// If the profile variable has the correct type
|
||||
if (typeName _profileValue == typeName (missionNamespace getvariable _name)) then {
|
||||
// Load the setting from the profile
|
||||
missionNamespace setvariable [_name, _profileValue];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
// 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;
|
||||
};
|
||||
} forEach GVAR(settings);
|
||||
|
@ -13,7 +13,7 @@
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
GVAR(settingsList) = [];
|
||||
GVAR(settings) = [];
|
||||
|
||||
// Load settings from main config
|
||||
_countOptions = count (configFile >> "ACE_Settings");
|
||||
@ -25,15 +25,13 @@ for "_index" from 0 to (_countOptions - 1) do {
|
||||
// Check if all settings should be forced
|
||||
if (GVAR(forceAllSettings)) then {
|
||||
{
|
||||
if !(missionNamespace getVariable format ["%1_forced", _x]) then {
|
||||
missionNamespace setVariable format ["%1_forced", _x, true];
|
||||
publicVariable format ["%1_forced", _name];
|
||||
};
|
||||
} forEach GVAR(settingsList);
|
||||
_x set [6, true];
|
||||
} forEach GVAR(settings);
|
||||
};
|
||||
|
||||
// @todo
|
||||
// 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";
|
||||
if !(isNil DFUNC(serverUserConfig)) then {
|
||||
[] call FUNC(serverUserConfig);
|
||||
@ -47,7 +45,7 @@ if (isClass (configFile >> "CfgPatches" >> "ACE_ServerSettings")) then {
|
||||
};
|
||||
} forEach GVAR(settingsList);
|
||||
};
|
||||
};
|
||||
};*/
|
||||
|
||||
// Load settings from mission config
|
||||
_countOptions = count (missionConfigFile >> "ACE_Settings");
|
||||
@ -59,9 +57,13 @@ for "_index" from 0 to (_countOptions - 1) do {
|
||||
// Check if all settings should be forced
|
||||
if (GVAR(forceAllSettings)) then {
|
||||
{
|
||||
if !(missionNamespace getVariable format ["%1_forced", _x]) then {
|
||||
missionNamespace setVariable format ["%1_forced", _x, true];
|
||||
publicVariable format ["%1_forced", _name];
|
||||
};
|
||||
} forEach GVAR(settingsList);
|
||||
_x set [6, true];
|
||||
} forEach GVAR(settings);
|
||||
};
|
||||
|
||||
// Publish all settings data
|
||||
publicVariable QGVAR(settings);
|
||||
// Publish all setting values
|
||||
{
|
||||
publicVariable (_x select 0);
|
||||
} forEach GVAR(settings);
|
||||
|
@ -28,6 +28,9 @@ _fnc_getValueWithType = {
|
||||
if (_typeName == "ARRAY") exitWith {
|
||||
getArray (_optionEntry >> "value")
|
||||
};
|
||||
if (_typeName == "COLOR") exitWith {
|
||||
getArray (_optionEntry >> "value")
|
||||
};
|
||||
_value
|
||||
};
|
||||
|
||||
@ -39,41 +42,59 @@ if (isNil _name) then {
|
||||
|
||||
// Get type from config
|
||||
_typeName = getText (_optionEntry >> "typeName");
|
||||
if (_typeName == "") then {
|
||||
_typeName = "SCALAR";
|
||||
};
|
||||
|
||||
// Read entry and cast it to the correct type
|
||||
_value = [_optionEntry, _typeName] call _fnc_getValueWithType;
|
||||
|
||||
// Init the variable and publish it
|
||||
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
|
||||
GVAR(settingsList) pushBack _name;
|
||||
// Add the setting to a list on the server
|
||||
// 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 {
|
||||
// The setting already exists.
|
||||
|
||||
// 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
|
||||
|
||||
// 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
|
||||
_value = [_optionEntry, _typeName] call _fnc_getValueWithType;
|
||||
|
||||
// Update the variable and publish it
|
||||
missionNamespace setVariable [_name, _value];
|
||||
publicVariable _name;
|
||||
|
||||
// Check if it needs forcing
|
||||
// Force the setting if requested
|
||||
if (getNumber (_optionEntry >> "force") > 0) then {
|
||||
missionNamespace setVariable [format ["%1_forced", _name], true];
|
||||
publicVariable format ["%1_forced", _name];
|
||||
_settingData set [6, true];
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user