PyLibMS 4.2.4__py3-none-any.whl → 4.3.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. lms/common/field/io.py +17 -6
  2. lms/common/field/lms_datatype.py +4 -6
  3. lms/common/field/lms_field.py +7 -3
  4. lms/common/lms_constants.py +1 -1
  5. lms/common/stream/fileinfo.py +12 -3
  6. lms/common/stream/hashtable.py +6 -1
  7. lms/common/stream/section.py +7 -7
  8. lms/fileio/encoding.py +1 -1
  9. lms/fileio/io.py +1 -1
  10. lms/flowchart/definitions/flowchart.py +8 -11
  11. lms/flowchart/definitions/node.py +127 -93
  12. lms/flowchart/definitions/node_type.py +35 -22
  13. lms/flowchart/flw3.py +126 -63
  14. lms/flowchart/msbf.py +107 -18
  15. lms/flowchart/msbfio.py +31 -31
  16. lms/message/lms_messagetext.py +21 -13
  17. lms/message/msbt.py +27 -18
  18. lms/message/msbtentry.py +10 -10
  19. lms/message/msbtio.py +32 -18
  20. lms/message/section/atr1.py +7 -8
  21. lms/message/section/txt2.py +1 -1
  22. lms/message/tag/io/param_io.py +6 -6
  23. lms/message/tag/io/tag_io.py +17 -16
  24. lms/message/tag/lms_tag.py +26 -16
  25. lms/project/definitions/tag.py +19 -17
  26. lms/project/msbp.py +7 -7
  27. lms/project/msbpread.py +5 -1
  28. lms/titleconfig/config.py +33 -19
  29. lms/titleconfig/definitions/attribute.py +0 -1
  30. lms/titleconfig/definitions/nodes.py +60 -31
  31. lms/titleconfig/definitions/tags.py +4 -2
  32. {pylibms-4.2.4.dist-info → pylibms-4.3.0.dist-info}/METADATA +17 -7
  33. {pylibms-4.2.4.dist-info → pylibms-4.3.0.dist-info}/RECORD +36 -37
  34. lms/titleconfig/presets/Tomodachi Life NA-EU.yaml +0 -7505
  35. {pylibms-4.2.4.dist-info → pylibms-4.3.0.dist-info}/WHEEL +0 -0
  36. {pylibms-4.2.4.dist-info → pylibms-4.3.0.dist-info}/licenses/LICENSE +0 -0
  37. {pylibms-4.2.4.dist-info → pylibms-4.3.0.dist-info}/top_level.txt +0 -0
lms/common/field/io.py CHANGED
@@ -1,15 +1,22 @@
1
1
  from typing import Callable
2
2
 
3
- from lms.common.field.lms_datatype import (LMS_DataType, is_bool_datatype,
4
- is_bytes_datatype, is_list_datatype,
5
- is_number_datatype)
3
+ from lms.common.field.lms_datatype import (
4
+ LMS_DataType,
5
+ is_bool_datatype,
6
+ is_bytes_datatype,
7
+ is_list_datatype,
8
+ is_number_datatype,
9
+ )
6
10
  from lms.common.field.lms_field import LMS_Field
7
11
  from lms.fileio.io import FileReader, FileWriter
8
12
  from lms.titleconfig.definitions.value import ValueDefinition
9
13
 
10
14
 
11
- def read_field(reader: FileReader, definition: ValueDefinition,
12
- read_variable_width_value: Callable | None = None) -> LMS_Field:
15
+ def read_field(
16
+ reader: FileReader,
17
+ definition: ValueDefinition,
18
+ read_variable_width_value: Callable | None = None,
19
+ ) -> LMS_Field:
13
20
  # String is excluded as their reading varies between MSBT/MSBF
14
21
  match definition.datatype:
15
22
  case LMS_DataType.UINT8:
