from pathlib import Path import os import sys import time import winsound FRAME_DELAY = 0.055 FRAME_SEPARATOR = "\f" def enable_ansi() -> None: # Modern Windows terminals understand ANSI after chcp 65001; this keeps # colors from hakari_dance.ans intact when possible. os.system("chcp 65001 >nul") def main() -> int: repo_root = Path(__file__).resolve().parents[2] dance_path = repo_root / "assets" / "animations" / "hakari_dance.ans" if not dance_path.exists(): dance_path = repo_root / "hakari_dance.ans" sound_path = repo_root / "assets" / "audio" / "hakari_dance.wav" if not sound_path.exists(): sound_path = repo_root / "hakari_dance.wav" if not dance_path.exists(): print("hakari_dance.ans not found") return 1 frames = dance_path.read_text(encoding="utf-8", errors="replace").split(FRAME_SEPARATOR) enable_ansi() if sound_path.exists(): winsound.PlaySound(str(sound_path), winsound.SND_FILENAME | winsound.SND_ASYNC) try: for frame in frames: os.system("cls") sys.stdout.write(frame) sys.stdout.flush() time.sleep(FRAME_DELAY) finally: winsound.PlaySound(None, winsound.SND_PURGE) sys.stdout.write("\033[0m") sys.stdout.flush() return 0 if __name__ == "__main__": raise SystemExit(main())