refactor: remove wildcard listener support

This commit is contained in:
2026-06-17 20:50:37 +02:00
parent 775c02794e
commit a69e81a3cb
-21
View File
@@ -12,7 +12,6 @@ public class CommandHookModSystem : ModSystem
internal static CommandHookModSystem? Instance; internal static CommandHookModSystem? Instance;
private readonly List<ICommandHookListener> listeners = new(); private readonly List<ICommandHookListener> listeners = new();
private readonly List<ICommandHookListener> wildcards = new();
private FrozenDictionary<string, FrozenDictionary<string, CommandRegistration>> registrations = private FrozenDictionary<string, FrozenDictionary<string, CommandRegistration>> registrations =
FrozenDictionary<string, FrozenDictionary<string, CommandRegistration>>.Empty; FrozenDictionary<string, FrozenDictionary<string, CommandRegistration>>.Empty;
@@ -38,7 +37,6 @@ public class CommandHookModSystem : ModSystem
{ {
harmony?.UnpatchAll(Mod.Info.ModID); harmony?.UnpatchAll(Mod.Info.ModID);
listeners.Clear(); listeners.Clear();
wildcards.Clear();
Instance = null; Instance = null;
} }
@@ -61,13 +59,11 @@ public class CommandHookModSystem : ModSystem
return; return;
listeners[i] = listener; listeners[i] = listener;
SyncWildcard(listener, commands);
Rebuild(); Rebuild();
return; return;
} }
listeners.Add(listener); listeners.Add(listener);
SyncWildcard(listener, commands);
} }
public void Unregister(ICommandHookListener listener) public void Unregister(ICommandHookListener listener)
@@ -78,7 +74,6 @@ public class CommandHookModSystem : ModSystem
continue; continue;
listeners.RemoveAt(i); listeners.RemoveAt(i);
wildcards.RemoveAll(w => w.ModId == listener.ModId);
Rebuild(); Rebuild();
return; return;
} }
@@ -94,10 +89,6 @@ public class CommandHookModSystem : ModSystem
if (commands == null || commands.Count == 0) if (commands == null || commands.Count == 0)
continue; continue;
bool isWildcard = commands.Count == 1 && commands[0] == "*";
if (isWildcard)
continue;
foreach (var cmd in commands) foreach (var cmd in commands)
{ {
if (!builder.TryGetValue(cmd, out var mods)) if (!builder.TryGetValue(cmd, out var mods))
@@ -109,10 +100,6 @@ public class CommandHookModSystem : ModSystem
} }
} }
foreach (var wildcard in wildcards)
foreach (var mods in builder.Values)
mods[wildcard.ModId] = wildcard.Registration;
var pruned = new Dictionary<string, FrozenDictionary<string, CommandRegistration>>( var pruned = new Dictionary<string, FrozenDictionary<string, CommandRegistration>>(
builder.Count builder.Count
); );
@@ -164,14 +151,6 @@ public class CommandHookModSystem : ModSystem
} }
} }
private void SyncWildcard(ICommandHookListener listener, IReadOnlyList<string> commands)
{
bool isWildcard = commands.Count == 1 && commands[0] == "*";
wildcards.RemoveAll(w => w.ModId == listener.ModId);
if (isWildcard)
wildcards.Add(listener);
}
private static bool CommandListEquals(IReadOnlyList<string> a, IReadOnlyList<string> b) private static bool CommandListEquals(IReadOnlyList<string> a, IReadOnlyList<string> b)
{ {
if (a.Count != b.Count) if (a.Count != b.Count)