Compare commits
28 Commits
81aca559c9
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 4a7ca281dd | |||
| d3b7ebfc15 | |||
| 3114e0ae7f | |||
| fb7bcf5780 | |||
| d1b569979e | |||
| 4c00d3b232 | |||
| 5907cd8f27 | |||
| 5915e928c3 | |||
| 6d22b5547c | |||
| 911d51815d | |||
| 4c77395fc7 | |||
| 4653050f45 | |||
| f8ad2a6439 | |||
| 514c7e9b22 | |||
| 0c33acf06d | |||
| 63775ae3ea | |||
| 862aa03549 | |||
| 816a28986c | |||
| 8d9abc8cb2 | |||
| 14961629f2 | |||
| 2a15e704b2 | |||
| 991bc5eb3e | |||
| 0a9380cd22 | |||
| d381ac1693 | |||
| 8a5e4a0fb1 | |||
| e5f7da3cc5 | |||
| 4f623656bb | |||
| acfc5e7324 |
+1
-31561
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,100 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def crop_icon(icon: str | None) -> list[int | str] | None:
|
||||
if not icon:
|
||||
return None
|
||||
|
||||
lines = icon.split("\n")
|
||||
xs: list[int] = []
|
||||
ys: list[int] = []
|
||||
|
||||
for y, line in enumerate(lines):
|
||||
for x, char in enumerate(line):
|
||||
if char != " ":
|
||||
xs.append(x)
|
||||
ys.append(y)
|
||||
|
||||
if not xs:
|
||||
return [0, 0, ""]
|
||||
|
||||
min_x = min(xs)
|
||||
max_x = max(xs)
|
||||
min_y = min(ys)
|
||||
max_y = max(ys)
|
||||
cropped_lines = [line[min_x : max_x + 1].rstrip() for line in lines[min_y : max_y + 1]]
|
||||
return [min_x, min_y, "\n".join(cropped_lines)]
|
||||
|
||||
|
||||
def compact_chains(data: object) -> list[list[object]]:
|
||||
if isinstance(data, dict):
|
||||
chains = data.get("chains")
|
||||
else:
|
||||
chains = data
|
||||
|
||||
if not isinstance(chains, list):
|
||||
raise ValueError("Input JSON does not contain a valid chains array")
|
||||
|
||||
compact: list[list[object]] = []
|
||||
|
||||
for chain in chains:
|
||||
if isinstance(chain, list):
|
||||
if len(chain) == 2 and isinstance(chain[1], list):
|
||||
compact.append(chain)
|
||||
continue
|
||||
if len(chain) == 3 and isinstance(chain[1], int) and isinstance(chain[2], list):
|
||||
compact.append([chain[0], chain[2]])
|
||||
continue
|
||||
raise ValueError("Invalid compact chain entry")
|
||||
|
||||
if not isinstance(chain, dict):
|
||||
raise ValueError("Expected verbose or compact chain entries as input")
|
||||
|
||||
items = chain.get("items")
|
||||
if not isinstance(items, list) or not items:
|
||||
continue
|
||||
|
||||
base_id = chain["base_id"]
|
||||
compact_items: list[list[object]] = []
|
||||
|
||||
for item in items:
|
||||
compact_items.append([
|
||||
item["item_id"],
|
||||
crop_icon(item.get("icon_nfp_16x16")),
|
||||
])
|
||||
|
||||
compact.append([base_id, compact_items])
|
||||
|
||||
return compact
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Rewrite atc_chains.json into a compact format used by compcount.lua."
|
||||
)
|
||||
parser.add_argument("source", nargs="?", default="atc_chains_uncompressed.json")
|
||||
parser.add_argument("destination", nargs="?", default="atc_chains.json")
|
||||
args = parser.parse_args()
|
||||
|
||||
source_path = Path(args.source)
|
||||
destination_path = Path(args.destination)
|
||||
original_text = source_path.read_text(encoding="utf-8")
|
||||
data = json.loads(original_text)
|
||||
compact = {"chains": compact_chains(data)}
|
||||
compact_text = json.dumps(compact, separators=(",", ":"))
|
||||
destination_path.write_text(compact_text, encoding="utf-8")
|
||||
|
||||
print(f"Compacted {source_path} -> {destination_path}")
|
||||
print(f"Old size: {len(original_text.encode('utf-8'))} bytes")
|
||||
print(f"New size: {len(compact_text.encode('utf-8'))} bytes")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
+875
-120
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def remove_icon_png_base64_lines(path: Path) -> int:
|
||||
original = path.read_text(encoding="utf-8")
|
||||
lines = original.splitlines(keepends=True)
|
||||
|
||||
kept_lines = []
|
||||
removed = 0
|
||||
|
||||
for line in lines:
|
||||
if '"icon_png_base64"' in line:
|
||||
removed += 1
|
||||
continue
|
||||
kept_lines.append(line)
|
||||
|
||||
if removed:
|
||||
path.write_text("".join(kept_lines), encoding="utf-8")
|
||||
|
||||
return removed
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Remove icon_png_base64 fields from atc_chains.json while preserving all other text."
|
||||
)
|
||||
parser.add_argument(
|
||||
"path",
|
||||
nargs="?",
|
||||
default="atc_chains.json",
|
||||
help="Path to the JSON file to rewrite in place.",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
path = Path(args.path)
|
||||
removed = remove_icon_png_base64_lines(path)
|
||||
print(f"Removed {removed} icon_png_base64 field(s) from {path}.")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,3 @@
|
||||
[
|
||||
|
||||
]
|
||||
Reference in New Issue
Block a user