Relocate main_utility menu functions
authorJeremy Stanley <fungi@yuggoth.org>
Thu, 26 Dec 2019 02:45:25 +0000 (02:45 +0000)
committerJeremy Stanley <fungi@yuggoth.org>
Mon, 30 Dec 2019 02:17:10 +0000 (02:17 +0000)
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
share/menu.yaml

index f16a2b4..1533b92 100644 (file)
@@ -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")
index 88b0138..2857c38 100644 (file)
@@ -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.