mirror of
https://github.com/mat-1/azalea.git
synced 2024-09-19 22:52:32 +00:00
improve usage
This commit is contained in:
parent
c10b732510
commit
2ddbc5cfc0
3 changed files with 11 additions and 7 deletions
|
@ -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\]`
|
|
@ -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')
|
||||
|
||||
|
|
|
@ -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 = []
|
||||
|
|
Loading…
Reference in a new issue