Relocate delete_avatar menu functions
authorJeremy Stanley <fungi@yuggoth.org>
Wed, 25 Dec 2019 22:49:48 +0000 (22:49 +0000)
committerJeremy Stanley <fungi@yuggoth.org>
Mon, 30 Dec 2019 02:17:10 +0000 (02:17 +0000)
Move the action and create logic for the delete_avatar state from
their respective facets to the menu module, hiding them behind
consistently-named entry points.

mudpy/menu.py
share/menu.yaml

index 39a5ad2..f16a2b4 100644 (file)
@@ -81,3 +81,20 @@ def choose_name_create_7(user):
 def delete_account_action_y(user):
     """Permanently delete the account and all avatars, as requested."""
     return user.destroy()
+
+
+def delete_avatar_action(user):
+    """Delete the selected avatar."""
+    return user.delete_avatar(
+        user.account.get("avatars")[int(user.choice) - 1])
+
+
+def delete_avatar_action_a(user):
+    """Abort avatar deletion."""
+    return True
+
+
+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())])
index b66074e..88b0138 100644 (file)
@@ -78,14 +78,12 @@ menu.delete_account.description: By deleting your account, all your avatars
 menu.delete_account.prompt: Are you certain you wish to permanently delete your
     account?
 
-menu.delete_avatar.action: user.delete_avatar(
-    user.account.get("avatars")[int(user.choice)-1])
-menu.delete_avatar.action_a: pass
+menu.delete_avatar.action: mudpy.menu.delete_avatar_action(user)
+menu.delete_avatar.action_a: mudpy.menu.delete_avatar_action_a(user)
 menu.delete_avatar.branch: main_utility
 menu.delete_avatar.branch_a: main_utility
 menu.delete_avatar.choice_a: abort selection
-menu.delete_avatar.create: dict([(str(x+1),y) for x,y in
-    enumerate(user.list_avatar_names())])
+menu.delete_avatar.create: mudpy.menu.delete_avatar_create(user)
 menu.delete_avatar.default: a
 menu.delete_avatar.description: This is the list of avatars available for you
     to delete.