Created
December 7, 2017 09:05
-
-
Save iamgreaser/0a7b7a114d0576908a305316cfff7001 to your computer and use it in GitHub Desktop.
My split timer for Zeux 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 -- | |
TIMERFILE = "/home/ben/timer.txt" | |
import math | |
import time | |
import inotify_simple | |
IFlags = inotify_simple.flags | |
IInstance = inotify_simple.INotify() | |
watch_flags = IFlags.OPEN | |
wd = IInstance.add_watch(".", watch_flags) | |
start = time.time() | |
timer_running = False | |
timer_yet_started = False | |
boss_timer_running = False | |
final_boss = False | |
last_fname = None | |
time_total = None | |
time_boss = None | |
boss_start = None | |
def format_time(jiffies): | |
if jiffies is None: | |
return "--:--:--.-" | |
j = jiffies | |
s = j//10 | |
j %= 10 | |
m = s//60 | |
s %= 60 | |
h = m//60 | |
m %= 60 | |
return "%02d:%02d:%02d.%01d" % (h,m,s,j) | |
def write_time(): | |
fp = open(TIMERFILE, "w") | |
fp.write("Boss: %s\nTotal: %s%s" % ( | |
format_time(time_boss), | |
format_time(time_total), | |
" - DONE!" if (timer_yet_started and not timer_running) else "", | |
)) | |
fp.close() | |
while True: | |
nowtime = time.time() | |
xtime = (nowtime-start)*10 | |
jiffies = int(math.floor(xtime)) | |
next_bound = 0.1 - (xtime-jiffies)/10.0 + 0.01 | |
#print(next_bound) | |
if timer_running: | |
time_total = jiffies | |
if boss_timer_running: | |
boss_xtime = (nowtime-boss_start)*10 | |
boss_jiffies = int(math.floor(boss_xtime)) | |
time_boss = boss_jiffies | |
write_time() | |
for event in IInstance.read(timeout=(next_bound*1000)): | |
#print(event) | |
fname = event.name.upper() | |
old_last_fname = last_fname | |
if (event.mask & IFlags.OPEN) != 0 and (event.mask & IFlags.ISDIR) == 0: | |
if fname == "CV_TITLE.MOD": | |
last_fname = fname | |
print("*** RESET TIMER") | |
timer_running = False | |
timer_yet_started = False | |
final_boss = False | |
boss_timer_running = False | |
time_total = None | |
time_boss = None | |
write_time() | |
elif fname == "CV_BALON.MOD": | |
last_fname = fname | |
elif fname == "CV_HEVEN.MOD": | |
last_fname = fname | |
elif fname == "CV_TECH.MOD": | |
last_fname = fname | |
elif fname == "CV_MAGIC.MOD": | |
last_fname = fname | |
elif fname == "CV_BOSS.MOD": | |
if timer_running and last_fname == "CV_HEVEN.MOD": | |
final_boss = True | |
if not boss_timer_running: | |
print("*** BOSS START") | |
boss_timer_running = True | |
boss_start = nowtime | |
last_fname = fname | |
elif fname == "CV_STORY.MOD": | |
if timer_running and last_fname == "CV_BOSS.MOD" and final_boss: | |
print("*** GAME WON") | |
timer_running = False | |
elif not timer_yet_started: | |
print("*** START TIMER") | |
timer_running = True | |
timer_yet_started = True | |
start = time.time() | |
last_fname = fname | |
print(fname) | |
if boss_timer_running and last_fname != "CV_BOSS.MOD": | |
if old_last_fname == "CV_BOSS.MOD": | |
print("*** BOSS END") | |
boss_timer_running = False | |
boss_xtime = (nowtime-boss_start)*10 | |
boss_jiffies = int(math.floor(boss_xtime)) | |
boss_time_total = boss_jiffies | |
#for flag in IFlags.from_mask(event.mask): | |
# print("\t" + str(flag)) | |
#time.sleep(next_bound) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment