Imported from archive.
authorJeremy Stanley <fungi@yuggoth.org>
Fri, 2 Sep 2005 02:51:15 +0000 (02:51 +0000)
committerJeremy Stanley <fungi@yuggoth.org>
Fri, 2 Sep 2005 02:51:15 +0000 (02:51 +0000)
* menu (menu:activate_avatar): New menu to delete an existing
avatar.

* menu (menu:delete_avatar), mudpy.py (User.delete_avatar): New menu
and supporting method to select an existing avatar.

menu
mudpy.py

diff --git a/menu b/menu
index c3388b3..b1ad12b 100644 (file)
--- a/menu
+++ b/menu
@@ -1,6 +1,16 @@
 [control]
 read_only = yes
 
+[menu:activate_avatar]
+action = user.avatar = universe.contents[user.account.getlist("avatars")[int(choice)-1]]
+action_a = pass
+branch = active
+branch_a = main_utility
+choice_a = abort selection
+create = dict([(str(x+1),y) for x,y in enumerate(user.list_avatar_names())])
+description = This is the list of avatars available for you to awaken.
+prompt = Whom would you like to awaken?
+
 [menu:active]
 prompt = >
 
@@ -45,6 +55,16 @@ create_6 = random_name()
 description = Your new avatar needs a name. This will be the name with which $(tpsp) grew up, and will initially be the name by which $(tpsp) is known in the world of Example. There are ways for your new avatar to make a name for $(tpop)self over time, so $(tpsp) won't be stuck going by such an unremarkable name forever.
 prompt = Choose a name for $(tpop):
 
+[menu:delete_avatar]
+action = user.delete_avatar(user.account.getlist("avatars")[int(choice)-1], universe)
+action_a = pass
+branch = main_utility
+branch_a = main_utility
+choice_a = abort selection
+create = dict([(str(x+1),y) for x,y in enumerate(user.list_avatar_names())])
+description = This is the list of avatars available for you to awaken.
+prompt = Whom would you like to awaken?
+
 [menu:disconnecting]
 description = $(red)Disconnecting...$(nrm)
 
@@ -64,12 +84,12 @@ error_differs = The two passwords did not match. Try again...
 
 [menu:main_utility]
 action_c = user.new_avatar()
-branch_a = active
+branch_a = activate_avatar
 branch_c = choose_gender
 branch_d = delete_avatar
 branch_l = disconnecting
 branch_p = delete_account
-choice_a = activate an existing avatar
+choice_a = awaken an existing avatar
 choice_c = create a new avatar
 choice_d = delete an unwanted avatar
 choice_l = leave example for now
@@ -77,8 +97,7 @@ choice_p = permanently remove your account
 demand_a = user.account.get("avatars")
 demand_c = len(user.account.getlist("avatars")) < universe.categories["internal"]["limits"].getint("max_avatars")
 demand_d = user.account.get("avatars")
-description = From here you can activate, create and delete avatars. An avatar is your persona in the world of Example.
-error_no_avatars = You don't have any avatars yet. An avatar is your persona in the world of Example. It is recommended that you create one now.
+description = From here you can awaken, create and delete avatars. An avatar is your persona in the world of Example. You can also leave or permanently delete your account.
 prompt = What would you like to do?
 
 [menu:verifying_new_password]
index b149fc4..444c2e1 100644 (file)
--- a/mudpy.py
+++ b/mudpy.py
@@ -75,7 +75,7 @@ class Element:
                else: return makedict(value)
        def set(self, facet, value):
                """Set values."""
-               if type(value) is long: value = repr(value).rstrip("L")
+               if type(value) is long: value = str(value)
                elif not type(value) is str: value = repr(value)
                universe.files[self.origin].data.set(self.key, facet, value)
 
@@ -401,20 +401,24 @@ class User:
        def new_avatar(self):
                """Instantiate a new, unconfigured avatar for this user."""
                counter = universe.categories["internal"]["counters"].getint("next_avatar")
-               while "avatar:" + repr(counter + 1) in universe.categories["actor"].keys(): counter += 1
+               while "avatar:" + str(counter + 1) in universe.categories["actor"].keys(): counter += 1
                universe.categories["internal"]["counters"].set("next_avatar", counter + 1)
-               self.avatar = Element("actor:avatar:" + repr(counter), universe)
+               self.avatar = Element("actor:avatar:" + str(counter), universe)
                avatars = self.account.getlist("avatars")
                avatars.append(self.avatar.key)
                self.account.set("avatars", avatars)
 
-       def list_avatar_names(self):
-               """A test function to list names of assigned avatars."""
+       def delete_avatar(self, avatar, universe):
+               """Remove an avatar from the world and from the user's list."""
+               if self.avatar is universe.contents[avatar]: self.avatar = None
+               universe.contents[avatar].delete()
                avatars = self.account.getlist("avatars")
-               avatar_names = []
-               for avatar in avatars:
-                       avatar_names.append(universe.contents[avatar].get("name"))
-               return avatar_names
+               avatars.remove(avatar)
+               self.account.set("avatars", avatars)
+
+       def list_avatar_names(self):
+               """List names of assigned avatars."""
+               return [ universe.contents[avatar].get("name") for avatar in self.account.getlist("avatars") ]
 
 def makelist(value):
        """Turn string into list type."""
@@ -626,7 +630,7 @@ def on_pulse():
 
        # update the log every now and then
        if check_time("frequency_log"):
-               log(repr(len(universe.userlist)) + " connection(s)")
+               log(str(len(universe.userlist)) + " connection(s)")
 
        # periodically save everything
        if check_time("frequency_save"):
@@ -756,23 +760,26 @@ def get_menu_prompt(state):
 
 def get_menu_choices(user):
        """Return a dict of choice:meaning."""
-       choices = {}
+       menu = universe.categories["menu"][user.state]
+       create_choices = menu.get("create")
+       if create_choices: choices = eval(create_choices)
+       else: choices = {}
        ignores = []
        options = {}
        creates = {}
-       for facet in universe.categories["menu"][user.state].facets():
+       for facet in menu.facets():
                if facet.startswith("demand_") and not eval(universe.categories["menu"][user.state].get(facet)):
                        ignores.append(facet.split("_", 2)[1])
-               elif facet.startswith("choice_"):
-                       options[facet] = facet.split("_", 2)[1]
                elif facet.startswith("create_"):
                        creates[facet] = facet.split("_", 2)[1]
-       for facet in options.keys():
-               if not options[facet] in ignores:
-                       choices[options[facet]] = universe.categories["menu"][user.state].get(facet)
+               elif facet.startswith("choice_"):
+                       options[facet] = facet.split("_", 2)[1]
        for facet in creates.keys():
                if not creates[facet] in ignores:
-                       choices[creates[facet]] = eval(universe.categories["menu"][user.state].get(facet))
+                       choices[creates[facet]] = eval(menu.get(facet))
+       for facet in options.keys():
+               if not options[facet] in ignores:
+                       choices[options[facet]] = menu.get(facet)
        return choices
 
 def get_formatted_menu_choices(state, choices):
@@ -1011,7 +1018,7 @@ def command_reload(user, command="", parameters=""):
 
 def command_quit(user, command="", parameters=""):
        """Quit the world."""
-       user.state = "disconnecting"
+       user.state = "main_utility"
 
 def command_help(user, command="", parameters=""):
        """List available commands and provide help for commands."""