Overlay default values if it doesn't exist
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using Craftimizer.Simulator.Actions;
|
using Craftimizer.Simulator.Actions;
|
||||||
using Craftimizer.Solver;
|
using Craftimizer.Solver;
|
||||||
|
using Craftimizer.Utils;
|
||||||
using Dalamud.Configuration;
|
using Dalamud.Configuration;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
@@ -84,7 +85,9 @@ public class Configuration : IPluginConfiguration
|
|||||||
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))]
|
||||||
public SolverConfig SimulatorSolverConfig { get; set; } = SolverConfig.SimulatorDefault;
|
public SolverConfig SimulatorSolverConfig { get; set; } = SolverConfig.SimulatorDefault;
|
||||||
|
[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;
|
||||||
public bool ShowOptimalMacroStat { get; set; } = true;
|
public bool ShowOptimalMacroStat { get; set; } = true;
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Craftimizer.Utils;
|
||||||
|
|
||||||
|
public class PopulateConverter : JsonConverter
|
||||||
|
{
|
||||||
|
public override bool CanConvert(Type objectType) =>
|
||||||
|
objectType.GetConstructor(Type.EmptyTypes) != null;
|
||||||
|
|
||||||
|
public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
existingValue ??= Activator.CreateInstance(objectType) ?? throw new ArgumentException($"Could not create object of type {objectType}", nameof(objectType));
|
||||||
|
serializer.Populate(reader, existingValue);
|
||||||
|
return existingValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||||
|
{
|
||||||
|
serializer.Serialize(writer, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user