Add connless fields to initialize

This commit is contained in:
ChillerDragon 2023-05-10 09:05:48 +02:00
parent ff4c28fd42
commit 1b445c3a12
11 changed files with 78 additions and 10 deletions

View file

@ -532,6 +532,41 @@ class CodeGenerator():
def __init__(self) -> None:
self.game_enums: list[GameEnumJson] = []
def write_init_method_header_connless7(
self,
out_file: TextIO,
msg: NetConnlessJson,
name_snake: str
) -> None:
comma: str = ''
if len(msg['members']) > 0:
comma = ',\n'
out_file.write( \
' def __init__(\n' \
f' self{comma}')
args: list[str] = []
for member in msg['members']:
ftype = 'int'
default = '-1'
if member['type']['kind'] == 'packed_addresses': # TODO: packed_addreses default value
ftype = 'int'
default = '0'
elif member['type']['kind'] == 'be_uint16': # TODO: be_uint16
ftype = 'int'
default = '0'
elif member['type']['kind'] == 'uint8': # TODO: uint8
ftype = 'int'
default = '0'
else:
raise ValueError(f"Error: unknown type {member['type']}")
name = name_to_snake(member["name"])
manual_default = get_default(f"connless.{name_snake}.{name}")
if manual_default:
default = manual_default
args.append(f' {name}: {ftype} = {default}')
out_file.write(',\n'.join(args) + '\n')
out_file.write(' ) -> None:\n')
def write_init_method_header(
self,
out_file: TextIO,
@ -661,14 +696,29 @@ class CodeGenerator():
out_file.write(get_dependencies_connless7(msg))
out_file.write('\n')
out_file.write(f'class Msg{name_camel}(PrettyPrint):\n')
out_file.write( \
' def __init__(\n' \
' self,\n' \
' ) -> None:\n')
self.write_init_method_header_connless7(out_file, msg, name_snake)
out_file.write(f" self.message_type: Literal['connless'] = 'connless'\n")
out_file.write(f" self.message_name: str = 'connless.{name_snake}'\n")
out_file.write(f" self.message_id: list[int] = {msg['id']}\n")
out_file.write('\n')
for member in msg['members']:
ftype = 'int'
if member['type']['kind'] == 'packed_addresses': # TODO: packed_addreses default value
ftype = 'int'
elif member['type']['kind'] == 'be_uint16': # TODO: be_uint16
ftype = 'int'
elif member['type']['kind'] == 'uint8': # TODO: uint8
ftype = 'int'
else:
raise ValueError(f"Error: unknown connless type {member['type']}")
name = name_to_snake(member["name"])
if ftype != '':
ftype = f': {ftype}'
if member['type']['kind'] == 'enum':
out_file.write(f" self.{name}{ftype} = {name}\n")
else:
out_file.write(f" self.{name}{ftype} = {name}\n")
out_file.write('\n')
out_file.write(' # first byte of data\n')
out_file.write(' # has to be the first byte of the message payload\n')
out_file.write(' # NOT the chunk header and NOT the message id\n')

View file

@ -10,11 +10,14 @@ from typing import Literal
class MsgCount(PrettyPrint):
def __init__(
self,
count: int = 0
) -> None:
self.message_type: Literal['connless'] = 'connless'
self.message_name: str = 'connless.count'
self.message_id: list[int] = [255, 255, 255, 255, 115, 105, 122, 50]
self.count: int = count
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -7,12 +7,13 @@ from typing import Literal
class MsgForwardCheck(PrettyPrint):
def __init__(
self,
self
) -> None:
self.message_type: Literal['connless'] = 'connless'
self.message_name: str = 'connless.forward_check'
self.message_id: list[int] = [255, 255, 255, 255, 102, 119, 63, 63]
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -7,12 +7,13 @@ from typing import Literal
class MsgForwardError(PrettyPrint):
def __init__(
self,
self
) -> None:
self.message_type: Literal['connless'] = 'connless'
self.message_name: str = 'connless.forward_error'
self.message_id: list[int] = [255, 255, 255, 255, 102, 119, 101, 114]
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -7,12 +7,13 @@ from typing import Literal
class MsgForwardOk(PrettyPrint):
def __init__(
self,
self
) -> None:
self.message_type: Literal['connless'] = 'connless'
self.message_name: str = 'connless.forward_ok'
self.message_id: list[int] = [255, 255, 255, 255, 102, 119, 111, 107]
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -7,12 +7,13 @@ from typing import Literal
class MsgForwardResponse(PrettyPrint):
def __init__(
self,
self
) -> None:
self.message_type: Literal['connless'] = 'connless'
self.message_name: str = 'connless.forward_response'
self.message_id: list[int] = [255, 255, 255, 255, 102, 119, 33, 33]
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -10,11 +10,14 @@ from typing import Literal
class MsgHeartbeat(PrettyPrint):
def __init__(
self,
alt_port: int = 0
) -> None:
self.message_type: Literal['connless'] = 'connless'
self.message_name: str = 'connless.heartbeat'
self.message_id: list[int] = [255, 255, 255, 255, 98, 101, 97, 50]
self.alt_port: int = alt_port
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -10,11 +10,14 @@ from typing import Literal
class MsgList(PrettyPrint):
def __init__(
self,
servers: int = 0
) -> None:
self.message_type: Literal['connless'] = 'connless'
self.message_name: str = 'connless.list'
self.message_id: list[int] = [255, 255, 255, 255, 108, 105, 115, 50]
self.servers: int = servers
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -7,12 +7,13 @@ from typing import Literal
class MsgRequestCount(PrettyPrint):
def __init__(
self,
self
) -> None:
self.message_type: Literal['connless'] = 'connless'
self.message_name: str = 'connless.request_count'
self.message_id: list[int] = [255, 255, 255, 255, 99, 111, 117, 50]
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -10,11 +10,14 @@ from typing import Literal
class MsgRequestInfo(PrettyPrint):
def __init__(
self,
token: int = 0
) -> None:
self.message_type: Literal['connless'] = 'connless'
self.message_name: str = 'connless.request_info'
self.message_id: list[int] = [255, 255, 255, 255, 103, 105, 101, 51]
self.token: int = token
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id

View file

@ -7,12 +7,13 @@ from typing import Literal
class MsgRequestList(PrettyPrint):
def __init__(
self,
self
) -> None:
self.message_type: Literal['connless'] = 'connless'
self.message_name: str = 'connless.request_list'
self.message_id: list[int] = [255, 255, 255, 255, 114, 101, 113, 50]
# first byte of data
# has to be the first byte of the message payload
# NOT the chunk header and NOT the message id