diff --git a/Penumbra/Api/PenumbraApi.cs b/Penumbra/Api/PenumbraApi.cs index 103178e4..9f7910ee 100644 --- a/Penumbra/Api/PenumbraApi.cs +++ b/Penumbra/Api/PenumbraApi.cs @@ -145,10 +145,7 @@ public class PenumbraApi : IDisposable, IPenumbraApi _redrawService = redrawService; _modFileSystem = modFileSystem; _configWindow = configWindow; - - _lumina = (Lumina.GameData?)_dalamud.GameData.GetType() - .GetField("gameData", BindingFlags.Instance | BindingFlags.NonPublic) - ?.GetValue(_dalamud.GameData); + _lumina = _dalamud.GameData.GameData; _resourceLoader.ResourceLoaded += OnResourceLoaded; _communicator.ModPathChanged.Subscribe(ModPathChangeSubscriber); diff --git a/Penumbra/Collections/Manager/ActiveCollections.cs b/Penumbra/Collections/Manager/ActiveCollections.cs index d8bbae4f..a78cc48b 100644 --- a/Penumbra/Collections/Manager/ActiveCollections.cs +++ b/Penumbra/Collections/Manager/ActiveCollections.cs @@ -43,7 +43,7 @@ public class ActiveCollections : ISavable, IDisposable Current = storage.DefaultNamed; Default = storage.DefaultNamed; Interface = storage.DefaultNamed; - Individuals = new IndividualCollections(actors.AwaitedService, config); + Individuals = new IndividualCollections(actors, config); _communicator.CollectionChange.Subscribe(OnCollectionChange, -100); LoadCollections(); UpdateCurrentCollectionInUse(); @@ -396,7 +396,7 @@ public class ActiveCollections : ISavable, IDisposable } configChanged |= ActiveCollectionMigration.MigrateIndividualCollections(_storage, Individuals, jObject); - configChanged |= Individuals.ReadJObject(jObject[nameof(Individuals)] as JArray, _storage); + configChanged |= Individuals.ReadJObject(_saveService, this, jObject[nameof(Individuals)] as JArray, _storage); // Save any changes. if (configChanged) diff --git a/Penumbra/Collections/Manager/IndividualCollections.Access.cs b/Penumbra/Collections/Manager/IndividualCollections.Access.cs index b81e72c1..93c555b3 100644 --- a/Penumbra/Collections/Manager/IndividualCollections.Access.cs +++ b/Penumbra/Collections/Manager/IndividualCollections.Access.cs @@ -40,7 +40,7 @@ public sealed partial class IndividualCollections : IReadOnlyList<(string Displa return true; if (identifier.Retainer is not ActorIdentifier.RetainerType.Mannequin && _config.UseOwnerNameForCharacterCollection) - return CheckWorlds(_actorManager.GetCurrentPlayer(), out collection); + return CheckWorlds(_actorService.AwaitedService.GetCurrentPlayer(), out collection); break; } @@ -50,7 +50,7 @@ public sealed partial class IndividualCollections : IReadOnlyList<(string Displa return true; // Handle generic NPC - var npcIdentifier = _actorManager.CreateIndividualUnchecked(IdentifierType.Npc, ByteString.Empty, ushort.MaxValue, + var npcIdentifier = _actorService.AwaitedService.CreateIndividualUnchecked(IdentifierType.Npc, ByteString.Empty, ushort.MaxValue, identifier.Kind, identifier.DataId); if (npcIdentifier.IsValid && _individuals.TryGetValue(npcIdentifier, out collection)) return true; @@ -59,7 +59,7 @@ public sealed partial class IndividualCollections : IReadOnlyList<(string Displa if (!_config.UseOwnerNameForCharacterCollection) return false; - identifier = _actorManager.CreateIndividualUnchecked(IdentifierType.Player, identifier.PlayerName, identifier.HomeWorld, + identifier = _actorService.AwaitedService.CreateIndividualUnchecked(IdentifierType.Player, identifier.PlayerName, identifier.HomeWorld, ObjectKind.None, uint.MaxValue); return CheckWorlds(identifier, out collection); } @@ -91,37 +91,37 @@ public sealed partial class IndividualCollections : IReadOnlyList<(string Displa if (identifier.Type != IdentifierType.Special) return (identifier, SpecialResult.Invalid); - if (_actorManager.ResolvePartyBannerPlayer(identifier.Special, out var id)) + if (_actorService.AwaitedService.ResolvePartyBannerPlayer(identifier.Special, out var id)) return (id, SpecialResult.PartyBanner); - if (_actorManager.ResolvePvPBannerPlayer(identifier.Special, out id)) + if (_actorService.AwaitedService.ResolvePvPBannerPlayer(identifier.Special, out id)) return (id, SpecialResult.PvPBanner); - if (_actorManager.ResolveMahjongPlayer(identifier.Special, out id)) + if (_actorService.AwaitedService.ResolveMahjongPlayer(identifier.Special, out id)) return (id, SpecialResult.Mahjong); switch (identifier.Special) { case ScreenActor.CharacterScreen when _config.UseCharacterCollectionInMainWindow: - return (_actorManager.GetCurrentPlayer(), SpecialResult.CharacterScreen); + return (_actorService.AwaitedService.GetCurrentPlayer(), SpecialResult.CharacterScreen); case ScreenActor.FittingRoom when _config.UseCharacterCollectionInTryOn: - return (_actorManager.GetCurrentPlayer(), SpecialResult.FittingRoom); + return (_actorService.AwaitedService.GetCurrentPlayer(), SpecialResult.FittingRoom); case ScreenActor.DyePreview when _config.UseCharacterCollectionInTryOn: - return (_actorManager.GetCurrentPlayer(), SpecialResult.DyePreview); + return (_actorService.AwaitedService.GetCurrentPlayer(), SpecialResult.DyePreview); case ScreenActor.Portrait when _config.UseCharacterCollectionsInCards: - return (_actorManager.GetCurrentPlayer(), SpecialResult.Portrait); + return (_actorService.AwaitedService.GetCurrentPlayer(), SpecialResult.Portrait); case ScreenActor.ExamineScreen: { - identifier = _actorManager.GetInspectPlayer(); + identifier = _actorService.AwaitedService.GetInspectPlayer(); if (identifier.IsValid) return (_config.UseCharacterCollectionInInspect ? identifier : ActorIdentifier.Invalid, SpecialResult.Inspect); - identifier = _actorManager.GetCardPlayer(); + identifier = _actorService.AwaitedService.GetCardPlayer(); if (identifier.IsValid) return (_config.UseCharacterCollectionInInspect ? identifier : ActorIdentifier.Invalid, SpecialResult.Card); return _config.UseCharacterCollectionInTryOn - ? (_actorManager.GetGlamourPlayer(), SpecialResult.Glamour) + ? (_actorService.AwaitedService.GetGlamourPlayer(), SpecialResult.Glamour) : (identifier, SpecialResult.Invalid); } default: return (identifier, SpecialResult.Invalid); @@ -129,10 +129,10 @@ public sealed partial class IndividualCollections : IReadOnlyList<(string Displa } public bool TryGetCollection(GameObject? gameObject, out ModCollection? collection) - => TryGetCollection(_actorManager.FromObject(gameObject, true, false, false), out collection); + => TryGetCollection(_actorService.AwaitedService.FromObject(gameObject, true, false, false), out collection); public unsafe bool TryGetCollection(FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject* gameObject, out ModCollection? collection) - => TryGetCollection(_actorManager.FromObject(gameObject, out _, true, false, false), out collection); + => TryGetCollection(_actorService.AwaitedService.FromObject(gameObject, out _, true, false, false), out collection); private bool CheckWorlds(ActorIdentifier identifier, out ModCollection? collection) { @@ -145,7 +145,7 @@ public sealed partial class IndividualCollections : IReadOnlyList<(string Displa if (_individuals.TryGetValue(identifier, out collection)) return true; - identifier = _actorManager.CreateIndividualUnchecked(identifier.Type, identifier.PlayerName, ushort.MaxValue, identifier.Kind, + identifier = _actorService.AwaitedService.CreateIndividualUnchecked(identifier.Type, identifier.PlayerName, ushort.MaxValue, identifier.Kind, identifier.DataId); if (identifier.IsValid && _individuals.TryGetValue(identifier, out collection)) return true; diff --git a/Penumbra/Collections/Manager/IndividualCollections.Files.cs b/Penumbra/Collections/Manager/IndividualCollections.Files.cs index 8adf03fa..b720c35c 100644 --- a/Penumbra/Collections/Manager/IndividualCollections.Files.cs +++ b/Penumbra/Collections/Manager/IndividualCollections.Files.cs @@ -6,6 +6,7 @@ using Dalamud.Interface.Internal.Notifications; using Newtonsoft.Json.Linq; using Penumbra.GameData.Actors; using Penumbra.String; +using Penumbra.Util; namespace Penumbra.Collections.Manager; @@ -25,7 +26,21 @@ public partial class IndividualCollections return ret; } - public bool ReadJObject(JArray? obj, CollectionStorage storage) + public bool ReadJObject(SaveService saver, ActiveCollections parent, JArray? obj, CollectionStorage storage) + { + if (_actorService.Valid) + return ReadJObjectInternal(obj, storage); + void Func() + { + if (ReadJObjectInternal(obj, storage)) + saver.ImmediateSave(parent); + _actorService.FinishedCreation -= Func; + } + _actorService.FinishedCreation += Func; + return false; + } + + private bool ReadJObjectInternal(JArray? obj, CollectionStorage storage) { if (obj == null) return true; @@ -35,7 +50,7 @@ public partial class IndividualCollections { try { - var identifier = _actorManager.FromJson(data as JObject); + var identifier = _actorService.AwaitedService.FromJson(data as JObject); var group = GetGroup(identifier); if (group.Length == 0 || group.Any(i => !i.IsValid)) { @@ -71,7 +86,6 @@ public partial class IndividualCollections NotificationType.Error); } } - return changes; } @@ -90,22 +104,22 @@ public partial class IndividualCollections var kind = ObjectKind.None; var lowerName = name.ToLowerInvariant(); // Prefer matching NPC names, fewer false positives than preferring players. - if (FindDataId(lowerName, _actorManager.Data.Companions, out var dataId)) + if (FindDataId(lowerName, _actorService.AwaitedService.Data.Companions, out var dataId)) kind = ObjectKind.Companion; - else if (FindDataId(lowerName, _actorManager.Data.Mounts, out dataId)) + else if (FindDataId(lowerName, _actorService.AwaitedService.Data.Mounts, out dataId)) kind = ObjectKind.MountType; - else if (FindDataId(lowerName, _actorManager.Data.BNpcs, out dataId)) + else if (FindDataId(lowerName, _actorService.AwaitedService.Data.BNpcs, out dataId)) kind = ObjectKind.BattleNpc; - else if (FindDataId(lowerName, _actorManager.Data.ENpcs, out dataId)) + else if (FindDataId(lowerName, _actorService.AwaitedService.Data.ENpcs, out dataId)) kind = ObjectKind.EventNpc; - var identifier = _actorManager.CreateNpc(kind, dataId); + var identifier = _actorService.AwaitedService.CreateNpc(kind, dataId); if (identifier.IsValid) { // If the name corresponds to a valid npc, add it as a group. If this fails, notify users. var group = GetGroup(identifier); var ids = string.Join(", ", group.Select(i => i.DataId.ToString())); - if (Add($"{_actorManager.Data.ToName(kind, dataId)} ({kind.ToName()})", group, collection)) + if (Add($"{_actorService.AwaitedService.Data.ToName(kind, dataId)} ({kind.ToName()})", group, collection)) Penumbra.Log.Information($"Migrated {name} ({kind.ToName()}) to NPC Identifiers [{ids}]."); else Penumbra.ChatService.NotificationMessage( @@ -115,10 +129,10 @@ public partial class IndividualCollections // If it is not a valid NPC name, check if it can be a player name. else if (ActorManager.VerifyPlayerName(name)) { - identifier = _actorManager.CreatePlayer(ByteString.FromStringUnsafe(name, false), ushort.MaxValue); + identifier = _actorService.AwaitedService.CreatePlayer(ByteString.FromStringUnsafe(name, false), ushort.MaxValue); var shortName = string.Join(" ", name.Split().Select(n => $"{n[0]}.")); // Try to migrate the player name without logging full names. - if (Add($"{name} ({_actorManager.Data.ToWorldName(identifier.HomeWorld)})", new[] + if (Add($"{name} ({_actorService.AwaitedService.Data.ToWorldName(identifier.HomeWorld)})", new[] { identifier, }, collection)) diff --git a/Penumbra/Collections/Manager/IndividualCollections.cs b/Penumbra/Collections/Manager/IndividualCollections.cs index 80fa6089..f333ed81 100644 --- a/Penumbra/Collections/Manager/IndividualCollections.cs +++ b/Penumbra/Collections/Manager/IndividualCollections.cs @@ -13,24 +13,17 @@ namespace Penumbra.Collections.Manager; public sealed partial class IndividualCollections { private readonly Configuration _config; - private readonly ActorManager _actorManager; + private readonly ActorService _actorService; private readonly List<(string DisplayName, IReadOnlyList Identifiers, ModCollection Collection)> _assignments = new(); private readonly Dictionary _individuals = new(); public IReadOnlyList<(string DisplayName, IReadOnlyList Identifiers, ModCollection Collection)> Assignments => _assignments; - // TODO - public IndividualCollections(ActorService actorManager, Configuration config) + public IndividualCollections(ActorService actorService, Configuration config) { _config = config; - _actorManager = actorManager.AwaitedService; - } - - public IndividualCollections(ActorManager actorManager, Configuration config) - { - _actorManager = actorManager; - _config = config; + _actorService = actorService; } public enum AddResult @@ -78,6 +71,7 @@ public sealed partial class IndividualCollections { identifiers = Array.Empty(); + var manager = _actorService.AwaitedService; switch (type) { case IdentifierType.Player: @@ -86,7 +80,7 @@ public sealed partial class IndividualCollections identifiers = new[] { - _actorManager.CreatePlayer(playerName, homeWorld), + manager.CreatePlayer(playerName, homeWorld), }; break; case IdentifierType.Retainer: @@ -95,18 +89,18 @@ public sealed partial class IndividualCollections identifiers = new[] { - _actorManager.CreateRetainer(retainerName, 0), + manager.CreateRetainer(retainerName, 0), }; break; case IdentifierType.Owned: if (!ByteString.FromString(name, out var ownerName)) return AddResult.Invalid; - - identifiers = dataIds.Select(id => _actorManager.CreateOwned(ownerName, homeWorld, kind, id)).ToArray(); + + identifiers = dataIds.Select(id => manager.CreateOwned(ownerName, homeWorld, kind, id)).ToArray(); break; case IdentifierType.Npc: identifiers = dataIds - .Select(id => _actorManager.CreateIndividual(IdentifierType.Npc, ByteString.Empty, ushort.MaxValue, kind, id)).ToArray(); + .Select(id => manager.CreateIndividual(IdentifierType.Npc, ByteString.Empty, ushort.MaxValue, kind, id)).ToArray(); break; default: identifiers = Array.Empty(); @@ -152,8 +146,8 @@ public sealed partial class IndividualCollections { identifier.CreatePermanent(), }, - IdentifierType.Owned => CreateNpcs(_actorManager, identifier.CreatePermanent()), - IdentifierType.Npc => CreateNpcs(_actorManager, identifier), + IdentifierType.Owned => CreateNpcs(_actorService.AwaitedService, identifier.CreatePermanent()), + IdentifierType.Npc => CreateNpcs(_actorService.AwaitedService, identifier), _ => Array.Empty(), }; } @@ -244,11 +238,11 @@ public sealed partial class IndividualCollections { return identifier.Type switch { - IdentifierType.Player => $"{identifier.PlayerName} ({_actorManager.Data.ToWorldName(identifier.HomeWorld)})", + IdentifierType.Player => $"{identifier.PlayerName} ({_actorService.AwaitedService.Data.ToWorldName(identifier.HomeWorld)})", IdentifierType.Retainer => $"{identifier.PlayerName} (Retainer)", IdentifierType.Owned => - $"{identifier.PlayerName} ({_actorManager.Data.ToWorldName(identifier.HomeWorld)})'s {_actorManager.Data.ToName(identifier.Kind, identifier.DataId)}", - IdentifierType.Npc => $"{_actorManager.Data.ToName(identifier.Kind, identifier.DataId)} ({identifier.Kind.ToName()})", + $"{identifier.PlayerName} ({_actorService.AwaitedService.Data.ToWorldName(identifier.HomeWorld)})'s {_actorService.AwaitedService.Data.ToName(identifier.Kind, identifier.DataId)}", + IdentifierType.Npc => $"{_actorService.AwaitedService.Data.ToName(identifier.Kind, identifier.DataId)} ({identifier.Kind.ToName()})", _ => string.Empty, }; } diff --git a/Penumbra/Penumbra.cs b/Penumbra/Penumbra.cs index 96e3b937..997ff784 100644 --- a/Penumbra/Penumbra.cs +++ b/Penumbra/Penumbra.cs @@ -44,31 +44,33 @@ public class Penumbra : IDalamudPlugin private PenumbraWindowSystem? _windowSystem; private bool _disposed; - private readonly ServiceManager _tmp; + private readonly ServiceProvider _services; public Penumbra(DalamudPluginInterface pluginInterface) { try { - _tmp = new ServiceManager(this, pluginInterface, Log); - ChatService = _tmp.Services.GetRequiredService(); - _validityChecker = _tmp.Services.GetRequiredService(); - _tmp.Services.GetRequiredService(); // Initialize because not required anywhere else. - _config = _tmp.Services.GetRequiredService(); - _characterUtility = _tmp.Services.GetRequiredService(); - _tempMods = _tmp.Services.GetRequiredService(); - _residentResources = _tmp.Services.GetRequiredService(); - _tmp.Services.GetRequiredService(); // Initialize because not required anywhere else. - _modManager = _tmp.Services.GetRequiredService(); - _collectionManager = _tmp.Services.GetRequiredService(); - _tempCollections = _tmp.Services.GetRequiredService(); - _redrawService = _tmp.Services.GetRequiredService(); - _communicatorService = _tmp.Services.GetRequiredService(); - _tmp.Services.GetRequiredService(); // Initialize because not required anywhere else. - _tmp.Services.GetRequiredService(); // Initialize because not required anywhere else. - using (var t = _tmp.Services.GetRequiredService().Measure(StartTimeType.PathResolver)) + var startTimer = new StartTracker(); + using var timer = startTimer.Measure(StartTimeType.Total); + _services = ServiceManager.CreateProvider(this, pluginInterface, Log, startTimer); + ChatService = _services.GetRequiredService(); + _validityChecker = _services.GetRequiredService(); + _services.GetRequiredService(); // Initialize because not required anywhere else. + _config = _services.GetRequiredService(); + _characterUtility = _services.GetRequiredService(); + _tempMods = _services.GetRequiredService(); + _residentResources = _services.GetRequiredService(); + _services.GetRequiredService(); // Initialize because not required anywhere else. + _modManager = _services.GetRequiredService(); + _collectionManager = _services.GetRequiredService(); + _tempCollections = _services.GetRequiredService(); + _redrawService = _services.GetRequiredService(); + _communicatorService = _services.GetRequiredService(); + _services.GetRequiredService(); // Initialize because not required anywhere else. + _services.GetRequiredService(); // Initialize because not required anywhere else. + using (var t = _services.GetRequiredService().Measure(StartTimeType.PathResolver)) { - _tmp.Services.GetRequiredService(); + _services.GetRequiredService(); } SetupInterface(); @@ -92,9 +94,9 @@ public class Penumbra : IDalamudPlugin private void SetupApi() { - using var timer = _tmp.Services.GetRequiredService().Measure(StartTimeType.Api); - var api = _tmp.Services.GetRequiredService(); - _tmp.Services.GetRequiredService(); + using var timer = _services.GetRequiredService().Measure(StartTimeType.Api); + var api = _services.GetRequiredService(); + _services.GetRequiredService(); api.ChangedItemTooltip += it => { if (it is Item) @@ -111,10 +113,10 @@ public class Penumbra : IDalamudPlugin { Task.Run(() => { - using var tInterface = _tmp.Services.GetRequiredService().Measure(StartTimeType.Interface); - var system = _tmp.Services.GetRequiredService(); - system.Window.Setup(this, _tmp.Services.GetRequiredService()); - _tmp.Services.GetRequiredService(); + using var tInterface = _services.GetRequiredService().Measure(StartTimeType.Interface); + var system = _services.GetRequiredService(); + system.Window.Setup(this, _services.GetRequiredService()); + _services.GetRequiredService(); if (!_disposed) _windowSystem = system; else @@ -162,7 +164,7 @@ public class Penumbra : IDalamudPlugin if (_disposed) return; - _tmp?.Dispose(); + _services?.Dispose(); _disposed = true; } @@ -183,7 +185,7 @@ public class Penumbra : IDalamudPlugin sb.Append($"> **`Auto-Deduplication: `** {_config.AutoDeduplicateOnImport}\n"); sb.Append($"> **`Debug Mode: `** {_config.DebugMode}\n"); sb.Append( - $"> **`Synchronous Load (Dalamud): `** {(_tmp.Services.GetRequiredService().GetDalamudConfig(DalamudServices.WaitingForPluginsOption, out bool v) ? v.ToString() : "Unknown")}\n"); + $"> **`Synchronous Load (Dalamud): `** {(_services.GetRequiredService().GetDalamudConfig(DalamudServices.WaitingForPluginsOption, out bool v) ? v.ToString() : "Unknown")}\n"); sb.Append( $"> **`Logging: `** Log: {_config.EnableResourceLogging}, Watcher: {_config.EnableResourceWatcher} ({_config.MaxResourceWatcherRecords})\n"); sb.Append($"> **`Use Ownership: `** {_config.UseOwnerNameForCharacterCollection}\n"); diff --git a/Penumbra/ServiceManager.cs b/Penumbra/Services/ServiceManager.cs similarity index 65% rename from Penumbra/ServiceManager.cs rename to Penumbra/Services/ServiceManager.cs index af2cec75..e973c784 100644 --- a/Penumbra/ServiceManager.cs +++ b/Penumbra/Services/ServiceManager.cs @@ -3,42 +3,58 @@ using Microsoft.Extensions.DependencyInjection; using OtterGui.Classes; using OtterGui.Log; using Penumbra.Api; +using Penumbra.Collections.Cache; using Penumbra.Collections.Manager; using Penumbra.GameData; using Penumbra.GameData.Data; -using Penumbra.Interop.ResourceLoading; using Penumbra.Interop.PathResolving; +using Penumbra.Interop.ResourceLoading; using Penumbra.Interop.ResourceTree; using Penumbra.Interop.Services; +using Penumbra.Meta; using Penumbra.Mods; -using Penumbra.Services; +using Penumbra.Mods.Manager; using Penumbra.UI; using Penumbra.UI.AdvancedWindow; using Penumbra.UI.ModsTab; using Penumbra.UI.Tabs; using Penumbra.Util; -using CharacterUtility = Penumbra.Interop.Services.CharacterUtility; -using ModFileSystemSelector = Penumbra.UI.ModsTab.ModFileSystemSelector; -using Penumbra.Mods.Manager; -using Penumbra.Collections.Cache; -using Penumbra.Meta; - -namespace Penumbra; -public class ServiceManager +namespace Penumbra.Services; + +public static class ServiceManager { - public readonly ServiceProvider Services; - - public ServiceManager(Penumbra penumbra, DalamudPluginInterface pi, Logger log) + public static ServiceProvider CreateProvider(Penumbra penumbra, DalamudPluginInterface pi, Logger log, StartTracker startTimer) { - var startTimer = new StartTracker(); - using var time = startTimer.Measure(StartTimeType.Total); - - var services = new ServiceCollection(); - // Add meta services. - services.AddSingleton(log) + var services = new ServiceCollection() + .AddSingleton(log) .AddSingleton(startTimer) - .AddSingleton() + .AddSingleton(penumbra) + .AddDalamud(pi) + .AddMeta() + .AddGameData() + .AddInterop() + .AddConfiguration() + .AddCollections() + .AddMods() + .AddResources() + .AddResolvers() + .AddInterface() + .AddModEditor() + .AddApi(); + + return services.BuildServiceProvider(new ServiceProviderOptions { ValidateOnBuild = true }); + } + + private static IServiceCollection AddDalamud(this IServiceCollection services, DalamudPluginInterface pi) + { + var dalamud = new DalamudServices(pi); + dalamud.AddServices(services); + return services; + } + + private static IServiceCollection AddMeta(this IServiceCollection services) + => services.AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() @@ -46,20 +62,16 @@ public class ServiceManager .AddSingleton() .AddSingleton(); - // Add Dalamud services - var dalamud = new DalamudServices(pi); - dalamud.AddServices(services); - services.AddSingleton(penumbra); - // Add Game Data - services.AddSingleton() + private static IServiceCollection AddGameData(this IServiceCollection services) + => services.AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton(); - // Add Game Services - services.AddSingleton() + private static IServiceCollection AddInterop(this IServiceCollection services) + => services.AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() @@ -72,12 +84,12 @@ public class ServiceManager .AddSingleton() .AddSingleton(); - // Add Configuration - services.AddTransient() + private static IServiceCollection AddConfiguration(this IServiceCollection services) + => services.AddTransient() .AddSingleton(); - // Add Collection Services - services.AddSingleton() + private static IServiceCollection AddCollections(this IServiceCollection services) + => services.AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() @@ -86,8 +98,8 @@ public class ServiceManager .AddSingleton() .AddSingleton(); - // Add Mod Services - services.AddSingleton() + private static IServiceCollection AddMods(this IServiceCollection services) + => services.AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() @@ -96,16 +108,16 @@ public class ServiceManager .AddSingleton() .AddSingleton() .AddSingleton() - .AddSingleton(s => (ModStorage) s.GetRequiredService()); + .AddSingleton(s => (ModStorage)s.GetRequiredService()); - // Add Resource services - services.AddSingleton() + private static IServiceCollection AddResources(this IServiceCollection services) + => services.AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton(); - // Add Path Resolver - services.AddSingleton() + private static IServiceCollection AddResolvers(this IServiceCollection services) + => services.AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() @@ -115,8 +127,8 @@ public class ServiceManager .AddSingleton() .AddSingleton(); - // Add Interface - services.AddSingleton() + private static IServiceCollection AddInterface(this IServiceCollection services) + => services.AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() @@ -147,8 +159,8 @@ public class ServiceManager .AddSingleton() .AddSingleton(); - // Add Mod Editor - services.AddSingleton() + private static IServiceCollection AddModEditor(this IServiceCollection services) + => services.AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() @@ -157,17 +169,9 @@ public class ServiceManager .AddSingleton() .AddSingleton(); - // Add API - services.AddSingleton() + private static IServiceCollection AddApi(this IServiceCollection services) + => services.AddSingleton() .AddSingleton(x => x.GetRequiredService()) .AddSingleton() .AddSingleton(); - - Services = services.BuildServiceProvider(new ServiceProviderOptions { ValidateOnBuild = true }); - } - - public void Dispose() - { - Services.Dispose(); - } } diff --git a/Penumbra/Services/ValidityChecker.cs b/Penumbra/Services/ValidityChecker.cs index a5bc3f3c..7ce8c803 100644 --- a/Penumbra/Services/ValidityChecker.cs +++ b/Penumbra/Services/ValidityChecker.cs @@ -1,13 +1,10 @@ using System; using System.Collections.Generic; -using System.IO; -using System.Linq; using System.Reflection; using Dalamud.Interface.Internal.Notifications; using Dalamud.Plugin; -using Penumbra.Util; -namespace Penumbra; +namespace Penumbra.Services; public class ValidityChecker { diff --git a/Penumbra/UI/ConfigWindow.cs b/Penumbra/UI/ConfigWindow.cs index d676cf62..12144957 100644 --- a/Penumbra/UI/ConfigWindow.cs +++ b/Penumbra/UI/ConfigWindow.cs @@ -7,6 +7,7 @@ using OtterGui; using OtterGui.Raii; using Penumbra.Api.Enums; using Penumbra.Mods; +using Penumbra.Services; using Penumbra.UI.Classes; using Penumbra.UI.Tabs; using Penumbra.Util;