From a322d9bdbdd497fdcc515964a033af40a7893659 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Tue, 29 Dec 2020 03:10:37 +0100 Subject: Updates to the future Wyrd syntax. --- tonkadur.py | 41 ++++++++++++++++++++++++----------------- tonkadur_ui.py | 33 ++++++++++++++++++--------------- 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/tonkadur.py b/tonkadur.py index afae903..7353c87 100644 --- a/tonkadur.py +++ b/tonkadur.py @@ -11,7 +11,7 @@ class Tonkadur: return 0.0 elif (typedef['category'] == "int"): return 0 - elif (typedef['category'] == "rich_text"): + elif (typedef['category'] == "text"): result = dict() result['content'] = [] result['effect'] = None @@ -36,7 +36,7 @@ class Tonkadur: self.program_counter = 0 self.allocated_data = 0 self.last_choice_index = -1 - self.available_choices = [] + self.available_options = [] self.memorized_target = [] with open(json_file, 'r') as f: @@ -62,7 +62,7 @@ class Tonkadur: def compute (self, computation): computation_category = computation['category'] - if (computation_category == "add_rich_text_effect"): + if (computation_category == "add_text_effect"): effect = dict() effect['name'] = computation['effect'] effect['parameters'] = [] @@ -172,7 +172,7 @@ class Tonkadur: base = self.compute(computation['base']).copy() base.append(self.compute(computation['extra'])) return base - elif (computation_category == "rich_text"): + elif (computation_category == "text"): result = dict() result['effect'] = None result['content'] = [] @@ -186,6 +186,10 @@ class Tonkadur: result['content'] = ['\n'] return result + elif (computation_category == "extra_computation"): + print("[E] Unhandled extra computation " + computation['name']) + + return None elif (computation_category == "size"): target = self.memory access = self.compute(computation['reference']) @@ -214,7 +218,7 @@ class Tonkadur: print("Unknown Wyrd computation: \"" + computation_category + "\"") def resolve_choice_to (self, index): - self.available_choices = [] + self.available_options = [] self.last_choice_index = index def store_integer (self, value): @@ -247,15 +251,15 @@ class Tonkadur: instruction_category = instruction['category'] #print("instruction:" + str(instruction)) - if (instruction_category == "add_choice"): + if (instruction_category == "add_text_option"): result = dict() - result["category"] = "option" + result["category"] = "text_option" result["label"] = self.compute(instruction['label']) - self.available_choices.append(result) + self.available_options.append(result) self.program_counter += 1 - elif (instruction_category == "add_event_input"): + elif (instruction_category == "add_event_option"): result = dict() - result["category"] = "event" + result["category"] = "event_option" result["name"] = instruction["event"] params = [] @@ -263,7 +267,7 @@ class Tonkadur: params.append(self.compute(param)) result["parameters"] = params - self.available_choices.append(result) + self.available_options.append(result) self.program_counter += 1 elif (instruction_category == "assert"): condition = self.compute(instruction['condition']) @@ -289,10 +293,10 @@ class Tonkadur: result["category"] = "end" return result - elif (instruction_category == "event_call"): + elif (instruction_category == "extra_instruction"): result = dict() - result["category"] = "event" - result["name"] = instruction["event"] + result["category"] = "extra_instruction" + result["name"] = instruction["name"] params = [] for param in instruction['parameters']: @@ -301,6 +305,9 @@ class Tonkadur: result["parameters"] = params self.program_counter += 1 + + print("[E] Unhandled extra instruction " + str(result)) + return result elif (instruction_category == "remove"): pre_val = self.memory @@ -316,10 +323,10 @@ class Tonkadur: del pre_val[last_access] self.program_counter += 1 - elif (instruction_category == "resolve_choices"): + elif (instruction_category == "resolve_choice"): result = dict() - result["category"] = "resolve_choices" - result["choices"] = self.available_choices + result["category"] = "resolve_choice" + result["options"] = self.available_options self.program_counter += 1 return result diff --git a/tonkadur_ui.py b/tonkadur_ui.py index c3751dd..2dc563e 100644 --- a/tonkadur_ui.py +++ b/tonkadur_ui.py @@ -17,19 +17,19 @@ parser.add_argument( help = 'Wyrd JSON file to load.', ) -def display_rich_text (rich_text): +def display_text (text): str_content = "" - if (not (rich_text['effect'] is None)): - str_content += "{(" + str(rich_text['effect']) + ") " + if (not (text['effect'] is None)): + str_content += "{(" + str(text['effect']) + ") " - for c in rich_text['content']: + for c in text['content']: if (isinstance(c, str)): str_content += c else: - str_content += display_rich_text(c) + str_content += display_text(c) - if (not (rich_text['effect'] is None)): + if (not (text['effect'] is None)): str_content += "}" return str_content @@ -45,11 +45,11 @@ try: print("Program ended") break elif (result_category == "display"): - print(display_rich_text(result['content'])) + print(display_text(result['content'])) elif (result_category == "prompt_integer"): while True: user_input = input( - display_rich_text(result['label']) + display_text(result['label']) + " " + "[" + str(result['min']) @@ -70,7 +70,7 @@ try: elif (result_category == "prompt_string"): while True: user_input = input( - display_rich_text(result['label']) + display_text(result['label']) + " " + "[" + str(result['min']) @@ -88,24 +88,27 @@ try: state.store_string(user_input) elif (result_category == "assert"): - print("Assert failed at line " + str(result['line']) + ":" + str(display_rich_text(result['message']))) + print( + "Assert failed at line " + + str(result['line']) + + ":" + + str(display_text(result['message'])) + ) print(str(state.memory)) - elif (result_category == "resolve_choices"): + elif (result_category == "resolve_choice"): current_choice = 0; - for choice in result['choices']: + for choice in result['options']: if (choice["category"] == "option"): print( str(current_choice) + ". " - + display_rich_text(choice["label"]) + + display_text(choice["label"]) ) current_choice += 1 user_choice = input("Your choice? ") state.resolve_choice_to(int(user_choice)) - elif (result_category == "event"): - print("Unhandled event:" + str(result)) except: print("failed at line " + str(state.program_counter) + ".\n") -- cgit v1.2.3-70-g09d2