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

View File

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