Cotton code
83 lines · 3.4 KB · PythonRaw
#!/usr/bin/env python3"""Put the cassette's painted materials into the Loom package's catalogue.    python3 scripts/import-cassette-materials.py [<layers directory>]The layers are Round 22's bare cassette (music22-cassette, 7 Nov 2026: theworn black cassette of the Dark Room's `playlists` picture the owner chose,painted square-on with Codex as wordless cut-outs; the originals stay on theSSD). The directory holds them as the face lays them (CottonFaces'`Cotton/CassetteParts.swift`, after the directory's `layout.json`, in theshell's 1200 x 745 pixels). No word, number, pack share or hub angle is onany of them: the face draws those live.    cassette-shell         the worn black shell, its hub holes and window cut out    cassette-shell-shadow  the shell's shadow, 60 px past it on every side    cassette-label-blank   the cream paper label with its red rule    cassette-hub           one cream six-tooth hub, turned round its centre    cassette-pack          one wound tape pack, full, scaled by its share    cassette-window-dark   the dark inside the shell, behind the packs    cassette-tape          the strip of tape between the packsEach is 4x what it is drawn at on a phone, declared 3x (2x on the Mac) as thecard paper is; the face sets the scale it draws each at. The old casedcassette's layers (case, J-card, counter, label) are removed."""import jsonimport pathlibimport shutilimport sysHERE = pathlib.Path(__file__).resolve().parentCATALOGUE = HERE.parent / 'apps/loom/Sources/CottonPaper/Media.xcassets'NAMES = [    'cassette-shell', 'cassette-shell-shadow', 'cassette-label-blank', 'cassette-hub',    'cassette-pack', 'cassette-window-dark', 'cassette-tape',]# The old cased cassette's pictures (29 Oct 2026), gone with its face.GONE = [    'cassette-case-lid', 'cassette-case-tray', 'cassette-case-shadow', 'cassette-counter',    'cassette-counter-wheel', 'cassette-jcard', 'cassette-label',]DEFAULT = '/Volumes/Cotton SSD/lanes/features/out/music22-cassette'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}')    for name in GONE:        folder = CATALOGUE / f'{name}.imageset'        if folder.exists():            shutil.rmtree(folder)            print(f'{name} removed')    print(f'{total // 1024} KB in all')if __name__ == '__main__':    main(sys.argv[1] if len(sys.argv) > 1 else DEFAULT)