toto-script-tool 1.0.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.
toto/SilkyEngineMES.py ADDED
@@ -0,0 +1,54 @@
1
+ import re
2
+ import textwrap
3
+
4
+ from .util import TextLine
5
+
6
+
7
+ class SilkyEngineMES:
8
+ @staticmethod
9
+ def get_paths(workpath):
10
+ return workpath.glob('*.txt')
11
+
12
+ @staticmethod
13
+ def extract_lines(keybase, text):
14
+ newlines = []
15
+ trans = []
16
+ group = ''
17
+ key = None
18
+ for i, line in enumerate(text.splitlines()):
19
+ if line == '#1-STR_UNCRYPT' and not key:
20
+ key = f'<<<TRANS:{keybase}-{i}>>>'
21
+ newlines.append(line)
22
+ elif key and line in {'#1-TO_NEW_STRING', '[0]', '#1-STR_UNCRYPT', '#3'}:
23
+ continue
24
+ elif key and line.startswith('["'):
25
+ group += line[2:-2]
26
+ elif key and line in {'#1-PUSH', '#1-RETURN'}:
27
+ newlines.append(key)
28
+ newlines.append(line)
29
+ trans.append(TextLine(key, group, ''))
30
+ key = None
31
+ group = ''
32
+ elif key:
33
+ raise ValueError(f"Unknown line ({keybase}#{i}): {line!r}.")
34
+ else:
35
+ newlines.append(line)
36
+
37
+ return newlines, trans
38
+
39
+ @staticmethod
40
+ def insert_lines(keybase, text, trans, width=65, wrap=None):
41
+ newlines = []
42
+ for line in text.splitlines():
43
+ if m := re.match(rf'<<<TRANS:{keybase}-\d+>>>', line):
44
+ if width:
45
+ lines = textwrap.wrap(trans[m.group(0)].text.strip(), width=width)
46
+ lines = ['["' + x + '"]' for x in lines]
47
+ text = '\n#1-TO_NEW_STRING\n[0]\n#1-STR_UNCRYPT\n'.join(lines)
48
+ else:
49
+ text = '["' + trans[m.group(0)].text.strip() + '"]'
50
+ newlines.append(text + trans[m.group(0)].eol)
51
+ else:
52
+ newlines.append(line)
53
+
54
+ return newlines
toto/__about__.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = "1.0.0"
toto/__init__.py ADDED
@@ -0,0 +1 @@
1
+