DayZ 1.24
Loading...
Searching...
No Matches
PluginLocalProfile.c
Go to the documentation of this file.
2{
7
9 {
10 m_ConfigParams = new map<string, string>;
11 m_ConfigParamsArray = new map<string, ref TStringArray>;
12 m_ConfigParamsInArray = new map<string, ref map<string, string>>;
13 m_ConfigParamsArrayInArray = new map<string, ref array<ref map<string, string>>>;
14 }
15
16 override string GetFileName()
17 {
19 }
20
21 override void OnInit()
22 {
23 super.OnInit();
24
25 LoadConfigFile();
26 }
27
29 {
30 TStringArray file_content = GetFileContent();
31
32 string line_content = "";
33 string param_name = "";
34 string param_value = "";
36 int pos_sep = -1;
37
38 for (int i = 0; i < file_content.Count(); ++i)
39 {
41
42 param_content = ParseTextToParameter(line_content);
43
44 if (param_content.Count() == 0)
45 {
46 PrintString(GetFileName() + "(" + i.ToString() + "): Error in config -> Maybe missing '=' !");
47 return false;
48 }
49
52
53 //{{name = apple, damage = 0.5, quantity = 2},{name = banana, damage = 0.5, quantity = 2}}
54
56 ParseTextToArray(param_value, array_items);
57 //{name = apple, damage = 0.5, quantity = 2}
58 //{name = banana, damage = 0.5, quantity = 2}
59
61
62 if (array_items.Count() > 0)
63 {
64 m_ConfigParamsArray.Set(param_name, array_items);
65
66 for (int j = 0; j < array_items.Count(); ++j)
67 {
68 string array_content = array_items.Get(j);
69 //{name = apple, damage = 0.5, quantity = 2}
70
71 array_content_raw.Clear();
72
73 ParseTextToArray(array_content, array_content_raw);
74 //name = apple
75 //damage = 0.5
76 //quantity = 2
77
78 if (array_content_raw.Count() > 0)
79 {
80 if (!m_ConfigParamsArrayInArray.Contains(param_name))
81 m_ConfigParamsArrayInArray.Set(param_name, new array<ref map<string, string>>);
82
83 array<ref map<string, string>> params_in_array = m_ConfigParamsArrayInArray.Get(param_name);
85
86 for (int k = 0; k < array_content_raw.Count(); ++k)
87 {
88 string params = array_content_raw.Get(k);
89 TStringArray p = ParseTextToParameter(params);
90
91 if (p.Count() == 2)
92 parameters.Set(p.Get(0), p.Get(1));
93 }
94
96 }
97 }
98 }
99 else
100 m_ConfigParams.Set(param_name, param_value);
101 }
102
103 return true;
104 }
105
107 {
108 ClearFileNoSave();
109
110 int i;
111 int j;
112 int k;
113
114 string variable_name;
115 string variable_value;
116 string text;
118
119 for (i = 0; i < m_ConfigParams.Count(); ++i)
120 {
121 variable_name = m_ConfigParams.GetKey(i);
122 variable_value = m_ConfigParams.GetElement(i);
123
125
126 AddNewLineNoSave(text);
127 }
128
129 for (i = 0; i < m_ConfigParamsArray.Count(); ++i)
130 {
131 variable_name = m_ConfigParamsArray.GetKey(i);
132 variable_array = m_ConfigParamsArray.GetElement(i);
133
134 if (m_ConfigParamsArrayInArray.Contains(variable_name))
135 continue;
136
137 text = variable_name + " = {";
138
139 for (j = 0; j < variable_array.Count(); ++j)
140 {
141 if (j > 0)
142 text += ",";
143
144 text += variable_array.Get(j);
145 }
146
147 text += "}";
148
149 AddNewLineNoSave(text);
150 }
151
152 for (i = 0; i < m_ConfigParamsArrayInArray.Count(); ++i)
153 {
154 variable_name = m_ConfigParamsArrayInArray.GetKey(i);
155 array<ref map<string, string>> variable_param = m_ConfigParamsArrayInArray.GetElement(i);
156
157 text = variable_name + " = {";
158
159 if (variable_param != NULL)
160 {
161 for (j = 0; j < variable_param.Count(); ++j)
162 {
163 if (j > 0)
164 text += ",";
165 text += "{";
166
168 for (k = 0; k < params.Count(); ++k)
169 {
170 if (k > 0)
171 text += ",";
172
173 string param_name = params.GetKey(k);
174 string param_value = params.GetElement(k);
175
176 text += param_name + "=" + param_value;
177 }
178
179 text += "}";
180 }
181 }
182
183 text += "}";
184
185 AddNewLineNoSave(text);
186 }
187
188 SaveFile();
189 }
190
191 bool IsTextArray(string text)
192 {
193 if (text.Length() > 0 && text.Substring(0, 1) == "{")
194 {
195 if (text.Substring(text.Length() - 1, 1) == "}")
196 return true;
197 }
198
199 return false;
200 }
201
203 {
205
206 int pos = text.IndexOf("=");
207
208 if (pos > 0)
209 {
210 string param_name = text.Substring(0, pos).Trim();
211 int pos_end = text.Length() - pos;
212 string param_value = text.Substring(pos + 1, pos_end - 1).Trim();
213
214 int lenght = param_value.Length();
215 if (lenght > 1 && param_value.Substring(0, 1) == "\"" && param_value.Substring(lenght - 1, 1) == "\"")
216 param_value = param_value.Substring(1, lenght - 2);
217
218 ret.Insert(param_name);
219 ret.Insert(param_value);
220 }
221
222 return ret;
223 }
224
226 {
227 if (!IsTextArray(text))
228 return NULL;
229
230 text = text.Substring(1, text.Length() - 2);
231
232 int pos_array_start = text.IndexOf("{");
233 int pos_array_end = text.IndexOf("}");
234
235 if (pos_array_start > -1 && pos_array_end > -1)
236 {
237 while (true)
238 {
240 ret.Insert(array_value);
241
242 pos_array_start = text.IndexOfFrom(pos_array_end, "{");
243 pos_array_end = text.IndexOfFrom(pos_array_start, "}");
244
245 if (pos_array_start == -1)
246 break;
247 }
248 }
249 else
250 text.Split(",", ret);
251
252 return ret;
253 }
254
256 {
258 ParseTextToArray(text, array_items);
259
261
263
264 for (int i = 0; i < array_items.Count(); ++i)
265 {
266 string param = array_items.Get(i);
267 TStringArray t_param = ParseTextToParameter(param);
268
269 string param_name = t_param.Get(0);
270 string param_value = t_param.Get(1);
271
273 }
274
275 ret.Insert(ret_param);
276
277 return ret;
278 }
279
281 {
282 string ret_value = STRING_EMPTY;
283
284 if (m_ConfigParams.Contains(param_name))
285 ret_value = m_ConfigParams.Get(param_name);
286
287 return ret_value;
288 }
289
291 {
292 if (m_ConfigParamsArray.Contains(param_name))
293 return m_ConfigParamsArray.Get(param_name);
294
295 return NULL;
296 }
297
299 {
300 string ret_value = STRING_EMPTY;
303
304 if (m_ConfigParamsArrayInArray.Contains(param_name))
305 {
306 sub_arrays = m_ConfigParamsArrayInArray.Get(param_name);
307
308 if (sub_arrays != NULL)
309 {
310 if (sub_array_index < sub_arrays.Count())
311 {
313
314 if (param.Contains(sub_param_name))
316 }
317 }
318 }
319
320 return ret_value;
321 }
322
323 void SaveParameter(string param_name, string value, bool save_in_file = true)
324 {
325 if (param_name == "" || param_name == "scene_editor_scene")
326 Log("SaveParameter: " + param_name + " = " + value, "");
327
328 m_ConfigParams.Set(param_name, value);
329
330 if (save_in_file)
331 SaveConfigToFile();
332 }
333
335 {
336 m_ConfigParamsArray.Set(param_name, value);
337
338 if (save_in_file)
339 SaveConfigToFile();
340 }
341
343 {
344 array<ref map<string, string>> sub_arrays = m_ConfigParamsArrayInArray.Get(param_name);
347
348 if (save_in_file)
349 SaveConfigToFile();
350 }
351
352 void RenameParameter(string old_name, string new_name, bool save_in_file = true)
353 {
354 if (m_ConfigParams.Contains(old_name))
355 {
356 m_ConfigParams.ReplaceKey(old_name, new_name);
357
358 if (save_in_file)
359 SaveConfigToFile();
360 }
361 }
362
363 void RenameParameterArray(string old_name, string new_name, bool save_in_file = true)
364 {
365 if (m_ConfigParamsArray.Contains(old_name))
366 {
367 m_ConfigParamsArray.ReplaceKey(old_name, new_name);
368
369 if (save_in_file)
370 SaveConfigToFile();
371 }
372 }
373
374 void RemoveParameter(string name, bool save_in_file = true)
375 {
376 m_ConfigParams.Remove(name);
377
378 if (save_in_file)
379 SaveConfigToFile();
380 }
381
382 void RemoveParameterArray(string name, bool save_in_file = true)
383 {
384 m_ConfigParamsArray.Remove(name);
385
386 if (save_in_file)
387 SaveConfigToFile();
388 }
389
390 void SetParameterString(string name, string value, bool save_in_file = true)
391 {
392 string s = "\"" + value + "\"";
393 SaveParameter(name, s, save_in_file);
394 }
395
396 void SetParameterInt(string name, int value, bool save_in_file = true)
397 {
398 SaveParameter(name, value.ToString(), save_in_file);
399 }
400
401 void SetParameterFloat(string name, float value, bool save_in_file = true)
402 {
403 SaveParameter(name, value.ToString(), save_in_file);
404 }
405
406 void SetParameterBool(string name, bool value, bool save_in_file = true)
407 {
408 SaveParameter(name, value.ToString(), save_in_file);
409 }
410
412 {
413 SaveParameterArray(name, value, save_in_file);
414 }
415
420
422 {
423 string loaded_param = LoadParameter(name);
424 string ret_value = STRING_EMPTY;
425
426 if (loaded_param != "")
427 {
429 loaded_param.Split("\"", arr);
430 if (arr.Count() > 0)
431 ret_value = arr.Get(0);
432 }
433 else
434 SetParameterString(name, ret_value);
435
436 return ret_value;
437 }
438
440 {
441 string loaded_param = LoadParameter(name);
442 int ret_value = 0;
443
444 if (loaded_param != "")
445 ret_value = loaded_param.ToInt();
446 else
447 SetParameterInt(name, ret_value);
448
449 return ret_value;
450 }
451
453 {
454 string loaded_param = LoadParameter(name);
455 float ret_value = 0;
456
457 if (loaded_param != "")
458 ret_value = loaded_param.ToFloat();
459 else
460 SetParameterFloat(name, ret_value);
461
462 return ret_value;
463 }
464
466 {
467 string loaded_param = LoadParameter(name);
468 bool ret_value = false;
469
470 if (loaded_param != "")
471 {
472 int v = loaded_param.ToInt();
473 if (v == 1)
474 ret_value = true;
475 }
476 else
477 SetParameterBool(name, ret_value);
478
479 return ret_value;
480 }
481
483 {
485
486 if (m_ConfigParamsArray.Contains(name))
487 ret_value = m_ConfigParamsArray.Get(name);
488 else
489 {
491 SetParameterArray(name, ret_value);
492 }
493
494 return ret_value;
495 }
496
498 {
499 string loaded_param = LoadSubParameter(param_name, sub_array_index, sub_param_name);
500 string ret_value = STRING_EMPTY;
501
503
504 if (loaded_param != "")
505 {
506 arr.Clear();
507 loaded_param.Split("\"", arr);
508 ret_value = arr.Get(1);
509 }
510
511 return ret_value;
512 }
513
515 {
517
518 if (m_ConfigParamsArrayInArray.Contains(param_name))
519 {
521
522 array<ref map<string, string>> arrays_in_parameter = m_ConfigParamsArrayInArray.Get(param_name);
523
524 for (int i = 0; i < arrays_in_parameter.Count(); ++i)
525 {
527
528 string sub_param = STRING_EMPTY;
529
530 if (sub_parameter.Contains(sub_param_name))
532
533 ret_value.Insert(sub_param);
534 }
535 }
536
537 return ret_value;
538 }
539}
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
class LogTemplates Log(string message, LogTemplateID template_id=0)
Creates debug log (optional) from LogTemplate which are registred.
TStringArray ParseTextToArray(string text, out TStringArray ret)
array< ref map< string, string > > ParseTextArrayToParameters(string text)
TStringArray LoadParameterArray(string param_name)
void SetParameterString(string name, string value, bool save_in_file=true)
override string GetFileName()
ref map< string, ref array< ref map< string, string > > > m_ConfigParamsArrayInArray
bool IsTextArray(string text)
void SetParameterBool(string name, bool value, bool save_in_file=true)
void SaveParameterArray(string param_name, TStringArray value, bool save_in_file=true)
override void OnInit()
void SetSubParameterInArray(string param_name, int sub_array_index, string sub_param_name, string sub_param_value, bool save_in_file=true)
bool GetParameterBool(string name)
TStringArray GetAllSubParametersInArrayString(string param_name, string sub_param_name)
float GetParameterFloat(string name)
void RenameParameterArray(string old_name, string new_name, bool save_in_file=true)
TStringArray ParseTextToParameter(string text)
void SaveParameter(string param_name, string value, bool save_in_file=true)
void SetParameterFloat(string name, float value, bool save_in_file=true)
TStringArray GetParameterArray(string name)
ref map< string, string > m_ConfigParams
void RemoveParameterArray(string name, bool save_in_file=true)
void RenameParameter(string old_name, string new_name, bool save_in_file=true)
string LoadParameter(string param_name)
string LoadSubParameter(string param_name, int sub_array_index, string sub_param_name)
void RemoveParameter(string name, bool save_in_file=true)
void SetParameterInt(string name, int value, bool save_in_file=true)
int GetParameterInt(string name)
void SaveSubParameterInArray(string param_name, int sub_array_index, string sub_param_name, string sub_param_value, bool save_in_file=true)
void SetParameterArray(string name, TStringArray value, bool save_in_file=true)
string GetSubParameterInArrayString(string param_name, int sub_array_index, string sub_param_name)
string GetParameterString(string name)
ref map< string, ref TStringArray > m_ConfigParamsArray
ref map< string, ref map< string, string > > m_ConfigParamsInArray
override string GetFileName()
const string CFG_FILE_USER_PROFILE
Definition constants.c:230
array< string > TStringArray
Definition EnScript.c:666
void PrintString(string s)
Helper for printing out string expression. Example: PrintString("Hello " + var);.
Definition EnScript.c:344
const string STRING_EMPTY
Definition constants.c:54