Skip to content

Commit 002a636

Browse files
committed
Special config parsing for PlayerClass
1 parent 81c00f3 commit 002a636

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

RLBotCS/ManagerTools/ConfigParser.cs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Diagnostics;
1+
using System.Diagnostics;
22
using Microsoft.Extensions.Logging;
33
using RLBot.Flat;
44
using RLBotCS.Model;
@@ -182,6 +182,39 @@ private T GetEnum<T>(TomlTable table, string key, T fallback)
182182
return fallback;
183183
}
184184

185+
private PlayerClass GetAgentType(TomlTable table)
186+
{
187+
if (table.TryGetValue(Fields.AgentType, out var raw))
188+
{
189+
if (raw is string val)
190+
{
191+
switch (val.ToLower())
192+
{
193+
case "rlbot":
194+
return PlayerClass.CustomBot;
195+
case "psyonix":
196+
return PlayerClass.PsyonixBot;
197+
case "human":
198+
return PlayerClass.Human;
199+
default:
200+
throw new InvalidCastException(
201+
$"{_context.ToStringWithEnd(Fields.AgentType)} has invalid value \"{raw}\". "
202+
+ $"Find valid values on https:/wiki.rlbot.org."
203+
);
204+
}
205+
}
206+
else
207+
{
208+
throw new InvalidCastException(
209+
$"{_context.ToStringWithEnd(Fields.AgentType)} has value {raw}, but a value of type {typeof(PlayerClass).Name} was expected."
210+
);
211+
}
212+
}
213+
214+
_missingValues.Add(_context.ToStringWithEnd(Fields.AgentType));
215+
return PlayerClass.CustomBot;
216+
}
217+
185218
private static string? CombinePaths(string? parent, string? child)
186219
{
187220
if (parent == null || child == null)
@@ -267,7 +300,7 @@ private PlayerConfigurationT ParseCarTable(TomlTable table, string matchConfigPa
267300
loadoutFileOverride = Path.Combine(matchConfigDir, loadoutFileOverride);
268301
}
269302

270-
PlayerClass playerClass = GetEnum(table, Fields.AgentType, PlayerClass.CustomBot);
303+
PlayerClass playerClass = GetAgentType(table);
271304
if (playerClass == PlayerClass.Human)
272305
{
273306
return new PlayerConfigurationT

RLBotCSTests/TestTomls/bad_team.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
[[cars]]
44
team = 42
5-
type = "PsyonixBot"
5+
type = "Psyonix"

RLBotCSTests/TestTomls/edge.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ gravity = "rEvErsE"
1515
[[cars]]
1616
# No config
1717
name = "Boomer"
18-
type = "pSyOniXbOt"
18+
type = "pSyOniX"
1919
skill = "pro"
2020

2121
[[cars]]

0 commit comments

Comments
 (0)