Cotton code
72 lines · 3.2 KB · PythonRaw
#!/usr/bin/env python3"""Put the todo's index card and its tray, painted, into the Loom package's catalogue.    python3 scripts/import-todos-materials.py [<layers directory>]The layers were painted with Codex (29 Oct 2026, after the index-card picturethe owner chose, `objects-2/todos/3-punched-card`) and cut out of the paintings(the tray keyed off magenta, the card and the tabs off green, the card's stockbrought to the chosen picture's cream, the tray's shadow made from itssilhouette, the steel made seamless at its own colour); the directory holdsthem as the face lays them (CottonFaces' `Cotton/TodoCardFace.swift`, thesteel by `FaceGroundSurface`). No word or number is on any of them: the facetypes the title, the description, the due date on its tab and the day thetodo was made live, on the painted rules.    todo-tray          the steel card tray, its stack of blank cards and tabs behind    todo-tray-front    its front wall and lip, laid over the front card's foot    todo-tray-shadow   its shadow on the steel, larger than the tray    todo-card          the blank ruled index card standing at the front    todo-tab           the blank salmon tab its due date is typed on    todo-tab-late      the same tab in red, for a todo past its dayEach is at least 3x the most it is drawn at on a phone (the shadow, a blur,half that), declared 3x (2x on the Mac) as the card paper is; the face setsthe frame it draws each at. The card's rules, the lip's height, the frontcard's place in the tray and the tabs' tapered ends, measured off thepaintings, are the face's knobs (`TodoCardFaceKnobs`): a repainted layer owesnew ones."""import jsonimport pathlibimport sysHERE = pathlib.Path(__file__).resolve().parentCATALOGUE = HERE.parent / 'apps/loom/Sources/CottonPaper/Media.xcassets'NAMES = ['todo-tray', 'todo-tray-front', 'todo-tray-shadow', 'todo-card', 'todo-tab', 'todo-tab-late']def imageset(name, extension):    folder = CATALOGUE / f'{name}.imageset'    folder.mkdir(exist_ok=True)    for old in folder.iterdir():        old.unlink()    contents = {        'images': [            {'filename': f'{name}.{extension}', 'idiom': 'universal', 'scale': '3x'},            {'filename': f'{name}.{extension}', '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}.{extension}'def main(source):    source = pathlib.Path(source)    total = 0    for name in NAMES:        found = [source / f'{name}.{extension}' for extension in ('png', 'jpg') if (source / f'{name}.{extension}').exists()]        if len(found) != 1:            sys.exit(f'{source} holds {len(found)} pictures named {name}, not one')        picture = found[0]        target = imageset(name, picture.suffix[1:])        target.write_bytes(picture.read_bytes())        total += picture.stat().st_size        print(f'{picture.name} -> {name}')    print(f'{total // 1024} KB in all')if __name__ == '__main__':    main(sys.argv[1] if len(sys.argv) > 1 else str(pathlib.Path.home() / 'lane-briefs/todo-card-face/layers'))