Finish snap init args generation
This commit is contained in:
parent
37ec4349aa
commit
211f470e7b
|
@ -559,7 +559,7 @@ class CodeGenerator():
|
|||
self,
|
||||
member: NetMessageMemberJson,
|
||||
name_snake: str,
|
||||
message_type: Literal['game', 'system', 'connless']
|
||||
message_type: Literal['game', 'system', 'connless', 'snap']
|
||||
) -> list[str]:
|
||||
"""
|
||||
get_init_member_header_def
|
||||
|
@ -648,9 +648,27 @@ class CodeGenerator():
|
|||
elif arr_member['kind'] in ('int32', 'tick', 'enum'):
|
||||
ftype = f'Annotated[list[int], {size}]'
|
||||
default = '[' + ', '.join(["0"] * size) + ']'
|
||||
elif arr_member['kind'] == 'array': # snap de client info has an array of int32 arrays as field
|
||||
# should probably do some kind of recursion here
|
||||
# but it breaks my brain
|
||||
sub_size: int = arr_member['count']
|
||||
if sub_size is None:
|
||||
print("Error: size is none for the following sub member")
|
||||
print(arr_member)
|
||||
exit(1)
|
||||
sub_arr_member: ArrayMemberTypeJson = arr_member['member_type']
|
||||
if sub_arr_member['kind'] == 'int32':
|
||||
ftype = f'Annotated[list[list[int]], ({size},{sub_size})]'
|
||||
inner_default = '[' + ', '.join(["0"] * sub_size) + ']'
|
||||
default = '[' + ',\n '.join([inner_default] * size) + ']'
|
||||
else:
|
||||
raise ValueError( \
|
||||
f"Error: msg {name_to_snake(member['name'])} " \
|
||||
f"has unknown array sub member type {arr_member['type']}")
|
||||
else:
|
||||
raise ValueError( \
|
||||
f"Error: unknown array member type {member['type']}")
|
||||
f"Error: msg {name_to_snake(member['name'])} " \
|
||||
f"has unknown array member type {member['type']}")
|
||||
# Initializing lists with defaults
|
||||
# And type annotation can get quite long
|
||||
# So split it in two lines
|
||||
|
@ -734,7 +752,19 @@ 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)
|
||||
comma: str = ''
|
||||
if len(obj['members']) > 0:
|
||||
comma = ',\n'
|
||||
out_file.write( \
|
||||
' def __init__(\n' \
|
||||
f' self{comma}')
|
||||
args: list[str] = []
|
||||
for member in obj['members']:
|
||||
mem_defs: list[str] = self.gen_init_member_header_def(member, name_snake, 'snap')
|
||||
for mem_def in mem_defs:
|
||||
args.append(f' {mem_def}')
|
||||
out_file.write(',\n'.join(args) + '\n')
|
||||
out_file.write(' ) -> None:\n')
|
||||
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")
|
||||
|
|
Loading…
Reference in a new issue