Remove ISubMod.

This commit is contained in:
Ottermandias 2024-04-19 18:28:25 +02:00
parent 8fc7de64d9
commit 9f4c6767f8
23 changed files with 123 additions and 184 deletions

View file

@ -29,7 +29,7 @@ public class DuplicateManager(ModManager modManager, SaveService saveService, Co
Worker = Task.Run(() => CheckDuplicates(filesTmp, _cancellationTokenSource.Token), _cancellationTokenSource.Token);
}
public void DeleteDuplicates(ModFileCollection files, Mod mod, ISubMod option, bool useModManager)
public void DeleteDuplicates(ModFileCollection files, Mod mod, SubMod option, bool useModManager)
{
if (!Worker.IsCompleted || _duplicates.Count == 0)
return;
@ -72,7 +72,7 @@ public class DuplicateManager(ModManager modManager, SaveService saveService, Co
return;
void HandleSubMod(ISubMod subMod, int groupIdx, int optionIdx)
void HandleSubMod(SubMod subMod, int groupIdx, int optionIdx)
{
var changes = false;
var dict = subMod.Files.ToDictionary(kvp => kvp.Key,
@ -86,8 +86,7 @@ public class DuplicateManager(ModManager modManager, SaveService saveService, Co
}
else
{
var sub = (SubMod)subMod;
sub.FileData = dict;
subMod.FileData = dict;
saveService.ImmediateSaveSync(new ModSaveGroup(mod, groupIdx, config.ReplaceNonAsciiOnImport));
}
}

View file

@ -5,7 +5,7 @@ namespace Penumbra.Mods.Editor;
public class FileRegistry : IEquatable<FileRegistry>
{
public readonly List<(ISubMod, Utf8GamePath)> SubModUsage = [];
public readonly List<(SubMod, Utf8GamePath)> SubModUsage = [];
public FullPath File { get; private init; }
public Utf8RelPath RelPath { get; private init; }
public long FileSize { get; private init; }

View file

@ -6,8 +6,8 @@ using Penumbra.String.Classes;
namespace Penumbra.Mods.Editor;
public record struct AppliedModData(
IReadOnlyCollection<KeyValuePair<Utf8GamePath, FullPath>> FileRedirections,
IReadOnlyCollection<MetaManipulation> Manipulations)
Dictionary<Utf8GamePath, FullPath> FileRedirections,
HashSet<MetaManipulation> Manipulations)
{
public static readonly AppliedModData Empty = new([], []);
}
@ -19,14 +19,10 @@ public interface IMod
public int Index { get; }
public ModPriority Priority { get; }
public IReadOnlyList<IModGroup> Groups { get; }
public AppliedModData GetData(ModSettings? settings = null);
public ISubMod Default { get; }
public IReadOnlyList<IModGroup> Groups { get; }
public IEnumerable<SubMod> AllSubMods { get; }
// Cache
public int TotalManipulations { get; }
}

View file

@ -29,7 +29,7 @@ public class ModEditor(
public int OptionIdx { get; private set; }
public IModGroup? Group { get; private set; }
public ISubMod? Option { get; private set; }
public SubMod? Option { get; private set; }
public void LoadMod(Mod mod)
=> LoadMod(mod, -1, 0);
@ -104,7 +104,7 @@ public class ModEditor(
=> Clear();
/// <summary> Apply a option action to all available option in a mod, including the default option. </summary>
public static void ApplyToAllOptions(Mod mod, Action<ISubMod, int, int> action)
public static void ApplyToAllOptions(Mod mod, Action<SubMod, int, int> action)
{
action(mod.Default, -1, 0);
foreach (var (group, groupIdx) in mod.Groups.WithIndex())

View file

@ -38,13 +38,13 @@ public class ModFileCollection : IDisposable
public bool Ready { get; private set; } = true;
public void UpdateAll(Mod mod, ISubMod option)
public void UpdateAll(Mod mod, SubMod option)
{
UpdateFiles(mod, new CancellationToken());
UpdatePaths(mod, option, false, new CancellationToken());
}
public void UpdatePaths(Mod mod, ISubMod option)
public void UpdatePaths(Mod mod, SubMod option)
=> UpdatePaths(mod, option, true, new CancellationToken());
public void Clear()
@ -59,7 +59,7 @@ public class ModFileCollection : IDisposable
public void ClearMissingFiles()
=> _missing.Clear();
public void RemoveUsedPath(ISubMod option, FileRegistry? file, Utf8GamePath gamePath)
public void RemoveUsedPath(SubMod option, FileRegistry? file, Utf8GamePath gamePath)
{
_usedPaths.Remove(gamePath);
if (file != null)
@ -69,10 +69,10 @@ public class ModFileCollection : IDisposable
}
}
public void RemoveUsedPath(ISubMod option, FullPath file, Utf8GamePath gamePath)
public void RemoveUsedPath(SubMod option, FullPath file, Utf8GamePath gamePath)
=> RemoveUsedPath(option, _available.FirstOrDefault(f => f.File.Equals(file)), gamePath);
public void AddUsedPath(ISubMod option, FileRegistry? file, Utf8GamePath gamePath)
public void AddUsedPath(SubMod option, FileRegistry? file, Utf8GamePath gamePath)
{
_usedPaths.Add(gamePath);
if (file == null)
@ -82,7 +82,7 @@ public class ModFileCollection : IDisposable
file.SubModUsage.Add((option, gamePath));
}
public void AddUsedPath(ISubMod option, FullPath file, Utf8GamePath gamePath)
public void AddUsedPath(SubMod option, FullPath file, Utf8GamePath gamePath)
=> AddUsedPath(option, _available.FirstOrDefault(f => f.File.Equals(file)), gamePath);
public void ChangeUsedPath(FileRegistry file, int pathIdx, Utf8GamePath gamePath)
@ -154,7 +154,7 @@ public class ModFileCollection : IDisposable
_usedPaths.Clear();
}
private void UpdatePaths(Mod mod, ISubMod option, bool clearRegistries, CancellationToken tok)
private void UpdatePaths(Mod mod, SubMod option, bool clearRegistries, CancellationToken tok)
{
tok.ThrowIfCancellationRequested();
ClearPaths(clearRegistries, tok);

View file

@ -30,16 +30,16 @@ public class ModFileEditor(ModFileCollection files, ModManager modManager, Commu
return num;
}
public void Revert(Mod mod, ISubMod option)
public void Revert(Mod mod, SubMod option)
{
files.UpdateAll(mod, option);
Changes = false;
}
/// <summary> Remove all path redirections where the pointed-to file does not exist. </summary>
public void RemoveMissingPaths(Mod mod, ISubMod option)
public void RemoveMissingPaths(Mod mod, SubMod option)
{
void HandleSubMod(ISubMod subMod, int groupIdx, int optionIdx)
void HandleSubMod(SubMod subMod, int groupIdx, int optionIdx)
{
var newDict = subMod.Files.Where(kvp => CheckAgainstMissing(mod, subMod, kvp.Value, kvp.Key, subMod == option))
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
@ -61,7 +61,7 @@ public class ModFileEditor(ModFileCollection files, ModManager modManager, Commu
/// If path is empty, it will be deleted instead.
/// If pathIdx is equal to the total number of paths, path will be added, otherwise replaced.
/// </summary>
public bool SetGamePath(ISubMod option, int fileIdx, int pathIdx, Utf8GamePath path)
public bool SetGamePath(SubMod option, int fileIdx, int pathIdx, Utf8GamePath path)
{
if (!CanAddGamePath(path) || fileIdx < 0 || fileIdx > files.Available.Count)
return false;
@ -84,7 +84,7 @@ public class ModFileEditor(ModFileCollection files, ModManager modManager, Commu
/// Transform a set of files to the appropriate game paths with the given number of folders skipped,
/// and add them to the given option.
/// </summary>
public int AddPathsToSelected(ISubMod option, IEnumerable<FileRegistry> files1, int skipFolders = 0)
public int AddPathsToSelected(SubMod option, IEnumerable<FileRegistry> files1, int skipFolders = 0)
{
var failed = 0;
foreach (var file in files1)
@ -111,7 +111,7 @@ public class ModFileEditor(ModFileCollection files, ModManager modManager, Commu
}
/// <summary> Remove all paths in the current option from the given files. </summary>
public void RemovePathsFromSelected(ISubMod option, IEnumerable<FileRegistry> files1)
public void RemovePathsFromSelected(SubMod option, IEnumerable<FileRegistry> files1)
{
foreach (var file in files1)
{
@ -129,7 +129,7 @@ public class ModFileEditor(ModFileCollection files, ModManager modManager, Commu
}
/// <summary> Delete all given files from your filesystem </summary>
public void DeleteFiles(Mod mod, ISubMod option, IEnumerable<FileRegistry> files1)
public void DeleteFiles(Mod mod, SubMod option, IEnumerable<FileRegistry> files1)
{
var deletions = 0;
foreach (var file in files1)
@ -155,7 +155,7 @@ public class ModFileEditor(ModFileCollection files, ModManager modManager, Commu
}
private bool CheckAgainstMissing(Mod mod, ISubMod option, FullPath file, Utf8GamePath key, bool removeUsed)
private bool CheckAgainstMissing(Mod mod, SubMod option, FullPath file, Utf8GamePath key, bool removeUsed)
{
if (!files.Missing.Contains(file))
return true;

View file

@ -151,7 +151,7 @@ public class ModMerger : IDisposable
MergeIntoOption(MergeFromMod!.AllSubMods.Reverse(), option, true);
}
private void MergeIntoOption(IEnumerable<ISubMod> mergeOptions, SubMod option, bool fromFileToFile)
private void MergeIntoOption(IEnumerable<SubMod> mergeOptions, SubMod option, bool fromFileToFile)
{
var redirections = option.FileData.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
var swaps = option.FileSwapData.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

View file

@ -103,7 +103,7 @@ public class ModMetaEditor(ModManager modManager)
Changes = true;
}
public void Load(Mod mod, ISubMod currentOption)
public void Load(Mod mod, SubMod currentOption)
{
OtherImcCount = 0;
OtherEqpCount = 0;

View file

@ -11,7 +11,7 @@ public class ModSwapEditor(ModManager modManager)
public IReadOnlyDictionary<Utf8GamePath, FullPath> Swaps
=> _swaps;
public void Revert(ISubMod option)
public void Revert(SubMod option)
{
_swaps.SetTo(option.FileSwaps);
Changes = false;