1 using System.Collections;
2 using System.Collections.Generic;
16 private static bool initialized =
false;
21 [RuntimeInitializeOnLoadMethod]
23 [InitializeOnLoadMethod]
26 if(initialized)
return;
27 settings = AVR_SettingsParser.AutoParseSettingFiles();
42 public static Dictionary<string, string> settings =
new Dictionary<string, string>();
49 public static KeyCode
get_key(
string token) {
51 if (System.Enum.TryParse(AVR.Core.AVR_Settings.get_string(token), out key))
56 AVR.Core.AVR_DevConsole.cerror(token +
" does not contain a valid key or does not exist!",
"AVR_Settings");
68 if (settings.TryGetValue(token, out
string ret))
70 return int.Parse(ret);
72 else if(!initialized) {
74 return get_int(token);
78 AVR_DevConsole.warn(
"Settings do not contain key \"" + token +
"\". Using default value 0.");
89 if (settings.TryGetValue(token, out
string ret))
93 else if (!initialized)
96 return get_string(token);
100 AVR_DevConsole.warn(
"Settings do not contain key \"" + token +
"\". Using default value (empty string).");
111 if(settings.TryGetValue(token, out
string ret)) {
112 return float.Parse(ret);
114 else if (!initialized)
117 return get_float(token);
120 AVR_DevConsole.warn(
"Settings do not contain key \""+token+
"\". Using default value of 1.0f.");
131 if (settings.TryGetValue(token, out
string ret)) {
132 return bool.Parse(ret);
134 else if (!initialized)
137 return get_bool(token);
141 AVR_DevConsole.warn(
"Settings do not contain key \"" + token +
"\". Using default value of false.");
152 return settings.ContainsKey(token);
158 public static void set(
string token,
object value) {
159 settings[token] = value.ToString();
167 AVR.Core.AVR_DevConsole.print(
"Building SettingsTree...");
170 foreach(
string key
in settings.Keys) {
171 string[] dir = key.Split(
'/').Skip(1).ToArray();
172 add_node(dir, root, settings[key]);
179 foreach(
string d
in dir) {
180 if(!node.has_child(d)) {
183 node = node.get_children().First((c) => c.name==d);
201 this.fullname = this.name = name;
202 this.children =
new List<SettingsTreeNode>();
203 this.foldout =
false;
208 return this.children.Count<1;
212 return children.Any((child) => child.name==c);
216 this.children.Add(n);
217 n.fullname = this.fullname+
"/"+n.fullname;
221 return children.ToArray();
static void add_node(string[] dir, SettingsTreeNode node, string value)
SettingsTreeNode[] get_children()
static KeyCode get_key(string token)
Get a registered setting of the type KeyCode.
static void initialize()
Initialize settings. Calling multiple times will have no effect, use reconfigure() if you want to re-...
Contains constan values, settings etc. which can all be set through *.avr files. Duplicate settings w...
static bool token_exists(string token)
Check if a given token is registered as a setting.
static float get_float(string token)
Get a registered setting of the type float.
void traverse(System.Action< SettingsTreeNode > func)
List< SettingsTreeNode > children
SettingsTreeNode(string name)
static void set(string token, object value)
Set a setting with a specific token to a specific value.
static SettingsTreeNode build_tree()
Builds a tree-structure that contains all settings. Note: This may take a while to complete...
void add_child(SettingsTreeNode n)
static int get_int(string token)
Get a registered setting of the type int.
static bool get_bool(string token)
Get a registered setting of the type bool.
static string get_string(string token)
Get a registered setting of the type string.
static void reconfigure()
Re-initializes settings. Note: This will re-parse all settings files and might take a little...
Class representing a node from a settings-tree returned by AVR_Settings.build_tree() ...