diff options
| author | mat <github@matdoes.dev> | 2022-05-07 18:30:44 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-05-07 18:30:44 -0500 |
| commit | 2ddbc5cfc00897ed644f29456a52c4f07f94844f (patch) | |
| tree | eb0316b2a88fca19fc85e21653ab0dcdbda2beeb | |
| parent | c10b732510868819a652b76e31278906914d699d (diff) | |
| download | azalea-drasl-2ddbc5cfc00897ed644f29456a52c4f07f94844f.tar.xz | |
improve usage
| -rw-r--r-- | data-code-generator/README.md | 3 | ||||
| -rw-r--r-- | data-code-generator/main.py | 8 | ||||
| -rw-r--r-- | data-code-generator/packetcodegen.py | 7 |
3 files changed, 11 insertions, 7 deletions
diff --git a/data-code-generator/README.md b/data-code-generator/README.md index 1deeee4d..294242c9 100644 --- a/data-code-generator/README.md +++ b/data-code-generator/README.md @@ -2,3 +2,6 @@ Generate code for reading/writing packets from [Burger](https://github.com/pokec The directory name doesn't start with `azalea-` because it's not a Rust crate. +## Usage + +`python main.py [packet id] [clientbound or serverbound] \[game/handshake/login/status\]`
\ No newline at end of file diff --git a/data-code-generator/main.py b/data-code-generator/main.py index 07a591e4..c95bd080 100644 --- a/data-code-generator/main.py +++ b/data-code-generator/main.py @@ -39,9 +39,11 @@ with open('burger.json', 'r') as f: burger_data = json.load(f) burger_packets_data = burger_data[0]['packets']['packet'] -packet_ids = list(map(int, sys.argv[1:])) -print(packet_ids) -packetcodegen.generate(burger_packets_data, mappings, packet_ids) +packet_id, direction, state = int(sys.argv[1]), sys.argv[2], sys.argv[3] +print( + f'Generating code for packet id: {packet_id} with direction {direction} and state {state}') +packetcodegen.generate(burger_packets_data, mappings, + packet_id, direction, state) os.system('cd .. && cargo fmt') diff --git a/data-code-generator/packetcodegen.py b/data-code-generator/packetcodegen.py index 12855d08..59a48535 100644 --- a/data-code-generator/packetcodegen.py +++ b/data-code-generator/packetcodegen.py @@ -70,16 +70,15 @@ def write_packet_file(state, packet_name_snake_case, code): f.write(code) -def generate(burger_packets, mappings: Mappings, packet_ids): +def generate(burger_packets, mappings: Mappings, target_packet_id, target_packet_direction, target_packet_state): for packet in burger_packets.values(): - if packet['id'] not in packet_ids: + if packet['id'] != target_packet_id: continue direction = packet['direction'].lower() # serverbound or clientbound state = {'PLAY': 'game'}.get(packet['state'], packet['state'].lower()) - # TODO: have something better to control this - if state != 'game' or direction != 'clientbound': + if state != target_packet_state or direction != target_packet_direction: continue generated_packet_code = [] |
