From faa35feade5aff515195517e959fe11183ff83ee Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Wed, 15 Feb 2023 14:35:11 +0100 Subject: [PATCH] Config: Few JsonRequired attributes --- .../Configuration/AccountConfigurationV7.cs | 3 + .../Configuration/IPalacePalConfiguration.cs | 5 ++ Pal.Client/DependencyInjection/DIPlugin.cs | 73 +++++++++++++++++++ Pal.Client/Plugin.cs | 11 +-- 4 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 Pal.Client/DependencyInjection/DIPlugin.cs diff --git a/Pal.Client/Configuration/AccountConfigurationV7.cs b/Pal.Client/Configuration/AccountConfigurationV7.cs index 281c68d..2d74075 100644 --- a/Pal.Client/Configuration/AccountConfigurationV7.cs +++ b/Pal.Client/Configuration/AccountConfigurationV7.cs @@ -41,6 +41,7 @@ namespace Pal.Client.Configuration } [JsonInclude] + [JsonRequired] public EFormat Format { get; private set; } = EFormat.Unencrypted; /// @@ -48,11 +49,13 @@ namespace Pal.Client.Configuration /// [JsonPropertyName("Id")] [JsonInclude] + [JsonRequired] public string EncryptedId { get; private set; } = null!; [JsonInclude] public byte[]? Entropy { get; private set; } + [JsonRequired] public string Server { get; init; } = null!; [JsonIgnore] public bool IsUsable => DecryptAccountId() != null; diff --git a/Pal.Client/Configuration/IPalacePalConfiguration.cs b/Pal.Client/Configuration/IPalacePalConfiguration.cs index ecfb8a2..8b10b13 100644 --- a/Pal.Client/Configuration/IPalacePalConfiguration.cs +++ b/Pal.Client/Configuration/IPalacePalConfiguration.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Numerics; using ImGuiNET; +using Newtonsoft.Json; namespace Pal.Client.Configuration { @@ -59,8 +60,12 @@ namespace Pal.Client.Configuration public class MarkerConfiguration { + [JsonRequired] public bool Show { get; set; } + + [JsonRequired] public uint Color { get; set; } + public bool OnlyVisibleAfterPomander { get; set; } public bool Fill { get; set; } } diff --git a/Pal.Client/DependencyInjection/DIPlugin.cs b/Pal.Client/DependencyInjection/DIPlugin.cs new file mode 100644 index 0000000..d64368b --- /dev/null +++ b/Pal.Client/DependencyInjection/DIPlugin.cs @@ -0,0 +1,73 @@ +using Dalamud.Data; +using Dalamud.Game; +using Dalamud.Game.ClientState; +using Dalamud.Game.ClientState.Conditions; +using Dalamud.Game.ClientState.Objects; +using Dalamud.Game.Command; +using Dalamud.Game.Gui; +using Dalamud.Plugin; +using Microsoft.Extensions.DependencyInjection; +using Pal.Client.Properties; + +namespace Pal.Client.DependencyInjection +{ + /// + /// DI-aware Plugin. + /// + internal sealed class DIPlugin : IDalamudPlugin + { + private ServiceProvider? _serviceProvider; + + public string Name => Localization.Palace_Pal; + + public DIPlugin(DalamudPluginInterface pluginInterface, + ClientState clientState, + GameGui gameGui, + ChatGui chatGui, + ObjectTable objectTable, + Framework framework, + Condition condition, + CommandManager commandManager, + DataManager dataManager) + { + IServiceCollection services = new ServiceCollection(); + + // dalamud + services.AddSingleton(this); + services.AddSingleton(pluginInterface); + services.AddSingleton(gameGui); + services.AddSingleton(chatGui); + services.AddSingleton(objectTable); + services.AddSingleton(framework); + services.AddSingleton(condition); + services.AddSingleton(commandManager); + services.AddSingleton(dataManager); + + // palace pal + services.AddSingleton(); + + // build + _serviceProvider = services.BuildServiceProvider(new ServiceProviderOptions + { + ValidateOnBuild = true, + ValidateScopes = true, + }); + + // initialize plugin + _serviceProvider.GetRequiredService(); + } + + public void Dispose() + { + // ensure we're not calling dispose recursively on ourselves + if (_serviceProvider != null) + { + ServiceProvider serviceProvider = _serviceProvider; + _serviceProvider = null; + + serviceProvider.Dispose(); + } + + } + } +} diff --git a/Pal.Client/Plugin.cs b/Pal.Client/Plugin.cs index 1e486ac..60f5098 100644 --- a/Pal.Client/Plugin.cs +++ b/Pal.Client/Plugin.cs @@ -33,9 +33,10 @@ using Pal.Client.Net; namespace Pal.Client { - public class Plugin : IDalamudPlugin + public class Plugin : IDisposable { internal const uint ColorInvisible = 0; + private readonly IDalamudPlugin _dalamudPlugin; private LocalizedChatMessages _localizedChatMessages = new(); @@ -51,10 +52,10 @@ namespace Pal.Client internal ConcurrentQueue NextUpdateObjects { get; } = new(); internal IRenderer Renderer { get; private set; } = null!; - public string Name => Localization.Palace_Pal; - - public Plugin(DalamudPluginInterface pluginInterface, ChatGui chat) + public Plugin(DalamudPluginInterface pluginInterface, ChatGui chat, IDalamudPlugin dalamudPlugin) { + _dalamudPlugin = dalamudPlugin; + LanguageChanged(pluginInterface.UiLanguage); PluginLog.Information($"Install source: {pluginInterface.SourceRepository}"); @@ -669,7 +670,7 @@ namespace Pal.Client disposable.Dispose(); if (Service.Configuration.Renderer.SelectedRenderer == ERenderer.Splatoon) - Renderer = new SplatoonRenderer(Service.PluginInterface, this); + Renderer = new SplatoonRenderer(Service.PluginInterface, _dalamudPlugin); else Renderer = new SimpleRenderer(); }