improve usage

This commit is contained in:
mat 2022-05-07 18:30:44 -05:00
parent c10b732510
commit 2ddbc5cfc0
3 changed files with 11 additions and 7 deletions

View file

@ -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\]`

View file

@ -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')

View file

@ -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 = []