aboutsummaryrefslogtreecommitdiff |
diff options
author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2020-11-01 11:36:15 +0100 |
---|---|---|
committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2020-11-01 11:36:15 +0100 |
commit | f8140c6025bc74bac355c1b8cefd4e7fd2d75901 (patch) | |
tree | f1593971f8d334b1e84779095e57c84ae80a20a8 | |
parent | 08f7a91e1ba41f7be3ae8633827b46580c0aec91 (diff) | |
download | tonkadur-python-interpreter-f8140c6025bc74bac355c1b8cefd4e7fd2d75901.zip tonkadur-python-interpreter-f8140c6025bc74bac355c1b8cefd4e7fd2d75901.tar.bz2 |
Adds support for option+event user inputs.
-rw-r--r-- | tonkadur.py | 28 | ||||
-rw-r--r-- | tonkadur_ui.py | 7 |
2 files changed, 28 insertions, 7 deletions
diff --git a/tonkadur.py b/tonkadur.py index e8504b8..b20b1bd 100644 --- a/tonkadur.py +++ b/tonkadur.py @@ -23,7 +23,10 @@ class Tonkadur: elif (typedef['category'] == "pointer"): return [] elif (typedef['category'] == "structure"): - return copy.deepcopy(self.types[typedef['name']]) + if (typedef['name'] == "wild dict"): + return dict() + else: + return copy.deepcopy(self.types[typedef['name']]) def __init__ (self, json_file): self.memory = dict() @@ -198,8 +201,8 @@ class Tonkadur: # print("Reading " + str(addr) + " of " + str(target)) # print("addr = " + str(addr)) target = target[addr] - # if (isinstance(target, list)): - # print("That's a list.") + # if (isinstance(target, list)): + # print("That's a list.") return target elif (computation_category == "last_choice_index"): return self.last_choice_index @@ -241,9 +244,22 @@ class Tonkadur: #print("instruction:" + str(instruction)) if (instruction_category == "add_choice"): - self.available_choices.append( - self.compute(instruction['label']) - ) + result = dict() + result["category"] = "option" + result["label"] = self.compute(instruction['label']) + self.available_choices.append(result) + self.program_counter += 1 + elif (instruction_category == "add_event_input"): + result = dict() + result["category"] = "event" + result["name"] = instruction["event"] + params = [] + + for param in instruction['parameters']: + params.append(self.compute(param)) + + result["parameters"] = params + self.available_choices.append(result) self.program_counter += 1 elif (instruction_category == "assert"): condition = self.compute(instruction['condition']) diff --git a/tonkadur_ui.py b/tonkadur_ui.py index b4b7efc..c3751dd 100644 --- a/tonkadur_ui.py +++ b/tonkadur_ui.py @@ -94,7 +94,12 @@ try: current_choice = 0; for choice in result['choices']: - print(str(current_choice) + ". " + display_rich_text(choice)) + if (choice["category"] == "option"): + print( + str(current_choice) + + ". " + + display_rich_text(choice["label"]) + ) current_choice += 1 user_choice = input("Your choice? ") |