Advertisement
Guest User

Untitled

a guest
Jun 8th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Config_Manager extends JsonObject config (RPGO_SoldierSkills);
  2.  
  3. var config array<string> ConfigProperties;
  4.  
  5. static function Config_Manager GetConfigManager()
  6. {
  7.     return Config_Manager(class'Engine'.static.FindClassDefaultObject("Config_Manager"));
  8. }
  9.  
  10. static function SetConfigString(string PropertyName, coerce string Value)
  11. {
  12.     local Config_Manager ConfigManager;
  13.  
  14.     ConfigManager = GetConfigManager();
  15.     ConfigManager.SetStringValue(PropertyName, Value);
  16. }
  17.  
  18. static function int GetConfigIntValue(coerce string PropertyName, optional name Namespace)
  19. {
  20.     return int(GetConfigStringValue(PropertyName, Namespace));
  21. }
  22.  
  23. static function int GetConfigFloatValue(coerce string PropertyName, optional name Namespace)
  24. {
  25.     return float(GetConfigStringValue(PropertyName, Namespace));
  26. }
  27.  
  28. static function name GetConfigNameValue(coerce string PropertyName, optional name Namespace)
  29. {
  30.     return name(GetConfigStringValue(PropertyName, Namespace));
  31. }
  32.  
  33. static function int GetConfigByteValue(coerce string PropertyName, optional name Namespace)
  34. {
  35.     return byte(GetConfigStringValue(PropertyName, Namespace));
  36. }
  37.  
  38. static function bool GetConfigBoolValue(coerce string PropertyName, optional name Namespace)
  39. {
  40.     return bool(GetConfigStringValue(PropertyName, Namespace));
  41. }
  42.  
  43. static function vector GetConfigVectorValue(coerce string PropertyName, optional name Namespace)
  44. {
  45.     local Config_TaggedConfigProperty ConfigProperty;
  46.  
  47.     ConfigProperty = GetConfigProperty(PropertyName);
  48.  
  49.     if (ConfigProperty != none)
  50.     {
  51.         return ConfigProperty.GetVectorValue();
  52.     }
  53.  
  54.     return vect(0, 0, 0);
  55. }
  56.  
  57.  
  58. static function array<string> GetConfigArrayValue(coerce string PropertyName, optional name Namespace)
  59. {
  60.     local Config_TaggedConfigProperty ConfigProperty;
  61.     local array<string> Empty${1}< ${3} >
  62.  
  63.     ConfigProperty = GetConfigProperty(PropertyName, Namespace);
  64.  
  65.     if (ConfigProperty != none)
  66.     {
  67.         return ConfigProperty.GetArrayValue();
  68.     }
  69.  
  70.     EmptyArray.Length = 0; // Prevent unassigned warning
  71.  
  72.     return Empty${1}< ${3} >
  73. }
  74.  
  75.  
  76. static function string GetConfigStringValue(coerce string PropertyName, optional name Namespace)
  77. {
  78.     local Config_TaggedConfigProperty ConfigProperty;
  79.  
  80.     ConfigProperty = GetConfigProperty(PropertyName, Namespace);
  81.  
  82.     if (ConfigProperty != none)
  83.     {
  84.         return ConfigProperty.GetValue();
  85.     }
  86.  
  87.     return  "";
  88. }
  89.  
  90. static function string GetConfigTagValue(coerce string PropertyName, optional name Namespace)
  91. {
  92.     local Config_TaggedConfigProperty ConfigProperty;
  93.  
  94.     ConfigProperty = GetConfigProperty(PropertyName, Namespace);
  95.  
  96.     if (ConfigProperty != none)
  97.     {
  98.         return ConfigProperty.GetTagValue();
  99.     }
  100.  
  101.     return  "";
  102. }
  103.  
  104.  
  105. static function Config_TaggedConfigProperty GetConfigProperty(coerce string PropertyName, optional name Namespace)
  106. {
  107.     local Config_Manager ConfigManager;
  108.     local JSonObject JSonObject, JSonObjectProperty;
  109.     local Config_TaggedConfigProperty ConfigProperty;
  110.     local string SerializedConfigProperty;
  111.  
  112.     ConfigManager = GetConfigManager();
  113.  
  114.     //`LOG(default.class @ GetFuncName() @ ConfigManager @ `ShowVar(PropertyName) @ `ShowVar(Namespace),, 'RPG');
  115.  
  116.     if (Namespace != '')
  117.     {
  118.         PropertyName $= ":" $ Namespace;
  119.     }
  120.  
  121.     foreach ConfigManager.ConfigProperties(SerializedConfigProperty)
  122.     {
  123.         //`LOG(default.class @ GetFuncName() @ `ShowVar(SerializedConfigProperty),, 'RPG');
  124.  
  125.         JSonObject = class'JSonObject'.static.DecodeJson(SanitizeJson(SerializedConfigProperty));
  126.  
  127.         //`LOG(default.class @ GetFuncName() @ `ShowObj(JSonObject),, 'RPG');
  128.  
  129.         if (JSonObject != none)
  130.         {
  131.             ConfigProperty = new class'Config_TaggedConfigProperty';
  132.             JSonObjectProperty = JSonObject.GetObject(PropertyName);
  133.  
  134.             if (JSonObjectProperty != none)
  135.             {
  136.                 //`LOG(default.class @ GetFuncName() @ `ShowObj(JSonObjectProperty),, 'RPG');
  137.                 ConfigProperty.Deserialize(JSonObjectProperty);
  138.                 return ConfigProperty;
  139.             }
  140.         }
  141.     }
  142.  
  143.     `LOG(default.class @ GetFuncName() @ "could not find config property for" @ PropertyName,, 'RPG');
  144.  
  145.     return none;
  146. }
  147.  
  148. static function string SanitizeJson(string Json)
  149. {
  150.     local string Buffer;
  151.  
  152.     Buffer = Repl(Repl(Repl(Json, "\n", ""), " ", ""), "    ", "");
  153.  
  154.     if (CountCharacters(Buffer, "{") != CountCharacters(Buffer, "}"))
  155.     {
  156.         return "";
  157.     }
  158.  
  159.     Buffer = LTrimToFirstBracket(RTrimToFirstBracket(Buffer));
  160.  
  161.     return Buffer;
  162. }
  163.  
  164. static final function int CountCharacters(coerce string S, string Character)
  165. {
  166.     local int Count, Index;
  167.  
  168.     for (Index = 1; Index <= Len(S); Index++)
  169.     {
  170.         if (Left(S, 1) == Character)
  171.         {
  172.             Count++;
  173.         }
  174.         S = Right(S, Len(S) - 1);
  175.     }
  176.  
  177.     return Count;
  178. }
  179.  
  180. static final function string LTrimToFirstBracket(coerce string S)
  181. {
  182.     while (Left(S, 1) != "{")
  183.         S = Right(S, Len(S) - 1);
  184.     return S;
  185. }
  186. static final function string RTrimToFirstBracket(coerce string S)
  187. {
  188.     while (Right(S, 1) != "}")
  189.         S = Left(S, Len(S) - 1);
  190.     return S;
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement