From 85e648fc1e7c1d4ee40836bcd617d731a7fb7094 Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Thu, 26 Dec 2019 02:45:25 +0000 Subject: [PATCH] Relocate main_utility menu functions Move the action and demand logic for the main_utility state from their respective facets to the menu module, hiding them behind consistently-named entry points. --- mudpy/menu.py | 21 +++++++++++++++++++++ share/menu.yaml | 9 ++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/mudpy/menu.py b/mudpy/menu.py index f16a2b4..1533b92 100644 --- a/mudpy/menu.py +++ b/mudpy/menu.py @@ -98,3 +98,24 @@ def delete_avatar_create(user): """List available avatars for possible deletion.""" return dict( [(str(x + 1), y) for x, y in enumerate(user.list_avatar_names())]) + + +def main_utility_action_c(user): + """Create a new avatar.""" + return user.new_avatar() + + +def main_utility_demand_a(user): + """Only include avatar activation if the account has avatars.""" + return user.account.get("avatars") + + +def main_utility_demand_c(user): + """Only include avatar creation if avatar count is below the limit.""" + return (len(user.account.get("avatars")) < + mudpy.misc.universe.contents["mudpy.limit"].get("avatars")) + + +def main_utility_demand_d(user): + """Only include avatar deletion if the account has avatars.""" + return user.account.get("avatars") diff --git a/share/menu.yaml b/share/menu.yaml index 88b0138..2857c38 100644 --- a/share/menu.yaml +++ b/share/menu.yaml @@ -109,7 +109,7 @@ menu.entering_new_password.error_differs: The two passwords did not match. Try menu.telopt_negotiation.prompt: -menu.main_utility.action_c: user.new_avatar() +menu.main_utility.action_c: mudpy.menu.main_utility_action_c(user) menu.main_utility.branch_a: activate_avatar menu.main_utility.branch_c: choose_gender menu.main_utility.branch_d: delete_avatar @@ -120,10 +120,9 @@ menu.main_utility.choice_c: create a new avatar menu.main_utility.choice_d: delete an unwanted avatar menu.main_utility.choice_l: leave for now menu.main_utility.choice_p: permanently remove your account -menu.main_utility.demand_a: user.account.get("avatars") -menu.main_utility.demand_c: len(user.account.get("avatars")) < - universe.contents["mudpy.limit"].get("avatars") -menu.main_utility.demand_d: user.account.get("avatars") +menu.main_utility.demand_a: mudpy.menu.main_utility_demand_a(user) +menu.main_utility.demand_c: mudpy.menu.main_utility_demand_c(user) +menu.main_utility.demand_d: mudpy.menu.main_utility_demand_d(user) menu.main_utility.description: $(red)$(inc:banner.txt)$(nrm)$(eol)$(eol)From here you can awaken, create and delete avatars. An avatar is your persona in the World. You can also leave or permanently delete your account. -- 2.11.0