48 lines
1.1 KiB
Python
48 lines
1.1 KiB
Python
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:
|
|
root = Path(__file__).resolve().parent
|
|
dance_path = root / "hakari_dance.ans"
|
|
sound_path = 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())
|