Use improved filesystem.

This commit is contained in:
Ottermandias 2025-06-13 17:27:49 +02:00
parent 4981b0348f
commit 1f4ec984b3
3 changed files with 5 additions and 15 deletions

View file

@ -80,7 +80,7 @@ public sealed class ModFileSystem : FileSystem<Mod>, IDisposable, ISavable, ISer
// Update sort order when defaulted mod names change.
private void OnModDataChange(ModDataChangeType type, Mod mod, string? oldName)
{
if (!type.HasFlag(ModDataChangeType.Name) || oldName == null || !FindLeaf(mod, out var leaf))
if (!type.HasFlag(ModDataChangeType.Name) || oldName == null || !TryGetValue(mod, out var leaf))
return;
var old = oldName.FixName();
@ -111,7 +111,7 @@ public sealed class ModFileSystem : FileSystem<Mod>, IDisposable, ISavable, ISer
CreateDuplicateLeaf(parent, mod.Name.Text, mod);
break;
case ModPathChangeType.Deleted:
if (FindLeaf(mod, out var leaf))
if (TryGetValue(mod, out var leaf))
Delete(leaf);
break;
@ -124,16 +124,6 @@ public sealed class ModFileSystem : FileSystem<Mod>, IDisposable, ISavable, ISer
}
}
// Search the entire filesystem for the leaf corresponding to a mod.
public bool FindLeaf(Mod mod, [NotNullWhen(true)] out Leaf? leaf)
{
leaf = Root.GetAllDescendants(ISortMode<Mod>.Lexicographical)
.OfType<Leaf>()
.FirstOrDefault(l => l.Value == mod);
return leaf != null;
}
// Used for saving and loading.
private static string ModToIdentifier(Mod mod)
=> mod.ModPath.Name;