Skip to content

Commit

Permalink
Allow for restarting sim during input formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Kataiser committed Jun 14, 2023
1 parent ae1ea91 commit ca86150
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
13 changes: 12 additions & 1 deletion movement sim/input_formatter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os
import time

import pyperclip
import yaml


def main():
def main(config_mtime=None):
# this is used to convert from a list of input tuples (e.g. [[2, 'r'], [4, 'l'], [3, '']]) to something that can just be pasted into studio
# just copy a list from results.txt and it'll automatically become converted in your clipboard

Expand Down Expand Up @@ -38,6 +39,16 @@ def main():
print()
pyperclip.copy(out_joined)

config_mtime_now = os.path.getmtime('config.yaml')

if config_mtime and config_mtime_now != config_mtime:
if input("config.yaml has been modified, would you like to rerun the simulator? Input Y for yes, anything else for no: ").lower() == 'y':
print("")
return
else:
print("")
config_mtime = config_mtime_now

time.sleep(0.5)


Expand Down
15 changes: 12 additions & 3 deletions movement sim/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@

class Config:
def __init__(self):
update_check.is_latest_commit()

with open('config.yaml', 'r') as config_file:
cfg_dict = yaml.safe_load(config_file)
self.mtime = os.path.getmtime('config.yaml')

# yes this is awkward but I don't care
self.frames: int = int(cfg_dict['frames'])
Expand Down Expand Up @@ -66,6 +65,16 @@ def __init__(self):


def main():
config_mtime = sim_main(True)

while True:
input_formatter.main(config_mtime)
config_mtime = sim_main(False)

def sim_main(do_update_check: bool) -> float:
if do_update_check:
update_check.is_latest_commit()

start_time: float = time.perf_counter()
sys.stdout = Logger()
cfg: Config = Config()
Expand Down Expand Up @@ -183,7 +192,7 @@ def main():
os.startfile(sys.stdout.filename)

sys.stdout = sys.__stdout__
input_formatter.main()
return cfg.mtime


# simulate X axis inputs
Expand Down

0 comments on commit ca86150

Please sign in to comment.