This commit is contained in:
Ottermandias 2023-03-25 16:12:14 +01:00
parent d58a3e0fe7
commit 355206e0cf

View file

@ -16,13 +16,12 @@ public partial class ModCollection
// Enable or disable the mod inheritance of mod idx. // Enable or disable the mod inheritance of mod idx.
public bool SetModInheritance( int idx, bool inherit ) public bool SetModInheritance( int idx, bool inherit )
{ {
if( FixInheritance( idx, inherit ) ) if (!FixInheritance(idx, inherit))
{ return false;
ModSettingChanged.Invoke( ModSettingChange.Inheritance, idx, inherit ? 0 : 1, 0, false );
return true; ModSettingChanged.Invoke( ModSettingChange.Inheritance, idx, inherit ? 0 : 1, 0, false );
} return true;
return false;
} }
// Set the enabled state mod idx to newValue if it differs from the current enabled state. // Set the enabled state mod idx to newValue if it differs from the current enabled state.
@ -30,24 +29,21 @@ public partial class ModCollection
public bool SetModState( int idx, bool newValue ) public bool SetModState( int idx, bool newValue )
{ {
var oldValue = _settings[ idx ]?.Enabled ?? this[ idx ].Settings?.Enabled ?? false; var oldValue = _settings[ idx ]?.Enabled ?? this[ idx ].Settings?.Enabled ?? false;
if( newValue != oldValue ) if (newValue == oldValue)
{ return false;
var inheritance = FixInheritance( idx, false );
_settings[ idx ]!.Enabled = newValue; var inheritance = FixInheritance( idx, false );
ModSettingChanged.Invoke( ModSettingChange.EnableState, idx, inheritance ? -1 : newValue ? 0 : 1, 0, false ); _settings[ idx ]!.Enabled = newValue;
return true; ModSettingChanged.Invoke( ModSettingChange.EnableState, idx, inheritance ? -1 : newValue ? 0 : 1, 0, false );
} return true;
return false;
} }
// Enable or disable the mod inheritance of every mod in mods. // Enable or disable the mod inheritance of every mod in mods.
public void SetMultipleModInheritances( IEnumerable< Mod > mods, bool inherit ) public void SetMultipleModInheritances( IEnumerable< Mod > mods, bool inherit )
{ {
if( mods.Aggregate( false, ( current, mod ) => current | FixInheritance( mod.Index, inherit ) ) ) if( mods.Aggregate( false, ( current, mod ) => current | FixInheritance( mod.Index, inherit ) ) )
{
ModSettingChanged.Invoke( ModSettingChange.MultiInheritance, -1, -1, 0, false ); ModSettingChanged.Invoke( ModSettingChange.MultiInheritance, -1, -1, 0, false );
}
} }
// Set the enabled state of every mod in mods to the new value. // Set the enabled state of every mod in mods to the new value.
@ -58,12 +54,12 @@ public partial class ModCollection
foreach( var mod in mods ) foreach( var mod in mods )
{ {
var oldValue = _settings[ mod.Index ]?.Enabled; var oldValue = _settings[ mod.Index ]?.Enabled;
if( newValue != oldValue ) if (newValue == oldValue)
{ continue;
FixInheritance( mod.Index, false );
_settings[ mod.Index ]!.Enabled = newValue; FixInheritance( mod.Index, false );
changes = true; _settings[ mod.Index ]!.Enabled = newValue;
} changes = true;
} }
if( changes ) if( changes )
@ -77,15 +73,14 @@ public partial class ModCollection
public bool SetModPriority( int idx, int newValue ) public bool SetModPriority( int idx, int newValue )
{ {
var oldValue = _settings[ idx ]?.Priority ?? this[ idx ].Settings?.Priority ?? 0; var oldValue = _settings[ idx ]?.Priority ?? this[ idx ].Settings?.Priority ?? 0;
if( newValue != oldValue ) if (newValue == oldValue)
{ return false;
var inheritance = FixInheritance( idx, false );
_settings[ idx ]!.Priority = newValue; var inheritance = FixInheritance( idx, false );
ModSettingChanged.Invoke( ModSettingChange.Priority, idx, inheritance ? -1 : oldValue, 0, false ); _settings[ idx ]!.Priority = newValue;
return true; ModSettingChanged.Invoke( ModSettingChange.Priority, idx, inheritance ? -1 : oldValue, 0, false );
} return true;
return false;
} }
// Set a given setting group settingName of mod idx to newValue if it differs from the current value and fix it if necessary. // Set a given setting group settingName of mod idx to newValue if it differs from the current value and fix it if necessary.
@ -126,9 +121,7 @@ public partial class ModCollection
{ {
var settings = _settings[ idx ]; var settings = _settings[ idx ];
if( inherit == ( settings == null ) ) if( inherit == ( settings == null ) )
{
return false; return false;
}
_settings[ idx ] = inherit ? null : this[ idx ].Settings?.DeepCopy() ?? ModSettings.DefaultSettings( Penumbra.ModManager[ idx ] ); _settings[ idx ] = inherit ? null : this[ idx ].Settings?.DeepCopy() ?? ModSettings.DefaultSettings( Penumbra.ModManager[ idx ] );
return true; return true;
@ -140,8 +133,6 @@ public partial class ModCollection
private void SaveOnChange( bool inherited ) private void SaveOnChange( bool inherited )
{ {
if( !inherited ) if( !inherited )
{
Penumbra.SaveService.QueueSave(this); Penumbra.SaveService.QueueSave(this);
}
} }
} }