DI: Remove Service class
This commit is contained in:
parent
e27f5a3201
commit
5c82382161
@ -39,6 +39,7 @@ namespace Pal.Client.Configuration
|
|||||||
new JsonSerializerOptions
|
new JsonSerializerOptions
|
||||||
{ WriteIndented = true, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }),
|
{ WriteIndented = true, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }),
|
||||||
Encoding.UTF8);
|
Encoding.UTF8);
|
||||||
|
|
||||||
if (queue && config is ConfigurationV7 v7)
|
if (queue && config is ConfigurationV7 v7)
|
||||||
Saved?.Invoke(this, v7);
|
Saved?.Invoke(this, v7);
|
||||||
}
|
}
|
||||||
@ -60,7 +61,7 @@ namespace Pal.Client.Configuration
|
|||||||
var v7 = MigrateToV7(configurationV1);
|
var v7 = MigrateToV7(configurationV1);
|
||||||
Save(v7, queue: false);
|
Save(v7, queue: false);
|
||||||
|
|
||||||
//File.Move(_pluginInterface.ConfigFile.FullName, _pluginInterface.ConfigFile.FullName + ".old", true);
|
File.Move(_pluginInterface.ConfigFile.FullName, _pluginInterface.ConfigFile.FullName + ".old", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,10 +108,15 @@ namespace Pal.Client.DependencyInjection
|
|||||||
_serviceProvider.GetService<RepoVerification>();
|
_serviceProvider.GetService<RepoVerification>();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_serviceProvider.GetRequiredService<Hooks>();
|
// set up legacy services
|
||||||
|
LocalState.PluginInterface = pluginInterface;
|
||||||
|
LocalState.Mode = _serviceProvider.GetRequiredService<IPalacePalConfiguration>().Mode;
|
||||||
|
|
||||||
|
// windows that have logic to open on startup
|
||||||
_serviceProvider.GetRequiredService<AgreementWindow>();
|
_serviceProvider.GetRequiredService<AgreementWindow>();
|
||||||
_serviceProvider.GetRequiredService<ConfigWindow>();
|
|
||||||
_serviceProvider.GetRequiredService<StatisticsWindow>();
|
// initialize components that are mostly self-contained/self-registered
|
||||||
|
_serviceProvider.GetRequiredService<Hooks>();
|
||||||
_serviceProvider.GetRequiredService<PalCommand>();
|
_serviceProvider.GetRequiredService<PalCommand>();
|
||||||
_serviceProvider.GetRequiredService<FrameworkService>();
|
_serviceProvider.GetRequiredService<FrameworkService>();
|
||||||
_serviceProvider.GetRequiredService<ChatService>();
|
_serviceProvider.GetRequiredService<ChatService>();
|
||||||
|
@ -5,6 +5,8 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
using Dalamud.Plugin;
|
||||||
|
using Pal.Client.Configuration;
|
||||||
using Pal.Client.Extensions;
|
using Pal.Client.Extensions;
|
||||||
|
|
||||||
namespace Pal.Client
|
namespace Pal.Client
|
||||||
@ -17,6 +19,9 @@ namespace Pal.Client
|
|||||||
private static readonly JsonSerializerOptions JsonSerializerOptions = new() { IncludeFields = true };
|
private static readonly JsonSerializerOptions JsonSerializerOptions = new() { IncludeFields = true };
|
||||||
private const int CurrentVersion = 4;
|
private const int CurrentVersion = 4;
|
||||||
|
|
||||||
|
internal static DalamudPluginInterface PluginInterface { get; set; }
|
||||||
|
internal static EMode Mode { get; set; }
|
||||||
|
|
||||||
public uint TerritoryType { get; set; }
|
public uint TerritoryType { get; set; }
|
||||||
public ConcurrentBag<Marker> Markers { get; set; } = new();
|
public ConcurrentBag<Marker> Markers { get; set; } = new();
|
||||||
|
|
||||||
@ -27,7 +32,7 @@ namespace Pal.Client
|
|||||||
|
|
||||||
private void ApplyFilters()
|
private void ApplyFilters()
|
||||||
{
|
{
|
||||||
if (Service.Configuration.Mode == Configuration.EMode.Offline)
|
if (Mode == EMode.Offline)
|
||||||
Markers = new ConcurrentBag<Marker>(Markers.Where(x => x.Seen || (x.WasImported && x.Imports.Count > 0)));
|
Markers = new ConcurrentBag<Marker>(Markers.Where(x => x.Seen || (x.WasImported && x.Imports.Count > 0)));
|
||||||
else
|
else
|
||||||
// ensure old import markers are removed if they are no longer part of a "current" import
|
// 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);
|
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<LocalState> action)
|
public static void ForEach(Action<LocalState> action)
|
||||||
{
|
{
|
||||||
|
@ -13,6 +13,11 @@ using Pal.Client.Configuration;
|
|||||||
|
|
||||||
namespace Pal.Client
|
namespace Pal.Client
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 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 .
|
||||||
|
/// </summary>
|
||||||
|
/// <see cref="DependencyInjection.DependencyInjectionContext"/>
|
||||||
internal sealed class Plugin : IDisposable
|
internal sealed class Plugin : IDisposable
|
||||||
{
|
{
|
||||||
private readonly IServiceProvider _serviceProvider;
|
private readonly IServiceProvider _serviceProvider;
|
||||||
@ -33,10 +38,6 @@ namespace Pal.Client
|
|||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
_renderAdapter = renderAdapter;
|
_renderAdapter = renderAdapter;
|
||||||
|
|
||||||
// initialize legacy services
|
|
||||||
pluginInterface.Create<Service>();
|
|
||||||
Service.Configuration = configuration;
|
|
||||||
|
|
||||||
LanguageChanged(pluginInterface.UiLanguage);
|
LanguageChanged(pluginInterface.UiLanguage);
|
||||||
|
|
||||||
pluginInterface.UiBuilder.Draw += Draw;
|
pluginInterface.UiBuilder.Draw += Draw;
|
||||||
@ -55,26 +56,23 @@ namespace Pal.Client
|
|||||||
configWindow.IsOpen = true;
|
configWindow.IsOpen = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region IDisposable Support
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_pluginInterface.UiBuilder.Draw -= Draw;
|
_pluginInterface.UiBuilder.Draw -= Draw;
|
||||||
_pluginInterface.UiBuilder.OpenConfigUi -= OpenConfigUi;
|
_pluginInterface.UiBuilder.OpenConfigUi -= OpenConfigUi;
|
||||||
_pluginInterface.LanguageChanged -= LanguageChanged;
|
_pluginInterface.LanguageChanged -= LanguageChanged;
|
||||||
}
|
}
|
||||||
#endregion
|
|
||||||
|
|
||||||
private void LanguageChanged(string languageCode)
|
private void LanguageChanged(string languageCode)
|
||||||
{
|
{
|
||||||
Localization.Culture = new CultureInfo(languageCode);
|
Localization.Culture = new CultureInfo(languageCode);
|
||||||
_serviceProvider.GetRequiredService<WindowSystem>().Windows.OfType<ILanguageChanged>().Each(w => w.LanguageChanged());
|
_serviceProvider.GetRequiredService<WindowSystem>().Windows.OfType<ILanguageChanged>()
|
||||||
|
.Each(w => w.LanguageChanged());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Draw()
|
private void Draw()
|
||||||
{
|
{
|
||||||
if (_renderAdapter.Implementation is SimpleRenderer sr)
|
_renderAdapter.DrawLayers();
|
||||||
sr.DrawLayers();
|
|
||||||
|
|
||||||
_serviceProvider.GetRequiredService<WindowSystem>().Draw();
|
_serviceProvider.GetRequiredService<WindowSystem>().Draw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,5 +29,11 @@ namespace Pal.Client.Rendering
|
|||||||
|
|
||||||
public IRenderElement CreateElement(Marker.EType type, Vector3 pos, uint color, bool fill = false)
|
public IRenderElement CreateElement(Marker.EType type, Vector3 pos, uint color, bool fill = false)
|
||||||
=> Implementation.CreateElement(type, pos, color, fill);
|
=> Implementation.CreateElement(type, pos, color, fill);
|
||||||
|
|
||||||
|
public void DrawLayers()
|
||||||
|
{
|
||||||
|
if (Implementation is SimpleRenderer sr)
|
||||||
|
sr.DrawLayers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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!;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user