"""The streak animations: one module per streak level, plus one for the calm ones. A task ticked by hand whose streak reaches a level (routine/model.py STREAK_LEVELS: 7, 21, 42, 66, 100, 150, 254, 365, then every 100 past 365 counts as the top level again) plays one of that level's animations instead of its set's; a task marked calm plays one of the calm streak ones. level0.py .. level7.py ANIMS = [(fn, colour, sound), ...]: 8 animations for that level calm.py ANIMS = [...]: 4 calm streak animations (any level, calm tasks) level0_sounds.py .. SOUNDS = [fn, ...]: each fn() -> a buf (tools/sound_kit.py); its calm_sounds.py __name__ is the sound's name, the one ANIMS gives (without .wav) A level whose module doesn't exist yet is simply left empty: the app falls back to the nearest lower level that has animations. Each module only imports the kits (from anim_kit import ... / from sound_kit import ...), never another level, so work on different levels never touches the same file. Every animation is 24 frames (anim_kit.STREAK_FRAMES, 2 s at 12 fps), shows the streak number (anim_kit.NUM) and has a sound of its own; every name and sound is unique across everything (tools/gen_animations.py refuses duplicates). python3 tools/gen_animations.py --level 0 --out DIR just this level, into DIR (not shared/) python3 tools/gen_sounds.py --level 0 --out DIR its sounds into DIR/sounds/ python3 tools/preview_animations.py DIR/sheets --json DIR/animations.json --streak 0 """ import importlib import sys NAMES = ["level%d" % k for k in range(8)] + ["calm"] def key_of(name): """"level3" -> 3, "calm" -> "calm".""" return "calm" if name == "calm" else int(name[5:]) def load(kind="", strict=True, only=None): """{key: module} for every streak module that exists (key = level number or "calm"); kind "" = the animation modules, "_sounds" = the sound ones. strict: an import error stops everything; otherwise a module other than only that fails is skipped with a warning.""" out = {} for name in NAMES: try: mod = importlib.import_module("streak_anims." + name + kind) except ModuleNotFoundError as e: if e.name == "streak_anims." + name + kind: continue # not written yet if strict or key_of(name) == only: raise print("warning: skipping %s%s: %s" % (name, kind, e), file=sys.stderr) continue except Exception as e: # noqa: BLE001 - someone else's module mid-edit if strict or key_of(name) == only: raise print("warning: skipping %s%s: %r" % (name, kind, e), file=sys.stderr) continue out[key_of(name)] = mod return out