#!/usr/bin/env python3 """Put Card design's textures-v2 into the Loom package's catalogue as a card's paper. python3 scripts/import-card-paper.py [] Every face's card is drawn from these (CottonPaper's `Paper/CardPaper.swift`, `onCardPaper`), at 1080x1350, 3x a 360x450 pt card: deck-paper-shape card-shape.png: the 4:5 mask the paper is cut by deck-paper-mottle card-mottle.png, multiplied at the theme's opacity deck-paper-rim card-rim.png, multiplied deck-rule-notched card-border-notched.png: the rule, recoloured per band deck-rule-ornament card-border-ornament-notched.png: the note's rule """ import json import pathlib import sys HERE = pathlib.Path(__file__).resolve().parent CATALOGUE = HERE.parent / 'apps/loom/Sources/CottonPaper/Media.xcassets' COPIED = { 'deck-paper-shape': 'card-shape.png', 'deck-paper-mottle': 'card-mottle.png', 'deck-paper-rim': 'card-rim.png', 'deck-rule-notched': 'card-border-notched.png', 'deck-rule-ornament': 'card-border-ornament-notched.png', } def imageset(name): folder = CATALOGUE / f'{name}.imageset' folder.mkdir(exist_ok=True) contents = { 'images': [ {'filename': f'{name}.png', 'idiom': 'universal', 'scale': '3x'}, {'filename': f'{name}.png', 'idiom': 'mac', 'scale': '2x'}, ], 'info': {'author': 'xcode', 'version': 1}, 'properties': {'preserves-vector-representation': False}, } (folder / 'Contents.json').write_text(json.dumps(contents, indent=2) + '\n') return folder / f'{name}.png' def main(source): source = pathlib.Path(source) for name, file in COPIED.items(): target = imageset(name) target.write_bytes((source / file).read_bytes()) print(f'{file} -> {name}') if __name__ == '__main__': main(sys.argv[1] if len(sys.argv) > 1 else str(pathlib.Path.home() / 'lane-briefs/carddesign-images/art/textures-v2'))