Change configuration to STJ
This commit is contained in:
@@ -2,20 +2,21 @@ using Craftimizer.Simulator.Actions;
|
|||||||
using Craftimizer.Solver;
|
using Craftimizer.Solver;
|
||||||
using Craftimizer.Utils;
|
using Craftimizer.Utils;
|
||||||
using Dalamud.Configuration;
|
using Dalamud.Configuration;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace Craftimizer.Plugin;
|
namespace Craftimizer.Plugin;
|
||||||
|
|
||||||
[Serializable]
|
|
||||||
public class Macro
|
public class Macro
|
||||||
{
|
{
|
||||||
public static event Action<Macro>? OnMacroChanged;
|
public static event Action<Macro>? OnMacroChanged;
|
||||||
|
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
[JsonProperty(PropertyName = "Actions")]
|
[JsonInclude] [JsonPropertyName("Actions")]
|
||||||
private List<ActionType> actions { get; set; } = [];
|
internal List<ActionType> actions { get; set; } = [];
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public IReadOnlyList<ActionType> Actions
|
public IReadOnlyList<ActionType> Actions
|
||||||
{
|
{
|
||||||
@@ -33,7 +34,6 @@ public class Macro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
|
||||||
public class MacroCopyConfiguration
|
public class MacroCopyConfiguration
|
||||||
{
|
{
|
||||||
public enum CopyType
|
public enum CopyType
|
||||||
@@ -72,26 +72,22 @@ public class MacroCopyConfiguration
|
|||||||
public bool CombineMacro { get; set; }
|
public bool CombineMacro { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
public partial class Configuration : IPluginConfiguration
|
||||||
public class Configuration : IPluginConfiguration
|
|
||||||
{
|
{
|
||||||
public int Version { get; set; } = 1;
|
public int Version { get; set; } = 1;
|
||||||
|
|
||||||
public static event Action? OnMacroListChanged;
|
public static event Action? OnMacroListChanged;
|
||||||
|
|
||||||
[JsonProperty(PropertyName = "Macros")]
|
[JsonInclude] [JsonPropertyName("Macros")]
|
||||||
private List<Macro> macros { get; set; } = [];
|
internal List<Macro> macros { get; private set; } = [];
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public IReadOnlyList<Macro> Macros => macros;
|
public IReadOnlyList<Macro> Macros => macros;
|
||||||
public int ReliabilitySimulationCount { get; set; } = 500;
|
public int ReliabilitySimulationCount { get; set; } = 500;
|
||||||
public bool ConditionRandomness { get; set; } = true;
|
public bool ConditionRandomness { get; set; } = true;
|
||||||
|
|
||||||
[JsonConverter(typeof(PopulateConverter))]
|
[JsonPropertyName("SimulatorSolverConfig")]
|
||||||
[JsonProperty(PropertyName = "SimulatorSolverConfig")]
|
|
||||||
public SolverConfig RecipeNoteSolverConfig { get; set; } = SolverConfig.RecipeNoteDefault;
|
public SolverConfig RecipeNoteSolverConfig { get; set; } = SolverConfig.RecipeNoteDefault;
|
||||||
[JsonConverter(typeof(PopulateConverter))]
|
|
||||||
public SolverConfig EditorSolverConfig { get; set; } = SolverConfig.EditorDefault;
|
public SolverConfig EditorSolverConfig { get; set; } = SolverConfig.EditorDefault;
|
||||||
[JsonConverter(typeof(PopulateConverter))]
|
|
||||||
public SolverConfig SynthHelperSolverConfig { get; set; } = SolverConfig.SynthHelperDefault;
|
public SolverConfig SynthHelperSolverConfig { get; set; } = SolverConfig.SynthHelperDefault;
|
||||||
|
|
||||||
public bool EnableSynthHelper { get; set; } = true;
|
public bool EnableSynthHelper { get; set; } = true;
|
||||||
@@ -140,6 +136,26 @@ public class Configuration : IPluginConfiguration
|
|||||||
OnMacroListChanged?.Invoke();
|
OnMacroListChanged?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Save() =>
|
[JsonSerializable(typeof(Configuration))]
|
||||||
Service.PluginInterface.SavePluginConfig(this);
|
internal partial class JsonContext : JsonSerializerContext { }
|
||||||
|
|
||||||
|
public void Save()
|
||||||
|
{
|
||||||
|
var f = Service.PluginInterface.ConfigFile;
|
||||||
|
using var stream = new FileStream(f.FullName, FileMode.Create, FileAccess.Write);
|
||||||
|
JsonSerializer.Serialize(stream, this, JsonContext.Default.Configuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Configuration Load()
|
||||||
|
{
|
||||||
|
// return Service.PluginInterface.GetPluginConfig() as Configuration ?? new();
|
||||||
|
|
||||||
|
var f = Service.PluginInterface.ConfigFile;
|
||||||
|
if (f.Exists)
|
||||||
|
{
|
||||||
|
using var stream = f.OpenRead();
|
||||||
|
return JsonSerializer.Deserialize(stream, JsonContext.Default.Configuration) ?? new();
|
||||||
|
}
|
||||||
|
return new();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Craftimizer.Plugin;
|
namespace Craftimizer.Plugin;
|
||||||
|
|
||||||
@@ -44,7 +45,7 @@ public sealed class Plugin : IDalamudPlugin
|
|||||||
Service.Initialize(this, pluginInterface);
|
Service.Initialize(this, pluginInterface);
|
||||||
|
|
||||||
WindowSystem = new("Craftimizer");
|
WindowSystem = new("Craftimizer");
|
||||||
Configuration = pluginInterface.GetPluginConfig() as Configuration ?? new();
|
Configuration = Configuration.Load();
|
||||||
Hooks = new();
|
Hooks = new();
|
||||||
Chat = new();
|
Chat = new();
|
||||||
IconManager = new();
|
IconManager = new();
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ using Craftimizer.Plugin;
|
|||||||
using Dalamud.Game.Command;
|
using Dalamud.Game.Command;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
namespace Craftimizer.Utils;
|
namespace Craftimizer.Utils;
|
||||||
@@ -66,7 +65,6 @@ public sealed class AttributeCommandManager : IDisposable
|
|||||||
throw new InvalidOperationException($"Failed to register command '{alias}'.");
|
throw new InvalidOperationException($"Failed to register command '{alias}'.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.Debug($"Initalized {RegisteredCommands.Count} commands");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
|
|||||||
Reference in New Issue
Block a user