branch_a = main_utility
choice_a = abort selection
create = dict([(str(x+1),y) for x,y in enumerate(user.list_avatar_names())])
+default = 1
description = This is the list of avatars available for you to awaken.
prompt = Whom would you like to awaken?
[menu:choose_name]
action = user.avatar.set("name", user.menu_choices[choice])
branch = main_utility
-branch_m = choose_name
-choice_m = generate more names
+branch_g = choose_name
+choice_g = generate more names
create_1 = random_name()
-create_3 = random_name()
create_2 = random_name()
-create_5 = random_name()
+create_3 = random_name()
create_4 = random_name()
-create_7 = random_name()
+create_5 = random_name()
create_6 = random_name()
+create_7 = random_name()
+default = g
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_account]
+action_y = user.delete()
+branch_n = main_utility
+branch_y = disconnecting
+choice_n = no, don't delete my account
+choice_y = yes, permanently delete my account
+default = n
+description = By deleting your account, all your avatars will also be permanently deleted.
+prompt = Are you certain you wish to permanently delete your account?
+
[menu:delete_avatar]
-action = user.delete_avatar(user.account.getlist("avatars")[int(choice)-1], universe)
+action = user.delete_avatar(user.account.getlist("avatars")[int(choice)-1])
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())])
+default = a
description = This is the list of avatars available for you to awaken.
-prompt = Whom would you like to awaken?
+prompt = Whom would you like to delete?
[menu:disconnecting]
description = $(red)Disconnecting...$(nrm)
choice_d = delete an unwanted avatar
choice_l = leave example for now
choice_p = permanently remove your account
-demand_a = user.account.get("avatars")
+demand_a = user.account.getlist("avatars")
demand_c = len(user.account.getlist("avatars")) < universe.categories["internal"]["limits"].getint("max_avatars")
-demand_d = user.account.get("avatars")
+demand_d = user.account.getlist("avatars")
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?
def facets(self):
"""Return a list of facets for this element."""
return universe.files[self.origin].data.options(self.key)
- def get(self, facet, default=""):
+ def get(self, facet, default=None):
"""Retrieve values."""
+ if default is None: default = ""
if universe.files[self.origin].data.has_option(self.key, facet):
return universe.files[self.origin].data.get(self.key, facet)
else: return default
- def getboolean(self, facet, default=False):
+ def getboolean(self, facet, default=None):
"""Retrieve values as boolean type."""
+ if default is None: default=False
if universe.files[self.origin].data.has_option(self.key, facet):
return universe.files[self.origin].data.getboolean(self.key, facet)
else: return default
- def getint(self, facet, default=0):
+ def getint(self, facet, default=None):
"""Return values as int/long type."""
+ if default is None: default = 0
if universe.files[self.origin].data.has_option(self.key, facet):
return universe.files[self.origin].data.getint(self.key, facet)
else: return default
- def getfloat(self, facet, default=0.0):
+ def getfloat(self, facet, default=None):
"""Return values as float type."""
+ if default is None: default = 0.0
if universe.files[self.origin].data.has_option(self.key, facet):
return universe.files[self.origin].data.getfloat(self.key, facet)
else: return default
- def getlist(self, facet, default=[]):
+ def getlist(self, facet, default=None):
"""Return values as list type."""
+ if default is None: default = []
value = self.get(facet)
- if not value: return default
- else: return makelist(value)
- def getdict(self, facet, default={}):
+ if value: return makelist(value)
+ else: return default
+ def getdict(self, facet, default=None):
"""Return values as dict type."""
+ if default is None: default = {}
value = self.get(facet)
- if not value: return default
- else: return makedict(value)
+ if value: return makedict(value)
+ else: return default
def set(self, facet, value):
"""Set values."""
if type(value) is long: value = str(value)
include_file = path_join(dirname(filename), include_file)
DataFile(include_file, universe)
def save(self):
- if self.data.sections() and ( not self.data.has_option("control", "read_only") or not self.data.getboolean("control", "read_only") ):
+ if ( self.data.sections() or exists(self.filename) ) and not ( self.data.has_option("control", "read_only") and self.data.getboolean("control", "read_only") ):
if not exists(dirname(self.filename)): makedirs(dirname)
file_descriptor = file(self.filename, "w")
if self.filename in universe.private_files and oct(S_IMODE(stat(self.filename)[ST_MODE])) != 0600:
def new_avatar(self):
"""Instantiate a new, unconfigured avatar for this user."""
- counter = universe.categories["internal"]["counters"].getint("next_avatar")
- 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:" + str(counter), universe)
+ counter = 0
+ while "avatar:" + self.account.get("name") + ":" + str(counter) in universe.categories["actor"].keys(): counter += 1
+ self.avatar = Element("actor:avatar:" + self.account.get("name") + ":" + str(counter), universe)
avatars = self.account.getlist("avatars")
avatars.append(self.avatar.key)
self.account.set("avatars", avatars)
- def delete_avatar(self, avatar, universe):
+ def delete_avatar(self, avatar):
"""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.remove(avatar)
self.account.set("avatars", avatars)
+ def delete(self):
+ """Delete the user and associated avatars."""
+ for avatar in self.account.getlist("avatars"): self.delete_avatar(avatar)
+ self.account.delete()
+
def list_avatar_names(self):
"""List names of assigned avatars."""
return [ universe.contents[avatar].get("name") for avatar in self.account.getlist("avatars") ]
def get_formatted_default_menu_choice(state):
"""Default menu choice foratted for inclusion in a prompt string."""
- default = get_default_menu_choice(state)
- if default: return "[$(red)" + default + "$(nrm)] "
+ default_choice = get_default_menu_choice(state)
+ if default_choice: return "[$(red)" + default_choice + "$(nrm)] "
else: return ""
def get_menu_description(state, error):
def get_choice_branch(user, choice):
"""Returns the new state matching the given choice."""
branches = get_menu_branches(user.state)
- if not choice: choice = get_default_menu_choice(user.state)
if choice in branches.keys(): return branches[choice]
elif choice in user.menu_choices.keys(): return get_default_branch(user.state)
else: return ""
def get_choice_action(user, choice):
"""Run any indicated script for the given choice."""
actions = get_menu_actions(user.state)
- if not choice: choice = get_default_menu_choice(user.state)
if choice in actions.keys(): return actions[choice]
elif choice in user.menu_choices.keys(): return get_default_action(user.state)
else: return ""
choice = user.input_queue.pop(0)
if choice: choice = choice.lower()
else: choice = ""
-
+ if not choice: choice = get_default_menu_choice(user.state)
if choice in user.menu_choices:
exec(get_choice_action(user, choice))
new_state = get_choice_branch(user, choice)