Some fixes with collection inheritance.

This commit is contained in:
Ottermandias 2022-07-15 10:19:52 +02:00
parent 9508b8d9b3
commit 3e9f9289e5
4 changed files with 35 additions and 13 deletions

View file

@ -115,7 +115,7 @@ public partial class ModCollection
newCollection.Index = _collections.Count; newCollection.Index = _collections.Count;
_collections.Add( newCollection ); _collections.Add( newCollection );
newCollection.Save(); newCollection.Save();
PluginLog.Debug( "Added collection {Name:l}.", newCollection.Name ); PluginLog.Debug( "Added collection {Name:l}.", newCollection.AnonymizedName );
CollectionChanged.Invoke( CollectionType.Inactive, null, newCollection ); CollectionChanged.Invoke( CollectionType.Inactive, null, newCollection );
SetCollection( newCollection.Index, CollectionType.Current ); SetCollection( newCollection.Index, CollectionType.Current );
return true; return true;
@ -154,8 +154,17 @@ public partial class ModCollection
} }
var collection = _collections[ idx ]; var collection = _collections[ idx ];
// Clear own inheritances.
foreach(var inheritance in collection.Inheritance)
{
collection.ClearSubscriptions( inheritance );
}
collection.Delete(); collection.Delete();
_collections.RemoveAt( idx ); _collections.RemoveAt( idx );
// Clear external inheritances.
foreach( var c in _collections ) foreach( var c in _collections )
{ {
var inheritedIdx = c._inheritance.IndexOf( collection ); var inheritedIdx = c._inheritance.IndexOf( collection );
@ -170,7 +179,7 @@ public partial class ModCollection
} }
} }
PluginLog.Debug( "Removed collection {Name:l}.", collection.Name ); PluginLog.Debug( "Removed collection {Name:l}.", collection.AnonymizedName );
CollectionChanged.Invoke( CollectionType.Inactive, collection, null ); CollectionChanged.Invoke( CollectionType.Inactive, collection, null );
return true; return true;
} }

View file

@ -67,7 +67,7 @@ public partial class ModCollection
} }
catch( Exception e ) catch( Exception e )
{ {
PluginLog.Error( $"Could not save collection {Name}:\n{e}" ); PluginLog.Error( $"Could not save collection {AnonymizedName}:\n{e}" );
} }
} }
@ -90,11 +90,11 @@ public partial class ModCollection
try try
{ {
file.Delete(); file.Delete();
PluginLog.Information( "Deleted collection file {File:l} for {Name:l}.", file.FullName, Name ); PluginLog.Information( "Deleted collection file for {Name:l}.", AnonymizedName );
} }
catch( Exception e ) catch( Exception e )
{ {
PluginLog.Error( $"Could not delete collection file {file.FullName} for {Name}:\n{e}" ); PluginLog.Error( $"Could not delete collection file for {AnonymizedName}:\n{e}" );
} }
} }
@ -105,7 +105,7 @@ public partial class ModCollection
inheritance = Array.Empty< string >(); inheritance = Array.Empty< string >();
if( !file.Exists ) if( !file.Exists )
{ {
PluginLog.Error( $"Could not read collection because {file.FullName} does not exist." ); PluginLog.Error( $"Could not read collection because file does not exist." );
return null; return null;
} }
@ -123,7 +123,7 @@ public partial class ModCollection
} }
catch( Exception e ) catch( Exception e )
{ {
PluginLog.Error( $"Could not read collection information from {file.FullName}:\n{e}" ); PluginLog.Error( $"Could not read collection information from file:\n{e}" );
} }
return null; return null;

View file

@ -88,13 +88,18 @@ public partial class ModCollection
public void RemoveInheritance( int idx ) public void RemoveInheritance( int idx )
{ {
var inheritance = _inheritance[ idx ]; var inheritance = _inheritance[ idx ];
inheritance.ModSettingChanged -= OnInheritedModSettingChange; ClearSubscriptions( inheritance );
inheritance.InheritanceChanged -= OnInheritedInheritanceChange;
_inheritance.RemoveAt( idx ); _inheritance.RemoveAt( idx );
InheritanceChanged.Invoke( false ); InheritanceChanged.Invoke( false );
PluginLog.Debug( "Removed {InheritedName:l} from {Name:l} inheritances.", inheritance.AnonymizedName, AnonymizedName ); PluginLog.Debug( "Removed {InheritedName:l} from {Name:l} inheritances.", inheritance.AnonymizedName, AnonymizedName );
} }
private void ClearSubscriptions( ModCollection other )
{
other.ModSettingChanged -= OnInheritedModSettingChange;
other.InheritanceChanged -= OnInheritedInheritanceChange;
}
// Order in the inheritance list is relevant. // Order in the inheritance list is relevant.
public void MoveInheritance( int from, int to ) public void MoveInheritance( int from, int to )
{ {
@ -115,6 +120,13 @@ public partial class ModCollection
ModSettingChanged.Invoke( type, modIdx, oldValue, groupIdx, true ); ModSettingChanged.Invoke( type, modIdx, oldValue, groupIdx, true );
return; return;
default: default:
if( modIdx < 0 || modIdx >= _settings.Count )
{
PluginLog.Warning(
$"Collection state broken, Mod {modIdx} in inheritance does not exist. ({_settings.Count} mods exist)." );
return;
}
if( _settings[ modIdx ] == null ) if( _settings[ modIdx ] == null )
{ {
ModSettingChanged.Invoke( type, modIdx, oldValue, groupIdx, true ); ModSettingChanged.Invoke( type, modIdx, oldValue, groupIdx, true );

View file

@ -5,6 +5,7 @@ using Penumbra.Collections;
using Penumbra.Mods; using Penumbra.Mods;
using Penumbra.UI.Classes; using Penumbra.UI.Classes;
using System; using System;
using System.Linq;
using System.Numerics; using System.Numerics;
using Dalamud.Logging; using Dalamud.Logging;
@ -43,13 +44,13 @@ public partial class ConfigWindow
{ {
PluginLog.Error( $"Exception thrown during ModPanel Render:\n{e}" ); PluginLog.Error( $"Exception thrown during ModPanel Render:\n{e}" );
PluginLog.Error( $"{Penumbra.ModManager.Count} Mods\n" PluginLog.Error( $"{Penumbra.ModManager.Count} Mods\n"
+ $"{Penumbra.CollectionManager.Current.Name} Current Collection\n" + $"{Penumbra.CollectionManager.Current.AnonymizedName} Current Collection\n"
+ $"{Penumbra.CollectionManager.Current.Settings.Count} Settings\n" + $"{Penumbra.CollectionManager.Current.Settings.Count} Settings\n"
+ $"{_selector.SortMode} Sort Mode\n" + $"{_selector.SortMode.Name} Sort Mode\n"
+ $"{_selector.SelectedLeaf?.Name ?? "NULL"} Selected Leaf\n" + $"{_selector.SelectedLeaf?.Name ?? "NULL"} Selected Leaf\n"
+ $"{_selector.Selected?.Name ?? "NULL"} Selected Mod\n" + $"{_selector.Selected?.Name ?? "NULL"} Selected Mod\n"
+ $"{string.Join( ", ", Penumbra.CollectionManager.Current.Inheritance )} Inheritances\n" + $"{string.Join( ", ", Penumbra.CollectionManager.Current.Inheritance.Select(c => c.AnonymizedName) )} Inheritances\n"
+ $"{_selector.SelectedSettingCollection.Name} Collection\n" ); + $"{_selector.SelectedSettingCollection.AnonymizedName} Collection\n" );
} }
} }