mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Dev helper function to convert settings to code (#5752)
* Dev helper function to convert settings to code * fix double // * Add movedToSQF config * Fix paramArray settings * Add movedToSQF to moveMarkers * Add tabs
This commit is contained in:
parent
e24ed0fa92
commit
00ba133b21
@ -1,6 +1,7 @@
|
||||
TRACE_1("",QUOTE(ADDON));
|
||||
|
||||
PREP(cbaSettings);
|
||||
PREP(cbaSettings_convertHelper);
|
||||
PREP(cbaSettings_loadFromConfig);
|
||||
PREP(cbaSettings_settingChanged);
|
||||
PREP(cbaSettings_transferUserSettings);
|
||||
|
@ -76,12 +76,14 @@ private _countOptions = count _settingsConfig;
|
||||
TRACE_1("Reading settings from configFile",_countOptions);
|
||||
for "_index" from 0 to (_countOptions - 1) do {
|
||||
private _optionEntry = _settingsConfig select _index;
|
||||
if ((getNumber (_optionEntry >> "movedToSQF")) == 0) then {
|
||||
if (isNil (configName _optionEntry)) then {
|
||||
[_optionEntry] call FUNC(cbaSettings_loadFromConfig);
|
||||
} else {
|
||||
WARNING_1("Setting [%1] - Already defined from somewhere else??",_varName);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
_settingsConfig = missionConfigFile >> "ACE_Settings";
|
||||
_countOptions = count _settingsConfig;
|
||||
@ -92,7 +94,7 @@ for "_index" from 0 to (_countOptions - 1) do {
|
||||
if ((toLower _settingName) in GVAR(cbaSettings_forcedSettings)) then {
|
||||
WARNING_1("Setting [%1] - Already Forced - ignoring missionConfig",_varName);
|
||||
} else {
|
||||
if (isNil _settingName) then {
|
||||
if ((isNil _settingName) && {(getNumber (_settingsConfig >> _settingName >> "movedToSQF")) == 0}) then {
|
||||
// New setting, that was first defined in missionConfigFile
|
||||
[_optionEntry] call FUNC(cbaSettings_loadFromConfig);
|
||||
} else {
|
||||
|
128
addons/common/functions/fnc_cbaSettings_convertHelper.sqf
Normal file
128
addons/common/functions/fnc_cbaSettings_convertHelper.sqf
Normal file
@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Author: PabstMirror
|
||||
* Dev function: Converts ace_settings to code, outputs to clipboard
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Addon <STRING>
|
||||
*
|
||||
* Return Value:
|
||||
* None
|
||||
*
|
||||
* Example:
|
||||
* ["ace_weaponselect"] call ace_common_fnc_cbaSettings_convertHelper
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#define DEBUG_MODE_FULL
|
||||
#include "script_component.hpp"
|
||||
|
||||
params ["_addon"];
|
||||
|
||||
private _output = [format ["// CBA Settings [ADDON: %1]:", _addon]];
|
||||
|
||||
private _addonSearch = _addon + "_";
|
||||
private _addonSearchCount = count _addonSearch;
|
||||
TRACE_2("",_addonSearch, _addonSearchCount);
|
||||
|
||||
private _settings = configProperties [configFile >> "ACE_Settings", "(isClass _x) && {((configName _x) select [0, _addonSearchCount]) == _addonSearch}"];
|
||||
|
||||
{
|
||||
private _config = _x;
|
||||
private _varName = configName _config;
|
||||
private _typeName = toUpper getText (_config >> "typeName");
|
||||
if (_typeName == "") then {
|
||||
WARNING_1("Setting [%1] Has no typeName",_varName);
|
||||
_typeName = "SCALAR";
|
||||
};
|
||||
TRACE_2("loadFromConfig",_varName,_typeName);
|
||||
|
||||
private _isClientSettable = (getNumber (_config >> "isClientSettable")) > 0;
|
||||
private _localizedName = getText (_config >> "displayName");
|
||||
private _localizedDescription = getText (_config >> "description");
|
||||
private _isForced = (getNumber (_config >> "force")) > 0;
|
||||
private _category = getText (_config >> "category");
|
||||
|
||||
private _cbaIsGlobal = (!_isClientSettable) || _isForced;
|
||||
if (_isForced) then {GVAR(cbaSettings_forcedSettings) pushBack (toLower _varName);};
|
||||
|
||||
// Basic handling of setting types CBA doesn't support:
|
||||
if (_typeName == "ARRAY") exitWith {
|
||||
WARNING_1("Setting [%1] is type ARRAY - limited support",_varName);
|
||||
private _value = getArray (_config >> "value");
|
||||
if (isServer) then {missionNamespace setVariable [_varName, _value, true];};
|
||||
};
|
||||
|
||||
private _cbaSettingType = "";
|
||||
private _cbaValueInfo = [];
|
||||
_cbaValueInfoHint = "default value";
|
||||
switch (_typeName) do {
|
||||
case ("SCALAR"): { // ACE's Scalar can be a float or an index for a list
|
||||
if (!isNumber (_config >> "value")) then {WARNING_2("Setting [%1] - value type [%2] is missing number",_varName,_typeName);};
|
||||
if (isArray (_config >> "values")) then {
|
||||
_cbaSettingType = "LIST"; // [_values, _valueTitles, _defaultIndex]
|
||||
private _values = [];
|
||||
private _valueTitles = [];
|
||||
{
|
||||
_values pushBack _forEachIndex;
|
||||
_valueTitles pushBack (if ((_x select [0, 1]) == "$") then {localize (_x select [1]);} else {_x});
|
||||
} forEach (getArray (_config >> "values"));
|
||||
_cbaValueInfo = [_values, _valueTitles, getNumber (_config >> "value")];
|
||||
} else {
|
||||
_cbaSettingType = "SLIDER"; // [_min, _max, _default, _trailingDecimals]
|
||||
_cbaValueInfo = if (isArray (_config >> "sliderSettings")) then {
|
||||
getArray (_config >> "sliderSettings");
|
||||
} else {
|
||||
[-1, 5000, 0, 1]
|
||||
};
|
||||
_cbaValueInfo set [2, getNumber (_config >> "value")];
|
||||
_cbaValueInfoHint = "[min, max, default value, trailing decimals (-1 for whole numbers only)]";
|
||||
};
|
||||
};
|
||||
case ("BOOL"): {
|
||||
if (!isNumber (_config >> "value")) then {WARNING_2("Setting [%1] - value type [%2] is missing number",_varName,_typeName);};
|
||||
_cbaSettingType = "CHECKBOX";
|
||||
_cbaValueInfo = (getNumber (_config >> "value")) > 0;
|
||||
};
|
||||
case ("COLOR"): {
|
||||
if (!isArray (_config >> "value")) then {WARNING_2("Setting [%1] - value type [%2] is missing array",_varName,_typeName);};
|
||||
_cbaSettingType = "COLOR";
|
||||
_cbaValueInfo = getArray (_config >> "value");
|
||||
};
|
||||
case ("STRING"): {
|
||||
if (!isText (_config >> "value")) then {WARNING_2("Setting [%1] - value type [%2] is missing text",_varName,_typeName);};
|
||||
_cbaSettingType = "EDITBOX";
|
||||
_cbaValueInfo = getText (_config >> "value");
|
||||
};
|
||||
};
|
||||
|
||||
if (_cbaSettingType == "") exitWith {ERROR_3("Setting [%1] - value type [%2] is unknown - %3",_varName,_typeName,_cbaValueInfo);};
|
||||
|
||||
if (_localizedDescription == "") then {_localizedDescription = _varName};
|
||||
if (_category == "") then {
|
||||
WARNING_1("Setting [%1] - no category",_varName);
|
||||
_category = "Uncategorized";
|
||||
};
|
||||
private _uncat = false;
|
||||
if (((_varName select [0, 4]) == "ACE_") && {(_category select [0, 3]) != "ACE"}) then {_uncat = true; _category = format ["ACE %1", _category];};
|
||||
if (((_varName select [0, 5]) == "ACEX_") && {(_category select [0, 4]) != "ACEX"}) then {_uncat = true; _category = format ["ACEX %1", _category];};
|
||||
|
||||
private _gvarName = _varName select [_addonSearchCount];
|
||||
|
||||
_output pushBack "";
|
||||
_output pushBack format ["["];
|
||||
_output pushBack format [" QGVAR(%1), ""%2"",", _gvarName, _cbaSettingType];
|
||||
_output pushBack format [" [LSTRING(), LSTRING()], // %1, %2", _localizedName, _localizedDescription];
|
||||
_output pushBack format [" ""%1"", // %2", ["localize LSTRING()", _category] select _uncat, _category];
|
||||
_output pushBack format [" %1, // %2", _cbaValueInfo, _cbaValueInfoHint];
|
||||
_output pushBack format [" %1, // isGlobal", _cbaIsGlobal];
|
||||
if ((_varName select [0, 4]) == "ACE_") then {
|
||||
_output pushBack format [" {[QGVAR(%1), _this] call EFUNC(common,cbaSettings_settingChanged)}] call CBA_settings_fnc_init;", _gvarName];
|
||||
} else {
|
||||
_output pushBack format [" {[""%1"", _this] call ace_common_fnc_cbaSettings_settingChanged}", _varName];
|
||||
};
|
||||
_output pushBack "] call CBA_settings_fnc_init;";
|
||||
} forEach _settings;
|
||||
|
||||
copyToClipboard (_output joinString endl);
|
||||
|
||||
INFO_1("Settings sqf copied to clipboard for %1",_addon);
|
@ -38,18 +38,22 @@ TRACE_1("Reading missionConfigFile params",_paramsArray);
|
||||
|
||||
// The setting is not forced, so update the value
|
||||
// Read entry and cast it to the correct type from the existing variable
|
||||
(cba_settings_default getVariable [_settingName, []]) params ["", "", ["_settingType", ""]];
|
||||
private _validValue = false;
|
||||
switch (true) do {
|
||||
case (_typeName == "SCALAR"): {_validValue = true;};
|
||||
case (_typeName == "BOOL"): {
|
||||
_settingValue = _settingValue > 0;
|
||||
_validValue = true;
|
||||
case (_settingType == "LIST");
|
||||
case (_settingType == "SCALAR"): {
|
||||
_validValue = [_settingName, _settingValue] call CBA_settings_fnc_check;
|
||||
};
|
||||
//TODO: Handle ARRAY,COLOR,STRING??? (bool/scalar covers most important settings)
|
||||
case (_settingType == "CHECKBOX"): {
|
||||
_settingValue = _settingValue > 0;
|
||||
_validValue = [_settingName, _settingValue] call CBA_settings_fnc_check;
|
||||
};
|
||||
// Will not Handle ARRAY,COLOR,STRING??? (bool/scalar covers most important settings)
|
||||
};
|
||||
|
||||
if (!_validValue) exitWith {
|
||||
WARNING_3("readSettingsFromParamsArray - param [%1] type not valid [%2] - expected type [%3]", _settingName,_settingValue,_typeName);
|
||||
WARNING_3("readSettingsFromParamsArray - param [%1] type not valid [%2] - expected type [%3]", _settingName,_settingValue,_settingType);
|
||||
};
|
||||
|
||||
if ([_settingName, "mission"] call CBA_settings_fnc_isForced) then {
|
||||
@ -57,7 +61,7 @@ TRACE_1("Reading missionConfigFile params",_paramsArray);
|
||||
};
|
||||
|
||||
// Set the setting as a mission setting and force it
|
||||
TRACE_2("setSettingMission from module",_settingName,_value);
|
||||
["CBA_settings_setSettingMission", [_settingName, _value, true]] call CBA_fnc_localEvent;
|
||||
private _return = ["CBA_settings_setSettingMission", [_settingName, _settingValue, true]] call CBA_fnc_localEvent;
|
||||
TRACE_3("setSettingMission from paramsArray",_settingName,_settingValue,_return);
|
||||
};
|
||||
} forEach _paramsArray;
|
||||
|
8
addons/markers/ACE_Settings.hpp
Normal file
8
addons/markers/ACE_Settings.hpp
Normal file
@ -0,0 +1,8 @@
|
||||
class ACE_Settings {
|
||||
class GVAR(movableMarkersEnabled) {
|
||||
movedToSQF = 1;
|
||||
};
|
||||
class GVAR(moveRestriction) {
|
||||
movedToSQF = 1;
|
||||
};
|
||||
};
|
@ -15,6 +15,7 @@ class CfgPatches {
|
||||
};
|
||||
|
||||
#include "CfgEventHandlers.hpp"
|
||||
#include "ACE_Settings.hpp"
|
||||
#include "CfgVehicles.hpp"
|
||||
|
||||
#include "InsertMarker.hpp"
|
||||
|
Loading…
Reference in New Issue
Block a user