93 lines
2.0 KiB
C#
93 lines
2.0 KiB
C#
using Dalamud.Configuration;
|
|
using Dalamud.Plugin;
|
|
using Ktisis.Structs.Env;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Xml.Linq;
|
|
|
|
namespace VoidBox;
|
|
|
|
[Serializable]
|
|
public class Configuration : IPluginConfiguration
|
|
{
|
|
private static readonly JsonSerializer _jsonSerializer = JsonSerializer.CreateDefault();
|
|
|
|
[NonSerialized]
|
|
private IDalamudPluginInterface? _pluginInterface;
|
|
|
|
[JsonProperty]
|
|
private Guid _loginGuid;
|
|
[NonSerialized]
|
|
private SavedEnv? _loginEnv;
|
|
|
|
[JsonProperty]
|
|
private Guid _housingGuid = new("4e4e2dbc-6bda-4b33-95f1-0865d939498a");
|
|
[NonSerialized]
|
|
private SavedEnv? _housingEnv;
|
|
|
|
public int Version { get; set; } = 0;
|
|
|
|
public bool IsEnabled = true;
|
|
|
|
public List<SavedEnv> Envs = [];
|
|
|
|
[JsonIgnore]
|
|
public SavedEnv? LoginEnv
|
|
{
|
|
get => _loginEnv;
|
|
set
|
|
{
|
|
_loginEnv = value;
|
|
_loginGuid = value?.Id ?? default;
|
|
}
|
|
}
|
|
|
|
[JsonIgnore]
|
|
public SavedEnv? HousingEnv
|
|
{
|
|
get => _housingEnv;
|
|
set
|
|
{
|
|
_housingEnv = value;
|
|
_housingGuid = value?.Id ?? default;
|
|
}
|
|
}
|
|
|
|
internal void Initialize(IDalamudPluginInterface pluginInterface)
|
|
{
|
|
_pluginInterface = pluginInterface;
|
|
|
|
_loginEnv = Service.Envs.FirstOrDefault(v => v.Env.Id == _loginGuid).Env;
|
|
_housingEnv = Service.Envs.FirstOrDefault(v => v.Env.Id == _housingGuid).Env;
|
|
}
|
|
|
|
public void Save()
|
|
{
|
|
_pluginInterface!.SavePluginConfig(this);
|
|
}
|
|
}
|
|
|
|
public sealed record SavedEnv
|
|
{
|
|
public static readonly SavedEnv Unchanged = new(default, "Unchanged", null);
|
|
|
|
public SavedEnv(string name, EnvState env)
|
|
: this(Guid.NewGuid(), name, new EnvState?(env))
|
|
{
|
|
}
|
|
|
|
private SavedEnv(Guid id, string name, EnvState? env)
|
|
{
|
|
Id = id;
|
|
Name = name;
|
|
Env = env;
|
|
}
|
|
|
|
public Guid Id { get; set; }
|
|
public string Name { get; set; }
|
|
public EnvState? Env { get; }
|
|
}
|