mirror of
https://github.com/mat-1/azalea.git
synced 2024-09-20 07:02:31 +00:00
Fix migrate
This commit is contained in:
parent
479c054747
commit
dc5a9149a5
2 changed files with 17 additions and 8 deletions
|
@ -18,7 +18,7 @@ def padded_hex(n: int):
|
||||||
|
|
||||||
|
|
||||||
class PacketIdentifier:
|
class PacketIdentifier:
|
||||||
def __init__(self, packet_id, direction, state):
|
def __init__(self, packet_id: int, direction: str, state: str):
|
||||||
self.packet_id = packet_id
|
self.packet_id = packet_id
|
||||||
self.direction = direction
|
self.direction = direction
|
||||||
self.state = state
|
self.state = state
|
||||||
|
@ -29,6 +29,12 @@ class PacketIdentifier:
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash((self.packet_id, self.direction, self.state))
|
return hash((self.packet_id, self.direction, self.state))
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f'{self.packet_id} {self.direction} {self.state}'
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f'PacketIdentifier({self.packet_id}, {self.direction}, {self.state})'
|
||||||
|
|
||||||
|
|
||||||
def group_packets(packets: list[PacketIdentifier]):
|
def group_packets(packets: list[PacketIdentifier]):
|
||||||
packet_groups: dict[tuple[str, str], list[int]] = {}
|
packet_groups: dict[tuple[str, str], list[int]] = {}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from codegen.lib.utils import PacketIdentifier, group_packets
|
from lib.utils import PacketIdentifier, group_packets
|
||||||
import lib.code.utils
|
import lib.code.utils
|
||||||
import lib.code.version
|
import lib.code.version
|
||||||
import lib.code.packet
|
import lib.code.packet
|
||||||
|
@ -24,19 +24,19 @@ for packet in old_packet_list:
|
||||||
assert packet['class'].endswith('.class')
|
assert packet['class'].endswith('.class')
|
||||||
packet_name = old_mappings.get_class(packet['class'][:-6])
|
packet_name = old_mappings.get_class(packet['class'][:-6])
|
||||||
old_packets[PacketIdentifier(
|
old_packets[PacketIdentifier(
|
||||||
packet['id'], packet['direction'], packet['state'])] = packet_name
|
packet['id'], packet['direction'].lower(), packet['state'].lower())] = packet_name
|
||||||
for packet in new_packet_list:
|
for packet in new_packet_list:
|
||||||
assert packet['class'].endswith('.class')
|
assert packet['class'].endswith('.class')
|
||||||
packet_name = new_mappings.get_class(packet['class'][:-6])
|
packet_name = new_mappings.get_class(packet['class'][:-6])
|
||||||
new_packets[PacketIdentifier(
|
new_packets[PacketIdentifier(
|
||||||
packet['id'], packet['direction'], packet['state'])] = packet_name
|
packet['id'], packet['direction'].lower(), packet['state'].lower())] = packet_name
|
||||||
|
|
||||||
|
|
||||||
# find removed packets
|
# find removed packets
|
||||||
removed_packets: list[PacketIdentifier] = []
|
removed_packets: list[PacketIdentifier] = []
|
||||||
for packet in old_packets:
|
for packet in old_packets:
|
||||||
if packet not in new_packets:
|
if packet not in new_packets or new_packets[packet] != old_packets[packet]:
|
||||||
removed_packets.append(packet)
|
removed_packets.append(packet)
|
||||||
|
print('Removed packet:', packet)
|
||||||
for (direction, state), packets in group_packets(removed_packets).items():
|
for (direction, state), packets in group_packets(removed_packets).items():
|
||||||
lib.code.packet.remove_packet_ids(packets, direction, state)
|
lib.code.packet.remove_packet_ids(packets, direction, state)
|
||||||
|
|
||||||
|
@ -48,6 +48,8 @@ for old_packet, old_packet_name in old_packets.items():
|
||||||
for new_packet, new_packet_name in new_packets.items():
|
for new_packet, new_packet_name in new_packets.items():
|
||||||
if old_packet == new_packet and old_packet.packet_id != new_packet.packet_id:
|
if old_packet == new_packet and old_packet.packet_id != new_packet.packet_id:
|
||||||
changed_packets[old_packet] = new_packet.packet_id
|
changed_packets[old_packet] = new_packet.packet_id
|
||||||
|
print('Changed packet id:', old_packet, '->',
|
||||||
|
new_packet, f'({new_packet_name})')
|
||||||
for (direction, state), packets in group_packets(list(changed_packets.keys())).items():
|
for (direction, state), packets in group_packets(list(changed_packets.keys())).items():
|
||||||
lib.code.packet.remove_packet_ids(packets, direction, state)
|
lib.code.packet.remove_packet_ids(packets, direction, state)
|
||||||
|
|
||||||
|
@ -57,11 +59,12 @@ print()
|
||||||
# find added packets
|
# find added packets
|
||||||
added_packets: list[PacketIdentifier] = []
|
added_packets: list[PacketIdentifier] = []
|
||||||
for packet in new_packets:
|
for packet in new_packets:
|
||||||
if packet not in old_packets:
|
if packet not in old_packets and new_packets[packet] == old_packets[packet]:
|
||||||
added_packets.append(packet)
|
added_packets.append(packet)
|
||||||
|
print('Added packet:', packet)
|
||||||
for packet in added_packets:
|
for packet in added_packets:
|
||||||
lib.code.packet.generate_packet(
|
lib.code.packet.generate_packet(
|
||||||
new_burger_data, new_mappings, packet.packet_id, packet.direction, packet.state)
|
new_burger_data[0]['packets']['packet'], new_mappings, packet.packet_id, packet.direction, packet.state)
|
||||||
lib.code.utils.fmt()
|
lib.code.utils.fmt()
|
||||||
|
|
||||||
print('Done!')
|
print('Done!')
|
||||||
|
|
Loading…
Reference in a new issue