koro 2.0.2__py3-none-any.whl → 2.0.3__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.
koro/py.typed ADDED
File without changes
koro/slot/bin.py CHANGED
@@ -5,7 +5,6 @@ from ..stage import Stage
5
5
  from .file import FileSlot
6
6
  from .xml import XmlSlot
7
7
 
8
-
9
8
  __all__ = ["BinSlot"]
10
9
 
11
10
 
koro/slot/save.py CHANGED
@@ -1,12 +1,20 @@
1
+ from collections.abc import Mapping, Sequence
1
2
  from enum import Enum, unique
2
3
  from io import BytesIO
3
4
  from operator import index as ix
4
5
  from os.path import basename, dirname, join
5
- from typing import TYPE_CHECKING, Annotated, Any, Literal, SupportsIndex
6
- from collections.abc import Mapping, Sequence
6
+ from typing import (
7
+ TYPE_CHECKING,
8
+ Annotated,
9
+ Any,
10
+ Final,
11
+ Literal,
12
+ SupportsIndex,
13
+ TypeAlias,
14
+ )
15
+ from warnings import warn
7
16
 
8
17
  from ..stage import Stage
9
-
10
18
  from . import Slot
11
19
  from .xml import XmlSlot
12
20
 
@@ -16,7 +24,13 @@ else:
16
24
  StrOrBytesPath = Any
17
25
 
18
26
 
19
- __all__ = ["EditorPage", "get_slots", "SaveSlot"]
27
+ __all__ = ["EditorPage", "SaveSlot"]
28
+
29
+ _SIZE_LIMIT: Final[int] = 156864
30
+
31
+ SlotNumber: TypeAlias = Literal[
32
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
33
+ ]
20
34
 
21
35
 
22
36
  @unique
@@ -30,23 +44,23 @@ class SaveSlot(Slot):
30
44
  __match_args__ = ("path", "page", "index")
31
45
  __slots__ = ("_offset", "_path")
32
46
 
33
- _offset: Literal[8, 156392, 312776, 469160]
47
+ _offset: Literal[8, 156872, 313736, 470600]
34
48
  _path: str | bytes
35
49
 
36
50
  def __init__(
37
51
  self,
38
52
  path: StrOrBytesPath,
39
53
  page: EditorPage,
40
- index: Annotated[
41
- SupportsIndex,
42
- Literal[
43
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20
44
- ],
45
- ],
54
+ index: Annotated[SupportsIndex, SlotNumber],
46
55
  ) -> None:
47
56
  index = ix(index) - 1
48
- if index in range(0, 20):
49
- self._offset = 8 + 156864 * (index & 3) # type: ignore[assignment]
57
+ if index in range(20):
58
+ if page == EditorPage.HUDSON and index in range(5):
59
+ warn(
60
+ "Modifications to Hudson 01-05 are ignored by the game. These stages are read from disc (/data/A19S00X.bin) and are empty by default when inspected with this library; writes made by this library will have no effect in-game.",
61
+ RuntimeWarning,
62
+ )
63
+ self._offset = 8 + _SIZE_LIMIT * (index & 3) # type: ignore[assignment]
50
64
  self._path = join(path, f"ed{(index >> 2) + 5 * page.value:02}.dat") # type: ignore[arg-type]
51
65
  else:
52
66
  raise ValueError("index must be between 1 and 20")
@@ -69,10 +83,8 @@ class SaveSlot(Slot):
69
83
  return hash((self._offset, self._path))
70
84
 
71
85
  @property
