From 0516f764c1fcffe40417c9b67e500febd831afe5 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Fri, 7 Aug 2020 11:14:55 +0200 Subject: Initial commit. --- tonkadur_ui.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tonkadur_ui.py (limited to 'tonkadur_ui.py') diff --git a/tonkadur_ui.py b/tonkadur_ui.py new file mode 100644 index 0000000..4ffaca4 --- /dev/null +++ b/tonkadur_ui.py @@ -0,0 +1,48 @@ +import argparse + +import tonkadur + +parser = argparse.ArgumentParser( + description = ( + "Tonkadur Python Interpreter" + ) +) + +parser.add_argument( + '-f', + '--file', + dest='world_file', + type = str, + help = 'Wyrd JSON file to load.', +) + +args = parser.parse_args() +state = tonkadur.Tonkadur(args.world_file) + +#try: +while True: + result = state.run() + result_category = result['category'] + + if (result_category == "end"): + print("Program ended") + break + elif (result_category == "display"): + print(result['content']) + elif (result_category == "assert"): + print("Assert failed at line " + str(result['line']) + ":" + str(result['message'])) + elif (result_category == "resolve_choices"): + current_choice = 0; + + for choice in result['choices']: + print(str(current_choice) + ". " + ''.join(choice[0]['content'])) + current_choice += 1 + + user_choice = input("Your choice? ") + state.resolve_choice_to(result['choices'][int(user_choice)][1]) + elif (result_category == "event"): + print("Unhandled event:" + str(result)) + +#except Error: +# print("failed.\n") +print(str(state.memory)) -- cgit v1.2.3-70-g09d2