Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update to newest spec
  • Loading branch information
VirxEC committed Jun 7, 2025
commit aa43e8ce2756b7f24c6d868ed851a90dd7058eab
116 changes: 75 additions & 41 deletions rlbot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,30 +94,28 @@ def load_match_config(config_path: Path | str) -> flat.MatchConfiguration:

match variant:
case "rlbot":
variety, use_config = flat.CustomBot(), True
abs_config_path = (config_path.parent / car_config).resolve()
players.append(
load_player_config(abs_config_path, team, name, loadout_file)
)
case "psyonix":
variety, use_config = flat.Psyonix(skill), True
abs_config_path = (config_path.parent / car_config).resolve()
players.append(
load_psyonix_config(
team,
skill,
name,
loadout_file,
abs_config_path,
)
)
case "human":
variety, use_config = flat.Human(), False
case "partymember":
logger.warning("PartyMember player type is not supported yet.")
variety, use_config = flat.PartyMember(), False
players.append(flat.PlayerConfiguration(flat.Human(), team, 0))
case t:
raise ConfigParsingException(
f"Invalid player type {repr(t)} for player {len(players)}."
)

if use_config and car_config:
abs_config_path = (config_path.parent / car_config).resolve()
players.append(
load_player_config(abs_config_path, variety, team, name, loadout_file) # type: ignore
)
else:
loadout = load_player_loadout(loadout_file, team) if loadout_file else None
players.append(
flat.PlayerConfiguration(variety, name, team, loadout=loadout)
)

scripts: list[flat.ScriptConfiguration] = []
for script_table in config.get("scripts", []):
if script_config := __str(script_table, "config_file"):
Expand Down Expand Up @@ -170,7 +168,9 @@ def load_match_config(config_path: Path | str) -> flat.MatchConfiguration:
existing_match_behavior=__enum(
match_table, "existing_match_behavior", flat.ExistingMatchBehavior
),
enable_rendering=__bool(match_table, "enable_rendering"),
enable_rendering=__enum(
match_table, "enable_rendering", flat.DebugRendering.OffByDefault
),
enable_state_setting=__bool(match_table, "enable_state_setting"),
freeplay=__bool(match_table, "freeplay"),
)
Expand Down Expand Up @@ -217,8 +217,7 @@ def load_player_loadout(path: Path | str, team: int) -> flat.PlayerLoadout:


def load_player_config(
path: Path | str | None,
type: flat.CustomBot | flat.Psyonix,
path: Path | str,
team: int,
name_override: str | None = None,
loadout_override: Path | str | None = None,
Expand All @@ -227,20 +226,6 @@ def load_player_config(
Reads the bot toml file at the provided path and
creates a `PlayerConfiguration` of the given type for the given team.
"""
if path is None:
loadout = (
load_player_loadout(loadout_override, team)
if loadout_override is not None
else None
)

return flat.PlayerConfiguration(
type,
name_override or "",
team,
loadout=loadout,
)

path = Path(path)
with open(path, "rb") as f:
config = tomllib.load(f)
Expand All @@ -266,15 +251,64 @@ def load_player_config(
)

return flat.PlayerConfiguration(
type,
name_override or __str(settings, "name"),
flat.CustomBot(
name_override or __str(settings, "name"),
str(root_dir),
run_command,
loadout,
__str(settings, "agent_id"),
__bool(settings, "hivemind"),
),
team,
0,
)


def load_psyonix_config(
team: int,
skill_level: flat.PsyonixSkill,
name_override: str | None = None,
loadout_override: Path | str | None = None,
path: Path | str | None = None,
) -> flat.PlayerConfiguration:
"""
Creates a `PlayerConfiguration` for a Psyonix bot of the given team and skill.
If a path is provided, it will be used override the default name and loadout.
"""
name = name_override
loadout_path = loadout_override

# Don't parse the toml file if we have no data we need to extract,
# even if a path to a toml file is provided.
if path is not None and (name is None or loadout_path is None):
path = Path(path)
with open(path, "rb") as f:
config = tomllib.load(f)

settings = __table(config, "settings")

if name is None:
name = __str(settings, "name")

if loadout_path is None:
loadout_path = (
path.parent / Path(__str(settings, "loadout_file"))
if "loadout_file" in settings
else None
)

loadout = (
load_player_loadout(loadout_path, team) if loadout_path is not None else None
)

return flat.PlayerConfiguration(
flat.PsyonixBot(
name or "",
loadout,
skill_level,
),
team,
str(root_dir),
run_command,
loadout,
0,
__str(settings, "agent_id"),
__bool(settings, "hivemind"),
)


Expand Down
10 changes: 6 additions & 4 deletions rlbot/managers/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ def _try_initialize(self):

# Search match settings for our name
for player in self.match_config.player_configurations:
if player.player_id == self.player_id:
self.name = player.name
self.logger = get_logger(self.name)
break
match player.variety.item:
case flat.CustomBot(name):
if player.player_id == self.player_id:
self.name = name
self.logger = get_logger(self.name)
break

try:
self.initialize()
Expand Down
10 changes: 6 additions & 4 deletions rlbot/managers/hivemind.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@ def _try_initialize(self):
# Search match settings for our spawn ids
for player_id in self.player_ids:
for player in self.match_config.player_configurations:
if player.player_id == player_id:
self.names.append(player.name)
self.loggers.append(get_logger(player.name))
break
match player.variety.item:
case flat.CustomBot(name):
if player.player_id == player_id:
self.names.append(name)
self.loggers.append(get_logger(name))
break

try:
self.initialize()
Expand Down