make packets slotted objects
This commit is contained in:
parent
54f1c1d760
commit
e6faf92841
1 changed files with 5 additions and 8 deletions
|
@ -19,12 +19,13 @@ REGISTRY_ENTRY = """
|
||||||
REGISTRY = {entries}\n"""
|
REGISTRY = {entries}\n"""
|
||||||
OBJECT = """
|
OBJECT = """
|
||||||
class {name}(Packet):
|
class {name}(Packet):
|
||||||
|
__slots__ = {slots}
|
||||||
{fields}
|
{fields}
|
||||||
|
|
||||||
_state : int = {state}
|
_state : int = {state}
|
||||||
|
|
||||||
_ids : Dict[int, int] = {ids}
|
_ids : Dict[int, int] = {ids}
|
||||||
_definitions : Dict[int, List[Tuple[str, Type]]] = {slots}
|
_definitions : Dict[int, List[Tuple[str, Type]]] = {definitions}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
TYPE_MAP = {
|
TYPE_MAP = {
|
||||||
|
@ -99,8 +100,8 @@ class PacketClassWriter:
|
||||||
OBJECT.format(
|
OBJECT.format(
|
||||||
name=self.title,
|
name=self.title,
|
||||||
ids='{\n\t\t' + ',\n\t\t'.join(self.ids) + '\n\t}\n',
|
ids='{\n\t\t' + ',\n\t\t'.join(self.ids) + '\n\t}\n',
|
||||||
slots=self.slots,
|
definitions='{\n\t\t' + '\n\t\t'.join(self.slots) + '\n\t}\n',
|
||||||
fields=self.fields,
|
fields='\n\t'.join(self.fields),
|
||||||
state=self.state,
|
state=self.state,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -228,11 +229,7 @@ def compile():
|
||||||
with open(mc_path / f"proto/{state}/{direction}/{packet}.py", "w") as f:
|
with open(mc_path / f"proto/{state}/{direction}/{packet}.py", "w") as f:
|
||||||
f.write(
|
f.write(
|
||||||
PacketClassWriter(
|
PacketClassWriter(
|
||||||
pkt["name"],
|
pkt["name"], ids, slots, fields, _STATE_MAP[state]
|
||||||
ids,
|
|
||||||
'{\n\t\t' + '\n\t\t'.join(slots) + '\n\t}\n',
|
|
||||||
'\n\t'.join(fields),
|
|
||||||
_STATE_MAP[state]
|
|
||||||
).compile()
|
).compile()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue