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

@ -88,13 +88,18 @@ public partial class ModCollection
public void RemoveInheritance( int idx )
{
var inheritance = _inheritance[ idx ];
inheritance.ModSettingChanged -= OnInheritedModSettingChange;
inheritance.InheritanceChanged -= OnInheritedInheritanceChange;
ClearSubscriptions( inheritance );
_inheritance.RemoveAt( idx );
InheritanceChanged.Invoke( false );
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.
public void MoveInheritance( int from, int to )
{
@ -115,6 +120,13 @@ public partial class ModCollection
ModSettingChanged.Invoke( type, modIdx, oldValue, groupIdx, true );
return;
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 )
{
ModSettingChanged.Invoke( type, modIdx, oldValue, groupIdx, true );