72
- def index(
73
- self,
74
- ) -> Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]:
75
- return (int(basename(self._path)[2:4]) % 5 >> 2 | self._offset // 156864) + 1 # type: ignore[return-value]
86
+ def index(self) -> SlotNumber:
87
+ return (int(basename(self._path)[2:4]) % 5 >> 2 | self._offset // _SIZE_LIMIT) + 1 # type: ignore[return-value]
76
88
 
77
89
  def load(self) -> Stage | None:
78
90
  try:
@@ -82,10 +94,8 @@ class SaveSlot(Slot):
82
94
  block: bytearray = bytearray()
83
95
  while True:
84
96
  block.clear()
85
- block.extend(f.read1())
86
- if len(b.getbuffer()) + len(block) > 156864:
87
- del block[156864 - len(b.getbuffer()) :]
88
- if block[-1]:
97
+ block.extend(f.read1(_SIZE_LIMIT - len(b.getbuffer())))
98
+ if block and block[-1]:
89
99
  b.write(block)
90
100
  else:
91
101
  while block:
@@ -115,11 +125,13 @@ class SaveSlot(Slot):
115
125
 
116
126
  def save(self, data: Stage | None) -> None:
117
127
  binary: bytes = b"" if data is None else XmlSlot.serialize(data)
118
- if len(binary) > 156864:
128
+ if len(binary) > _SIZE_LIMIT:
119
129
  raise ValueError("serialized stage data is too large to save")
120
130
  try:
121
131
  with open(self._path, "xb") as f:
122
- f.write(bytes(638976))
132
+ f.write(
133
+ bytes(638976)
134
+ ) # Weird. Would expect this to be 627464 (8 + 4 * (_SIZE_LIMIT))
123
135
  if data is None:
124
136
  return
125
137
  except FileExistsError:
@@ -127,10 +139,11 @@ class SaveSlot(Slot):
127
139
  with open(self._path, "r+b") as f:
128
140
  f.seek(self._offset)
129
141
  f.write(binary)
130
- f.write(bytes(156864 - len(binary)))
142
+ f.write(bytes(_SIZE_LIMIT - len(binary)))
131
143
 
132
144
 
133
145
  def get_slots(save: StrOrBytesPath, /) -> Mapping[EditorPage, Sequence[SaveSlot]]:
146
+ warn("function get_slots is deprecated", DeprecationWarning)
134
147
  return {
135
148
  page: tuple(SaveSlot(save, page, i) for i in range(1, 21))
136
149
  for page in EditorPage
koro/slot/xml.py CHANGED
@@ -12,7 +12,6 @@ from ..stage.part import (
12
12
  BasePart,
13
13
  BlinkingTile,
14
14
  Bumper,
15
- TextBox,
16
15
  Cannon,
17
16
  ConveyorBelt,
18
17
  DashTunnel,
@@ -41,6 +40,7 @@ from ..stage.part import (
41
40
  Speed,
42
41
  Spring,
43
42
  Start,
43
+ TextBox,
44
44
  Thorn,
45
45
  TimedDevice,
46
46
  ToyTrain,
koro/stage/model.py CHANGED
@@ -1,7 +1,6 @@
1
1
  from enum import Enum, unique
2
2
  from typing import TypeAlias
3
3
 
4
-
5
4
  __all__ = ["DecorationModel", "DeviceModel", "Model", "PartModel"]
6
5
 
7
6
 
koro/stage/part.py CHANGED
@@ -2,14 +2,13 @@ from __future__ import annotations
2
2
 
3
3
  from abc import ABC, abstractmethod
4
4
  from collections.abc import Iterable, MutableSequence
5
- from enum import Enum, unique, Flag
5
+ from enum import Enum, Flag, unique
6
6
  from operator import index
7
7
  from sys import maxsize
8
8
  from typing import Any, Final, Iterator, Literal, Self, SupportsIndex, overload
9
9
 
10
10
  from .model import DecorationModel, DeviceModel, PartModel
11
11
 
12
-
13
12
  __all__ = [
14
13
  "Ant",
15
14
  "BasePart",
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: koro
3
- Version: 2.0.2
3
+ Version: 2.0.3
4
4
  Summary: Tools for manipulating levels made in Marble Saga: Kororinpa
5
5
  Home-page: https://github.com/DigitalDetective47/koro
6
6
  Author: DigitalDetective47
@@ -14,6 +14,7 @@ Classifier: Programming Language :: Python :: 3
14
14
  Classifier: Programming Language :: Python :: 3 :: Only
15
15
  Classifier: Programming Language :: Python :: 3.11
16
16
  Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
17
18
  Classifier: Topic :: File Formats
18
19
  Classifier: Topic :: Games/Entertainment
19
20
  Classifier: Typing :: Typed
@@ -0,0 +1,15 @@
1
+ koro/__init__.py,sha256=5_P8Q_L1Jo-bqMmzAK9tPKkmaSffbuid16voHwj8vys,192
2
+ koro/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ koro/slot/__init__.py,sha256=YJ3FjOF4o1Vo8joMpLTw27-Dwaoxq5YfQSER-ymJjFE,398
4
+ koro/slot/bin.py,sha256=Q0vKE5hTzGIGER-kpZnRykA3oAkXaK6uSAibS5Y1gBM,6527
5
+ koro/slot/file.py,sha256=QxBIXzFqzT6mzVZ5bq8xeR8vWfcNFpjHzsEEEqSzlz4,1656
6
+ koro/slot/save.py,sha256=bX9XW8qcNbd2qelwmHRoPMkQsQkL-ZAFx_F5sW-xWRE,4916
7
+ koro/slot/xml.py,sha256=TXogt9AlR93_jG63j2fv3AeEbkB4D8xp3CE1OI_2OjA,42147
8
+ koro/stage/__init__.py,sha256=xdMGSuI4fNDVSSHnuSwMyzFVyRxpcsSDxCl0EQWGJJM,2448
9
+ koro/stage/model.py,sha256=ZxmuKceendBqtVgmkJUYwbVzb7lGGhSoeCumgx3zwuQ,8428
10
+ koro/stage/part.py,sha256=QE7BFltmhm2pTQKjMrH0bxMj5h5Z8neOxxQEMd6RDGw,46885
11
+ koro-2.0.3.dist-info/LICENSE,sha256=awOCsWJ58m_2kBQwBUGWejVqZm6wuRtCL2hi9rfa0X4,1211
12
+ koro-2.0.3.dist-info/METADATA,sha256=ErAsRu5QewfmllvUwcsbuD-RUB2f6zJhNxzwiWdoZJA,4405
13
+ koro-2.0.3.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
14
+ koro-2.0.3.dist-info/top_level.txt,sha256=Msq6ssMwv56hnBQqwaTdJJkxM7x7BZ-3JfQbkepQAEY,5
15
+ koro-2.0.3.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (70.3.0)
2
+ Generator: setuptools (75.8.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,14 +0,0 @@
1
- koro/__init__.py,sha256=5_P8Q_L1Jo-bqMmzAK9tPKkmaSffbuid16voHwj8vys,192
2
- koro/slot/__init__.py,sha256=YJ3FjOF4o1Vo8joMpLTw27-Dwaoxq5YfQSER-ymJjFE,398
3
- koro/slot/bin.py,sha256=KaspkI3MZAoUTkVD8cSNP8sjn_ZI9U7qLt885zEK5C0,6528
4
- koro/slot/file.py,sha256=QxBIXzFqzT6mzVZ5bq8xeR8vWfcNFpjHzsEEEqSzlz4,1656
5
- koro/slot/save.py,sha256=ng1lCfUunJxsok9Isux2sRfth3VbB8vRvcpz4zDIelM,4450
6
- koro/slot/xml.py,sha256=evjIx-egPC43HqMCtBmmrjggyZ3xjERquqhaSIFQz0I,42147
7
- koro/stage/__init__.py,sha256=xdMGSuI4fNDVSSHnuSwMyzFVyRxpcsSDxCl0EQWGJJM,2448
8
- koro/stage/model.py,sha256=JNN6xT9o-47oTETu0_bWZpVBPOm2xkRgItKnREExbHo,8429
9
- koro/stage/part.py,sha256=zo2uxQ6QccG3Ja7sos6IUiwnjvXJDFoWRcTbUVXeQ5E,46886
10
- koro-2.0.2.dist-info/LICENSE,sha256=awOCsWJ58m_2kBQwBUGWejVqZm6wuRtCL2hi9rfa0X4,1211
11
- koro-2.0.2.dist-info/METADATA,sha256=fhMg_HIOEOu69Q0bjpExNDLIWqMx0l0pD4PpR2VkOvE,4354
12
- koro-2.0.2.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
13
- koro-2.0.2.dist-info/top_level.txt,sha256=Msq6ssMwv56hnBQqwaTdJJkxM7x7BZ-3JfQbkepQAEY,5
14
- koro-2.0.2.dist-info/RECORD,,
File without changes