Remove single object change functions and update from mod manager.

This commit is contained in:
Ottermandias 2022-05-21 20:50:13 +02:00
parent 4613461154
commit ced5e344cf
2 changed files with 3 additions and 92 deletions

View file

@ -266,7 +266,6 @@ public partial class ModCollection
ModOptionChangeType.OptionFilesChanged => ( false, true, false ),
ModOptionChangeType.OptionSwapsChanged => ( false, true, false ),
ModOptionChangeType.OptionMetaChanged => ( false, true, true ),
ModOptionChangeType.OptionUpdated => ( false, true, true ),
ModOptionChangeType.DisplayChange => ( false, false, false ),
_ => ( false, false, false ),
};

View file

@ -23,7 +23,6 @@ public enum ModOptionChangeType
OptionFilesChanged,
OptionSwapsChanged,
OptionMetaChanged,
OptionUpdated,
DisplayChange,
}
@ -171,7 +170,7 @@ public sealed partial class Mod
}
option.Name = newName;
return;
break;
}
ModOptionChanged.Invoke( ModOptionChangeType.DisplayChange, mod, groupIdx, optionIdx, -1 );
@ -244,41 +243,11 @@ public sealed partial class Mod
}
}
public void OptionSetManipulation( Mod mod, int groupIdx, int optionIdx, MetaManipulation manip, bool delete = false )
{
var subMod = GetSubMod( mod, groupIdx, optionIdx );
if( delete )
{
if( !subMod.ManipulationData.Remove( manip ) )
{
return;
}
}
else
{
if( subMod.ManipulationData.TryGetValue( manip, out var oldManip ) )
{
if( manip.EntryEquals( oldManip ) )
{
return;
}
subMod.ManipulationData.Remove( oldManip );
subMod.ManipulationData.Add( manip );
}
else
{
subMod.ManipulationData.Add( manip );
}
}
ModOptionChanged.Invoke( ModOptionChangeType.OptionMetaChanged, mod, groupIdx, optionIdx, -1 );
}
public void OptionSetManipulations( Mod mod, int groupIdx, int optionIdx, HashSet< MetaManipulation > manipulations )
{
var subMod = GetSubMod( mod, groupIdx, optionIdx );
if( subMod.Manipulations.All( m => manipulations.TryGetValue( m, out var old ) && old.EntryEquals( m ) ) )
if( subMod.Manipulations.Count == manipulations.Count
&& subMod.Manipulations.All( m => manipulations.TryGetValue( m, out var old ) && old.EntryEquals( m ) ) )
{
return;
}
@ -287,15 +256,6 @@ public sealed partial class Mod
ModOptionChanged.Invoke( ModOptionChangeType.OptionMetaChanged, mod, groupIdx, optionIdx, -1 );
}
public void OptionSetFile( Mod mod, int groupIdx, int optionIdx, Utf8GamePath gamePath, FullPath? newPath )
{
var subMod = GetSubMod( mod, groupIdx, optionIdx );
if( OptionSetFile( subMod.FileData, gamePath, newPath ) )
{
ModOptionChanged.Invoke( ModOptionChangeType.OptionFilesChanged, mod, groupIdx, optionIdx, -1 );
}
}
public void OptionSetFiles( Mod mod, int groupIdx, int optionIdx, Dictionary< Utf8GamePath, FullPath > replacements )
{
var subMod = GetSubMod( mod, groupIdx, optionIdx );
@ -319,15 +279,6 @@ public sealed partial class Mod
}
}
public void OptionSetFileSwap( Mod mod, int groupIdx, int optionIdx, Utf8GamePath gamePath, FullPath? newPath )
{
var subMod = GetSubMod( mod, groupIdx, optionIdx );
if( OptionSetFile( subMod.FileSwapData, gamePath, newPath ) )
{
ModOptionChanged.Invoke( ModOptionChangeType.OptionSwapsChanged, mod, groupIdx, optionIdx, -1 );
}
}
public void OptionSetFileSwaps( Mod mod, int groupIdx, int optionIdx, Dictionary< Utf8GamePath, FullPath > swaps )
{
var subMod = GetSubMod( mod, groupIdx, optionIdx );
@ -340,16 +291,6 @@ public sealed partial class Mod
ModOptionChanged.Invoke( ModOptionChangeType.OptionSwapsChanged, mod, groupIdx, optionIdx, -1 );
}
public void OptionUpdate( Mod mod, int groupIdx, int optionIdx, Dictionary< Utf8GamePath, FullPath > replacements,
HashSet< MetaManipulation > manipulations, Dictionary< Utf8GamePath, FullPath > swaps )
{
var subMod = GetSubMod( mod, groupIdx, optionIdx );
subMod.FileData = replacements;
subMod.ManipulationData = manipulations;
subMod.FileSwapData = swaps;
ModOptionChanged.Invoke( ModOptionChangeType.OptionUpdated, mod, groupIdx, optionIdx, -1 );
}
public static bool VerifyFileName( Mod mod, IModGroup? group, string newName, bool message )
{
var path = newName.RemoveInvalidPathSymbols();
@ -383,34 +324,6 @@ public sealed partial class Mod
};
}
private static bool OptionSetFile( IDictionary< Utf8GamePath, FullPath > dict, Utf8GamePath gamePath, FullPath? newPath )
{
if( dict.TryGetValue( gamePath, out var oldPath ) )
{
if( newPath == null )
{
dict.Remove( gamePath );
return true;
}
if( newPath.Value.Equals( oldPath ) )
{
return false;
}
dict[ gamePath ] = newPath.Value;
return true;
}
if( newPath == null )
{
return false;
}
dict.Add( gamePath, newPath.Value );
return true;
}
private static void OnModOptionChange( ModOptionChangeType type, Mod mod, int groupIdx, int _, int _2 )
{
// File deletion is handled in the actual function.
@ -444,7 +357,6 @@ public sealed partial class Mod
ModOptionChangeType.OptionFilesChanged => 0 < ( mod.TotalFileCount = mod.AllSubMods.Sum( s => s.Files.Count ) ),
ModOptionChangeType.OptionSwapsChanged => 0 < ( mod.TotalSwapCount = mod.AllSubMods.Sum( s => s.FileSwaps.Count ) ),
ModOptionChangeType.OptionMetaChanged => 0 < ( mod.TotalManipulations = mod.AllSubMods.Sum( s => s.Manipulations.Count ) ),
ModOptionChangeType.OptionUpdated => mod.SetCounts(),
ModOptionChangeType.DisplayChange => false,
_ => false,
};