GameSetupSaveData.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using SOTF_Struct.Data;
  2. using SOTF_Struct.Generic;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace SOTF_Savegame_Editor.SOTFSave {
  9. public class GameSetupSaveData {
  10. public class DataObject {
  11. public string GameSetup { get; set; }
  12. }
  13. public string Version { get; set; }
  14. public DataObject Data { get; set; }
  15. protected GameSetup? _data = null;
  16. public GameSetup? GameSetup {
  17. get {
  18. if (this._data == null) {
  19. System.Text.Json.JsonSerializerOptions options = new() {
  20. NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString | System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals,
  21. AllowTrailingCommas = true,
  22. IgnoreReadOnlyFields = true,
  23. IgnoreReadOnlyProperties = true
  24. };
  25. this._data = System.Text.Json.JsonSerializer.Deserialize<GameSetup>(this.Data.GameSetup.Replace("\"NaN\"", "0"), options);
  26. }
  27. return this._data;
  28. }
  29. }
  30. public dynamic GetSetting(string key) {
  31. if (this._data == null) {
  32. this._data = System.Text.Json.JsonSerializer.Deserialize<GameSetup>(this.Data.GameSetup.Replace("\"NaN\"", "0"));
  33. }
  34. if (this._data == null) {
  35. System.Diagnostics.Debug.WriteLine("GameSetup._data is null");
  36. return "";
  37. }
  38. foreach (Settings setting in this._data._settings)
  39. if (setting.Name == key)
  40. if (setting.SettingType == 3)
  41. return setting.StringValue;
  42. else if (setting.SettingType == 0)
  43. return setting.BoolValue;
  44. return "";
  45. }
  46. public string GetString(string key) {
  47. if (this._data == null) {
  48. this._data = System.Text.Json.JsonSerializer.Deserialize<GameSetup>(this.Data.GameSetup.Replace("\"NaN\"", "0"));
  49. }
  50. if (this._data == null) {
  51. System.Diagnostics.Debug.WriteLine("GameSetup._data is null");
  52. return "";
  53. }
  54. foreach (Settings setting in _data._settings)
  55. if (setting.Name == key)
  56. return setting.StringValue;
  57. return "";
  58. }
  59. public string GetString(string key, string Default) {
  60. if (this._data == null) {
  61. this._data = System.Text.Json.JsonSerializer.Deserialize<GameSetup>(this.Data.GameSetup.Replace("\"NaN\"", "0"));
  62. }
  63. if (this._data == null) {
  64. System.Diagnostics.Debug.WriteLine("GameSetup._data is null");
  65. return Default;
  66. }
  67. foreach (Settings setting in _data._settings)
  68. if (setting.Name == key)
  69. return setting.StringValue;
  70. return Default;
  71. }
  72. public int GetInt(string key) {
  73. if (this._data == null) {
  74. this._data = System.Text.Json.JsonSerializer.Deserialize<GameSetup>(this.Data.GameSetup.Replace("\"NaN\"", "0"));
  75. }
  76. if (this._data == null) {
  77. System.Diagnostics.Debug.WriteLine("GameSetup._data is null");
  78. return 0;
  79. }
  80. foreach (Settings setting in _data._settings)
  81. if (setting.Name == key)
  82. return setting.IntValue;
  83. return 0;
  84. }
  85. public int GetInt(string key, int Default) {
  86. if (this._data == null) {
  87. this._data = System.Text.Json.JsonSerializer.Deserialize<GameSetup>(this.Data.GameSetup.Replace("\"NaN\"", "0"));
  88. }
  89. if (this._data == null) {
  90. System.Diagnostics.Debug.WriteLine("GameSetup._data is null");
  91. return Default;
  92. }
  93. foreach (Settings setting in _data._settings)
  94. if (setting.Name == key)
  95. return setting.IntValue;
  96. return Default;
  97. }
  98. public double GetFloat(string key) {
  99. if (this._data == null) {
  100. this._data = System.Text.Json.JsonSerializer.Deserialize<GameSetup>(this.Data.GameSetup.Replace("\"NaN\"", "0"));
  101. }
  102. if (this._data == null) {
  103. System.Diagnostics.Debug.WriteLine("GameSetup._data is null");
  104. return 0.0f;
  105. }
  106. foreach (Settings setting in _data._settings)
  107. if (setting.Name == key)
  108. return setting.FloatValue;
  109. return 0.0f;
  110. }
  111. public double GetFloat(string key, double Default) {
  112. if (this._data == null) {
  113. this._data = System.Text.Json.JsonSerializer.Deserialize<GameSetup>(this.Data.GameSetup.Replace("\"NaN\"", "0"));
  114. }
  115. if (this._data == null) {
  116. System.Diagnostics.Debug.WriteLine("GameSetup._data is null");
  117. return Default;
  118. }
  119. foreach (Settings setting in _data._settings)
  120. if (setting.Name == key)
  121. return setting.FloatValue;
  122. return Default;
  123. }
  124. public bool GetBool(string key) {
  125. if (this._data == null) {
  126. this._data = System.Text.Json.JsonSerializer.Deserialize<GameSetup>(this.Data.GameSetup.Replace("\"NaN\"", "0"));
  127. }
  128. if (this._data == null) {
  129. System.Diagnostics.Debug.WriteLine("GameSetup._data is null");
  130. return false;
  131. }
  132. foreach (Settings setting in _data._settings)
  133. if (setting.Name == key)
  134. return setting.BoolValue;
  135. return false;
  136. }
  137. public bool GetBool(string key, bool Default) {
  138. if (this._data == null) {
  139. this._data = System.Text.Json.JsonSerializer.Deserialize<GameSetup>(this.Data.GameSetup.Replace("\"NaN\"", "0"));
  140. }
  141. if (this._data == null) {
  142. System.Diagnostics.Debug.WriteLine("GameSetup._data is null");
  143. return Default;
  144. }
  145. foreach (Settings setting in _data._settings)
  146. if (setting.Name == key)
  147. return setting.BoolValue;
  148. return Default;
  149. }
  150. public double[] GetFloatArray(string key) {
  151. if (this._data == null) {
  152. this._data = System.Text.Json.JsonSerializer.Deserialize<GameSetup>(this.Data.GameSetup.Replace("\"NaN\"", "0"));
  153. }
  154. if (this._data == null) {
  155. System.Diagnostics.Debug.WriteLine("GameSetup._data is null");
  156. return new double[] {};
  157. }
  158. foreach (Settings setting in _data._settings)
  159. if (setting.Name == key)
  160. return setting.FloatArrayValue;
  161. return new double[] { };
  162. }
  163. }
  164. }