You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+71-2Lines changed: 71 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,75 @@ A Python module implemented in Rust for serializing and deserializing RLBot's fl
6
6
7
7
To provide a fast, safe, and easy to use Python module for serializing and deserializing RLBot's flatbuffers.
8
8
9
-
A majority of the code is generated in the `build.rs` upon first compile and thrown into `src/`.
9
+
A majority of the code is generated in the `build.rs` upon first compile and thrown into `src/python`.
10
10
11
-
This includes the code generated by `flac`, the Python wrapper binds to the generated Rust code, and the Python type hints.
11
+
This includes the code generated by `flatc` (living in `src/generated`), the Python wrapper binds to the generated Rust code, and the Python type hints (`rlbot_flatbuffers.pyi`).
12
+
13
+
### Basic usage
14
+
15
+
All classes and methods should have types hints readable by your IDE, removing the guesswork of common operations.
16
+
17
+
#### Creating
18
+
19
+
```python
20
+
import rlbot_flatbuffers as flat
21
+
22
+
desired_ball = flat.DesiredBallState(
23
+
physics=flat.Physics(
24
+
location=flat.Vector3Partial(z=200),
25
+
velocity=flat.Vector3Partial(x=1500, y=1500),
26
+
angular_velocity=flat.Vector3Partial(),
27
+
),
28
+
)
29
+
30
+
desired_game_info = flat.DesiredGameInfoState(
31
+
world_gravity_z=-100,
32
+
game_speed=2,
33
+
)
34
+
35
+
desired_game_state = flat.DesiredGameState(
36
+
ball_state=desired_ball,
37
+
game_info_state=desired_game_info,
38
+
)
39
+
```
40
+
41
+
In the above code, we:
42
+
43
+
- Set the ball to:
44
+
- Location (0, 0, 200)
45
+
- Velocity (1500, 1500, 0)
46
+
- Angular velocity of (0, 0, 0)
47
+
- Don't set the car states
48
+
- Set the game info state:
49
+
- World gravity to -100
50
+
- Game speed to 2x default
51
+
- Don't set end match or paused
52
+
- Don't set any console commands
53
+
54
+
All values are optional when creating a class and have the proper defaults.
55
+
56
+
#### Reading values
57
+
58
+
```python
59
+
defhandle_packet(packet: flat.GameTickPacket):
60
+
if packet.game_info.game_state_type notin {
61
+
flat.GameStateType.Active,
62
+
flat.GameStateType.Kickoff,
63
+
}:
64
+
# Return early if the game isn't active
65
+
return
66
+
67
+
# Print the ball's location
68
+
print(packet.ball.physics.location)
69
+
70
+
for car in packet.players:
71
+
# Print the every car's location
72
+
print(car.physics.location)
73
+
```
74
+
75
+
The goal of the above was to feel familiar to RLBot v4 while providing a more Pythonic interface.
76
+
77
+
- All enum types are hashable and can be used in a set, allowing for easy checks against them.
78
+
- Every class implements `__str__`, `__repr__`, and `__hash__` methods.
79
+
- All enums also implement `__int__` and `__richcmp__`.
80
+
- Lists no longer have `num_x` fields accompanying them, they are just Python lists of the appropriate length.
0 commit comments