koro 2.0.0rc2__py3-none-any.whl → 2.0.1__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/__init__.py +8 -8
- koro/slot/__init__.py +21 -21
- koro/slot/bin.py +158 -155
- koro/slot/file.py +70 -67
- koro/slot/save.py +138 -135
- koro/slot/xml.py +845 -783
- koro/stage/__init__.py +99 -98
- koro/stage/model.py +288 -284
- koro/stage/part.py +1754 -1704
- {koro-2.0.0rc2.dist-info → koro-2.0.1.dist-info}/LICENSE +24 -24
- koro-2.0.1.dist-info/METADATA +52 -0
- koro-2.0.1.dist-info/RECORD +14 -0
- {koro-2.0.0rc2.dist-info → koro-2.0.1.dist-info}/WHEEL +1 -1
- koro-2.0.0rc2.dist-info/METADATA +0 -21
- koro-2.0.0rc2.dist-info/RECORD +0 -14
- {koro-2.0.0rc2.dist-info → koro-2.0.1.dist-info}/top_level.txt +0 -0
koro/slot/save.py
CHANGED
@@ -1,135 +1,138 @@
|
|
1
|
-
from enum import Enum, unique
|
2
|
-
from io import BytesIO
|
3
|
-
from operator import index as ix
|
4
|
-
from os.path import basename, dirname, join
|
5
|
-
from typing import TYPE_CHECKING, Annotated, Any, Literal, SupportsIndex
|
6
|
-
from collections.abc import Mapping, Sequence
|
7
|
-
|
8
|
-
from ..stage import Stage
|
9
|
-
|
10
|
-
from . import Slot
|
11
|
-
from .xml import XmlSlot
|
12
|
-
|
13
|
-
if TYPE_CHECKING:
|
14
|
-
from _typeshed import StrOrBytesPath
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
return
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
def
|
112
|
-
return
|
113
|
-
|
114
|
-
def
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
1
|
+
from enum import Enum, unique
|
2
|
+
from io import BytesIO
|
3
|
+
from operator import index as ix
|
4
|
+
from os.path import basename, dirname, join
|
5
|
+
from typing import TYPE_CHECKING, Annotated, Any, Literal, SupportsIndex
|
6
|
+
from collections.abc import Mapping, Sequence
|
7
|
+
|
8
|
+
from ..stage import Stage
|
9
|
+
|
10
|
+
from . import Slot
|
11
|
+
from .xml import XmlSlot
|
12
|
+
|
13
|
+
if TYPE_CHECKING:
|
14
|
+
from _typeshed import StrOrBytesPath
|
15
|
+
else:
|
16
|
+
StrOrBytesPath = Any
|
17
|
+
|
18
|
+
|
19
|
+
__all__ = ["EditorPage", "get_slots", "SaveSlot"]
|
20
|
+
|
21
|
+
|
22
|
+
@unique
|
23
|
+
class EditorPage(Enum):
|
24
|
+
ORIGINAL = 0
|
25
|
+
FRIEND = 1
|
26
|
+
HUDSON = 2
|
27
|
+
|
28
|
+
|
29
|
+
class SaveSlot(Slot):
|
30
|
+
__match_args__ = ("path", "page", "index")
|
31
|
+
__slots__ = ("_offset", "_path")
|
32
|
+
|
33
|
+
_offset: Literal[8, 156392, 312776, 469160]
|
34
|
+
_path: str | bytes
|
35
|
+
|
36
|
+
def __init__(
|
37
|
+
self,
|
38
|
+
path: StrOrBytesPath,
|
39
|
+
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
|
+
],
|
46
|
+
) -> None:
|
47
|
+
index = ix(index) - 1
|
48
|
+
if index in range(0, 20):
|
49
|
+
self._offset = 8 + 156864 * (index & 3) # type: ignore[assignment]
|
50
|
+
self._path = join(path, f"ed{(index >> 2) + 5 * page.value:02}.dat") # type: ignore[arg-type]
|
51
|
+
else:
|
52
|
+
raise ValueError("index must be between 1 and 20")
|
53
|
+
|
54
|
+
def __bool__(self) -> bool:
|
55
|
+
try:
|
56
|
+
with open(self._path, "rb") as f:
|
57
|
+
f.seek(self._offset)
|
58
|
+
return f.read(1) != b"\x00"
|
59
|
+
except FileNotFoundError:
|
60
|
+
return False
|
61
|
+
|
62
|
+
def __eq__(self, other: Any, /) -> bool:
|
63
|
+
if isinstance(other, SaveSlot):
|
64
|
+
return self._path == other._path and self._offset == other._offset
|
65
|
+
else:
|
66
|
+
return NotImplemented
|
67
|
+
|
68
|
+
def __hash__(self) -> int:
|
69
|
+
return hash((self._offset, self._path))
|
70
|
+
|
71
|
+
@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]
|
76
|
+
|
77
|
+
def load(self) -> Stage | None:
|
78
|
+
try:
|
79
|
+
with open(self._path, "rb") as f:
|
80
|
+
f.seek(self._offset)
|
81
|
+
with BytesIO() as b:
|
82
|
+
block: bytearray = bytearray()
|
83
|
+
while True:
|
84
|
+
block.clear()
|
85
|
+
block.extend(f.read1())
|
86
|
+
print(block)
|
87
|
+
if len(b.getbuffer()) + len(block) > 156864:
|
88
|
+
del block[156864 - len(b.getbuffer()) :]
|
89
|
+
if block[-1]:
|
90
|
+
b.write(block)
|
91
|
+
else:
|
92
|
+
while block:
|
93
|
+
if block[len(block) >> 1]:
|
94
|
+
b.write(block[: (len(block) >> 1) + 1])
|
95
|
+
del block[: (len(block) >> 1) + 1]
|
96
|
+
else:
|
97
|
+
del block[len(block) >> 1 :]
|
98
|
+
data: bytes = b.getvalue()
|
99
|
+
if data:
|
100
|
+
return XmlSlot.deserialize(data)
|
101
|
+
else:
|
102
|
+
return None
|
103
|
+
except FileNotFoundError:
|
104
|
+
return None
|
105
|
+
|
106
|
+
@property
|
107
|
+
def page(self) -> EditorPage:
|
108
|
+
return EditorPage(int(basename(self._path)[2:4]) // 5)
|
109
|
+
|
110
|
+
@property
|
111
|
+
def path(self) -> StrOrBytesPath:
|
112
|
+
return dirname(self._path)
|
113
|
+
|
114
|
+
def __repr__(self) -> str:
|
115
|
+
return f"{type(self).__name__}({self.path!r}, {self.page!r}, {self.index!r})"
|
116
|
+
|
117
|
+
def save(self, data: Stage | None) -> None:
|
118
|
+
binary: bytes = b"" if data is None else XmlSlot.serialize(data)
|
119
|
+
if len(binary) > 156864:
|
120
|
+
raise ValueError("serialized stage data is too large to save")
|
121
|
+
try:
|
122
|
+
with open(self._path, "xb") as f:
|
123
|
+
f.write(bytes(638976))
|
124
|
+
if data is None:
|
125
|
+
return
|
126
|
+
except FileExistsError:
|
127
|
+
pass
|
128
|
+
with open(self._path, "r+b") as f:
|
129
|
+
f.seek(self._offset)
|
130
|
+
f.write(binary)
|
131
|
+
f.write(bytes(156864 - len(binary)))
|
132
|
+
|
133
|
+
|
134
|
+
def get_slots(save: StrOrBytesPath, /) -> Mapping[EditorPage, Sequence[SaveSlot]]:
|
135
|
+
return {
|
136
|
+
page: tuple(SaveSlot(save, page, i) for i in range(1, 21))
|
137
|
+
for page in EditorPage
|
138
|
+
}
|