Move CollectionManager out of ModManager

This commit is contained in:
Ottermandias 2022-03-23 11:45:38 +01:00
parent 0eff4e2e67
commit 9c0fc8a8c7
19 changed files with 94 additions and 102 deletions

View file

@ -26,8 +26,8 @@ public partial class SettingsInterface
}
var modManager = Penumbra.ModManager;
var items = modManager.Collections.DefaultCollection.Cache?.ChangedItems ?? new Dictionary< string, object? >();
var forced = modManager.Collections.ForcedCollection.Cache?.ChangedItems ?? new Dictionary< string, object? >();
var items = Penumbra.CollectionManager.DefaultCollection.Cache?.ChangedItems ?? new Dictionary< string, object? >();
var forced = Penumbra.CollectionManager.ForcedCollection.Cache?.ChangedItems ?? new Dictionary< string, object? >();
using var raii = ImGuiRaii.DeferredEnd( ImGui.EndTabItem );

View file

@ -31,7 +31,7 @@ public partial class SettingsInterface
private void UpdateNames()
{
_collections = Penumbra.ModManager.Collections.Collections.Values.Prepend( ModCollection.Empty ).ToArray();
_collections = Penumbra.CollectionManager.Collections.Values.Prepend( ModCollection.Empty ).ToArray();
_collectionNames = string.Join( "\0", _collections.Skip( 1 ).Select( c => c.Name ) ) + '\0';
_collectionNamesWithNone = "None\0" + _collectionNames;
UpdateIndices();
@ -51,18 +51,18 @@ public partial class SettingsInterface
}
private void UpdateIndex()
=> _currentCollectionIndex = GetIndex( Penumbra.ModManager.Collections.CurrentCollection ) - 1;
=> _currentCollectionIndex = GetIndex( Penumbra.CollectionManager.CurrentCollection ) - 1;
public void UpdateForcedIndex()
=> _currentForcedIndex = GetIndex( Penumbra.ModManager.Collections.ForcedCollection );
=> _currentForcedIndex = GetIndex( Penumbra.CollectionManager.ForcedCollection );
public void UpdateDefaultIndex()
=> _currentDefaultIndex = GetIndex( Penumbra.ModManager.Collections.DefaultCollection );
=> _currentDefaultIndex = GetIndex( Penumbra.CollectionManager.DefaultCollection );
private void UpdateCharacterIndices()
{
_currentCharacterIndices.Clear();
foreach( var kvp in Penumbra.ModManager.Collections.CharacterCollection )
foreach( var kvp in Penumbra.CollectionManager.CharacterCollection )
{
_currentCharacterIndices[ kvp.Key ] = GetIndex( kvp.Value );
}
@ -84,11 +84,10 @@ public partial class SettingsInterface
private void CreateNewCollection( Dictionary< string, ModSettings > settings )
{
var manager = Penumbra.ModManager;
if( manager.Collections.AddCollection( _newCollectionName, settings ) )
if( Penumbra.CollectionManager.AddCollection( _newCollectionName, settings ) )
{
UpdateNames();
SetCurrentCollection( manager.Collections.Collections[ _newCollectionName ], true );
SetCurrentCollection( Penumbra.CollectionManager.Collections[ _newCollectionName ], true );
}
_newCollectionName = string.Empty;
@ -98,10 +97,9 @@ public partial class SettingsInterface
{
if( ImGui.Button( "Clean Settings" ) )
{
var manager = Penumbra.ModManager;
var changes = ModFunctions.CleanUpCollection( manager.Collections.CurrentCollection.Settings,
manager.BasePath.EnumerateDirectories() );
manager.Collections.CurrentCollection.UpdateSettings( changes );
var changes = ModFunctions.CleanUpCollection( Penumbra.CollectionManager.CurrentCollection.Settings,
Penumbra.ModManager.BasePath.EnumerateDirectories() );
Penumbra.CollectionManager.CurrentCollection.UpdateSettings( changes );
}
ImGuiCustom.HoverTooltip(
@ -126,10 +124,9 @@ public partial class SettingsInterface
var hover = ImGui.IsItemHovered();
ImGui.SameLine();
var manager = Penumbra.ModManager;
if( ImGui.Button( "Duplicate Current Collection" ) && _newCollectionName.Length > 0 )
{
CreateNewCollection( manager.Collections.CurrentCollection.Settings );
CreateNewCollection( Penumbra.CollectionManager.CurrentCollection.Settings );
}
hover |= ImGui.IsItemHovered();
@ -140,13 +137,13 @@ public partial class SettingsInterface
ImGui.SetTooltip( "Please enter a name before creating a collection." );
}
var deleteCondition = manager.Collections.Collections.Count > 1
&& manager.Collections.CurrentCollection.Name != ModCollection.DefaultCollection;
var deleteCondition = Penumbra.CollectionManager.Collections.Count > 1
&& Penumbra.CollectionManager.CurrentCollection.Name != ModCollection.DefaultCollection;
ImGui.SameLine();
if( ImGuiCustom.DisableButton( "Delete Current Collection", deleteCondition ) )
{
manager.Collections.RemoveCollection( manager.Collections.CurrentCollection.Name );
SetCurrentCollection( manager.Collections.CurrentCollection, true );
Penumbra.CollectionManager.RemoveCollection( Penumbra.CollectionManager.CurrentCollection.Name );
SetCurrentCollection( Penumbra.CollectionManager.CurrentCollection, true );
UpdateNames();
}
@ -169,7 +166,7 @@ public partial class SettingsInterface
return;
}
Penumbra.ModManager.Collections.SetCollection( _collections[ idx + 1 ], CollectionType.Current );
Penumbra.CollectionManager.SetCollection( _collections[ idx + 1 ], CollectionType.Current );
_currentCollectionIndex = idx;
_selector.Cache.TriggerListReset();
if( _selector.Mod != null )
@ -208,7 +205,7 @@ public partial class SettingsInterface
ImGui.SetNextItemWidth( SettingsMenu.InputTextWidth );
if( ImGui.Combo( "##Default Collection", ref index, _collectionNamesWithNone ) && index != _currentDefaultIndex )
{
Penumbra.ModManager.Collections.SetCollection( _collections[ index ], CollectionType.Default );
Penumbra.CollectionManager.SetCollection( _collections[ index ], CollectionType.Default );
_currentDefaultIndex = index;
}
@ -225,18 +222,17 @@ public partial class SettingsInterface
{
var index = _currentForcedIndex;
ImGui.SetNextItemWidth( SettingsMenu.InputTextWidth );
var manager = Penumbra.ModManager;
using var style = ImGuiRaii.PushStyle( ImGuiStyleVar.Alpha, 0.5f, manager.Collections.CharacterCollection.Count == 0 );
using var style = ImGuiRaii.PushStyle( ImGuiStyleVar.Alpha, 0.5f, Penumbra.CollectionManager.CharacterCollection.Count == 0 );
if( ImGui.Combo( "##Forced Collection", ref index, _collectionNamesWithNone )
&& index != _currentForcedIndex
&& manager.Collections.CharacterCollection.Count > 0 )
&& index != _currentForcedIndex
&& Penumbra.CollectionManager.CharacterCollection.Count > 0 )
{
manager.Collections.SetCollection( _collections[ index ], CollectionType.Forced );
Penumbra.CollectionManager.SetCollection( _collections[ index ], CollectionType.Forced );
_currentForcedIndex = index;
}
style.Pop();
if( manager.Collections.CharacterCollection.Count == 0 && ImGui.IsItemHovered() )
if( Penumbra.CollectionManager.CharacterCollection.Count == 0 && ImGui.IsItemHovered() )
{
ImGui.SetTooltip(
"Forced Collections only provide value if you have at least one Character Collection. There is no need to set one until then." );
@ -262,7 +258,7 @@ public partial class SettingsInterface
if( ImGuiCustom.DisableButton( "Create New Character Collection",
_newCharacterName.Length > 0 && Penumbra.Config.HasReadCharacterCollectionDesc ) )
{
Penumbra.ModManager.Collections.CreateCharacterCollection( _newCharacterName );
Penumbra.CollectionManager.CreateCharacterCollection( _newCharacterName );
_currentCharacterIndices[ _newCharacterName ] = 0;
_newCharacterName = string.Empty;
}
@ -344,15 +340,14 @@ public partial class SettingsInterface
DrawDefaultCollectionSelector();
DrawForcedCollectionSelector();
var manager = Penumbra.ModManager;
foreach( var name in manager.Collections.CharacterCollection.Keys.ToArray() )
foreach( var name in Penumbra.CollectionManager.CharacterCollection.Keys.ToArray() )
{
var idx = _currentCharacterIndices[ name ];
var tmp = idx;
ImGui.SetNextItemWidth( SettingsMenu.InputTextWidth );
if( ImGui.Combo( $"##{name}collection", ref tmp, _collectionNamesWithNone ) && idx != tmp )
{
manager.Collections.SetCollection( _collections[ tmp ], CollectionType.Character, name );
Penumbra.CollectionManager.SetCollection( _collections[ tmp ], CollectionType.Character, name );
_currentCharacterIndices[ name ] = tmp;
}
@ -362,7 +357,7 @@ public partial class SettingsInterface
if( ImGui.Button( $"{FontAwesomeIcon.Trash.ToIconString()}##{name}", Vector2.One * ImGui.GetFrameHeight() ) )
{
manager.Collections.RemoveCharacterCollection( name );
Penumbra.CollectionManager.RemoveCharacterCollection( name );
}
font.Pop();

View file

@ -49,17 +49,16 @@ public partial class SettingsInterface
using var raii = ImGuiRaii.DeferredEnd( ImGui.EndTable );
var manager = Penumbra.ModManager;
PrintValue( "Current Collection", manager.Collections.CurrentCollection.Name );
PrintValue( " has Cache", ( manager.Collections.CurrentCollection.Cache != null ).ToString() );
PrintValue( "Default Collection", manager.Collections.DefaultCollection.Name );
PrintValue( " has Cache", ( manager.Collections.DefaultCollection.Cache != null ).ToString() );
PrintValue( "Forced Collection", manager.Collections.ForcedCollection.Name );
PrintValue( " has Cache", ( manager.Collections.ForcedCollection.Cache != null ).ToString() );
PrintValue( "Mod Manager BasePath", manager.BasePath?.Name ?? "NULL" );
PrintValue( "Mod Manager BasePath-Full", manager.BasePath?.FullName ?? "NULL" );
PrintValue( "Current Collection", Penumbra.CollectionManager.CurrentCollection.Name );
PrintValue( " has Cache", ( Penumbra.CollectionManager.CurrentCollection.Cache != null ).ToString() );
PrintValue( "Default Collection", Penumbra.CollectionManager.DefaultCollection.Name );
PrintValue( " has Cache", ( Penumbra.CollectionManager.DefaultCollection.Cache != null ).ToString() );
PrintValue( "Forced Collection", Penumbra.CollectionManager.ForcedCollection.Name );
PrintValue( " has Cache", ( Penumbra.CollectionManager.ForcedCollection.Cache != null ).ToString() );
PrintValue( "Mod Manager BasePath", manager.BasePath.Name );
PrintValue( "Mod Manager BasePath-Full", manager.BasePath.FullName );
PrintValue( "Mod Manager BasePath IsRooted", Path.IsPathRooted( Penumbra.Config.ModDirectory ).ToString() );
PrintValue( "Mod Manager BasePath Exists",
manager.BasePath != null ? Directory.Exists( manager.BasePath.FullName ).ToString() : false.ToString() );
PrintValue( "Mod Manager BasePath Exists", Directory.Exists( manager.BasePath.FullName ).ToString() );
PrintValue( "Mod Manager Valid", manager.Valid.ToString() );
//PrintValue( "Resource Loader Enabled", _penumbra.ResourceLoader.IsEnabled.ToString() );
}
@ -122,7 +121,7 @@ public partial class SettingsInterface
return;
}
var cache = Penumbra.ModManager.Collections.CurrentCollection.Cache;
var cache = Penumbra.CollectionManager.CurrentCollection.Cache;
if( cache == null || !ImGui.BeginTable( "##MissingFilesDebugList", 1, ImGuiTableFlags.RowBg, -Vector2.UnitX ) )
{
return;

View file

@ -141,8 +141,8 @@ public partial class SettingsInterface
const ImGuiTableFlags flags = ImGuiTableFlags.RowBg | ImGuiTableFlags.ScrollX;
var modManager = Penumbra.ModManager;
var defaultCollection = modManager.Collections.DefaultCollection.Cache;
var forcedCollection = modManager.Collections.ForcedCollection.Cache;
var defaultCollection = Penumbra.CollectionManager.DefaultCollection.Cache;
var forcedCollection = Penumbra.CollectionManager.ForcedCollection.Cache;
var (defaultResolved, defaultMeta) = defaultCollection != null
? ( defaultCollection.ResolvedFiles.Count, defaultCollection.MetaManipulations.Count )

View file

@ -120,13 +120,13 @@ namespace Penumbra.UI
var lower = filter.ToLowerInvariant();
if( lower.StartsWith( "c:" ) )
{
_modFilterChanges = lower.Substring( 2 );
_modFilterChanges = lower[ 2.. ];
_modFilter = string.Empty;
_modFilterAuthor = string.Empty;
}
else if( lower.StartsWith( "a:" ) )
{
_modFilterAuthor = lower.Substring( 2 );
_modFilterAuthor = lower[ 2.. ];
_modFilter = string.Empty;
_modFilterChanges = string.Empty;
}
@ -147,11 +147,11 @@ namespace Penumbra.UI
_visibleFolders.Clear();
PluginLog.Debug( "Resetting mod selector list..." );
if( !_modsInOrder.Any() )
if( _modsInOrder.Count == 0 )
{
foreach( var modData in _manager.StructuredMods.AllMods( _manager.Config.SortFoldersFirst ) )
{
var mod = _manager.Collections.CurrentCollection.GetMod( modData );
var mod = Penumbra.CollectionManager.CurrentCollection.GetMod( modData );
_modsInOrder.Add( mod );
_visibleMods.Add( CheckFilters( mod ) );
}

View file

@ -127,7 +127,7 @@ public partial class SettingsInterface
private void Save()
{
Penumbra.ModManager.Collections.CurrentCollection.Save();
Penumbra.CollectionManager.CurrentCollection.Save();
}
private void DrawAboutTab()
@ -422,11 +422,10 @@ public partial class SettingsInterface
_fullFilenameList = null;
_selector.SaveCurrentMod();
// Since files may have changed, we need to recompute effective files.
var modManager = Penumbra.ModManager;
foreach( var collection in modManager.Collections.Collections.Values
foreach( var collection in Penumbra.CollectionManager.Collections.Values
.Where( c => c.Cache != null && c.Settings[ Mod!.Data.BasePath.Name ].Enabled ) )
{
collection.CalculateEffectiveFileList( false, modManager.Collections.IsActive( collection ) );
collection.CalculateEffectiveFileList( false, Penumbra.CollectionManager.IsActive( collection ) );
}
// If the mod is enabled in the current collection, its conflicts may have changed.

View file

@ -526,10 +526,10 @@ public partial class SettingsInterface
}
Cache.TriggerFilterReset();
var collection = Penumbra.ModManager.Collections.CurrentCollection;
var collection = Penumbra.CollectionManager.CurrentCollection;
if( collection.Cache != null )
{
collection.CalculateEffectiveFileList( metaManips, Penumbra.ModManager.Collections.IsActive( collection ) );
collection.CalculateEffectiveFileList( metaManips, Penumbra.CollectionManager.IsActive( collection ) );
}
collection.Save();
@ -609,7 +609,7 @@ public partial class SettingsInterface
private void DrawCollectionButton( string label, string tooltipLabel, float size, ModCollection collection )
{
if( collection == ModCollection.Empty
|| collection == Penumbra.ModManager.Collections.CurrentCollection )
|| collection == Penumbra.CollectionManager.CurrentCollection )
{
using var _ = ImGuiRaii.PushStyle( ImGuiStyleVar.Alpha, 0.5f );
ImGui.Button( label, Vector2.UnitX * size );
@ -638,10 +638,10 @@ public partial class SettingsInterface
- 4 * ImGui.GetStyle().ItemSpacing.X )
/ 2, 5f );
ImGui.SameLine();
DrawCollectionButton( "Default", "default", buttonSize, Penumbra.ModManager.Collections.DefaultCollection );
DrawCollectionButton( "Default", "default", buttonSize, Penumbra.CollectionManager.DefaultCollection );
ImGui.SameLine();
DrawCollectionButton( "Forced", "forced", buttonSize, Penumbra.ModManager.Collections.ForcedCollection );
DrawCollectionButton( "Forced", "forced", buttonSize, Penumbra.CollectionManager.ForcedCollection );
ImGui.SameLine();
ImGui.SetNextItemWidth( comboSize );

View file

@ -57,18 +57,17 @@ public partial class SettingsInterface : IDisposable
private void SaveCurrentCollection( bool recalculateMeta )
{
var current = Penumbra.ModManager.Collections.CurrentCollection;
var current = Penumbra.CollectionManager.CurrentCollection;
current.Save();
RecalculateCurrent( recalculateMeta );
}
private void RecalculateCurrent( bool recalculateMeta )
{
var modManager = Penumbra.ModManager;
var current = modManager.Collections.CurrentCollection;
var current = Penumbra.CollectionManager.CurrentCollection;
if( current.Cache != null )
{
current.CalculateEffectiveFileList( recalculateMeta, modManager.Collections.IsActive( current ) );
current.CalculateEffectiveFileList( recalculateMeta, Penumbra.CollectionManager.IsActive( current ) );
_menu.InstalledTab.Selector.Cache.TriggerFilterReset();
}
}