#!/usr/bin/env python3 """Write the names of the pictures Loom ships into the Rust tree. Kit pictures are data: a kit names a picture (an act's object, a chooser's picture, a step row's picture, a tool's picture) and Loom's catalogue, `apps/loom/Sources/CottonPaper/Media.xcassets`, holds it. The Rust guards that hold the two together (cotton-core `tests/act_pictures.rs`, cotton-ffi `phone/opened_tests.rs`) read nothing outside `crates/` (the rust-crate-local-reads test), so they read this list instead: every `.imageset` with a `Contents.json`, sorted, one name each. crates/cotton-core/src/definitions/loom_pictures.json every picture Loom ships pnpm gen:loom-pictures write it python3 scripts/gen-loom-pictures.py --check fail when it is stale Guard: `scripts/__tests__/loom-pictures.test.ts` runs `--check`, so an imageset added, renamed or removed without regenerating fails there. """ import json import pathlib import sys ROOT = pathlib.Path(__file__).resolve().parent.parent MEDIA = ROOT / 'apps/loom/Sources/CottonPaper/Media.xcassets' LIST = ROOT / 'crates/cotton-core/src/definitions/loom_pictures.json' def pictures(media=MEDIA): names = sorted(path.name.removesuffix('.imageset') for path in media.glob('*.imageset') if (path / 'Contents.json').is_file()) if not names: raise SystemExit(f'gen-loom-pictures: no imageset under {media}') return names def render(names): return json.dumps(names, indent=2) + '\n' def main(argv): text = render(pictures()) current = LIST.read_text() if LIST.exists() else None if current == text: return 0 if '--check' in argv: print(f'gen-loom-pictures: stale — run `pnpm gen:loom-pictures`: {LIST.relative_to(ROOT).as_posix()}', file=sys.stderr) return 1 LIST.write_text(text) return 0 if __name__ == '__main__': sys.exit(main(sys.argv[1:]))