Skip to content

Commit aa43e8c

Browse files
committed
Update to newest spec
1 parent e85c051 commit aa43e8c

File tree

3 files changed

+87
-49
lines changed

3 files changed

+87
-49
lines changed

rlbot/config.py

Lines changed: 75 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -94,30 +94,28 @@ def load_match_config(config_path: Path | str) -> flat.MatchConfiguration:
9494

9595
match variant:
9696
case "rlbot":
97-
variety, use_config = flat.CustomBot(), True
97+
abs_config_path = (config_path.parent / car_config).resolve()
98+
players.append(
99+
load_player_config(abs_config_path, team, name, loadout_file)
100+
)
98101
case "psyonix":
99-
variety, use_config = flat.Psyonix(skill), True
102+
abs_config_path = (config_path.parent / car_config).resolve()
103+
players.append(
104+
load_psyonix_config(
105+
team,
106+
skill,
107+
name,
108+
loadout_file,
109+
abs_config_path,
110+
)
111+
)
100112
case "human":
101-
variety, use_config = flat.Human(), False
102-
case "partymember":
103-
logger.warning("PartyMember player type is not supported yet.")
104-
variety, use_config = flat.PartyMember(), False
113+
players.append(flat.PlayerConfiguration(flat.Human(), team, 0))
105114
case t:
106115
raise ConfigParsingException(
107116
f"Invalid player type {repr(t)} for player {len(players)}."
108117
)
109118

110-
if use_config and car_config:
111-
abs_config_path = (config_path.parent / car_config).resolve()
112-
players.append(
113-
load_player_config(abs_config_path, variety, team, name, loadout_file) # type: ignore
114-
)
115-
else:
116-
loadout = load_player_loadout(loadout_file, team) if loadout_file else None
117-
players.append(
118-
flat.PlayerConfiguration(variety, name, team, loadout=loadout)
119-
)
120-
121119
scripts: list[flat.ScriptConfiguration] = []
122120
for script_table in config.get("scripts", []):
123121
if script_config := __str(script_table, "config_file"):
@@ -170,7 +168,9 @@ def load_match_config(config_path: Path | str) -> flat.MatchConfiguration:
170168
existing_match_behavior=__enum(
171169
match_table, "existing_match_behavior", flat.ExistingMatchBehavior
172170
),
173-
enable_rendering=__bool(match_table, "enable_rendering"),
171+
enable_rendering=__enum(
172+
match_table, "enable_rendering", flat.DebugRendering.OffByDefault
173+
),
174174
enable_state_setting=__bool(match_table, "enable_state_setting"),
175175
freeplay=__bool(match_table, "freeplay"),
176176
)
@@ -217,8 +217,7 @@ def load_player_loadout(path: Path | str, team: int) -> flat.PlayerLoadout:
217217

218218

219219
def load_player_config(
220-
path: Path | str | None,
221-
type: flat.CustomBot | flat.Psyonix,
220+
path: Path | str,
222221
team: int,
223222
name_override: str | None = None,
224223
loadout_override: Path | str | None = None,
@@ -227,20 +226,6 @@ def load_player_config(
227226
Reads the bot toml file at the provided path and
228227
creates a `PlayerConfiguration` of the given type for the given team.
229228
"""
230-
if path is None:
231-
loadout = (
232-
load_player_loadout(loadout_override, team)
233-
if loadout_override is not None
234-
else None
235-
)
236-
237-
return flat.PlayerConfiguration(
238-
type,
239-
name_override or "",
240-
team,
241-
loadout=loadout,
242-
)
243-
244229
path = Path(path)
245230
with open(path, "rb") as f:
246231
config = tomllib.load(f)
@@ -266,15 +251,64 @@ def load_player_config(
266251
)
267252

268253
return flat.PlayerConfiguration(
269-
type,
270-
name_override or __str(settings, "name"),
254+
flat.CustomBot(
255+
name_override or __str(settings, "name"),
256+
str(root_dir),
257+
run_command,
258+
loadout,
259+
__str(settings, "agent_id"),
260+
__bool(settings, "hivemind"),
261+
),
262+
team,
263+
0,
264+
)
265+
266+
267+
def load_psyonix_config(
268+
team: int,
269+
skill_level: flat.PsyonixSkill,
270+
name_override: str | None = None,
271+
loadout_override: Path | str | None = None,
272+
path: Path | str | None = None,
273+
) -> flat.PlayerConfiguration:
274+
"""
275+
Creates a `PlayerConfiguration` for a Psyonix bot of the given team and skill.
276+
If a path is provided, it will be used override the default name and loadout.
277+
"""
278+
name = name_override
279+
loadout_path = loadout_override
280+
281+
# Don't parse the toml file if we have no data we need to extract,
282+
# even if a path to a toml file is provided.
283+
if path is not None and (name is None or loadout_path is None):
284+
path = Path(path)
285+
with open(path, "rb") as f:
286+
config = tomllib.load(f)
287+
288+
settings = __table(config, "settings")
289+
290+
if name is None:
291+
name = __str(settings, "name")
292+
293+
if loadout_path is None:
294+
loadout_path = (
295+
path.parent / Path(__str(settings, "loadout_file"))
296+
if "loadout_file" in settings
297+
else None
298+
)
299+
300+
loadout = (
301+
load_player_loadout(loadout_path, team) if loadout_path is not None else None
302+
)
303+
304+
return flat.PlayerConfiguration(
305+
flat.PsyonixBot(
306+
name or "",
307+
loadout,
308+
skill_level,
309+
),
271310
team,
272-
str(root_dir),
273-
run_command,
274-
loadout,
275311
0,
276-
__str(settings, "agent_id"),
277-
__bool(settings, "hivemind"),
278312
)
279313

280314

rlbot/managers/bot.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,12 @@ def _try_initialize(self):
105105

106106
# Search match settings for our name
107107
for player in self.match_config.player_configurations:
108-
if player.player_id == self.player_id:
109-
self.name = player.name
110-
self.logger = get_logger(self.name)
111-
break
108+
match player.variety.item:
109+
case flat.CustomBot(name):
110+
if player.player_id == self.player_id:
111+
self.name = name
112+
self.logger = get_logger(self.name)
113+
break
112114

113115
try:
114116
self.initialize()

rlbot/managers/hivemind.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,12 @@ def _try_initialize(self):
107107
# Search match settings for our spawn ids
108108
for player_id in self.player_ids:
109109
for player in self.match_config.player_configurations:
110-
if player.player_id == player_id:
111-
self.names.append(player.name)
112-
self.loggers.append(get_logger(player.name))
113-
break
110+
match player.variety.item:
111+
case flat.CustomBot(name):
112+
if player.player_id == player_id:
113+
self.names.append(name)
114+
self.loggers.append(get_logger(name))
115+
break
114116

115117
try:
116118
self.initialize()

0 commit comments

Comments
 (0)