Skip to content

Commit 6e0c383

Browse files
committed
Add get_player_config which read tomls
1 parent 2a11dba commit 6e0c383

File tree

3 files changed

+95
-3
lines changed

3 files changed

+95
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
66
name = "rlbot"
77
description = "A high performance Python interface for communicating with RLBot v5."
88
dynamic = ["version"]
9-
requires-python = ">= 3.10"
9+
requires-python = ">= 3.11"
1010
dependencies = [
1111
"rlbot_flatbuffers~=0.6.0",
1212
"psutil==6.*",

rlbot/managers/match.py

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,97 @@
1+
import tomllib
12
from pathlib import Path
23
from time import sleep
3-
from typing import Optional
4+
from typing import Any, Optional
45

56
import psutil
67

78
from rlbot import flat, version
89
from rlbot.interface import RLBOT_SERVER_PORT, SocketRelay
910
from rlbot.utils import gateway
1011
from rlbot.utils.logging import DEFAULT_LOGGER
11-
from rlbot.utils.os_detector import MAIN_EXECUTABLE_NAME
12+
from rlbot.utils.os_detector import CURRENT_OS, MAIN_EXECUTABLE_NAME, OS
13+
14+
15+
def get_player_paint(config: dict[str, Any]) -> flat.LoadoutPaint:
16+
return flat.LoadoutPaint(
17+
config.get("car_paint_id", 0),
18+
config.get("decal_paint_id", 0),
19+
config.get("wheels_paint_id", 0),
20+
config.get("boost_paint_id", 0),
21+
config.get("antenna_paint_id", 0),
22+
config.get("hat_paint_id", 0),
23+
config.get("trails_paint_id", 0),
24+
config.get("goal_explosion_paint_id", 0),
25+
)
26+
27+
28+
def get_player_loadout(path: str, team: int) -> flat.PlayerLoadout:
29+
with open(path, "rb") as f:
30+
config = tomllib.load(f)
31+
32+
loadout = config["blue_loadout"] if team == 0 else config["orange_loadout"]
33+
paint = loadout.get("paint", None)
34+
35+
return flat.PlayerLoadout(
36+
loadout.get("team_color_id", 0),
37+
loadout.get("custom_color_id", 0),
38+
loadout.get("car_id", 0),
39+
loadout.get("decal_id", 0),
40+
loadout.get("wheels_id", 0),
41+
loadout.get("boost_id", 0),
42+
loadout.get("antenna_id", 0),
43+
loadout.get("hat_id", 0),
44+
loadout.get("paint_finish_id", 0),
45+
loadout.get("custom_finish_id", 0),
46+
loadout.get("engine_audio_id", 0),
47+
loadout.get("trails_id", 0),
48+
loadout.get("goal_explosion_id", 0),
49+
get_player_paint(paint) if paint is not None else None,
50+
)
51+
52+
53+
def get_player_config(
54+
type: flat.RLBot | flat.Psyonix, team: int, path: Path | str
55+
) -> flat.PlayerConfiguration:
56+
with open(path, "rb") as f:
57+
config = tomllib.load(f)
58+
59+
match path:
60+
case Path():
61+
parent = path.parent
62+
case _:
63+
parent = Path(path).parent
64+
65+
settings: dict[str, Any] = config["settings"]
66+
67+
location = parent
68+
if "location" in settings:
69+
location /= settings["location"]
70+
71+
run_command = settings.get("run_command", "")
72+
if CURRENT_OS == OS.LINUX and "run_command_linux" in settings:
73+
run_command = settings["run_command_linux"]
74+
75+
loadout_path = settings.get("looks_config", None)
76+
if loadout_path is not None:
77+
loadout_path = parent / loadout_path
78+
79+
loadout = (
80+
get_player_loadout(loadout_path, team)
81+
if loadout_path is not None and loadout_path.exists()
82+
else None
83+
)
84+
85+
return flat.PlayerConfiguration(
86+
type,
87+
settings["name"],
88+
team,
89+
str(location),
90+
str(run_command),
91+
loadout,
92+
0,
93+
settings.get("hivemind", False),
94+
)
1295

1396

1497
class MatchManager:

tests/read_toml.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from pathlib import Path
2+
3+
from rlbot import flat
4+
from rlbot.managers.match import get_player_config
5+
6+
CURRENT_FILE = Path(__file__).parent
7+
8+
if __name__ == "__main__":
9+
print(get_player_config(flat.RLBot(), 0, CURRENT_FILE / "necto/bot.toml"))

0 commit comments

Comments
 (0)