botch
This commit is contained in:
parent
6d83836fcb
commit
80f3b769a2
1 changed files with 10 additions and 2 deletions
|
@ -9,6 +9,8 @@ from typing import List, Dict, Union
|
|||
|
||||
from aiocraft.mc.types import *
|
||||
|
||||
# TODO de-spaghetti this file sometime!
|
||||
|
||||
DIR_MAP = {"toClient": "clientbound", "toServer": "serverbound"}
|
||||
PREFACE = """\"\"\"[!] This file is autogenerated\"\"\"\n\n"""
|
||||
IMPORTS = """from typing import Tuple, List, Dict
|
||||
|
@ -82,14 +84,16 @@ def parse_field(slot: dict) -> str:
|
|||
class PacketClassWriter:
|
||||
title : str
|
||||
ids : str
|
||||
attrs : List[str]
|
||||
slots : str
|
||||
fields: str
|
||||
state : int
|
||||
|
||||
|
||||
def __init__(self, title:str, ids:str, slots:str, fields:str, state:int):
|
||||
def __init__(self, title:str, ids:str, attrs:List[str], slots:str, fields:str, state:int):
|
||||
self.title = title
|
||||
self.ids = ids
|
||||
self.attrs = attrs
|
||||
self.slots = slots
|
||||
self.fields = fields
|
||||
self.state = state
|
||||
|
@ -101,6 +105,7 @@ class PacketClassWriter:
|
|||
name=self.title,
|
||||
ids='{\n\t\t' + ',\n\t\t'.join(self.ids) + '\n\t}\n',
|
||||
definitions='{\n\t\t' + '\n\t\t'.join(self.slots) + '\n\t}\n',
|
||||
slots=', '.join(f"'{x}'" for x in self.attrs),
|
||||
fields='\n\t'.join(self.fields),
|
||||
state=self.state,
|
||||
)
|
||||
|
@ -212,6 +217,7 @@ def compile():
|
|||
pkt = PACKETS[state][direction][packet]
|
||||
slots = []
|
||||
fields = set()
|
||||
attrs = set()
|
||||
ids = []
|
||||
for v in sorted(PACKETS[state][direction][packet]["definitions"].keys()):
|
||||
defn = pkt["definitions"][v]
|
||||
|
@ -224,12 +230,14 @@ def compile():
|
|||
for slot in defn["slots"]:
|
||||
v_slots.append(parse_slot(slot))
|
||||
fields.add(parse_field(slot))
|
||||
if "name" in slot:
|
||||
attrs.add(slot["name"])
|
||||
slots.append(f"{v} : [ {','.join(v_slots)} ],")
|
||||
|
||||
with open(mc_path / f"proto/{state}/{direction}/{packet}.py", "w") as f:
|
||||
f.write(
|
||||
PacketClassWriter(
|
||||
pkt["name"], ids, slots, fields, _STATE_MAP[state]
|
||||
pkt["name"], ids, attrs, slots, fields, _STATE_MAP[state]
|
||||
).compile()
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue