Skip to content

Commit 8c0a328

Browse files
authored
Merge pull request #48 from RLBot/set_game_state_api
Update set_game_state() API and add send_console_command()
2 parents 8a0850f + 99c1e1d commit 8c0a328

9 files changed

Lines changed: 45 additions & 20 deletions

File tree

‎rlbot/interface.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def send_msg(
120120
| flat.MatchConfiguration
121121
| flat.PlayerInput
122122
| flat.DesiredGameState
123+
| flat.ConsoleCommand
123124
| flat.RenderGroup
124125
| flat.RemoveRenderGroup
125126
| flat.MatchComm

‎rlbot/managers/bot.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,20 +274,26 @@ def send_match_comm(
274274
)
275275
)
276276

277-
def set_game_state(
277+
def send_console_command(self, cmd: str | flat.ConsoleCommand):
278+
cmd = cmd if isinstance(cmd, flat.ConsoleCommand) else flat.ConsoleCommand(cmd)
279+
self._game_interface.send_msg(cmd)
280+
281+
def set_game_state(self, game_state: flat.DesiredGameState):
282+
self._game_interface.send_msg(game_state)
283+
284+
def set_game_state_parts(
278285
self,
279286
balls: dict[int, flat.DesiredBallState] = {},
280287
cars: dict[int, flat.DesiredCarState] = {},
281288
match_info: flat.DesiredMatchInfo | None = None,
282-
commands: list[str] = [],
283289
):
284290
"""
285291
Sets the game to the desired state.
286292
Through this it is possible to manipulate the position, velocity, and rotations of cars and balls, and more.
287-
See wiki for a full break down and examples.
293+
See wiki for a full breakdown and examples.
288294
"""
289295

290-
game_state = fill_desired_game_state(balls, cars, match_info, commands)
296+
game_state = fill_desired_game_state(balls, cars, match_info)
291297
self._game_interface.send_msg(game_state)
292298

293299
def set_loadout(self, loadout: flat.PlayerLoadout, index: int | None = None):

‎rlbot/managers/hivemind.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,20 +290,26 @@ def send_match_comm(
290290
)
291291
)
292292

293-
def set_game_state(
293+
def send_console_command(self, cmd: str | flat.ConsoleCommand):
294+
cmd = cmd if isinstance(cmd, flat.ConsoleCommand) else flat.ConsoleCommand(cmd)
295+
self._game_interface.send_msg(cmd)
296+
297+
def set_game_state(self, game_state: flat.DesiredGameState):
298+
self._game_interface.send_msg(game_state)
299+
300+
def set_game_state_parts(
294301
self,
295302
balls: dict[int, flat.DesiredBallState] = {},
296303
cars: dict[int, flat.DesiredCarState] = {},
297304
match_info: flat.DesiredMatchInfo | None = None,
298-
commands: list[str] = [],
299305
):
300306
"""
301307
Sets the game to the desired state.
302308
Through this it is possible to manipulate the position, velocity, and rotations of cars and balls, and more.
303-
See wiki for a full break down and examples.
309+
See wiki for a full breakdown and examples.
304310
"""
305311

306-
game_state = fill_desired_game_state(balls, cars, match_info, commands)
312+
game_state = fill_desired_game_state(balls, cars, match_info)
307313
self._game_interface.send_msg(game_state)
308314

309315
def set_loadout(self, loadout: flat.PlayerLoadout, index: int):

‎rlbot/managers/match.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,20 +237,26 @@ def stop_match(self):
237237
self.packet = None
238238
self.rlbot_interface.stop_match()
239239

240-
def set_game_state(
240+
def send_console_command(self, cmd: str | flat.ConsoleCommand):
241+
cmd = cmd if isinstance(cmd, flat.ConsoleCommand) else flat.ConsoleCommand(cmd)
242+
self.rlbot_interface.send_msg(cmd)
243+
244+
def set_game_state(self, game_state: flat.DesiredGameState):
245+
self.rlbot_interface.send_msg(game_state)
246+
247+
def set_game_state_parts(
241248
self,
242249
balls: dict[int, flat.DesiredBallState] = {},
243250
cars: dict[int, flat.DesiredCarState] = {},
244251
match_info: flat.DesiredMatchInfo | None = None,
245-
commands: list[str] = [],
246252
):
247253
"""
248254
Sets the game to the desired state.
249255
Through this it is possible to manipulate the position, velocity, and rotations of cars and balls, and more.
250-
See wiki for a full break down and examples.
256+
See wiki for a full breakdown and examples.
251257
"""
252258

253-
game_state = fill_desired_game_state(balls, cars, match_info, commands)
259+
game_state = fill_desired_game_state(balls, cars, match_info)
254260
self.rlbot_interface.send_msg(game_state)
255261

256262
def shut_down(self, use_force_if_necessary: bool = True):

‎rlbot/managers/script.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,20 +234,26 @@ def send_match_comm(
234234
)
235235
)
236236

237-
def set_game_state(
237+
def send_console_command(self, cmd: str | flat.ConsoleCommand):
238+
cmd = cmd if isinstance(cmd, flat.ConsoleCommand) else flat.ConsoleCommand(cmd)
239+
self._game_interface.send_msg(cmd)
240+
241+
def set_game_state(self, game_state: flat.DesiredGameState):
242+
self._game_interface.send_msg(game_state)
243+
244+
def set_game_state_parts(
238245
self,
239246
balls: dict[int, flat.DesiredBallState] = {},
240247
cars: dict[int, flat.DesiredCarState] = {},
241248
match_info: flat.DesiredMatchInfo | None = None,
242-
commands: list[str] = [],
243249
):
244250
"""
245251
Sets the game to the desired state.
246252
Through this it is possible to manipulate the position, velocity, and rotations of cars and balls, and more.
247-
See wiki for a full break down and examples.
253+
See wiki for a full breakdown and examples.
248254
"""
249255

250-
game_state = fill_desired_game_state(balls, cars, match_info, commands)
256+
game_state = fill_desired_game_state(balls, cars, match_info)
251257
self._game_interface.send_msg(game_state)
252258

253259
def set_loadout(self, loadout: flat.PlayerLoadout, index: int):

‎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.56"
1+
__version__ = "2.0.0-beta.57"

‎tests/atba/atba.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def get_output(self, packet: flat.GamePacket) -> flat.ControllerState:
122122
def test_state_setting(self, packet: flat.GamePacket):
123123
if packet.match_info.seconds_elapsed > self.next_teleport:
124124
self.next_teleport = packet.match_info.seconds_elapsed + 10
125-
self.set_game_state(
125+
self.set_game_state_parts(
126126
{
127127
0: flat.DesiredBallState(
128128
flat.DesiredPhysics(

‎tests/many_match.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def handle_match_comm(comm: flat.MatchComm):
8080
match_manager.packet.match_info.match_phase == flat.MatchPhase.Active
8181
and match_manager.packet.match_info.game_time_remaining < 60 * 4 + 55
8282
):
83-
match_manager.set_game_state(commands=["Pause"])
83+
match_manager.send_console_command("Pause")
8484
paused = True
8585
break
8686
sleep(1)

‎tests/run_forever.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656

5757
while match_manager.packet.match_info.match_phase != flat.MatchPhase.Ended:
5858
if match_manager.packet.match_info.match_phase == flat.MatchPhase.Countdown:
59-
match_manager.set_game_state(
59+
match_manager.set_game_state_parts(
6060
match_info=flat.DesiredMatchInfo(game_speed=2)
6161
)
6262

0 commit comments

Comments
 (0)