diff --git a/Penumbra/Penumbra.cs b/Penumbra/Penumbra.cs index 7b9c9bb5..563bbee7 100644 --- a/Penumbra/Penumbra.cs +++ b/Penumbra/Penumbra.cs @@ -13,6 +13,7 @@ using Penumbra.Mods; using Penumbra.PlayerWatch; using Penumbra.UI; using Penumbra.Util; +using System.Linq; namespace Penumbra; @@ -36,6 +37,9 @@ public class Penumbra : IDalamudPlugin private WebServer? _webServer; + private readonly ModManager _modManager; + private readonly ModCollection[] _collections; + public Penumbra( DalamudPluginInterface pluginInterface ) { FFXIVClientStructs.Resolver.Initialize(); @@ -52,11 +56,11 @@ public class Penumbra : IDalamudPlugin var gameUtils = Service< ResidentResources >.Set(); PlayerWatcher = PlayerWatchFactory.Create( Dalamud.Framework, Dalamud.ClientState, Dalamud.Objects ); Service< MetaDefaults >.Set(); - var modManager = Service< ModManager >.Set(); + _modManager = Service< ModManager >.Set(); - modManager.DiscoverMods(); + _modManager.DiscoverMods(); - ObjectReloader = new ObjectReloader( modManager, Config.WaitFrames ); + ObjectReloader = new ObjectReloader( _modManager, Config.WaitFrames ); ResourceLoader = new ResourceLoader( this ); @@ -91,6 +95,8 @@ public class Penumbra : IDalamudPlugin PluginLog.Debug( "Triggered Redraw of {Player}.", p.Name ); ObjectReloader.RedrawObject( p, RedrawType.OnlyWithSettings ); }; + + _collections = _modManager.Collections.Collections.Values.ToArray(); } public bool Enable() @@ -191,12 +197,53 @@ public class Penumbra : IDalamudPlugin ShutdownWebServer(); } + public bool SetCollection(string type, string collection) + { + type = type.ToLower(); + collection = collection.ToLower(); + + if( type != "default" && type != "forced" ) + { + Dalamud.Chat.Print( "Second command argument is not default or forced, the correct command format is: /penumbra collection {default|forced} " ); + return false; + } + + var currentCollection = ( type == "default" ) ? _modManager.Collections.DefaultCollection : _modManager.Collections.ForcedCollection; + + if( collection == currentCollection.Name.ToLower() ) + { + Dalamud.Chat.Print( $"{currentCollection.Name} is already the active collection." ); + return false; + } + + var newCollection = ( collection == "none" ) ? ModCollection.Empty : _collections.FirstOrDefault( c => c.Name.ToLower() == collection ); + + if ( newCollection == null ) + { + Dalamud.Chat.Print( $"The collection {collection} does not exist." ); + return false; + } + + if( type == "default" ) + { + _modManager.Collections.SetDefaultCollection( newCollection ); + Dalamud.Chat.Print( $"Set { newCollection.Name } as default collection." ); + } + else if ( type == "forced" ) + { + _modManager.Collections.SetForcedCollection( newCollection ); + Dalamud.Chat.Print( $"Set { newCollection.Name } as forced collection." ); + } + + return true; + } + private void OnCommand( string command, string rawArgs ) { const string modsEnabled = "Your mods have now been enabled."; const string modsDisabled = "Your mods have now been disabled."; - var args = rawArgs.Split( new[] { ' ' }, 2 ); + var args = rawArgs.Split( new[] { ' ' }, 3 ); if( args.Length > 0 && args[ 0 ].Length > 0 ) { switch( args[ 0 ] ) @@ -249,6 +296,17 @@ public class Penumbra : IDalamudPlugin : modsDisabled ); break; } + case "collection": + { + if( args.Length == 3 ) + { + SetCollection(args[ 1 ], args[ 2 ]); + } else + { + Dalamud.Chat.Print( "Missing arguments, the correct command format is: /penumbra collection {default|forced} " ); + } + break; + } } return;