Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_JsonApiStructHandler.c
Go to the documentation of this file.
1
5
6//------------------------------------------------------------------------------------------------
9{
10 //------------------------------------------------------------------------------------------------
12 static void StoreValue(JsonApiStruct json, string variableName, string value, EJsonApiStructValueType type)
13 {
14 // Check json api struct
15 if (!json || variableName.IsEmpty() || value.IsEmpty())
16 return;
17
18 Print(string.Format("store: %1 = %2 (%3)", variableName, value, type));
19
20 // Store valu based on type
21 switch(type)
22 {
23 // Booleans
24 case EJsonApiStructValueType.TYPE_BOOL:
25 {
26 bool bValue = ToBool(value);
27 json.StoreBoolean(variableName, bValue);
28 break;
29 }
30
31 // Integers
32 case EJsonApiStructValueType.TYPE_INT:
33 {
34 int iValue = value.ToInt();
35 json.StoreInteger(variableName, iValue);
36 break;
37 }
38
39 // Floating decimals
40 case EJsonApiStructValueType.TYPE_FLOAT:
41 {
42 int fValue = value.ToFloat();
43 json.StoreFloat(variableName, fValue);
44 break;
45 }
46
47 // Strings
48 case EJsonApiStructValueType.TYPE_STRING:
49 {
50 json.StoreString(variableName, value);
51 break;
52 }
53 }
54 }
55
56 //------------------------------------------------------------------------------------------------
57 protected static bool ToBool(string value)
58 {
59 return value == "1" || value == "true";
60 }
61
62 //------------------------------------------------------------------------------------------------
63 static bool StringToBool(string str)
64 {
65 switch (str)
66 {
67 case "true": return true;
68 case "false": return false;
69 case "1": return true;
70 case "0": return false;
71 }
72
73 return false;
74 }
75
76 //------------------------------------------------------------------------------------------------
77 static string BoolToString(bool boolean)
78 {
79 if (boolean)
80 return "1";
81
82 return "0";
83 }
84};
85
86//------------------------------------------------------------------------------------------------
94
95//------------------------------------------------------------------------------------------------
98{
99 // Consts
100 protected const string DEFAULT_CONFIG_NAME = "Server setup";
101
102 // Attributes
103 [Attribute("config", UIWidgets.EditBox, "Group tag name for base server configuration")]
104 protected string m_sCategoryConfig;
105
106 [Attribute("", UIWidgets.EditBox, "Group tag name for generic game settings")]
107 protected string m_sCategoryGameConfig;
108
109 [Attribute("", UIWidgets.EditBox, "Group tag name for specific game (scenario) properties")]
111
112 // File properties
113 protected string m_sConfigName;
114
115 // Config properties containers
116 protected ref SCR_DSConfig m_DSConfig = new SCR_DSConfig(); // Config base
117 protected ref DSGameConfig m_DSGameConfig = new DSGameConfig(); // Generic game settings
118 protected ref DSGameProperties m_DSGameProperties = new DSGameProperties(); // Scenario
119 protected ref array<DSMod> m_aMods = {};
120
121 // Unified entries
122 protected ref array<ref Tuple2<string, ref SCR_WidgetListEntry>> m_aDSConfigEntries = {}; // string - tag
123
124 //------------------------------------------------------------------------------------------------
126 void DefineEntriesMap(array<ref SCR_WidgetListEntry> entries)
127 {
128 for (int i = 0, count = entries.Count(); i < count; i++)
129 {
130 m_aDSConfigEntries.Insert(
131 new Tuple2<string, ref SCR_WidgetListEntry>(
132 entries[i].GetGroupTag(),
133 entries[i]
134 )
135 );
136 }
137 }
138
139 //------------------------------------------------------------------------------------------------
140 // Store value API
141 //------------------------------------------------------------------------------------------------
142
143 //------------------------------------------------------------------------------------------------
145 void StoreCategoryToJson(JsonApiStruct json, string tag)
146 {
147 for (int i = 0, count = m_aDSConfigEntries.Count(); i < count; i++)
148 {
149 // Skip different tag
150 if (m_aDSConfigEntries[i].param1 != tag)
151 continue;
152
153 SCR_WidgetListEntry entry = m_aDSConfigEntries[i].param2;
154
155 // Store value
156 SCR_JsonApiStructHandler.StoreValue(
157 json,
158 entry.GetPropertyName(),
159 entry.ValueAsString(),
160 entry.GetType()
161 );
162
163 /*
164 Print(string.Format(
165 "Save - %1 > %2 : %3",
166 m_aDSConfigEntries[i].param1,
167 entry.GetPropertyName(),
168 entry.ValueAsString()
169 ));
170 */
171 }
172 }
173
174 //------------------------------------------------------------------------------------------------
177 {
178 //Print("-------------------------------------");
179
180 for (int i = 0, count = m_aDSConfigEntries.Count(); i < count; i++)
181 {
182 SCR_WidgetListEntry entry = m_aDSConfigEntries[i].param2;
183 if (!entry)
184 continue;
185
186 // Debug
187 //Print(entry.GetPropertyName() + " : " + entry.ValueAsString());
188 }
189
190 //Print("-------------------------------------");
191 }
192
193 //------------------------------------------------------------------------------------------------
194 // Protected
195 //------------------------------------------------------------------------------------------------
196
197 //------------------------------------------------------------------------------------------------
199 protected string DefaultConfigName()
200 {
201 string name = DEFAULT_CONFIG_NAME;
202
203 // Todo: counting and comparing of config names
204
205 return name;
206 }
207};
EDamageType type
base classes for filtering in server browser
Script class aggregating all dedicated server config part together.
void StoreFullJson()
Store values for all categories.
string DefaultConfigName()
Return default config name with number that should be unique to other other configs.
void DefineEntriesMap(array< ref SCR_WidgetListEntry > entries)
Pass entries and define entries map.
ref array< ref Tuple2< string, ref SCR_WidgetListEntry > > m_aDSConfigEntries
void StoreCategoryToJson(JsonApiStruct json, string tag)
Store all values for selected category.
ref DSGameProperties m_DSGameProperties
Handler for json api struct values.
static string BoolToString(bool boolean)
static bool StringToBool(string str)
static bool ToBool(string value)
Configurable class for widget.
string ValueAsString()
Return value from widget in string format.
EJsonApiStructValueType GetType()
string GetPropertyName()
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
SCR_FieldOfViewSettings Attribute
Tuple param1