[protocol] Add names to case-specific structs

This commit is contained in:
DankParrot 2020-08-22 16:49:35 -07:00
parent 75c1f4ce01
commit 2692a0eabf
2 changed files with 7 additions and 6 deletions

View File

@ -259,7 +259,8 @@ def print_rw_logic(types, value, name, read, prefix=''):
if isinstance(v, dict): # print_definition() already warns if this is false
if len(v) > 0:
for k1, v1 in v.items():
print_rw_logic(types, v1, k1, read, prefix=prefix)
prefix_case = f'{prefix}{k}.'
print_rw_logic(types, v1, k1, read, prefix=prefix_case)
else:
add_text('// no other fields')
#print_rw_logic(types, v, name, read, prefix=prefix)
@ -345,8 +346,8 @@ def print_definition(types, name, value, serverbound):
switch = get_switch_condition(name)
if switch != None:
# .switch(cond) {} block
# TODO: could give the union and its structs names to avoid having to manually resolve name conflicts ?
add_text('union {{')
newline()
add_text(f'union {{{{ // switch ({switch})')
indent()
for k, v in value.items():
if not isinstance(v, dict):
@ -354,14 +355,14 @@ def print_definition(types, name, value, serverbound):
continue
# switch case block
newline()
add_text(f'struct {{{{ // if {switch} == {k}')
add_text('struct {{')
indent()
if len(v) == 0:
add_text('// no other fields')
for k1, v1 in v.items():
print_definition(types, k1, v1, serverbound)
unindent()
add_text('}};')
add_text(f'}}}} {k};')
unindent()
add_text('}};')
else:

View File

@ -302,7 +302,7 @@
UpdateLatency: {
# in ms
newPing: varint
ping: varint
}
UpdateDisplayName: {