|
| 1 | +import tomllib |
1 | 2 | from pathlib import Path |
2 | 3 | from time import sleep |
3 | | -from typing import Optional |
| 4 | +from typing import Any, Optional |
4 | 5 |
|
5 | 6 | import psutil |
6 | 7 |
|
7 | 8 | from rlbot import flat, version |
8 | 9 | from rlbot.interface import RLBOT_SERVER_PORT, SocketRelay |
9 | 10 | from rlbot.utils import gateway |
10 | 11 | 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 | + ) |
12 | 95 |
|
13 | 96 |
|
14 | 97 | class MatchManager: |
|
0 commit comments