| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- using SOTF_Struct.Data;
- using SOTF_Struct.Generic;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace SOTF_Savegame_Editor.SOTFSave {
- public class GameSetupSaveData {
- public class DataObject {
- public string GameSetup { get; set; }
- }
- public string Version { get; set; }
- public DataObject Data { get; set; }
- protected GameSetup? _data = null;
- public GameSetup? GameSetup {
- get {
- if (this._data == null) {
- System.Text.Json.JsonSerializerOptions options = new() {
- NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString | System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals,
- AllowTrailingCommas = true,
- IgnoreReadOnlyFields = true,
- IgnoreReadOnlyProperties = true
- };
- this._data = System.Text.Json.JsonSerializer.Deserialize<GameSetup>(this.Data.GameSetup.Replace("\"NaN\"", "0"), options);
- }
- return this._data;
- }
- }
- public dynamic GetSetting(string key) {
- if (this._data == null) {
- this._data = System.Text.Json.JsonSerializer.Deserialize<GameSetup>(this.Data.GameSetup.Replace("\"NaN\"", "0"));
- }
- if (this._data == null) {
- System.Diagnostics.Debug.WriteLine("GameSetup._data is null");
- return "";
- }
- foreach (Settings setting in this._data._settings)
- if (setting.Name == key)
- if (setting.SettingType == 3)
- return setting.StringValue;
- else if (setting.SettingType == 0)
- return setting.BoolValue;
- return "";
- }
- public string GetString(string key) {
- if (this._data == null) {
- this._data = System.Text.Json.JsonSerializer.Deserialize<GameSetup>(this.Data.GameSetup.Replace("\"NaN\"", "0"));
- }
- if (this._data == null) {
- System.Diagnostics.Debug.WriteLine("GameSetup._data is null");
- return "";
- }
- foreach (Settings setting in _data._settings)
- if (setting.Name == key)
- return setting.StringValue;
- return "";
- }
- public string GetString(string key, string Default) {
- if (this._data == null) {
- this._data = System.Text.Json.JsonSerializer.Deserialize<GameSetup>(this.Data.GameSetup.Replace("\"NaN\"", "0"));
- }
- if (this._data == null) {
- System.Diagnostics.Debug.WriteLine("GameSetup._data is null");
- return Default;
- }
- foreach (Settings setting in _data._settings)
- if (setting.Name == key)
- return setting.StringValue;
- return Default;
- }
- public int GetInt(string key) {
- if (this._data == null) {
- this._data = System.Text.Json.JsonSerializer.Deserialize<GameSetup>(this.Data.GameSetup.Replace("\"NaN\"", "0"));
- }
- if (this._data == null) {
- System.Diagnostics.Debug.WriteLine("GameSetup._data is null");
- return 0;
- }
- foreach (Settings setting in _data._settings)
- if (setting.Name == key)
- return setting.IntValue;
- return 0;
- }
- public int GetInt(string key, int Default) {
- if (this._data == null) {
- this._data = System.Text.Json.JsonSerializer.Deserialize<GameSetup>(this.Data.GameSetup.Replace("\"NaN\"", "0"));
- }
- if (this._data == null) {
- System.Diagnostics.Debug.WriteLine("GameSetup._data is null");
- return Default;
- }
- foreach (Settings setting in _data._settings)
- if (setting.Name == key)
- return setting.IntValue;
- return Default;
- }
- public double GetFloat(string key) {
- if (this._data == null) {
- this._data = System.Text.Json.JsonSerializer.Deserialize<GameSetup>(this.Data.GameSetup.Replace("\"NaN\"", "0"));
- }
- if (this._data == null) {
- System.Diagnostics.Debug.WriteLine("GameSetup._data is null");
- return 0.0f;
- }
- foreach (Settings setting in _data._settings)
- if (setting.Name == key)
- return setting.FloatValue;
- return 0.0f;
- }
- public double GetFloat(string key, double Default) {
- if (this._data == null) {
- this._data = System.Text.Json.JsonSerializer.Deserialize<GameSetup>(this.Data.GameSetup.Replace("\"NaN\"", "0"));
- }
- if (this._data == null) {
- System.Diagnostics.Debug.WriteLine("GameSetup._data is null");
- return Default;
- }
- foreach (Settings setting in _data._settings)
- if (setting.Name == key)
- return setting.FloatValue;
- return Default;
- }
- public bool GetBool(string key) {
- if (this._data == null) {
- this._data = System.Text.Json.JsonSerializer.Deserialize<GameSetup>(this.Data.GameSetup.Replace("\"NaN\"", "0"));
- }
- if (this._data == null) {
- System.Diagnostics.Debug.WriteLine("GameSetup._data is null");
- return false;
- }
- foreach (Settings setting in _data._settings)
- if (setting.Name == key)
- return setting.BoolValue;
- return false;
- }
- public bool GetBool(string key, bool Default) {
- if (this._data == null) {
- this._data = System.Text.Json.JsonSerializer.Deserialize<GameSetup>(this.Data.GameSetup.Replace("\"NaN\"", "0"));
- }
- if (this._data == null) {
- System.Diagnostics.Debug.WriteLine("GameSetup._data is null");
- return Default;
- }
- foreach (Settings setting in _data._settings)
- if (setting.Name == key)
- return setting.BoolValue;
- return Default;
- }
- public double[] GetFloatArray(string key) {
- if (this._data == null) {
- this._data = System.Text.Json.JsonSerializer.Deserialize<GameSetup>(this.Data.GameSetup.Replace("\"NaN\"", "0"));
- }
- if (this._data == null) {
- System.Diagnostics.Debug.WriteLine("GameSetup._data is null");
- return new double[] {};
- }
- foreach (Settings setting in _data._settings)
- if (setting.Name == key)
- return setting.FloatArrayValue;
- return new double[] { };
- }
- }
- }
|