* menu (menu:activate_avatar): Add a default of the first avatar in
the list.
(menu:choose_name): Change the generate more names choice from m to
g and make it the default.
(menu:delete_avatar): Make abort the default choice and correct a
misleading copy/paste error in the prompt.
* menu (menu:delete_account), mudpy.py (User.delete): New menu and
supporting method to allow deletion of an existing account.
* mudpy.py (Element.get, Element.getboolean, Element.getdict)
(Element.getfloat, Element.getint, Element.getlist): Reworked
default parameter handling to fall back to the None type and then
replace it with the appropriate type of empty variable if not
overridden, solving obscure bugs arising from mutable sequence
reuse.
(get_choice_action, get_choice_branch, generic_menu_handler):
Consolidated default choice fallback into generic_menu_handler.
* testdata: Removed pending something better.
branch_a = main_utility
choice_a = abort selection
create = dict([(str(x+1),y) for x,y in enumerate(user.list_avatar_names())])
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?
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
[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_3 = random_name()
-create_5 = random_name()
+create_3 = random_name()
-create_7 = random_name()
+create_5 = 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):
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?
+
-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())])
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.
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)
[menu:disconnecting]
description = $(red)Disconnecting...$(nrm)
choice_d = delete an unwanted avatar
choice_l = leave example for now
choice_p = permanently remove your account
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_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?
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?
[control]
default_files = {"account": "account", "actor": "actor", "command": "command", "internal": "internal", "location": "location", "menu": "menu", "other": "other" }
[control]
default_files = {"account": "account", "actor": "actor", "command": "command", "internal": "internal", "location": "location", "menu": "menu", "other": "other" }
-include_files = testdata
private_files = account
read_only = yes
private_files = account
read_only = yes
def facets(self):
"""Return a list of facets for this element."""
return universe.files[self.origin].data.options(self.key)
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):
+ 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
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."""
"""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
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."""
"""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
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."""
"""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
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."""
"""Return values as list type."""
+ if default is None: default = []
- 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."""
"""Return values as dict type."""
+ if default is None: default = {}
- 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)
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):
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:
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."""
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)
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()
"""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)
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 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."""
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):
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)
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 ""
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)
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 ""
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 = ""
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)
if choice in user.menu_choices:
exec(get_choice_action(user, choice))
new_state = get_choice_branch(user, choice)
+++ /dev/null
-[prop:example_prop]
-name = The Example Prop
-
-[location:0:0:0:0]
-name = The Origin of the Universe
-
-[actor:example_actor]
-name = The Example Actor
-