59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
from pathlib import Path
|
|
import os
|
|
import sys
|
|
import msvcrt
|
|
import time
|
|
|
|
|
|
FRAME_DELAY = 0.045
|
|
FRAME_SEPARATOR = "\f"
|
|
|
|
|
|
def main() -> int:
|
|
root = Path(__file__).resolve().parent
|
|
intro_path = root / "casino_intro.ans"
|
|
if not intro_path.exists():
|
|
print("casino_intro.ans not found")
|
|
return 1
|
|
|
|
os.system("chcp 65001 >nul")
|
|
frames = intro_path.read_text(encoding="utf-8", errors="replace").split(FRAME_SEPARATOR)
|
|
loop_marker = "@@LOOP@@\n"
|
|
loop_start = 0
|
|
for idx, frame in enumerate(frames):
|
|
if frame.replace("\r\n", "\n") == loop_marker:
|
|
loop_start = idx + 1
|
|
break
|
|
try:
|
|
for frame in frames:
|
|
if frame.replace("\r\n", "\n") == loop_marker:
|
|
break
|
|
sys.stdout.write(frame)
|
|
sys.stdout.flush()
|
|
start = time.time()
|
|
while time.time() - start < FRAME_DELAY:
|
|
if msvcrt.kbhit():
|
|
key = msvcrt.getwch()
|
|
if key == "\r":
|
|
return 0
|
|
time.sleep(0.005)
|
|
loop_frames = frames[loop_start:] if loop_start else frames
|
|
while True:
|
|
for frame in loop_frames:
|
|
sys.stdout.write(frame)
|
|
sys.stdout.flush()
|
|
start = time.time()
|
|
while time.time() - start < FRAME_DELAY:
|
|
if msvcrt.kbhit():
|
|
key = msvcrt.getwch()
|
|
if key == "\r":
|
|
return 0
|
|
time.sleep(0.005)
|
|
finally:
|
|
sys.stdout.write("\033[0m\033[?25h\033[2J\033[H")
|
|
sys.stdout.flush()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|