Skip to content

Commit 3d368e8

Browse files
Merge pull request #34 from RLBot/cfg
Beta 48
2 parents 892b715 + baa380e commit 3d368e8

File tree

18 files changed

+168
-44
lines changed

18 files changed

+168
-44
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ pyrightconfig.json
175175

176176
# End of https://www.toptal.com/developers/gitignore/api/python
177177

178+
uv.lock
178179
.vscode/
179180
*.obj
180181
RLBotServer*

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ The following is how to setup a development environment for this project, NOT ho
3030
- `pip uninstall rlbot_flatbuffers`
3131
- `pip install --editable <path/to/rlbot_flatbuffers>`
3232

33-
This project is formatted using [Black](https://github.com/psf/black).
33+
This project is formatted using [Ruff](https://docs.astral.sh/ruff/formatter/).
3434

35-
- Install: `pip install black`.
36-
- Use: `black .`
35+
- Install: `pip install ruff`.
36+
- Sort imports: `ruff check --select I --fix`
37+
- Format code: `ruff format`
3738

3839
## Testing
3940

pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,12 @@ Repository = "https://github.com/RLBot/python-interface"
2323

2424
[tool.setuptools.dynamic]
2525
version = {attr = "rlbot.version.__version__"}
26+
27+
[dependency-groups]
28+
dev = [
29+
"ruff>=0.12.5",
30+
"toml>=0.10.2",
31+
]
32+
33+
[tool.ruff.format]
34+
docstring-code-format = true

rlbot/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .version import __version__
1+
from .version import __version__ as __version__

rlbot/config.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from typing import Any, Literal
44

55
import rlbot.flat as flat
6-
from rlbot.utils.logging import DEFAULT_LOGGER as logger
76
from rlbot.utils.os_detector import CURRENT_OS, OS
87

98

@@ -112,7 +111,7 @@ def load_match_config(config_path: Path | str) -> flat.MatchConfiguration:
112111
)
113112
)
114113
case "human":
115-
players.append(flat.PlayerConfiguration(flat.Human(), team, 0))
114+
players.append(get_human(team))
116115
case t:
117116
raise ConfigParsingException(
118117
f"Invalid player type {repr(t)} for player {len(players)}."
@@ -323,6 +322,13 @@ def load_psyonix_config(
323322
)
324323

325324

325+
def get_human(team: int) -> flat.PlayerConfiguration:
326+
"""
327+
Creates a `PlayerConfiguration` for a human player on the given team.
328+
"""
329+
return flat.PlayerConfiguration(flat.Human(), team)
330+
331+
326332
def load_script_config(path: Path | str) -> flat.ScriptConfiguration:
327333
"""
328334
Reads the script toml file at the provided path and creates a `ScriptConfiguration` from it.

rlbot/interface.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def disconnect(self):
323323
self.logger.critical("RLBot is not responding to our disconnect request!?")
324324
self._running = False
325325

326-
assert (
327-
not self._running
328-
), "Disconnect request or timeout should have set self._running to False"
326+
assert not self._running, (
327+
"Disconnect request or timeout should have set self._running to False"
328+
)
329329
self.is_connected = False

rlbot/managers/match.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,42 @@ def connect(
9494
rlbot_server_port=rlbot_server_port or self.rlbot_server_port,
9595
)
9696

97+
def run(self, *, background_thread: bool = False):
98+
"""
99+
Handle incoming messages until disconnected.
100+
101+
- background_thread: If `True`, a background thread will be started to process messages.
102+
"""
103+
self.rlbot_interface.run(background_thread=background_thread)
104+
105+
def connect_and_run(
106+
self,
107+
*,
108+
wants_match_communications: bool,
109+
wants_ball_predictions: bool,
110+
close_between_matches: bool = True,
111+
rlbot_server_ip: str = RLBOT_SERVER_IP,
112+
rlbot_server_port: Optional[int] = None,
113+
background_thread: bool = False,
114+
):
115+
"""
116+
Connects to the RLBot server specifying the given settings.
117+
118+
- wants_match_communications: Whether match communication messages should be sent to this process.
119+
- wants_ball_predictions: Whether ball prediction messages should be sent to this process.
120+
- close_between_matches: Whether RLBot should close this connection between matches, specifically upon
121+
`StartMatch` and `StopMatch` messages, since RLBot does not actually detect the ending of matches.
122+
- background_thread: If `True`, a background thread will be started to process messages.
123+
"""
124+
self.connect(
125+
wants_match_communications=wants_match_communications,
126+
wants_ball_predictions=wants_ball_predictions,
127+
close_between_matches=close_between_matches,
128+
rlbot_server_ip=rlbot_server_ip,
129+
rlbot_server_port=rlbot_server_port,
130+
)
131+
self.run(background_thread=background_thread)
132+
97133
def wait_for_first_packet(self):
98134
while self.packet is None or self.packet.match_info.match_phase in {
99135
flat.MatchPhase.Inactive,
@@ -117,12 +153,12 @@ def start_match(
117153
self.ensure_server_started()
118154

119155
if not self.rlbot_interface.is_connected:
120-
self.connect(
156+
self.connect_and_run(
121157
wants_match_communications=False,
122158
wants_ball_predictions=False,
123159
close_between_matches=False,
160+
background_thread=True,
124161
)
125-
self.rlbot_interface.run(background_thread=True)
126162

127163
self.rlbot_interface.start_match(config)
128164

@@ -136,7 +172,7 @@ def start_match(
136172

137173
def disconnect(self):
138174
"""
139-
Disconnect from the RLBotServer.
175+
Disconnect from RLBotServer.
140176
Note that the server will continue running as long as Rocket League does.
141177
"""
142178
self.rlbot_interface.disconnect()
@@ -167,8 +203,8 @@ def shut_down(self, use_force_if_necessary: bool = True):
167203

168204
self.logger.info("Shutting down RLBot...")
169205

170-
# In theory this is all we need for the server to cleanly shut itself down
171206
try:
207+
# In theory this is all we need for the server to cleanly shut itself down
172208
self.rlbot_interface.stop_match(shutdown_server=True)
173209
except BrokenPipeError:
174210
match gateway.find_server_process(self.main_executable_name)[0]:

rlbot/utils/maps.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"FuturaGarden": "UF_Day_P",
8484
"DFHStadium_Anniversary": "stadium_10a_p",
8585
"Holyfield": "Labs_Holyfield_Space_P",
86-
"DriftWoods_Night": "woods_night_p"
86+
"DriftWoods_Night": "woods_night_p",
8787
}
8888

8989
STANDARD_MAPS = [
@@ -138,5 +138,6 @@
138138
"Neotokyo_Arcade",
139139
"FuturaGarden",
140140
"DFHStadium_Anniversary",
141-
"DriftWoods_Night"
141+
"DriftWoods_Night",
142+
"NeoTokyo_Comic",
142143
]

rlbot/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.0.0-beta.47"
1+
__version__ = "2.0.0-beta.48"

tests/atba/atba.bot.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ root_dir = ""
1414
run_command = "..\\..\\venv\\Scripts\\python atba.py"
1515
# The command RLBot will call to start your bot on linux
1616
# If this isn't set, RLBot may attempt to run the Windows command under Wine
17-
run_command_linux = "../../venv/bin/python atba.py"
17+
run_command_linux = "../../.venv/bin/python atba.py"
1818

1919
[details]
2020
description = "Made possible by RLBot"

0 commit comments

Comments
 (0)