aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2020-08-30 16:14:54 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2020-08-30 16:14:54 +0200
commit48f780650c7d92c945989b45dc781d415c85a21d (patch)
tree623f298e233c01e47e6d6422c120f8df23476d84
parentb6108592b66cc14573e5614aa5c878b71c6be6cb (diff)
downloadtonkadur-python-interpreter-48f780650c7d92c945989b45dc781d415c85a21d.zip
tonkadur-python-interpreter-48f780650c7d92c945989b45dc781d415c85a21d.tar.bz2
Adds user prompts, removes address of player_choice.
-rw-r--r--tonkadur.py52
-rw-r--r--tonkadur_ui.py43
2 files changed, 91 insertions, 4 deletions
diff --git a/tonkadur.py b/tonkadur.py
index 61e87a8..146bfe4 100644
--- a/tonkadur.py
+++ b/tonkadur.py
@@ -34,6 +34,7 @@ class Tonkadur:
self.allocated_data = 0
self.last_choice_index = -1
self.available_choices = []
+ self.memorized_target = []
with open(json_file, 'r') as f:
json_content = json.load(f)
@@ -209,6 +210,28 @@ class Tonkadur:
self.available_choices = []
self.last_choice_index = index
+ def store_integer (self, value):
+ current_val = self.memory
+
+ for access in self.memorized_target:
+ pre_val = current_val
+ last_access = access
+ if (access in current_val):
+ current_val = current_val[access]
+
+ pre_val[last_access] = value
+
+ def store_string (self, value):
+ current_val = self.memory
+
+ for access in self.memorized_target:
+ pre_val = current_val
+ last_access = access
+ if (access in current_val):
+ current_val = current_val[access]
+
+ pre_val[last_access] = value
+
def run (self):
while True:
#print("\nmemory: " + str(self.memory))
@@ -219,9 +242,7 @@ class Tonkadur:
if (instruction_category == "add_choice"):
self.available_choices.append(
- [
- self.compute(instruction['label'])
- ]
+ self.compute(instruction['label'])
)
self.program_counter += 1
elif (instruction_category == "assert"):
@@ -308,6 +329,31 @@ class Tonkadur:
pre_val[last_access] = result
self.program_counter += 1
+ elif (instruction_category == "prompt_integer"):
+ result = dict()
+ result["category"] = "prompt_integer"
+ result["min"] = self.compute(instruction['min'])
+ result["max"] = self.compute(instruction['max'])
+ result["label"] = self.compute(instruction['label'])
+
+ self.memorized_target = self.compute(instruction['target'])
+
+ self.program_counter += 1
+
+ return result
+
+ elif (instruction_category == "prompt_string"):
+ result = dict()
+ result["category"] = "prompt_string"
+ result["min"] = self.compute(instruction['min'])
+ result["max"] = self.compute(instruction['max'])
+ result["label"] = self.compute(instruction['label'])
+
+ self.memorized_target = self.compute(instruction['target'])
+
+ self.program_counter += 1
+
+ return result
else:
print("Unknown Wyrd instruction: \"" + instruction_category + "\"")
diff --git a/tonkadur_ui.py b/tonkadur_ui.py
index 85f91e4..f27efd7 100644
--- a/tonkadur_ui.py
+++ b/tonkadur_ui.py
@@ -46,6 +46,47 @@ try:
break
elif (result_category == "display"):
print(display_rich_text(result['content']))
+ elif (result_category == "prompt_integer"):
+ while True:
+ user_input = input(
+ display_rich_text(result['label'])
+ + " "
+ + "["
+ + str(result['min'])
+ + ", "
+ + str(result['max'])
+ + "] "
+ )
+ user_input = int(user_input)
+ if (
+ (user_input >= result['min'])
+ and (user_input <= result['max'])
+ ):
+ break
+ else:
+ print("Value not within range.")
+ state.store_integer(user_input)
+
+ elif (result_category == "prompt_string"):
+ while True:
+ user_input = input(
+ display_rich_text(result['label'])
+ + " "
+ + "["
+ + str(result['min'])
+ + ", "
+ + str(result['max'])
+ + "] "
+ )
+ if (
+ (len(user_input) >= result['min'])
+ and (len(user_input) <= result['max'])
+ ):
+ break
+ else:
+ print("Input size not within range.")
+ state.store_string(user_input)
+
elif (result_category == "assert"):
print("Assert failed at line " + str(result['line']) + ":" + str(display_rich_text(result['message'])))
print(str(state.memory))
@@ -53,7 +94,7 @@ try:
current_choice = 0;
for choice in result['choices']:
- print(str(current_choice) + ". " + display_rich_text(choice[0]))
+ print(str(current_choice) + ". " + display_rich_text(choice))
current_choice += 1
user_choice = input("Your choice? ")