From c527d19117711e4d8c79b46bf33bb5a209428012 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Mon, 10 Apr 2023 00:31:29 +0200 Subject: [PATCH] Remove some static dependencies. --- Penumbra/Mods/ItemSwap/EquipmentSwap.cs | 15 ++++++++------- Penumbra/Mods/ItemSwap/ItemSwapContainer.cs | 10 +++++++--- Penumbra/Penumbra.cs | 15 +-------------- Penumbra/UI/AdvancedWindow/ItemSwapTab.cs | 7 ++++--- Penumbra/UI/AdvancedWindow/ModEditWindow.cs | 18 ++++++++++-------- 5 files changed, 30 insertions(+), 35 deletions(-) diff --git a/Penumbra/Mods/ItemSwap/EquipmentSwap.cs b/Penumbra/Mods/ItemSwap/EquipmentSwap.cs index 97398d87..1f1cecfb 100644 --- a/Penumbra/Mods/ItemSwap/EquipmentSwap.cs +++ b/Penumbra/Mods/ItemSwap/EquipmentSwap.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using Lumina.Data.Parsing; using Lumina.Excel.GeneratedSheets; +using Penumbra.GameData; using Penumbra.GameData.Data; using Penumbra.GameData.Enums; using Penumbra.GameData.Files; @@ -33,7 +34,7 @@ public static class EquipmentSwap : Array.Empty< EquipSlot >(); } - public static Item[] CreateTypeSwap( List< Swap > swaps, Func< Utf8GamePath, FullPath > redirections, Func< MetaManipulation, MetaManipulation > manips, + public static Item[] CreateTypeSwap( IObjectIdentifier identifier, List< Swap > swaps, Func< Utf8GamePath, FullPath > redirections, Func< MetaManipulation, MetaManipulation > manips, EquipSlot slotFrom, Item itemFrom, EquipSlot slotTo, Item itemTo ) { LookupItem( itemFrom, out var actualSlotFrom, out var idFrom, out var variantFrom ); @@ -43,7 +44,7 @@ public static class EquipmentSwap throw new ItemSwap.InvalidItemTypeException(); } - var ( imcFileFrom, variants, affectedItems ) = GetVariants( slotFrom, idFrom, idTo, variantFrom ); + var ( imcFileFrom, variants, affectedItems ) = GetVariants( identifier, slotFrom, idFrom, idTo, variantFrom ); var imcManip = new ImcManipulation( slotTo, variantTo, idTo.Value, default ); var imcFileTo = new ImcFile( imcManip ); var skipFemale = false; @@ -96,7 +97,7 @@ public static class EquipmentSwap return affectedItems; } - public static Item[] CreateItemSwap( List< Swap > swaps, Func< Utf8GamePath, FullPath > redirections, Func< MetaManipulation, MetaManipulation > manips, Item itemFrom, + public static Item[] CreateItemSwap( IObjectIdentifier identifier, List< Swap > swaps, Func< Utf8GamePath, FullPath > redirections, Func< MetaManipulation, MetaManipulation > manips, Item itemFrom, Item itemTo, bool rFinger = true, bool lFinger = true ) { // Check actual ids, variants and slots. We only support using the same slot. @@ -122,7 +123,7 @@ public static class EquipmentSwap var affectedItems = Array.Empty< Item >(); foreach( var slot in ConvertSlots( slotFrom, rFinger, lFinger ) ) { - ( var imcFileFrom, var variants, affectedItems ) = GetVariants( slot, idFrom, idTo, variantFrom ); + ( var imcFileFrom, var variants, affectedItems ) = GetVariants( identifier, slot, idFrom, idTo, variantFrom ); var imcManip = new ImcManipulation( slot, variantTo, idTo.Value, default ); var imcFileTo = new ImcFile( imcManip ); @@ -250,7 +251,7 @@ public static class EquipmentSwap variant = ( byte )( ( Quad )i.ModelMain ).B; } - private static (ImcFile, byte[], Item[]) GetVariants( EquipSlot slotFrom, SetId idFrom, SetId idTo, byte variantFrom ) + private static (ImcFile, byte[], Item[]) GetVariants( IObjectIdentifier identifier, EquipSlot slotFrom, SetId idFrom, SetId idTo, byte variantFrom ) { var entry = new ImcManipulation( slotFrom, variantFrom, idFrom.Value, default ); var imc = new ImcFile( entry ); @@ -258,12 +259,12 @@ public static class EquipmentSwap byte[] variants; if( idFrom.Value == idTo.Value ) { - items = Penumbra.Identifier.Identify( idFrom, variantFrom, slotFrom ).ToArray(); + items = identifier.Identify( idFrom, variantFrom, slotFrom ).ToArray(); variants = new[] { variantFrom }; } else { - items = Penumbra.Identifier.Identify( slotFrom.IsEquipment() + items = identifier.Identify( slotFrom.IsEquipment() ? GamePaths.Equipment.Mdl.Path( idFrom, GenderRace.MidlanderMale, slotFrom ) : GamePaths.Accessory.Mdl.Path( idFrom, GenderRace.MidlanderMale, slotFrom ) ).Select( kvp => kvp.Value ).OfType< Item >().ToArray(); variants = Enumerable.Range( 0, imc.Count + 1 ).Select( i => ( byte )i ).ToArray(); diff --git a/Penumbra/Mods/ItemSwap/ItemSwapContainer.cs b/Penumbra/Mods/ItemSwap/ItemSwapContainer.cs index c6f1b607..2ca70cda 100644 --- a/Penumbra/Mods/ItemSwap/ItemSwapContainer.cs +++ b/Penumbra/Mods/ItemSwap/ItemSwapContainer.cs @@ -8,12 +8,15 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using Penumbra.GameData; using Penumbra.Mods.Manager; namespace Penumbra.Mods.ItemSwap; public class ItemSwapContainer { + private readonly IObjectIdentifier _identifier; + private Dictionary< Utf8GamePath, FullPath > _modRedirections = new(); private HashSet< MetaManipulation > _modManipulations = new(); @@ -109,8 +112,9 @@ public class ItemSwapContainer } } - public ItemSwapContainer() + public ItemSwapContainer(IObjectIdentifier identifier) { + _identifier = identifier; LoadMod( null, null ); } @@ -129,7 +133,7 @@ public class ItemSwapContainer { Swaps.Clear(); Loaded = false; - var ret = EquipmentSwap.CreateItemSwap( Swaps, PathResolver( collection ), MetaResolver( collection ), from, to, useRightRing, useLeftRing ); + var ret = EquipmentSwap.CreateItemSwap( _identifier, Swaps, PathResolver( collection ), MetaResolver( collection ), from, to, useRightRing, useLeftRing ); Loaded = true; return ret; } @@ -138,7 +142,7 @@ public class ItemSwapContainer { Swaps.Clear(); Loaded = false; - var ret = EquipmentSwap.CreateTypeSwap( Swaps, PathResolver( collection ), MetaResolver( collection ), slotFrom, from, slotTo, to ); + var ret = EquipmentSwap.CreateTypeSwap( _identifier, Swaps, PathResolver( collection ), MetaResolver( collection ), slotFrom, from, slotTo, to ); Loaded = true; return ret; } diff --git a/Penumbra/Penumbra.cs b/Penumbra/Penumbra.cs index 6265e3fd..6dbcd3a8 100644 --- a/Penumbra/Penumbra.cs +++ b/Penumbra/Penumbra.cs @@ -1,10 +1,8 @@ using System; using System.IO; using System.Linq; -using System.Reflection; using System.Text; using System.Threading.Tasks; -using Dalamud.Interface.Windowing; using Dalamud.Plugin; using ImGuiNET; using Lumina.Excel.GeneratedSheets; @@ -12,16 +10,13 @@ using Microsoft.Extensions.DependencyInjection; using OtterGui; using OtterGui.Classes; using OtterGui.Log; -using OtterGui.Widgets; using Penumbra.Api; using Penumbra.Api.Enums; -using Penumbra.Interop; using Penumbra.UI; using Penumbra.Util; using Penumbra.Collections; using Penumbra.GameData; using Penumbra.GameData.Actors; -using Penumbra.GameData.Data; using Penumbra.Interop.ResourceLoading; using Penumbra.Interop.PathResolving; using CharacterUtility = Penumbra.Interop.Services.CharacterUtility; @@ -48,14 +43,12 @@ public class Penumbra : IDalamudPlugin public static ResidentResourceManager ResidentResources { get; private set; } = null!; public static CharacterUtility CharacterUtility { get; private set; } = null!; - public static GameEventManager GameEvents { get; private set; } = null!; public static MetaFileManager MetaFileManager { get; private set; } = null!; public static ModManager ModManager { get; private set; } = null!; public static ModCacheManager ModCaches { get; private set; } = null!; public static CollectionManager CollectionManager { get; private set; } = null!; public static TempCollectionManager TempCollections { get; private set; } = null!; public static TempModManager TempMods { get; private set; } = null!; - public static ResourceLoader ResourceLoader { get; private set; } = null!; public static FrameworkManager Framework { get; private set; } = null!; public static ActorManager Actors { get; private set; } = null!; public static IObjectIdentifier Identifier { get; private set; } = null!; @@ -65,9 +58,6 @@ public class Penumbra : IDalamudPlugin // TODO public static ValidityChecker ValidityChecker { get; private set; } = null!; - public static PerformanceTracker Performance { get; private set; } = null!; - - public readonly PathResolver PathResolver; public readonly RedrawService RedrawService; public readonly ModFileSystem ModFileSystem; public HttpApi HttpApi = null!; @@ -86,12 +76,10 @@ public class Penumbra : IDalamudPlugin ChatService = _tmp.Services.GetRequiredService(); Filenames = _tmp.Services.GetRequiredService(); SaveService = _tmp.Services.GetRequiredService(); - Performance = _tmp.Services.GetRequiredService(); ValidityChecker = _tmp.Services.GetRequiredService(); _tmp.Services.GetRequiredService(); Config = _tmp.Services.GetRequiredService(); CharacterUtility = _tmp.Services.GetRequiredService(); - GameEvents = _tmp.Services.GetRequiredService(); MetaFileManager = _tmp.Services.GetRequiredService(); Framework = _tmp.Services.GetRequiredService(); Actors = _tmp.Services.GetRequiredService().AwaitedService; @@ -107,11 +95,10 @@ public class Penumbra : IDalamudPlugin ModFileSystem = _tmp.Services.GetRequiredService(); RedrawService = _tmp.Services.GetRequiredService(); _tmp.Services.GetRequiredService(); - ResourceLoader = _tmp.Services.GetRequiredService(); ModCaches = _tmp.Services.GetRequiredService(); using (var t = _tmp.Services.GetRequiredService().Measure(StartTimeType.PathResolver)) { - PathResolver = _tmp.Services.GetRequiredService(); + _tmp.Services.GetRequiredService(); } SetupInterface(); diff --git a/Penumbra/UI/AdvancedWindow/ItemSwapTab.cs b/Penumbra/UI/AdvancedWindow/ItemSwapTab.cs index cc5e7cb6..57c52fd3 100644 --- a/Penumbra/UI/AdvancedWindow/ItemSwapTab.cs +++ b/Penumbra/UI/AdvancedWindow/ItemSwapTab.cs @@ -29,16 +29,17 @@ public class ItemSwapTab : IDisposable, ITab private readonly ItemService _itemService; private readonly CollectionManager _collectionManager; private readonly ModManager _modManager; - private readonly Configuration _config; + private readonly Configuration _config; public ItemSwapTab(CommunicatorService communicator, ItemService itemService, CollectionManager collectionManager, - ModManager modManager, Configuration config) + ModManager modManager, Configuration config, IdentifierService identifier) { _communicator = communicator; _itemService = itemService; _collectionManager = collectionManager; _modManager = modManager; _config = config; + _swapData = new ItemSwapContainer(identifier.AwaitedService); _selectors = new Dictionary { @@ -149,7 +150,7 @@ public class ItemSwapTab : IDisposable, ITab private ItemSelector? _weaponSource; private ItemSelector? _weaponTarget; private readonly WeaponSelector _slotSelector = new(); - private readonly ItemSwapContainer _swapData = new(); + private readonly ItemSwapContainer _swapData; private Mod? _mod; private ModSettings? _modSettings; diff --git a/Penumbra/UI/AdvancedWindow/ModEditWindow.cs b/Penumbra/UI/AdvancedWindow/ModEditWindow.cs index 59a78306..68265a43 100644 --- a/Penumbra/UI/AdvancedWindow/ModEditWindow.cs +++ b/Penumbra/UI/AdvancedWindow/ModEditWindow.cs @@ -25,11 +25,12 @@ public partial class ModEditWindow : Window, IDisposable { private const string WindowBaseLabel = "###SubModEdit"; - private readonly ModEditor _editor; - private readonly ModCacheManager _modCaches; - private readonly Configuration _config; - private readonly ItemSwapTab _itemSwapTab; - private readonly DataManager _gameData; + private readonly PerformanceTracker _performance; + private readonly ModEditor _editor; + private readonly ModCacheManager _modCaches; + private readonly Configuration _config; + private readonly ItemSwapTab _itemSwapTab; + private readonly DataManager _gameData; private Mod? _mod; private Vector2 _iconSize = Vector2.Zero; @@ -69,7 +70,7 @@ public partial class ModEditWindow : Window, IDisposable public override void PreDraw() { - using var performance = Penumbra.Performance.Measure(PerformanceType.UiAdvancedWindow); + using var performance = _performance.Measure(PerformanceType.UiAdvancedWindow); var sb = new StringBuilder(256); @@ -127,7 +128,7 @@ public partial class ModEditWindow : Window, IDisposable public override void Draw() { - using var performance = Penumbra.Performance.Measure(PerformanceType.UiAdvancedWindow); + using var performance = _performance.Measure(PerformanceType.UiAdvancedWindow); using var tabBar = ImRaii.TabBar("##tabs"); if (!tabBar) @@ -491,10 +492,11 @@ public partial class ModEditWindow : Window, IDisposable return new FullPath(path); } - public ModEditWindow(FileDialogService fileDialog, ItemSwapTab itemSwapTab, DataManager gameData, + public ModEditWindow(PerformanceTracker performance, FileDialogService fileDialog, ItemSwapTab itemSwapTab, DataManager gameData, Configuration config, ModEditor editor, ResourceTreeFactory resourceTreeFactory, ModCacheManager modCaches) : base(WindowBaseLabel) { + _performance = performance; _itemSwapTab = itemSwapTab; _config = config; _editor = editor;