| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- 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 PlayerStateSaveData {
- public class DataObject {
- public string PlayerState { get; set; }
- }
- public string Version { get; set; }
- public DataObject Data { get; set; }
- protected PlayerState? _data = null;
- public PlayerState? PlayerState {
- 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<PlayerState>(this.Data.PlayerState.Replace("\"NaN\"", "0"), options);
- }
- return this._data;
- }
- }
- public void Set(string key, bool value) {
- this.PlayerState.Set(key, value);
- }
- public void Set(string key, int value) {
- this.PlayerState.Set(key, value);
- }
- public void Set(string key, float value) {
- this.PlayerState.Set(key, value);
- }
- public void Set(string key, double value) {
- this.PlayerState.Set(key, value);
- }
- public void Set(string key, string value) {
- this.PlayerState.Set(key, value);
- }
- public void Set(string key, float[] value) {
- this.PlayerState.Set(key, value);
- }
- public void Set(string key, double[] value) {
- this.PlayerState.Set(key, value);
- }
- public dynamic GetSetting(string key) {
- if (this._data == null) {
- this._data = System.Text.Json.JsonSerializer.Deserialize<PlayerState>(this.Data.PlayerState.Replace("\"NaN\"", "0"));
- }
- if (this._data == null) {
- System.Diagnostics.Debug.WriteLine("PlayerState._data is null");
- return "";
- }
- foreach (Settings setting in this._data._entries)
- 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<PlayerState>(this.Data.PlayerState.Replace("\"NaN\"", "0"));
- }
- if (this._data == null) {
- System.Diagnostics.Debug.WriteLine("PlayerState._data is null");
- return "";
- }
- foreach (Settings setting in _data._entries)
- if (setting.Name == key)
- return setting.StringValue;
- return "";
- }
- public int GetInt(string key) {
- if (this._data == null) {
- this._data = System.Text.Json.JsonSerializer.Deserialize<PlayerState>(this.Data.PlayerState.Replace("\"NaN\"", "0"));
- }
- if (this._data == null) {
- System.Diagnostics.Debug.WriteLine("PlayerState._data is null");
- return 0;
- }
- foreach (Settings setting in _data._entries)
- if (setting.Name == key)
- return setting.IntValue;
- return 0;
- }
- public double GetFloat(string key) {
- if (this._data == null) {
- this._data = System.Text.Json.JsonSerializer.Deserialize<PlayerState>(this.Data.PlayerState.Replace("\"NaN\"", "0"));
- }
- if (this._data == null) {
- System.Diagnostics.Debug.WriteLine("PlayerState._data is null");
- return 0.0f;
- }
- foreach (Settings setting in _data._entries)
- if (setting.Name == key)
- return setting.FloatValue;
- return 0.0f;
- }
- public bool GetBool(string key) {
- if (this._data == null) {
- this._data = System.Text.Json.JsonSerializer.Deserialize<PlayerState>(this.Data.PlayerState.Replace("\"NaN\"", "0"));
- }
- if (this._data == null) {
- System.Diagnostics.Debug.WriteLine("PlayerState._data is null");
- return false;
- }
- foreach (Settings setting in _data._entries)
- if (setting.Name == key)
- return setting.BoolValue;
- return false;
- }
- public double[] GetFloatArray(string key) {
- if (this._data == null) {
- this._data = System.Text.Json.JsonSerializer.Deserialize<PlayerState>(this.Data.PlayerState.Replace("\"NaN\"", "0"));
- }
- if (this._data == null) {
- System.Diagnostics.Debug.WriteLine("PlayerState._data is null");
- return new double[] { };
- }
- foreach (Settings setting in _data._entries)
- if (setting.Name == key)
- return setting.FloatArrayValue;
- return new double[] { };
- }
- }
- }
|