|
1 | | -using System.Diagnostics; |
| 1 | +using System.Diagnostics; |
2 | 2 | using Microsoft.Extensions.Logging; |
3 | 3 | using RLBot.Flat; |
4 | 4 | using RLBotCS.Model; |
@@ -182,6 +182,39 @@ private T GetEnum<T>(TomlTable table, string key, T fallback) |
182 | 182 | return fallback; |
183 | 183 | } |
184 | 184 |
|
| 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 | + |
185 | 218 | private static string? CombinePaths(string? parent, string? child) |
186 | 219 | { |
187 | 220 | if (parent == null || child == null) |
@@ -267,7 +300,7 @@ private PlayerConfigurationT ParseCarTable(TomlTable table, string matchConfigPa |
267 | 300 | loadoutFileOverride = Path.Combine(matchConfigDir, loadoutFileOverride); |
268 | 301 | } |
269 | 302 |
|
270 | | - PlayerClass playerClass = GetEnum(table, Fields.AgentType, PlayerClass.CustomBot); |
| 303 | + PlayerClass playerClass = GetAgentType(table); |
271 | 304 | if (playerClass == PlayerClass.Human) |
272 | 305 | { |
273 | 306 | return new PlayerConfigurationT |
|
0 commit comments