refactor(patches)!: migrate definitions to JSONC and script fragments

Patch definitions under exe-patches/ and gui-patches/ move from
patch.json/locate.json to patch.jsonc/locate.jsonc. Each file now holds
only the data needed to apply the patch plus a short English comment
stating what it changes, why the local service cannot provide it, and
what happens without it. Every definition records the game versions it
was verified on (verified_on, required).

GUI patches keep their stock text and replacement in find.nut and
replace.nut next to patch.jsonc instead of escaped JSON strings, so the
script edits are readable, diffable and can carry Quirrel comments.
Matching treats CRLF and LF as the same line break because stock
scripts mix both; only the matched span is rewritten.

Loaders on both sides (packages/build, packages/exepatch, wtotools)
reject unknown keys so analysis text cannot creep back into the data.
JSONC parsing moves into a shared @wto/jsonc package; the build now
parses tuning/store.jsonc instead of scanning it with a regex.

Verified: npm run typecheck; check-patches (10/10 ready on 2.61.0.37);
check-gui (33 patches, 24 scripts compile); the TypeScript and Python
appliers produce identical scripts, byte-identical to the previous
definitions except one stock script with mixed line endings.

The 15 battle patches are migrated mechanically and still carry the
pending-review comment; they are rewritten by the LocalMP review.

BREAKING CHANGE: Patch loaders require JSONC definitions. Migrate patch.json and locate.json and move embedded GUI edits to separate Quirrel files.
This commit is contained in:
N0VAN0M4LY committed 2026-11-28 03:24:12 +08:00
1 parent b260d2899e
commit db981ab834
185 files changed
+2676 -1487

No files matched your search

+64
View File
@@ -0,0 +1,64 @@
"""JSON with comments: the format of the patch definitions and the local service's tuning files.
Line comments (//) and block comments are blanked out, outside string literals only; the rest
goes to json.loads, so error positions still match the file. Same rules as the TypeScript
reader in packages/jsonc.
"""
from __future__ import annotations
import json
from pathlib import Path
def loads(text: str):
return json.loads(_strip_comments(text))
def load_object(path: Path) -> dict:
"""The object stored in `path`; raises ValueError naming the file when it is not one."""
if not path.is_file():
raise ValueError(f"{path}: file not found")
try:
data = loads(path.read_text("utf-8-sig"))
except json.JSONDecodeError as error:
raise ValueError(f"{path}: invalid JSON: {error}") from error
if not isinstance(data, dict):
raise ValueError(f"{path}: expected a JSON object")
return data
def _strip_comments(text: str) -> str:
out: list[str] = []
index = 0
length = len(text)
while index < length:
ch = text[index]
nxt = text[index + 1] if index + 1 < length else ""
if ch == '"':
end = _string_end(text, index)
out.append(text[index:end])
index = end
elif ch == "/" and nxt == "/":
while index < length and text[index] != "\n":
index += 1
elif ch == "/" and nxt == "*":
end = text.find("*/", index + 2)
stop = length if end < 0 else end + 2
out.append("".join("\n" if c == "\n" else " " for c in text[index:stop]))
index = stop
else:
out.append(ch)
index += 1
return "".join(out)
def _string_end(text: str, start: int) -> int:
index = start + 1
while index < len(text):
if text[index] == "\\":
index += 2
elif text[index] == '"':
return index + 1
else:
index += 1
return len(text)