init
This commit is contained in:
commit
0cba7f5ee0
385 changed files with 17912 additions and 0 deletions
34
tools/make_traces.sh
Executable file
34
tools/make_traces.sh
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/env bash
|
||||
# Regenerates the conformance traces in tests/traces from the TS sim (godot-plan.md §2), then the
|
||||
# Godot runner checks them:
|
||||
# godot --headless --script res://tests/conformance.gd
|
||||
#
|
||||
# Usage: tools/make_traces.sh [games] [sets...] (default 1000 games; every set)
|
||||
# tools/make_traces.sh 1000 greedy nocards only the named sets
|
||||
# SIM points at files-tcg/sim (default ~/Troglodyte-Chamber/files-tcg/sim).
|
||||
set -euo pipefail
|
||||
|
||||
SIM="${SIM:-$HOME/Troglodyte-Chamber/files-tcg/sim}"
|
||||
OUT="$(cd "$(dirname "$0")/.." && pwd)/tests/traces"
|
||||
GAMES="${1:-1000}"
|
||||
shift || true
|
||||
ONLY=("$@")
|
||||
|
||||
trace() { # name games args...
|
||||
local name="$1" games="$2"
|
||||
shift 2
|
||||
if [ ${#ONLY[@]} -gt 0 ] && [[ ! " ${ONLY[*]} " == *" $name "* ]]; then return; fi
|
||||
(cd "$SIM" && node src/trace.ts --out "$OUT/$name" -n "$games" "$@")
|
||||
}
|
||||
|
||||
mkdir -p "$OUT"
|
||||
touch "$OUT/.gdignore"
|
||||
|
||||
# Random-vs-random games with every Set 1 card, under the default rules.
|
||||
trace main "$GAMES"
|
||||
# Also checks the move-list labels (describe.ts), which costs more per step.
|
||||
trace labels 100 --seed 5001 --labels
|
||||
# The greedy bot (GreedyBot): the runner checks it picks what the TS bot picked at every step.
|
||||
trace greedy 100 --seed 7001 --south greedy --north greedy
|
||||
trace greedy-random 50 --seed 8001 --south greedy --north random
|
||||
trace nocards 50 --seed 9001 --south nocards --north greedy
|
||||
113
tools/name_card_faces.py
Executable file
113
tools/name_card_faces.py
Executable file
|
|
@ -0,0 +1,113 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Renames exported card fronts (front-4985.png, ...) to card-name file names.
|
||||
|
||||
The card export writes one front per card copy, numbered in cards.csv row order. This matches
|
||||
them up by sorting the numbers, names each file the way CardFaces.slug does ("Execute: Force
|
||||
Reboot" -> execute-force-reboot.png), and gives each face the card-face import settings. A face
|
||||
that already exists is replaced, keeping its .import file (and so its uid).
|
||||
|
||||
tools/name_card_faces.py # show what would be renamed
|
||||
tools/name_card_faces.py --apply # rename
|
||||
tools/name_card_faces.py --csv PATH --dir PATH
|
||||
"""
|
||||
import argparse
|
||||
import csv
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
PROJECT = Path(__file__).resolve().parent.parent
|
||||
DEFAULT_CSV = Path.home() / "Troglodyte-Chamber/files-tcg/decks/files-deck-1/cards.csv"
|
||||
DEFAULT_DIR = PROJECT / "assets/cards"
|
||||
|
||||
IMPORT = """[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=2
|
||||
compress/high_quality=true
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=true
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=0
|
||||
"""
|
||||
|
||||
|
||||
def slug(name: str) -> str:
|
||||
return re.sub(r"[^a-z0-9]+", "-", name.lower()).strip("-")
|
||||
|
||||
|
||||
def main() -> int:
|
||||
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
ap.add_argument("--csv", type=Path, default=DEFAULT_CSV)
|
||||
ap.add_argument("--dir", type=Path, default=DEFAULT_DIR)
|
||||
ap.add_argument("--apply", action="store_true", help="rename the files (default: only show the plan)")
|
||||
args = ap.parse_args()
|
||||
|
||||
with args.csv.open(newline="") as f:
|
||||
rows = list(csv.DictReader(f))
|
||||
# One export per copy, so a card with Count 2 has two fronts.
|
||||
names = [r["Name"] for r in rows for _ in range(int(r.get("Count") or 1))]
|
||||
|
||||
fronts = sorted(args.dir.glob("front-*.png"), key=lambda p: int(re.search(r"\d+", p.stem).group()))
|
||||
if len(fronts) != len(names):
|
||||
print(f"{len(fronts)} fronts in {args.dir}, but {args.csv} has {len(names)} card copies. "
|
||||
"Export every card, in CSV order, then run this again.", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
done: set[str] = set()
|
||||
for front, name in zip(fronts, names):
|
||||
target = args.dir / f"{slug(name)}.png"
|
||||
if target.name in done:
|
||||
# A later copy of a card that's already named.
|
||||
print(f"{front.name} -> (copy of {name}, removed)")
|
||||
if args.apply:
|
||||
front.unlink()
|
||||
front.with_suffix(".png.import").unlink(missing_ok=True)
|
||||
continue
|
||||
done.add(target.name)
|
||||
replaced = " (replaces the old face)" if target.exists() else ""
|
||||
print(f"{front.name} -> {target.name}{replaced}")
|
||||
if not args.apply:
|
||||
continue
|
||||
front.replace(target)
|
||||
stale = front.with_suffix(".png.import")
|
||||
target_import = target.with_suffix(".png.import")
|
||||
if target_import.exists():
|
||||
stale.unlink(missing_ok=True)
|
||||
elif stale.exists():
|
||||
# Godot already imported the front: keep its uid, use the card-face settings.
|
||||
uid = re.search(r'^uid="[^"]+"$', stale.read_text(), re.M)
|
||||
text = IMPORT.replace('type="CompressedTexture2D"\n', f'type="CompressedTexture2D"\n{uid.group()}\n') if uid else IMPORT
|
||||
target_import.write_text(text)
|
||||
stale.unlink()
|
||||
else:
|
||||
target_import.write_text(IMPORT)
|
||||
|
||||
if not args.apply:
|
||||
print("\nNothing renamed yet. Run with --apply to rename.")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
53
tools/sync_data.py
Executable file
53
tools/sync_data.py
Executable file
|
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Copies the card data the GDScript engine reads from the files-tcg repo into data/
|
||||
(godot-plan.md M0). Run it after editing cards.csv; the conformance runner refuses traces made from
|
||||
a different CSV.
|
||||
|
||||
tools/sync_data.py copy
|
||||
tools/sync_data.py --check exit 1 if data/ is stale
|
||||
"""
|
||||
import argparse
|
||||
import filecmp
|
||||
import shutil
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
PROJECT = Path(__file__).resolve().parent.parent
|
||||
DEFAULT_REPO = Path.home() / "Troglodyte-Chamber" / "files-tcg"
|
||||
|
||||
# Repo path -> project path.
|
||||
FILES = {
|
||||
"decks/files-deck-1/cards.csv": "data/cards.csv",
|
||||
}
|
||||
|
||||
|
||||
def main() -> int:
|
||||
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
ap.add_argument("--repo", type=Path, default=DEFAULT_REPO, help="files-tcg checkout")
|
||||
ap.add_argument("--check", action="store_true", help="only report stale files")
|
||||
args = ap.parse_args()
|
||||
|
||||
stale = []
|
||||
for src_rel, dst_rel in FILES.items():
|
||||
src, dst = args.repo / src_rel, PROJECT / dst_rel
|
||||
if not src.exists():
|
||||
print(f"missing in repo: {src}", file=sys.stderr)
|
||||
return 2
|
||||
if dst.exists() and filecmp.cmp(src, dst, shallow=False):
|
||||
continue
|
||||
stale.append(dst_rel)
|
||||
if not args.check:
|
||||
dst.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copyfile(src, dst)
|
||||
print(f"updated {dst_rel}")
|
||||
if args.check:
|
||||
for f in stale:
|
||||
print(f"stale: {f}")
|
||||
return 1 if stale else 0
|
||||
if not stale:
|
||||
print("data/ is up to date")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Loading…
Add table
Add a link
Reference in a new issue