In order to simplify menu handlers, move the active choice into an
attribute of the User class so that only one object needs to be
handed off, and update menus accordingly.
self.address = ""
self.authenticated = False
self.avatar = None
self.address = ""
self.authenticated = False
self.avatar = None
self.columns = 79
self.connection = None
self.error = ""
self.columns = 79
self.connection = None
self.error = ""
return universe.groups["menu"][state].get("branch")
return universe.groups["menu"][state].get("branch")
-def get_choice_branch(user, choice):
+def get_choice_branch(user):
"""Returns the new state matching the given choice."""
branches = get_menu_branches(user.state)
"""Returns the new state matching the given choice."""
branches = get_menu_branches(user.state)
- if choice in branches.keys():
- return branches[choice]
- elif choice in user.menu_choices.keys():
+ if user.choice in branches.keys():
+ return branches[user.choice]
+ elif user.choice in user.menu_choices.keys():
return get_default_branch(user.state)
else:
return ""
return get_default_branch(user.state)
else:
return ""
return universe.groups["menu"][state].get("action")
return universe.groups["menu"][state].get("action")
-def get_choice_action(user, choice):
+def get_choice_action(user):
"""Run any indicated script for the given choice."""
actions = get_menu_actions(user.state)
"""Run any indicated script for the given choice."""
actions = get_menu_actions(user.state)
- if choice in actions.keys():
- return actions[choice]
- elif choice in user.menu_choices.keys():
+ if user.choice in actions.keys():
+ return actions[user.choice]
+ elif user.choice in user.menu_choices.keys():
return get_default_action(user.state)
else:
return ""
return get_default_action(user.state)
else:
return ""
# get a lower-case representation of the next line of input
if user.input_queue:
# get a lower-case representation of the next line of input
if user.input_queue:
- choice = user.input_queue.pop(0)
- if choice:
- choice = choice.lower()
+ user.choice = user.input_queue.pop(0)
+ if user.choice:
+ user.choice = user.choice.lower()
- choice = ""
- if not choice:
- choice = get_default_menu_choice(user.state)
- if choice in user.menu_choices:
- exec(get_choice_action(user, choice))
- new_state = get_choice_branch(user, choice)
+ user.choice = ""
+ if not user.choice:
+ user.choice = get_default_menu_choice(user.state)
+ if user.choice in user.menu_choices:
+ exec(get_choice_action(user))
+ new_state = get_choice_branch(user)
if new_state:
user.state = new_state
else:
if new_state:
user.state = new_state
else:
-menu.activate_avatar.action: user.activate_avatar_by_index(int(choice)-1)
+menu.activate_avatar.action: user.activate_avatar_by_index(int(user.choice)-1)
menu.activate_avatar.action_a: pass
menu.activate_avatar.branch_a: main_utility
menu.activate_avatar.choice_a: abort selection
menu.activate_avatar.action_a: pass
menu.activate_avatar.branch_a: main_utility
menu.activate_avatar.choice_a: abort selection
enumerate(user.list_avatar_names())])
menu.activate_avatar.default: "1"
menu.activate_avatar.description: This is the list of avatars available for you
enumerate(user.list_avatar_names())])
menu.activate_avatar.default: "1"
menu.activate_avatar.description: This is the list of avatars available for you
menu.activate_avatar.prompt: Whom would you like to awaken?
menu.active.prompt: ">"
menu.activate_avatar.prompt: Whom would you like to awaken?
menu.active.prompt: ">"
menu.checking_password.error_incorrect: Incorrect password, please try again...
menu.checking_password.prompt: "Password:"
menu.checking_password.error_incorrect: Incorrect password, please try again...
menu.checking_password.prompt: "Password:"
-menu.choose_gender.action: user.avatar.set("gender", user.menu_choices[choice])
+menu.choose_gender.action: user.avatar.set("gender",
+ user.menu_choices[user.choice])
menu.choose_gender.branch: choose_name
menu.choose_gender.choice_f: female
menu.choose_gender.choice_m: male
menu.choose_gender.branch: choose_name
menu.choose_gender.choice_f: female
menu.choose_gender.choice_m: male
Avatars are one of male or female at birth.
menu.choose_gender.prompt: "Pick a birth gender for your new avatar:"
Avatars are one of male or female at birth.
menu.choose_gender.prompt: "Pick a birth gender for your new avatar:"
-menu.choose_name.action: user.avatar.set("name", user.menu_choices[choice])
+menu.choose_name.action: user.avatar.set("name",
+ user.menu_choices[user.choice])
menu.choose_name.branch: main_utility
menu.choose_name.branch_g: choose_name
menu.choose_name.choice_g: generate more names
menu.choose_name.branch: main_utility
menu.choose_name.branch_g: choose_name
menu.choose_name.choice_g: generate more names
account?
menu.delete_avatar.action: user.delete_avatar(
account?
menu.delete_avatar.action: user.delete_avatar(
- user.account.get("avatars")[int(choice)-1])
+ user.account.get("avatars")[int(user.choice)-1])
menu.delete_avatar.action_a: pass
menu.delete_avatar.branch: main_utility
menu.delete_avatar.branch_a: main_utility
menu.delete_avatar.action_a: pass
menu.delete_avatar.branch: main_utility
menu.delete_avatar.branch_a: main_utility