From 4801af9c592d3ec2bc6020bc3fb6f226426e5aad Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Sat, 13 May 2023 16:33:12 +0200 Subject: [PATCH] A bit more snap generation prep --- scripts/generate_messages.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/scripts/generate_messages.py b/scripts/generate_messages.py index 6a952ba..8590799 100755 --- a/scripts/generate_messages.py +++ b/scripts/generate_messages.py @@ -88,23 +88,13 @@ class NetConnlessJson(TypedDict): name: list[str] members: list[NetConnlessMemberJson] -class SnapObjMemberJson(TypedDict): - name: list[str] - type: NetMessageMemberTypeJson - -class SnapObjJson(TypedDict): - id: int - name: list[str] - members: list[SnapObjMemberJson] - attributes: list[str] - class SpecJson(TypedDict): constants: list[ConstantJson] game_enumerations: list[GameEnumJson] game_messages: list[NetMessageJson] system_messages: list[NetMessageJson] connless_messages: list[NetConnlessJson] - snapshot_objects: list[SnapObjJson] + snapshot_objects: list[NetMessageJson] def gen_match_file_connless7( messages: list[NetConnlessJson] @@ -720,7 +710,7 @@ class CodeGenerator(): out_file.write(',\n'.join(args) + '\n') out_file.write(' ) -> None:\n') - def generate_snap_obj7(self, obj: SnapObjJson) -> None: + def generate_snap_obj7(self, obj: NetMessageJson) -> None: name_snake = name_to_snake(obj['name']) name_camel = name_to_camel(obj['name']) dirname = os.path.dirname(__file__) @@ -734,6 +724,13 @@ class CodeGenerator(): out_file.write('\n') out_file.write('from twnet_parser.pretty_print import PrettyPrint\n') out_file.write(f'class Obj{name_camel}(PrettyPrint):\n') + # self.write_init_method_header_connless7(out_file, obj, name_snake) + out_file.write(f" self.item_name: str = 'connless.{name_snake}'\n") + out_file.write(f" self.type_id: int = {obj['id']}\n") + out_file.write(f" self.id: int = 0\n") + out_file.write('\n') + self.generate_field_assignments_in_initialize(obj, out_file) + out_file.write('\n') def generate_msg_connless( self, @@ -966,7 +963,7 @@ class CodeGenerator(): game_messages: list[NetMessageJson] = spec_data['game_messages'] system_messages: list[NetMessageJson] = spec_data['system_messages'] connless_messages: list[NetConnlessJson] = spec_data['connless_messages'] - snapshot_objects: list[SnapObjJson] = spec_data['snapshot_objects'] + snapshot_objects: list[NetMessageJson] = spec_data['snapshot_objects'] self.gen_enum_file7() gen_match_file7('game', game_messages) gen_match_file7('system', system_messages) @@ -977,8 +974,8 @@ class CodeGenerator(): self.generate_msg(msg, 'system') for connless_msg in connless_messages: self.generate_msg_connless(connless_msg) - # for obj in snapshot_objects: - # self.generate_snap_obj7(obj) + for obj in snapshot_objects: + self.generate_snap_obj7(obj) def main() -> None: dirname = os.path.dirname(__file__)