mb-sc-tools 0.1.1__tar.gz
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.
- mb_sc_tools-0.1.1/CHANGELOG.md +11 -0
- mb_sc_tools-0.1.1/LICENSE +21 -0
- mb_sc_tools-0.1.1/MANIFEST.in +4 -0
- mb_sc_tools-0.1.1/PKG-INFO +113 -0
- mb_sc_tools-0.1.1/README.md +85 -0
- mb_sc_tools-0.1.1/pyproject.toml +45 -0
- mb_sc_tools-0.1.1/setup.cfg +4 -0
- mb_sc_tools-0.1.1/src/mb_sc_tools/__init__.py +23 -0
- mb_sc_tools-0.1.1/src/mb_sc_tools/astc.py +85 -0
- mb_sc_tools-0.1.1/src/mb_sc_tools/cli.py +137 -0
- mb_sc_tools-0.1.1/src/mb_sc_tools/codec.py +767 -0
- mb_sc_tools-0.1.1/src/mb_sc_tools/config.py +44 -0
- mb_sc_tools-0.1.1/src/mb_sc_tools.egg-info/PKG-INFO +113 -0
- mb_sc_tools-0.1.1/src/mb_sc_tools.egg-info/SOURCES.txt +16 -0
- mb_sc_tools-0.1.1/src/mb_sc_tools.egg-info/dependency_links.txt +1 -0
- mb_sc_tools-0.1.1/src/mb_sc_tools.egg-info/entry_points.txt +2 -0
- mb_sc_tools-0.1.1/src/mb_sc_tools.egg-info/requires.txt +3 -0
- mb_sc_tools-0.1.1/src/mb_sc_tools.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 bsod4ik
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mb-sc-tools
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Mobile-friendly Supercell .sc decoder and encoder for Python
|
|
5
|
+
Author: bsod4ik
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: supercell,brawl-stars,sc,texture,astc,mobile
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Classifier: Topic :: Utilities
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: zstandard>=0.22.0
|
|
25
|
+
Requires-Dist: lz4>=4.3.3
|
|
26
|
+
Requires-Dist: Pillow>=10.0.0
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
# mb-sc-tools
|
|
30
|
+
|
|
31
|
+
`mb-sc-tools` is a Python library and CLI for decoding and encoding Supercell `.sc` files on phones and desktops.
|
|
32
|
+
|
|
33
|
+
It supports:
|
|
34
|
+
|
|
35
|
+
- decoding `.sc` into PNG textures and `data.json`
|
|
36
|
+
- encoding edited PNGs back into `.sc`
|
|
37
|
+
- `SC` wrappers with `zstd`, `lzma`, and `lz4` payloads
|
|
38
|
+
- ARM64 phones and desktop systems
|
|
39
|
+
- automatic `astcenc` download on first use for ASTC/KTX textures
|
|
40
|
+
- configurable workspace, output paths, backup name, and ASTC encoder path
|
|
41
|
+
|
|
42
|
+
## Install
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install mb-sc-tools
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## CLI
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
mb-sc-tools
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Or direct commands:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
mb-sc-tools decode /path/to/ui.sc
|
|
58
|
+
mb-sc-tools encode /path/to/sc_decoded/ui
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
More explicit control:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
mb-sc-tools decode /path/to/ui.sc \
|
|
65
|
+
--workspace-root /tmp/sc-work \
|
|
66
|
+
--output-dir /tmp/sc-work/custom/ui \
|
|
67
|
+
--source-backup-name source.sc
|
|
68
|
+
|
|
69
|
+
mb-sc-tools encode /tmp/sc-work/custom/ui \
|
|
70
|
+
--workspace-root /tmp/sc-work \
|
|
71
|
+
--output /tmp/sc-work/sc_encoded/ui.sc
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Python API
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from pathlib import Path
|
|
78
|
+
|
|
79
|
+
from mb_sc_tools import (
|
|
80
|
+
DecodeOptions,
|
|
81
|
+
EncodeOptions,
|
|
82
|
+
WorkspaceConfig,
|
|
83
|
+
decode_to_workspace,
|
|
84
|
+
encode_folder,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
workspace = WorkspaceConfig(root=Path("/tmp/sc-work"))
|
|
88
|
+
|
|
89
|
+
decoded_dir, data = decode_to_workspace(
|
|
90
|
+
Path("/sdcard/ui.sc"),
|
|
91
|
+
options=DecodeOptions(
|
|
92
|
+
workspace=workspace,
|
|
93
|
+
source_backup_name="source.sc",
|
|
94
|
+
),
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
encoded_path = encode_folder(
|
|
98
|
+
decoded_dir,
|
|
99
|
+
options=EncodeOptions(
|
|
100
|
+
workspace=workspace,
|
|
101
|
+
output_path=Path("/tmp/sc-work/sc_encoded/ui.sc"),
|
|
102
|
+
),
|
|
103
|
+
)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Output layout
|
|
107
|
+
|
|
108
|
+
On Android/Termux, if `/sdcard/sc` exists the tool writes to:
|
|
109
|
+
|
|
110
|
+
- `/sdcard/sc/sc_decoded/<file_stem>/`
|
|
111
|
+
- `/sdcard/sc/sc_encoded/<original_name>.sc`
|
|
112
|
+
|
|
113
|
+
Otherwise it writes to a local `./sc/` workspace.
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# mb-sc-tools
|
|
2
|
+
|
|
3
|
+
`mb-sc-tools` is a Python library and CLI for decoding and encoding Supercell `.sc` files on phones and desktops.
|
|
4
|
+
|
|
5
|
+
It supports:
|
|
6
|
+
|
|
7
|
+
- decoding `.sc` into PNG textures and `data.json`
|
|
8
|
+
- encoding edited PNGs back into `.sc`
|
|
9
|
+
- `SC` wrappers with `zstd`, `lzma`, and `lz4` payloads
|
|
10
|
+
- ARM64 phones and desktop systems
|
|
11
|
+
- automatic `astcenc` download on first use for ASTC/KTX textures
|
|
12
|
+
- configurable workspace, output paths, backup name, and ASTC encoder path
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
pip install mb-sc-tools
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## CLI
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
mb-sc-tools
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or direct commands:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
mb-sc-tools decode /path/to/ui.sc
|
|
30
|
+
mb-sc-tools encode /path/to/sc_decoded/ui
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
More explicit control:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
mb-sc-tools decode /path/to/ui.sc \
|
|
37
|
+
--workspace-root /tmp/sc-work \
|
|
38
|
+
--output-dir /tmp/sc-work/custom/ui \
|
|
39
|
+
--source-backup-name source.sc
|
|
40
|
+
|
|
41
|
+
mb-sc-tools encode /tmp/sc-work/custom/ui \
|
|
42
|
+
--workspace-root /tmp/sc-work \
|
|
43
|
+
--output /tmp/sc-work/sc_encoded/ui.sc
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Python API
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from pathlib import Path
|
|
50
|
+
|
|
51
|
+
from mb_sc_tools import (
|
|
52
|
+
DecodeOptions,
|
|
53
|
+
EncodeOptions,
|
|
54
|
+
WorkspaceConfig,
|
|
55
|
+
decode_to_workspace,
|
|
56
|
+
encode_folder,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
workspace = WorkspaceConfig(root=Path("/tmp/sc-work"))
|
|
60
|
+
|
|
61
|
+
decoded_dir, data = decode_to_workspace(
|
|
62
|
+
Path("/sdcard/ui.sc"),
|
|
63
|
+
options=DecodeOptions(
|
|
64
|
+
workspace=workspace,
|
|
65
|
+
source_backup_name="source.sc",
|
|
66
|
+
),
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
encoded_path = encode_folder(
|
|
70
|
+
decoded_dir,
|
|
71
|
+
options=EncodeOptions(
|
|
72
|
+
workspace=workspace,
|
|
73
|
+
output_path=Path("/tmp/sc-work/sc_encoded/ui.sc"),
|
|
74
|
+
),
|
|
75
|
+
)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Output layout
|
|
79
|
+
|
|
80
|
+
On Android/Termux, if `/sdcard/sc` exists the tool writes to:
|
|
81
|
+
|
|
82
|
+
- `/sdcard/sc/sc_decoded/<file_stem>/`
|
|
83
|
+
- `/sdcard/sc/sc_encoded/<original_name>.sc`
|
|
84
|
+
|
|
85
|
+
Otherwise it writes to a local `./sc/` workspace.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=69", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mb-sc-tools"
|
|
7
|
+
version = "0.1.1"
|
|
8
|
+
description = "Mobile-friendly Supercell .sc decoder and encoder for Python"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [
|
|
14
|
+
{name = "bsod4ik"}
|
|
15
|
+
]
|
|
16
|
+
keywords = ["supercell", "brawl-stars", "sc", "texture", "astc", "mobile"]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 3 - Alpha",
|
|
19
|
+
"Environment :: Console",
|
|
20
|
+
"Intended Audience :: Developers",
|
|
21
|
+
"Operating System :: OS Independent",
|
|
22
|
+
"Programming Language :: Python :: 3",
|
|
23
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
24
|
+
"Programming Language :: Python :: 3.10",
|
|
25
|
+
"Programming Language :: Python :: 3.11",
|
|
26
|
+
"Programming Language :: Python :: 3.12",
|
|
27
|
+
"Programming Language :: Python :: 3.13",
|
|
28
|
+
"Topic :: Multimedia :: Graphics",
|
|
29
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
30
|
+
"Topic :: Utilities",
|
|
31
|
+
]
|
|
32
|
+
dependencies = [
|
|
33
|
+
"zstandard>=0.22.0",
|
|
34
|
+
"lz4>=4.3.3",
|
|
35
|
+
"Pillow>=10.0.0",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[project.scripts]
|
|
39
|
+
mb-sc-tools = "mb_sc_tools.cli:main"
|
|
40
|
+
|
|
41
|
+
[tool.setuptools]
|
|
42
|
+
package-dir = {"" = "src"}
|
|
43
|
+
|
|
44
|
+
[tool.setuptools.packages.find]
|
|
45
|
+
where = ["src"]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from .codec import decode_file, decode_to_workspace, encode_folder
|
|
2
|
+
from .config import (
|
|
3
|
+
DATA_JSON_NAME,
|
|
4
|
+
DEFAULT_SOURCE_BACKUP,
|
|
5
|
+
DecodeOptions,
|
|
6
|
+
EncodeOptions,
|
|
7
|
+
WorkspaceConfig,
|
|
8
|
+
get_default_workspace_root,
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"DATA_JSON_NAME",
|
|
13
|
+
"DEFAULT_SOURCE_BACKUP",
|
|
14
|
+
"DecodeOptions",
|
|
15
|
+
"EncodeOptions",
|
|
16
|
+
"WorkspaceConfig",
|
|
17
|
+
"decode_file",
|
|
18
|
+
"decode_to_workspace",
|
|
19
|
+
"encode_folder",
|
|
20
|
+
"get_default_workspace_root",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
__version__ = "0.1.1"
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import platform
|
|
4
|
+
import shutil
|
|
5
|
+
import urllib.request
|
|
6
|
+
import zipfile
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AstcError(RuntimeError):
|
|
11
|
+
pass
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
KNOWN_ASTCENC = [
|
|
15
|
+
Path("/root/tools/astcenc/bin/astcenc-neon"),
|
|
16
|
+
Path("/root/tools/astcenc/bin/astcenc-sve_128"),
|
|
17
|
+
Path("/root/tools/astcenc/bin/astcenc-sve_256"),
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
AUTO_ASTCENC_RELEASE = {
|
|
21
|
+
("Linux", "aarch64"): (
|
|
22
|
+
"https://github.com/ARM-software/astc-encoder/releases/download/5.3.0/"
|
|
23
|
+
"astcenc-5.3.0-linux-arm64.zip",
|
|
24
|
+
"bin/astcenc-neon",
|
|
25
|
+
),
|
|
26
|
+
("Linux", "x86_64"): (
|
|
27
|
+
"https://github.com/ARM-software/astc-encoder/releases/download/5.3.0/"
|
|
28
|
+
"astcenc-5.3.0-linux-x64.zip",
|
|
29
|
+
"bin/astcenc-avx2",
|
|
30
|
+
),
|
|
31
|
+
("Windows", "AMD64"): (
|
|
32
|
+
"https://github.com/ARM-software/astc-encoder/releases/download/5.3.0/"
|
|
33
|
+
"astcenc-5.3.0-windows-x64.zip",
|
|
34
|
+
"bin/astcenc-avx2.exe",
|
|
35
|
+
),
|
|
36
|
+
("Windows", "ARM64"): (
|
|
37
|
+
"https://github.com/ARM-software/astc-encoder/releases/download/5.3.0/"
|
|
38
|
+
"astcenc-5.3.0-windows-arm64.zip",
|
|
39
|
+
"bin/astcenc-neon.exe",
|
|
40
|
+
),
|
|
41
|
+
("Darwin", "arm64"): (
|
|
42
|
+
"https://github.com/ARM-software/astc-encoder/releases/download/5.3.0/"
|
|
43
|
+
"astcenc-5.3.0-macos-universal.zip",
|
|
44
|
+
"bin/astcenc-neon",
|
|
45
|
+
),
|
|
46
|
+
("Darwin", "x86_64"): (
|
|
47
|
+
"https://github.com/ARM-software/astc-encoder/releases/download/5.3.0/"
|
|
48
|
+
"astcenc-5.3.0-macos-universal.zip",
|
|
49
|
+
"bin/astcenc-avx2",
|
|
50
|
+
),
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def ensure_astcenc(user_path: str | None = None) -> Path:
|
|
55
|
+
if user_path:
|
|
56
|
+
path = Path(user_path).expanduser()
|
|
57
|
+
if not path.is_file():
|
|
58
|
+
raise AstcError(f"astcenc not found: {path}")
|
|
59
|
+
return path
|
|
60
|
+
|
|
61
|
+
system_path = shutil.which("astcenc")
|
|
62
|
+
if system_path:
|
|
63
|
+
return Path(system_path)
|
|
64
|
+
|
|
65
|
+
for candidate in KNOWN_ASTCENC:
|
|
66
|
+
if candidate.is_file():
|
|
67
|
+
return candidate
|
|
68
|
+
|
|
69
|
+
key = (platform.system(), platform.machine())
|
|
70
|
+
if key not in AUTO_ASTCENC_RELEASE:
|
|
71
|
+
raise AstcError(f"Unsupported platform for astcenc auto-download: {key}")
|
|
72
|
+
|
|
73
|
+
url, relbin = AUTO_ASTCENC_RELEASE[key]
|
|
74
|
+
cache_dir = Path.home() / ".cache" / "mb_sc_tools" / "astcenc"
|
|
75
|
+
cache_dir.mkdir(parents=True, exist_ok=True)
|
|
76
|
+
binary_path = cache_dir / relbin
|
|
77
|
+
if binary_path.is_file():
|
|
78
|
+
return binary_path
|
|
79
|
+
|
|
80
|
+
zip_path = cache_dir / "astcenc.zip"
|
|
81
|
+
urllib.request.urlretrieve(url, zip_path)
|
|
82
|
+
with zipfile.ZipFile(zip_path) as archive:
|
|
83
|
+
archive.extractall(cache_dir)
|
|
84
|
+
binary_path.chmod(0o755)
|
|
85
|
+
return binary_path
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from .codec import decode_to_workspace, encode_folder
|
|
7
|
+
from .config import DATA_JSON_NAME, DecodeOptions, EncodeOptions, WorkspaceConfig, get_default_workspace_root
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def panel(title: str, lines: list[str]) -> str:
|
|
11
|
+
width = max(len(title) + 2, *(len(line) for line in lines), 32)
|
|
12
|
+
top = "┌" + "─" * (width + 2) + "┐"
|
|
13
|
+
mid = f"│ {title.ljust(width)} │"
|
|
14
|
+
body = "\n".join(f"│ {line.ljust(width)} │" for line in lines)
|
|
15
|
+
bottom = "└" + "─" * (width + 2) + "┘"
|
|
16
|
+
return "\n".join([top, mid, body, bottom])
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def ask(prompt: str, default: str | None = None) -> str:
|
|
20
|
+
suffix = f" [{default}]" if default else ""
|
|
21
|
+
value = input(f"{prompt}{suffix}: ").strip()
|
|
22
|
+
return value or (default or "")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def find_sc_candidates() -> list[Path]:
|
|
26
|
+
root = get_default_workspace_root().parent if get_default_workspace_root().name == "sc" else Path("/sdcard")
|
|
27
|
+
roots = [Path("/sdcard"), get_default_workspace_root(), Path.cwd(), root]
|
|
28
|
+
found: list[Path] = []
|
|
29
|
+
for base in roots:
|
|
30
|
+
if not base.exists():
|
|
31
|
+
continue
|
|
32
|
+
for item in sorted(base.glob("*.sc")):
|
|
33
|
+
if item.is_file() and item not in found:
|
|
34
|
+
found.append(item)
|
|
35
|
+
return found[:20]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def find_decoded_candidates() -> list[Path]:
|
|
39
|
+
decoded_root = get_default_workspace_root() / "sc_decoded"
|
|
40
|
+
if not decoded_root.exists():
|
|
41
|
+
return []
|
|
42
|
+
return sorted(
|
|
43
|
+
[item for item in decoded_root.iterdir() if item.is_dir() and (item / DATA_JSON_NAME).is_file()],
|
|
44
|
+
key=lambda item: item.stat().st_mtime,
|
|
45
|
+
reverse=True,
|
|
46
|
+
)[:20]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def interactive_decode() -> None:
|
|
50
|
+
candidates = find_sc_candidates()
|
|
51
|
+
lines = ["Found .sc files:"]
|
|
52
|
+
lines.extend(f"{idx + 1}. {path}" for idx, path in enumerate(candidates)) if candidates else lines.append("nothing found, type the path manually")
|
|
53
|
+
print(panel("mb-sc-tools Decode", lines))
|
|
54
|
+
default = str(candidates[0]) if candidates else str(Path.cwd() / "ui.sc")
|
|
55
|
+
source = Path(ask("Path to .sc file", default)).expanduser().resolve()
|
|
56
|
+
workspace_root = ask("Workspace root", str(get_default_workspace_root()))
|
|
57
|
+
options = DecodeOptions(workspace=WorkspaceConfig(root=Path(workspace_root)))
|
|
58
|
+
out_dir, data = decode_to_workspace(source, options=options)
|
|
59
|
+
print()
|
|
60
|
+
print(panel("Decode Complete", [f"Folder: {out_dir}", f"PNG: {len(data['textures'])}", f"JSON: {out_dir / DATA_JSON_NAME}"]))
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def interactive_encode() -> None:
|
|
64
|
+
candidates = find_decoded_candidates()
|
|
65
|
+
lines = ["Found decoded folders:"]
|
|
66
|
+
lines.extend(f"{idx + 1}. {path}" for idx, path in enumerate(candidates)) if candidates else lines.append("nothing found, type the path manually")
|
|
67
|
+
print(panel("mb-sc-tools Encode", lines))
|
|
68
|
+
default = str(candidates[0]) if candidates else str(get_default_workspace_root() / "sc_decoded" / "ui")
|
|
69
|
+
decoded_dir = Path(ask("Path to decoded folder", default)).expanduser().resolve()
|
|
70
|
+
workspace_root = ask("Workspace root", str(get_default_workspace_root()))
|
|
71
|
+
options = EncodeOptions(workspace=WorkspaceConfig(root=Path(workspace_root)))
|
|
72
|
+
encoded_path = encode_folder(decoded_dir, options=options)
|
|
73
|
+
print()
|
|
74
|
+
print(panel("Encode Complete", [f"SC: {encoded_path}"]))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def interactive_menu() -> int:
|
|
78
|
+
while True:
|
|
79
|
+
print()
|
|
80
|
+
print(panel("mb-sc-tools", ["1. Decode .sc -> PNG + data.json", "2. Encode decoded folder -> .sc", "3. Exit"]))
|
|
81
|
+
choice = ask("Select", "1")
|
|
82
|
+
print()
|
|
83
|
+
if choice == "1":
|
|
84
|
+
interactive_decode()
|
|
85
|
+
elif choice == "2":
|
|
86
|
+
interactive_encode()
|
|
87
|
+
elif choice == "3":
|
|
88
|
+
return 0
|
|
89
|
+
else:
|
|
90
|
+
print("Unknown choice")
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
94
|
+
parser = argparse.ArgumentParser(description="Decode and encode Supercell .sc files")
|
|
95
|
+
subparsers = parser.add_subparsers(dest="command")
|
|
96
|
+
|
|
97
|
+
decode_parser = subparsers.add_parser("decode", help="Decode a .sc file")
|
|
98
|
+
decode_parser.add_argument("input", help="Input .sc file")
|
|
99
|
+
decode_parser.add_argument("-o", "--output-dir", help="Explicit decoded output directory")
|
|
100
|
+
decode_parser.add_argument("--workspace-root", help="Workspace root")
|
|
101
|
+
decode_parser.add_argument("--astcenc", help="Path to astcenc binary")
|
|
102
|
+
decode_parser.add_argument("--source-backup-name", default="original.sc", help="Name of source .sc backup inside decoded folder")
|
|
103
|
+
|
|
104
|
+
encode_parser = subparsers.add_parser("encode", help="Encode a decoded folder")
|
|
105
|
+
encode_parser.add_argument("input", help="Decoded folder with PNGs and data.json")
|
|
106
|
+
encode_parser.add_argument("-o", "--output", help="Output .sc file")
|
|
107
|
+
encode_parser.add_argument("--workspace-root", help="Workspace root")
|
|
108
|
+
encode_parser.add_argument("--astcenc", help="Path to astcenc binary")
|
|
109
|
+
|
|
110
|
+
return parser
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def main(argv: list[str] | None = None) -> int:
|
|
114
|
+
parser = build_parser()
|
|
115
|
+
args = parser.parse_args(argv)
|
|
116
|
+
|
|
117
|
+
if args.command == "decode":
|
|
118
|
+
options = DecodeOptions(
|
|
119
|
+
output_dir=Path(args.output_dir).expanduser().resolve() if args.output_dir else None,
|
|
120
|
+
workspace=WorkspaceConfig(root=Path(args.workspace_root).expanduser().resolve()) if args.workspace_root else None,
|
|
121
|
+
astcenc_path=args.astcenc,
|
|
122
|
+
source_backup_name=args.source_backup_name,
|
|
123
|
+
)
|
|
124
|
+
out_dir, data = decode_to_workspace(Path(args.input).expanduser().resolve(), options=options)
|
|
125
|
+
print(panel("Decode Complete", [f"Folder: {out_dir}", f"PNG: {len(data['textures'])}", f"JSON: {out_dir / DATA_JSON_NAME}"]))
|
|
126
|
+
return 0
|
|
127
|
+
if args.command == "encode":
|
|
128
|
+
options = EncodeOptions(
|
|
129
|
+
output_path=Path(args.output).expanduser().resolve() if args.output else None,
|
|
130
|
+
workspace=WorkspaceConfig(root=Path(args.workspace_root).expanduser().resolve()) if args.workspace_root else None,
|
|
131
|
+
astcenc_path=args.astcenc,
|
|
132
|
+
)
|
|
133
|
+
encoded_path = encode_folder(Path(args.input).expanduser().resolve(), options=options)
|
|
134
|
+
print(panel("Encode Complete", [f"SC: {encoded_path}"]))
|
|
135
|
+
return 0
|
|
136
|
+
|
|
137
|
+
return interactive_menu()
|