diff --git a/RLBotCS/ManagerTools/ConfigParser.cs b/RLBotCS/ManagerTools/ConfigParser.cs index 8bbb6d4..5062421 100644 --- a/RLBotCS/ManagerTools/ConfigParser.cs +++ b/RLBotCS/ManagerTools/ConfigParser.cs @@ -167,7 +167,7 @@ private T GetEnum(TomlTable table, string key, T fallback) return res; throw new InvalidCastException( $"{_context.ToStringWithEnd(key)} has invalid value \"{raw}\". " - + $"Find valid values on https:/wiki.rlbot.org." + + $"Find valid values on https://wiki.rlbot.org." ); } else @@ -199,7 +199,7 @@ private PlayerClass GetAgentType(TomlTable table) default: throw new InvalidCastException( $"{_context.ToStringWithEnd(Fields.AgentType)} has invalid value \"{raw}\". " - + $"Find valid values on https:/wiki.rlbot.org." + + $"Find valid values on https://wiki.rlbot.org." ); } } diff --git a/RLBotCS/ManagerTools/MatchStarter.cs b/RLBotCS/ManagerTools/MatchStarter.cs index 3d0f1ad..dd01036 100644 --- a/RLBotCS/ManagerTools/MatchStarter.cs +++ b/RLBotCS/ManagerTools/MatchStarter.cs @@ -130,6 +130,21 @@ public void OnMapSpawn(string mapName, PlayerSpawner spawner) } } + private static string DedupName(string name, Dictionary nameCounts) + { + if (nameCounts.TryGetValue(name, out int count)) + { + nameCounts[name] = ++count; + name += $" ({count + 1})"; + } + else + { + nameCounts[name] = 0; + } + + return name; + } + private void PreprocessMatch(MatchConfigurationT matchConfig) { Dictionary playerNames = []; @@ -138,43 +153,28 @@ private void PreprocessMatch(MatchConfigurationT matchConfig) foreach (var player in matchConfig.PlayerConfigurations) { // De-duplicating similar names. Overwrites original value. - - if (player.Variety.Value is CustomBotT config) + switch (player.Variety.Value) { - string playerName = config.Name ?? ""; - if (playerNames.TryGetValue(playerName, out int value)) - { - playerNames[playerName] = ++value; - config.Name = playerName + $" ({value + 1})"; - } - else - { - playerNames[playerName] = 0; - config.Name = playerName; - } + case CustomBotT config: + string playerName = config.Name ?? ""; + config.Name = DedupName(playerName, playerNames); - if (config.Hivemind) - { - _hivemindNameMap[config.Name] = playerName; - } + if (config.Hivemind) + { + _hivemindNameMap[config.Name] = playerName; + } + break; + case PsyonixBotT config: + config.Name = DedupName(config.Name ?? "", playerNames); + break; } } Dictionary scriptNames = []; - foreach (var scriptConfig in matchConfig.ScriptConfigurations) + foreach (var script in matchConfig.ScriptConfigurations) { // De-duplicating similar names. Overwrites original value. - string scriptName = scriptConfig.Name ?? ""; - if (scriptNames.TryGetValue(scriptName, out int value)) - { - scriptNames[scriptName] = ++value; - scriptConfig.Name = scriptName + $" ({value})"; - } - else - { - scriptNames[scriptName] = 0; - scriptConfig.Name = scriptName; - } + script.Name = DedupName(script.Name ?? "", scriptNames); } }