Compare commits

..

4 Commits

Author SHA1 Message Date
ad7d65cd80 More minor fixes to formatting 2025-01-30 14:49:39 -06:00
7c01b9a17c Minor fix to output formatting 2025-01-30 14:48:37 -06:00
86641f9959 Wait less busily
This resolution is still fine for perfect inputs as it's a much higher frequency than the polling rate of the game
2025-01-30 14:47:31 -06:00
38915249af Fancy output displays 2025-01-30 14:46:13 -06:00

View File

@@ -49,10 +49,22 @@ def main():
"R": "45" "R": "45"
} }
drummapping = { drummapping = {
"U": '\033[32mCHAKA\033[0m', "U": {
"D": '\033[33mDON\033[0m', "string": "CHAKA",
"L": '\033[31mPATA\033[0m', "color": 32
"R": '\033[34mPON\033[0m' },
"D": {
"string": "DON",
"color": 33
},
"L": {
"string": "PATA",
"color": 31
},
"R": {
"string": "PON",
"color": 34
},
} }
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Play a sequence of Patapon commands on repeat" description="Play a sequence of Patapon commands on repeat"
@@ -88,6 +100,12 @@ def main():
remaining_iterations = args.iterations remaining_iterations = args.iterations
lastbeat = 0 lastbeat = 0
# Get a ghost string to use for fancy input display stuffs
ghoststring="\033[37m"
for i, key in enumerate(sequence):
ghoststring += drummapping.get(key,{}).get('string',' ')
ghoststring+="~\033[0m"
# Wait for user confirmation # Wait for user confirmation
input("Press enter on-beat to sync up with Patapon...") input("Press enter on-beat to sync up with Patapon...")
synctime = time.perf_counter() + startup_delay synctime = time.perf_counter() + startup_delay
@@ -95,23 +113,26 @@ def main():
# Play da notes # Play da notes
try: try:
while remaining_iterations > 0: while remaining_iterations > 0:
print(ghoststring, end="\r", flush=True)
for i, key in enumerate(sequence): for i, key in enumerate(sequence):
while time.perf_counter() < synctime + lastbeat: while time.perf_counter() < synctime + lastbeat:
time.sleep(0.01)
pass pass
lastbeat += beat_interval lastbeat += beat_interval
button = keymapping.get(key, '-') button = keymapping.get(key, '-')
if button != '-': if button != '-':
if not args.dry_run: if not args.dry_run:
ydotool(key=button, delay=args.key_delay, multiplier=args.bpm) ydotool(key=button, delay=args.key_delay, multiplier=args.bpm)
print(drummapping.get(key, '-'), end="", flush=True) print(f"\033[{drummapping.get(key,{}).get('color',0)}m{drummapping.get(key,{}).get('string','-')}\033[0m", end="", flush=True)
else: else:
print(" ", end="", flush=True) print(" ", end="", flush=True)
remaining_iterations -= 1 remaining_iterations -= 1
print(f"~ ({remaining_iterations} remaining)") print(f"~ ({remaining_iterations} remaining)" + " " * len(str(args.iterations)), end="\r")
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
print("Interrupt") print("Interrupt")
pass pass
print("")
print(f"Total iterations: {args.iterations - remaining_iterations}") print(f"Total iterations: {args.iterations - remaining_iterations}")
return 0 return 0