From c01bc823d50a654b10ff1b752e7ce0db715646c7 Mon Sep 17 00:00:00 2001 From: Jeremy Stanley Date: Wed, 25 Dec 2019 22:49:48 +0000 Subject: [PATCH] Relocate delete_avatar menu functions 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 | 17 +++++++++++++++++ share/menu.yaml | 8 +++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/mudpy/menu.py b/mudpy/menu.py index 39a5ad2..f16a2b4 100644 --- a/mudpy/menu.py +++ b/mudpy/menu.py @@ -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())]) diff --git a/share/menu.yaml b/share/menu.yaml index b66074e..88b0138 100644 --- a/share/menu.yaml +++ b/share/menu.yaml @@ -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. -- 2.11.0