X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=mudpy.py;h=444c2e1d611f9e26c0f4b26b42e17bd9f8f2cd4b;hp=b149fc45061d2935cff302937f5338c6252e33f3;hb=91749717dfe1950b4a7118de97f86f61c4d95f9e;hpb=bc857f2685bcbe1772d943a04bdbafd6aafcb883 diff --git a/mudpy.py b/mudpy.py index b149fc4..444c2e1 100644 --- 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."""