16 override string GetFileName()
21 override void OnInit()
32 string line_content =
"";
33 string param_name =
"";
34 string param_value =
"";
38 for (
int i = 0; i < file_content.Count(); ++i )
40 line_content = file_content.Get(i);
42 param_content = ParseTextToParameter(line_content);
44 if ( param_content.Count() == 0 )
46 PrintString(GetFileName()+
"("+i.ToString()+
"): Error in config -> Maybe missing '=' !");
50 param_name = param_content.Get(0);
51 param_value = param_content.Get(1);
56 ParseTextToArray(param_value, array_items);
62 if ( array_items.Count() > 0 )
64 m_ConfigParamsArray.Set(param_name, array_items);
66 for (
int j = 0; j < array_items.Count(); ++j )
68 string array_content = array_items.Get(j);
71 array_content_raw.Clear();
73 ParseTextToArray(array_content, array_content_raw);
78 if ( array_content_raw.Count() > 0 )
80 if ( !m_ConfigParamsArrayInArray.Contains(param_name) )
88 for (
int k = 0; k < array_content_raw.Count(); ++k )
90 string params = array_content_raw.Get(k);
95 parameters.Set(p.Get(0), p.Get(1));
99 params_in_array.Insert(parameters);
105 m_ConfigParams.Set(param_name, param_value);
112 void SaveConfigToFile()
120 string variable_name;
121 string variable_value;
125 for ( i = 0; i < m_ConfigParams.Count(); ++i)
127 variable_name = m_ConfigParams.GetKey(i);
128 variable_value = m_ConfigParams.GetElement(i);
130 text = variable_name +
" = " + variable_value;
132 AddNewLineNoSave(text);
135 for ( i = 0; i < m_ConfigParamsArray.Count(); ++i)
137 variable_name = m_ConfigParamsArray.GetKey(i);
138 variable_array = m_ConfigParamsArray.GetElement(i);
140 if ( m_ConfigParamsArrayInArray.Contains(variable_name) )
145 text = variable_name +
" = {";
147 for ( j = 0; j < variable_array.Count(); ++j )
154 text += variable_array.Get(j);
159 AddNewLineNoSave(text);
162 for ( i = 0; i < m_ConfigParamsArrayInArray.Count(); ++i)
164 variable_name = m_ConfigParamsArrayInArray.GetKey(i);
167 text = variable_name +
" = {";
169 if ( variable_param != NULL )
171 for ( j = 0; j < variable_param.Count(); ++j )
180 for ( k = 0; k < params.Count(); ++k )
187 string param_name = params.GetKey(k);
188 string param_value = params.GetElement(k);
190 text += param_name+
"="+param_value;
199 AddNewLineNoSave(text);
205 bool IsTextArray(
string text)
207 if ( text.Length() > 0 && text.Substring(0, 1) ==
"{" )
209 if ( text.Substring(text.Length() - 1, 1) ==
"}" )
222 int pos = text.IndexOf(
"=");
226 string param_name = text.Substring(0, pos).Trim();
227 int pos_end = text.Length() - pos;
228 string param_value = text.Substring(pos + 1, pos_end - 1).Trim();
230 int lenght = param_value.Length();
231 if (lenght > 1 && param_value.Substring(0, 1) ==
"\"" && param_value.Substring(lenght - 1, 1) ==
"\"" )
233 param_value = param_value.Substring(1, lenght - 2);
236 ret.Insert(param_name);
237 ret.Insert(param_value);
245 if ( !IsTextArray(text) )
250 text = text.Substring(1, text.Length() - 2);
252 int pos_array_start = text.IndexOf(
"{");
253 int pos_array_end = text.IndexOf(
"}");
255 if ( pos_array_start > -1 && pos_array_end > -1 )
259 string array_value = text.Substring(pos_array_start , pos_array_end - pos_array_start + 1 );
260 ret.Insert(array_value);
262 pos_array_start = text.IndexOfFrom(pos_array_end,
"{");
263 pos_array_end = text.IndexOfFrom(pos_array_start,
"}");
265 if ( pos_array_start == -1 )
273 text.Split(
",", ret);
282 ParseTextToArray(text, array_items);
288 for (
int i = 0; i < array_items.Count(); ++i )
290 string param = array_items.Get(i);
293 string param_name = t_param.Get(0);
294 string param_value = t_param.Get(1);
296 ret_param.Set(param_name, param_value);
299 ret.Insert(ret_param);
304 string LoadParameter(
string param_name)
308 if ( m_ConfigParams.Contains(param_name) )
310 ret_value = m_ConfigParams.Get(param_name);
318 if ( m_ConfigParamsArray.Contains(param_name) )
320 return m_ConfigParamsArray.Get(param_name);
326 string LoadSubParameter(
string param_name,
int sub_array_index,
string sub_param_name)
332 if ( m_ConfigParamsArrayInArray.Contains(param_name) )
334 sub_arrays = m_ConfigParamsArrayInArray.Get(param_name);
336 if ( sub_arrays != NULL )
338 if ( sub_array_index < sub_arrays.Count() )
340 param = sub_arrays.Get(sub_array_index);
342 if ( param.Contains(sub_param_name) )
344 ret_value = param.Get(sub_param_name);
353 void SaveParameter(
string param_name,
string value,
bool save_in_file =
true)
355 if ( param_name ==
"" || param_name ==
"scene_editor_scene" )
357 Log(
"SaveParameter: "+param_name+
" = "+value,
"");
360 m_ConfigParams.Set(param_name, value);
368 void SaveParameterArray(
string param_name,
TStringArray value,
bool save_in_file =
true)
370 m_ConfigParamsArray.Set(param_name, value);
378 void SaveSubParameterInArray(
string param_name,
int sub_array_index,
string sub_param_name,
string sub_param_value,
bool save_in_file =
true)
382 sub_parameter.Set(sub_param_name, sub_param_value);
390 void RenameParameter(
string old_name,
string new_name,
bool save_in_file =
true)
392 if ( m_ConfigParams.Contains(old_name) )
394 m_ConfigParams.ReplaceKey(old_name, new_name);
403 void RenameParameterArray(
string old_name,
string new_name,
bool save_in_file =
true)
405 if ( m_ConfigParamsArray.Contains(old_name) )
407 m_ConfigParamsArray.ReplaceKey(old_name, new_name);
416 void RemoveParameter(
string name,
bool save_in_file =
true)
418 m_ConfigParams.Remove(
name);
426 void RemoveParameterArray(
string name,
bool save_in_file =
true)
428 m_ConfigParamsArray.Remove(
name);
436 void SetParameterString(
string name,
string value,
bool save_in_file =
true)
438 string s =
"\""+value+
"\"";
439 SaveParameter(
name, s, save_in_file);
442 void SetParameterInt(
string name,
int value,
bool save_in_file =
true)
444 SaveParameter(
name, value.ToString(), save_in_file);
447 void SetParameterFloat(
string name,
float value,
bool save_in_file =
true)
449 SaveParameter(
name, value.ToString(), save_in_file);
452 void SetParameterBool(
string name,
bool value,
bool save_in_file =
true)
454 SaveParameter(
name, value.ToString(), save_in_file);
457 void SetParameterArray(
string name,
TStringArray value,
bool save_in_file =
true)
459 SaveParameterArray(
name, value, save_in_file);
462 void SetSubParameterInArray(
string param_name,
int sub_array_index,
string sub_param_name,
string sub_param_value,
bool save_in_file =
true)
464 SaveSubParameterInArray(param_name, sub_array_index, sub_param_name, sub_param_value, save_in_file);
467 string GetParameterString(
string name)
469 string loaded_param = LoadParameter(
name);
472 if ( loaded_param !=
"" )
475 loaded_param.Split(
"\"", arr);
476 if ( arr.Count() > 0 )
478 ret_value = arr.Get(0);
483 SetParameterString(
name, ret_value);
489 int GetParameterInt(
string name)
491 string loaded_param = LoadParameter(
name);
494 if ( loaded_param !=
"" )
496 ret_value = loaded_param.ToInt();
500 SetParameterInt(
name, ret_value);
506 float GetParameterFloat(
string name)
508 string loaded_param = LoadParameter(
name);
511 if ( loaded_param !=
"" )
513 ret_value = loaded_param.ToFloat();
517 SetParameterFloat(
name, ret_value);
523 bool GetParameterBool(
string name)
525 string loaded_param = LoadParameter(
name);
526 bool ret_value =
false;
528 if ( loaded_param !=
"" )
530 int v = loaded_param.ToInt();
538 SetParameterBool(
name, ret_value);
548 if ( m_ConfigParamsArray.Contains(
name) )
550 ret_value = m_ConfigParamsArray.Get(
name);
555 SetParameterArray(
name, ret_value);
561 string GetSubParameterInArrayString(
string param_name,
int sub_array_index,
string sub_param_name)
563 string loaded_param = LoadSubParameter(param_name, sub_array_index, sub_param_name);
568 if ( loaded_param !=
"" )
571 loaded_param.Split(
"\"", arr);
572 ret_value = arr.Get(1);
578 TStringArray GetAllSubParametersInArrayString(
string param_name,
string sub_param_name)
582 if ( m_ConfigParamsArrayInArray.Contains(param_name) )
588 for (
int i = 0; i < arrays_in_parameter.Count(); ++i )
594 if ( sub_parameter.Contains(sub_param_name) )
596 sub_param = sub_parameter.Get(sub_param_name);
599 ret_value.Insert(sub_param);