refactor: remove wildcard listener support
This commit is contained in:
@@ -12,7 +12,6 @@ public class CommandHookModSystem : ModSystem
|
||||
internal static CommandHookModSystem? Instance;
|
||||
|
||||
private readonly List<ICommandHookListener> listeners = new();
|
||||
private readonly List<ICommandHookListener> wildcards = new();
|
||||
|
||||
private FrozenDictionary<string, FrozenDictionary<string, CommandRegistration>> registrations =
|
||||
FrozenDictionary<string, FrozenDictionary<string, CommandRegistration>>.Empty;
|
||||
@@ -38,7 +37,6 @@ public class CommandHookModSystem : ModSystem
|
||||
{
|
||||
harmony?.UnpatchAll(Mod.Info.ModID);
|
||||
listeners.Clear();
|
||||
wildcards.Clear();
|
||||
Instance = null;
|
||||
}
|
||||
|
||||
@@ -61,13 +59,11 @@ public class CommandHookModSystem : ModSystem
|
||||
return;
|
||||
|
||||
listeners[i] = listener;
|
||||
SyncWildcard(listener, commands);
|
||||
Rebuild();
|
||||
return;
|
||||
}
|
||||
|
||||
listeners.Add(listener);
|
||||
SyncWildcard(listener, commands);
|
||||
}
|
||||
|
||||
public void Unregister(ICommandHookListener listener)
|
||||
@@ -78,7 +74,6 @@ public class CommandHookModSystem : ModSystem
|
||||
continue;
|
||||
|
||||
listeners.RemoveAt(i);
|
||||
wildcards.RemoveAll(w => w.ModId == listener.ModId);
|
||||
Rebuild();
|
||||
return;
|
||||
}
|
||||
@@ -94,10 +89,6 @@ public class CommandHookModSystem : ModSystem
|
||||
if (commands == null || commands.Count == 0)
|
||||
continue;
|
||||
|
||||
bool isWildcard = commands.Count == 1 && commands[0] == "*";
|
||||
if (isWildcard)
|
||||
continue;
|
||||
|
||||
foreach (var cmd in commands)
|
||||
{
|
||||
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>>(
|
||||
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)
|
||||
{
|
||||
if (a.Count != b.Count)
|
||||
|
||||
Reference in New Issue
Block a user