From e6faf928410f3c6f6ffae348ee357c6bbc88d560 Mon Sep 17 00:00:00 2001 From: alemi Date: Wed, 17 Nov 2021 18:11:49 +0100 Subject: [PATCH] make packets slotted objects --- compiler/proto.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/compiler/proto.py b/compiler/proto.py index a6bab24..c8148ea 100644 --- a/compiler/proto.py +++ b/compiler/proto.py @@ -19,12 +19,13 @@ REGISTRY_ENTRY = """ REGISTRY = {entries}\n""" OBJECT = """ class {name}(Packet): + __slots__ = {slots} {fields} _state : int = {state} _ids : Dict[int, int] = {ids} - _definitions : Dict[int, List[Tuple[str, Type]]] = {slots} + _definitions : Dict[int, List[Tuple[str, Type]]] = {definitions} """ TYPE_MAP = { @@ -99,8 +100,8 @@ class PacketClassWriter: OBJECT.format( name=self.title, ids='{\n\t\t' + ',\n\t\t'.join(self.ids) + '\n\t}\n', - slots=self.slots, - fields=self.fields, + definitions='{\n\t\t' + '\n\t\t'.join(self.slots) + '\n\t}\n', + fields='\n\t'.join(self.fields), state=self.state, ) @@ -228,11 +229,7 @@ def compile(): with open(mc_path / f"proto/{state}/{direction}/{packet}.py", "w") as f: f.write( PacketClassWriter( - pkt["name"], - ids, - '{\n\t\t' + '\n\t\t'.join(slots) + '\n\t}\n', - '\n\t'.join(fields), - _STATE_MAP[state] + pkt["name"], ids, slots, fields, _STATE_MAP[state] ).compile() )