X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=mudpy.py;h=006b6a89ed49ecccb4c4eb2395287bae39504361;hp=444c2e1d611f9e26c0f4b26b42e17bd9f8f2cd4b;hb=7a6aa3bc9d4a51bf19f3a967c736e532952d887f;hpb=91749717dfe1950b4a7118de97f86f61c4d95f9e diff --git a/mudpy.py b/mudpy.py index 444c2e1..006b6a8 100644 --- a/mudpy.py +++ b/mudpy.py @@ -43,36 +43,42 @@ class Element: 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) @@ -111,7 +117,7 @@ class DataFile: 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: @@ -400,15 +406,14 @@ class 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) - 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() @@ -416,6 +421,11 @@ class User: 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") ] @@ -726,8 +736,8 @@ def get_default_menu_choice(state): 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): @@ -807,7 +817,6 @@ def get_default_branch(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 "" @@ -827,7 +836,6 @@ def get_default_action(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 "" @@ -855,7 +863,7 @@ def generic_menu_handler(user): 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)