diff --git a/Pal.Client/Configuration/ConfigurationManager.cs b/Pal.Client/Configuration/ConfigurationManager.cs index ac2b808..2e8e284 100644 --- a/Pal.Client/Configuration/ConfigurationManager.cs +++ b/Pal.Client/Configuration/ConfigurationManager.cs @@ -39,6 +39,7 @@ namespace Pal.Client.Configuration new JsonSerializerOptions { WriteIndented = true, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }), Encoding.UTF8); + if (queue && config is ConfigurationV7 v7) Saved?.Invoke(this, v7); } @@ -60,7 +61,7 @@ namespace Pal.Client.Configuration var v7 = MigrateToV7(configurationV1); Save(v7, queue: false); - //File.Move(_pluginInterface.ConfigFile.FullName, _pluginInterface.ConfigFile.FullName + ".old", true); + File.Move(_pluginInterface.ConfigFile.FullName, _pluginInterface.ConfigFile.FullName + ".old", true); } } diff --git a/Pal.Client/DependencyInjection/DependencyInjectionContext.cs b/Pal.Client/DependencyInjection/DependencyInjectionContext.cs index d8b5e55..6d2812f 100644 --- a/Pal.Client/DependencyInjection/DependencyInjectionContext.cs +++ b/Pal.Client/DependencyInjection/DependencyInjectionContext.cs @@ -108,10 +108,15 @@ namespace Pal.Client.DependencyInjection _serviceProvider.GetService(); #endif - _serviceProvider.GetRequiredService(); + // set up legacy services + LocalState.PluginInterface = pluginInterface; + LocalState.Mode = _serviceProvider.GetRequiredService().Mode; + + // windows that have logic to open on startup _serviceProvider.GetRequiredService(); - _serviceProvider.GetRequiredService(); - _serviceProvider.GetRequiredService(); + + // initialize components that are mostly self-contained/self-registered + _serviceProvider.GetRequiredService(); _serviceProvider.GetRequiredService(); _serviceProvider.GetRequiredService(); _serviceProvider.GetRequiredService(); diff --git a/Pal.Client/LocalState.cs b/Pal.Client/LocalState.cs index 8713da6..41a125d 100644 --- a/Pal.Client/LocalState.cs +++ b/Pal.Client/LocalState.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.Json; +using Dalamud.Plugin; +using Pal.Client.Configuration; using Pal.Client.Extensions; namespace Pal.Client @@ -17,6 +19,9 @@ namespace Pal.Client private static readonly JsonSerializerOptions JsonSerializerOptions = new() { IncludeFields = true }; private const int CurrentVersion = 4; + internal static DalamudPluginInterface PluginInterface { get; set; } + internal static EMode Mode { get; set; } + public uint TerritoryType { get; set; } public ConcurrentBag Markers { get; set; } = new(); @@ -27,7 +32,7 @@ namespace Pal.Client private void ApplyFilters() { - if (Service.Configuration.Mode == Configuration.EMode.Offline) + if (Mode == EMode.Offline) Markers = new ConcurrentBag(Markers.Where(x => x.Seen || (x.WasImported && x.Imports.Count > 0))); else // ensure old import markers are removed if they are no longer part of a "current" import @@ -121,7 +126,7 @@ namespace Pal.Client public string GetSaveLocation() => GetSaveLocation(TerritoryType); - private static string GetSaveLocation(uint territoryType) => Path.Join(Service.PluginInterface.GetPluginConfigDirectory(), $"{territoryType}.json"); + private static string GetSaveLocation(uint territoryType) => Path.Join(PluginInterface.GetPluginConfigDirectory(), $"{territoryType}.json"); public static void ForEach(Action action) { diff --git a/Pal.Client/Plugin.cs b/Pal.Client/Plugin.cs index 2ee2e09..ddd2399 100644 --- a/Pal.Client/Plugin.cs +++ b/Pal.Client/Plugin.cs @@ -13,6 +13,11 @@ using Pal.Client.Configuration; namespace Pal.Client { + /// + /// With all DI logic elsewhere, this plugin shell really only takes care of a few things around events that + /// need to be sent to different receivers depending on priority or configuration . + /// + /// internal sealed class Plugin : IDisposable { private readonly IServiceProvider _serviceProvider; @@ -33,10 +38,6 @@ namespace Pal.Client _configuration = configuration; _renderAdapter = renderAdapter; - // initialize legacy services - pluginInterface.Create(); - Service.Configuration = configuration; - LanguageChanged(pluginInterface.UiLanguage); pluginInterface.UiBuilder.Draw += Draw; @@ -55,26 +56,23 @@ namespace Pal.Client configWindow.IsOpen = true; } - #region IDisposable Support public void Dispose() { _pluginInterface.UiBuilder.Draw -= Draw; _pluginInterface.UiBuilder.OpenConfigUi -= OpenConfigUi; _pluginInterface.LanguageChanged -= LanguageChanged; } - #endregion private void LanguageChanged(string languageCode) { Localization.Culture = new CultureInfo(languageCode); - _serviceProvider.GetRequiredService().Windows.OfType().Each(w => w.LanguageChanged()); + _serviceProvider.GetRequiredService().Windows.OfType() + .Each(w => w.LanguageChanged()); } private void Draw() { - if (_renderAdapter.Implementation is SimpleRenderer sr) - sr.DrawLayers(); - + _renderAdapter.DrawLayers(); _serviceProvider.GetRequiredService().Draw(); } } diff --git a/Pal.Client/Rendering/RenderAdapter.cs b/Pal.Client/Rendering/RenderAdapter.cs index da8a28f..4afca66 100644 --- a/Pal.Client/Rendering/RenderAdapter.cs +++ b/Pal.Client/Rendering/RenderAdapter.cs @@ -29,5 +29,11 @@ namespace Pal.Client.Rendering public IRenderElement CreateElement(Marker.EType type, Vector3 pos, uint color, bool fill = false) => Implementation.CreateElement(type, pos, color, fill); + + public void DrawLayers() + { + if (Implementation is SimpleRenderer sr) + sr.DrawLayers(); + } } } diff --git a/Pal.Client/Service.cs b/Pal.Client/Service.cs deleted file mode 100644 index b5d0dc5..0000000 --- a/Pal.Client/Service.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using Dalamud.IoC; -using Dalamud.Plugin; -using Pal.Client.Configuration; - -namespace Pal.Client -{ - [Obsolete] - public class Service - { - [PluginService] public static DalamudPluginInterface PluginInterface { get; private set; } = null!; - - internal static IPalacePalConfiguration Configuration { get; set; } = null!; - } -}