@@ -43,7 +50,11 @@ def read_field(reader: FileReader, definition: ValueDefinition,
43
50
  return LMS_Field(value, definition) # type: ignore
44
51
 
45
52
 
46
- def write_field(writer: FileWriter, field: LMS_Field, write_variable_width_value: Callable | None = None) -> None:
53
+ def write_field(
54
+ writer: FileWriter,
55
+ field: LMS_Field,
56
+ write_variable_width_value: Callable | None = None,
57
+ ) -> None:
47
58
  if is_number_datatype(field.value, field.datatype):
48
59
  write_functions: dict[LMS_DataType, Callable] = {
49
60
  LMS_DataType.UINT8: writer.write_uint8,
@@ -119,9 +119,7 @@ class LMS_DataType(Enum):
119
119
  try:
120
120
  return sizes[self]
121
121
  except KeyError:
122
- raise TypeError(
123
- f"Stream size is not defined for '{self.to_string()}'."
124
- )
122
+ raise TypeError(f"Stream size is not defined for '{self.to_string()}'.")
125
123
 
126
124
  @classmethod
127
125
  def from_string(cls, string: str):
@@ -138,8 +136,8 @@ class LMS_DataType(Enum):
138
136
 
139
137
 
140
138
  def verify_number_from_datatype(
141
- value: int | float,
142
- datatype: LMS_DataType,
139
+ value: int | float,
140
+ datatype: LMS_DataType,
143
141
  ):
144
142
  if datatype is LMS_DataType.FLOAT32:
145
143
  max_value = FLOAT32_MAX
@@ -150,7 +148,7 @@ def verify_number_from_datatype(
150
148
  max_value = 2 ** (bits - 1)
151
149
  min_value = -max_value
152
150
  else:
153
- min_value, max_value = 0, (2 ** bits) - 1
151
+ min_value, max_value = 0, (2**bits) - 1
154
152
 
155
153
  if not min_value <= value <= max_value:
156
154
  raise ValueError(
@@ -37,7 +37,9 @@ class LMS_FieldMap:
37
37
  return {field.name: field.value for field in self.fields.values()}
38
38
 
39
39
  @staticmethod
40
- def create_default_dict_map(definitions: list[ValueDefinition]) -> dict[str, FieldValue]:
40
+ def create_default_dict_map(
41
+ definitions: list[ValueDefinition],
42
+ ) -> dict[str, FieldValue]:
41
43
  map = {}
42
44
  for definition in definitions:
43
45
  match definition.datatype:
@@ -101,7 +103,9 @@ class LMS_Field:
101
103
  """
102
104
 
103
105
  def __init__(
104
- self, value: int | str | float | bytes | bool, definition: ValueDefinition,
106
+ self,
107
+ value: int | str | float | bytes | bool,
108
+ definition: ValueDefinition,
105
109
  ):
106
110
  _verify_value_from_definition(value, definition)
107
111
  self._definition = definition
@@ -145,7 +149,7 @@ class LMS_Field:
145
149
 
146
150
 
147
151
  def _verify_value_from_definition(
148
- value: int | str | float | bytes | bool, definition: ValueDefinition
152
+ value: int | str | float | bytes | bool, definition: ValueDefinition
149
153
  ) -> None:
150
154
  datatype = definition.datatype
151
155
 
@@ -3,7 +3,7 @@ PADDING_BYTE = b"\x00"
3
3
 
4
4
  SIZE_OFFSET = 0x12
5
5
  SECTION_DATA_START = 0x20
6
- SECTION_PADDING_BYTE = b"\xAB"
6
+ SECTION_PADDING_BYTE = b"\xab"
7
7
 
8
8
  LITTLE_ENDIAN_BOM = b"\xff\xfe"
9
9
  BIG_ENDIAN_BOM = b"\xfe\xff"
@@ -1,5 +1,10 @@
1
1
  from lms.common import lms_exceptions
2
- from lms.common.lms_constants import BIG_ENDIAN_BOM, SECTION_DATA_START, LITTLE_ENDIAN_BOM, SIZE_OFFSET
2
+ from lms.common.lms_constants import (
3
+ BIG_ENDIAN_BOM,
4
+ SECTION_DATA_START,
5
+ LITTLE_ENDIAN_BOM,
6
+ SIZE_OFFSET,
7
+ )
3
8
  from lms.common.lms_fileinfo import LMS_FileInfo
4
9
  from lms.fileio.encoding import FileEncoding
5
10
  from lms.fileio.io import FileReader, FileWriter
@@ -25,7 +30,9 @@ def read_file_info(reader: FileReader, expected_magic: str) -> LMS_FileInfo:
25
30
  version = reader.read_uint8()
26
31
 
27
32
  if version < 3:
28
- raise lms_exceptions.LMS_UnsupportedFileVersionError("Only version 3+ files are supported!")
33
+ raise lms_exceptions.LMS_UnsupportedFileVersionError(
34
+ "Only version 3+ files are supported!"
35
+ )
29
36
 
30
37
  section_count = reader.read_uint16()
31
38
 
@@ -34,7 +41,9 @@ def read_file_info(reader: FileReader, expected_magic: str) -> LMS_FileInfo:
34
41
 
35
42
  reader.seek(0, 2)
36
43
  if file_size != (real_size := reader.tell()):
37
- raise lms_exceptions.LMS_MisalignedSizeError(f"File size is misaligned!` Got {file_size} expected {real_size}.")
44
+ raise lms_exceptions.LMS_MisalignedSizeError(
45
+ f"File size is misaligned!` Got {file_size} expected {real_size}."
46
+ )
38
47
 
39
48
  reader.seek(SECTION_DATA_START)
40
49
 
@@ -27,7 +27,12 @@ def read_labels(reader: FileReader) -> tuple[dict, int]:
27
27
  return sorted_labels, slot_count
28
28
 
29
29
 
30
- def write_labels(writer: FileWriter, labels: list[str], slot_count: int, index_map: dict[str, int] = None) -> None:
30
+ def write_labels(
31
+ writer: FileWriter,
32
+ labels: list[str],
33
+ slot_count: int,
34
+ index_map: dict[str, int] = None,
35
+ ) -> None:
31
36
  writer.write_uint32(slot_count)
32
37
 
33
38
  hash_slots = {}
@@ -2,12 +2,12 @@ from typing import Any, Callable, Generator
2
2
 
3
3
  from lms.fileio.io import FileReader, FileWriter
4
4
 
5
- SECTION_PADDING_BYTE = b"\xAB"
5
+ SECTION_PADDING_BYTE = b"\xab"
6
6
  SECTION_ALIGNMENT = 16
7
7
 
8
8
 
9
9
  def read_section_data(
10
- reader: FileReader, section_count: int
10
+ reader: FileReader, section_count: int
11
11
  ) -> Generator[tuple[str, int], Any, None]:
12
12
  reader.seek(0x20)
13
13
  for _ in range(section_count):
@@ -24,11 +24,11 @@ def read_section_data(
24
24
 
25
25
 
26
26
  def write_section(
27
- writer: FileWriter,
28
- magic: str,
29
- section_call: Callable,
30
- data: list[Any],
31
- *write_arguments: Any,
27
+ writer: FileWriter,
28
+ magic: str,
29
+ section_call: Callable,
30
+ data: list[Any],
31
+ *write_arguments: Any,
32
32
  ) -> None:
33
33
  writer.write_string(magic)
34
34
  size_offset = writer.tell()
lms/fileio/encoding.py CHANGED
@@ -10,7 +10,7 @@ class FileEncoding(IntEnum):
10
10
  UTF32 = 0x02
11
11
 
12
12
  def to_string_format(
13
- self, is_big_endian: bool = False
13
+ self, is_big_endian: bool = False
14
14
  ) -> Literal["UTF-8", "UTF-16-BE", "UTF-16-LE", "UTF-32-BE", "UTF-32-LE"]:
15
15
  """Converts the FileEncoding to string format."""
16
16
  match self:
lms/fileio/io.py CHANGED
@@ -106,7 +106,7 @@ class FileReader:
106
106
  def read_encoded_string(self):
107
107
  message = b""
108
108
  while (
109
- raw_char := self.read_bytes(self.encoding.width)
109
+ raw_char := self.read_bytes(self.encoding.width)
110
110
  ) != self.encoding.terminator:
111
111
  message += raw_char
112
112
  return message.decode(self.encoding.to_string_format(self.is_big_endian))
@@ -7,7 +7,9 @@ from lms.flowchart.definitions.node import LMS_EntryNode, LMS_BranchNode, LMS_Ba
7
7
  class LMS_Flowchart:
8
8
  """Class that represents a flowchart in a MSBF file."""
9
9
 
10
- def __init__(self, entry_point: LMS_EntryNode, id_generator: Callable[[], int]) -> None:
10
+ def __init__(
11
+ self, entry_point: LMS_EntryNode, id_generator: Callable[[], int]
12
+ ) -> None:
11
13
  self._entry_node = entry_point
12
14
  self._nodes: dict[int, LMS_BaseNode] = {}
13
15
  self._id_generator = id_generator
@@ -16,7 +18,6 @@ class LMS_Flowchart:
16
18
  for node in entry_point.get_descendents():
17
19
  self._nodes[node.id] = node
18
20
 
19
-
20
21
  def __iter__(self) -> Iterator[LMS_BaseNode]:
21
22
  return iter(self._nodes.values())
22
23
 
@@ -28,7 +29,7 @@ class LMS_Flowchart:
28
29
 
29
30
  @property
30
31
  def name(self) -> str:
31
- """The name of the flowchart. """
32
+ """The name of the flowchart."""
32
33
  return self._entry_node.flowchart_name
33
34
 
34
35
  @name.setter
@@ -41,7 +42,7 @@ class LMS_Flowchart:
41
42
  return self._entry_node
42
43
 
43
44
  @property
44
- def nodes(self) -> MappingProxyType[LMS_BaseNode]:
45
+ def nodes(self) -> MappingProxyType[int, LMS_BaseNode]:
45
46
  """All nodes in the flowchart instance."""
46
47
  return MappingProxyType(self._nodes)
47
48
 
@@ -51,16 +52,12 @@ class LMS_Flowchart:
51
52
 
52
53
  :param node: the node to add.
53
54
  """
54
- if not isinstance(node, LMS_BaseNode):
55
- raise TypeError(f"Node type '{type(node).__name__}' is not a child of LMS_BaseNode!")
56
-
57
- if node in self._nodes.values():
58
- raise ValueError(f"Node of ID '{node.id}' is already registered to this flowchart!")
55
+ if node.id is None:
56
+ raise ValueError("Node must be registered to an MSBF file before a flowchart!")
59
57
 
60
- node.id = self._id_generator()
61
58
  self._nodes[node.id] = node
62
59
 
63
- def delete_node(self, node_id: int) -> None:
60
+ def deregister_node(self, node_id: int) -> None:
64
61
  """
65
62
  Deletes a node from the flowchart.
66
63