* archetype, mudpy.conf (__control), mudpy.py (User.new_avatar),
template: Retermed template as archetype.
* mudpy.py: Added more code commentary, and refactored some sections
of the source to improve readability.
(DataFile.is_writeable, DataFile.save): Abstracted out the writeable
check from the save method into a separate method.
(DataFile.save): Adjusted to only write when elements within that
file have been modified.
(Element.delete): Removed obsolete method, recently implemented more
cleanly as remove_facet.
[__control__]
read_only = yes
[__control__]
read_only = yes
-[template:actor]
-default_location = location:0,0,1
+[archetype:avatar]
+default_location = location:0,0,1
+inherit = archetype:actor
+
--- /dev/null
+[__control__]
+include_files = second_square/index
+read_only = yes
+
--- /dev/null
+[__control__]
+include_files = [ "location", "prop" ]
+read_only = yes
+
--- /dev/null
+[prop:fountain]
+impression = An inviting public fountain bubbles here, tempting you with thirst.
+keywords = fountain water
+location = location:0,0,0
+
-default_files = {"account": "account", "actor": "actor", "command": "command", "internal": "internal", "location": "location", "menu": "menu", "other": "other" }
-include_files = ["example", "template"]
+default_files = { "account": "account", "actor": "actor", "command": "command", "internal": "internal", "location": "location", "menu": "menu", "other": "other", "prop": "prop" }
+include_files = [ "archetype", "example/index" ]
private_files = account
read_only = yes
private_files = account
read_only = yes
punctuation_say = .
[internal:limits]
punctuation_say = .
[internal:limits]
max_avatars = 7
password_tries = 3
max_avatars = 7
password_tries = 3
class Element:
"""An element of the universe."""
class Element:
"""An element of the universe."""
- def __init__(self, key, universe, origin=""):
- """Default values for the in-memory element variables."""
+ def __init__(self, key, universe, filename=""):
+ """Set up a new element."""
+
+ # not owned by a user by default (used for avatars)
+
+ # no contents in here by default
+
+ # keep track of our key name
+
+ # parse out appropriate category and subkey names, add to list
if self.key.find(":") > 0:
self.category, self.subkey = self.key.split(":", 1)
else:
if self.key.find(":") > 0:
self.category, self.subkey = self.key.split(":", 1)
else:
self.subkey = self.key
if not self.category in universe.categories: self.category = "other"
universe.categories[self.category][self.subkey] = self
self.subkey = self.key
if not self.category in universe.categories: self.category = "other"
universe.categories[self.category][self.subkey] = self
- self.origin = origin
- if not self.origin: self.origin = universe.default_origins[self.category]
- if not isabs(self.origin):
- self.origin = abspath(self.origin)
+
+ # get an appropriate filename for the origin
+ if not filename: filename = universe.default_origins[self.category]
+ if not isabs(filename): filename = abspath(filename)
+
+ # add the file if it doesn't exist yet
+ if not filename in universe.files: DataFile(filename, universe)
+
+ # record a pointer to the origin file
+ self.origin = universe.files[filename]
+
+ # add a data section to the origin if necessary
+ if not self.origin.data.has_section(self.key):
+ self.origin.data.add_section(self.key)
+
+ # add this element to the universe contents
universe.contents[self.key] = self
universe.contents[self.key] = self
- if not self.origin in universe.files:
- DataFile(self.origin, universe)
- if not universe.files[self.origin].data.has_section(self.key):
- universe.files[self.origin].data.add_section(self.key)
def destroy(self):
"""Remove an element from the universe and destroy it."""
log("Destroying: " + self.key + ".", 2)
def destroy(self):
"""Remove an element from the universe and destroy it."""
log("Destroying: " + self.key + ".", 2)
- universe.files[self.origin].data.remove_section(self.key)
+ self.origin.data.remove_section(self.key)
del universe.categories[self.category][self.subkey]
del universe.contents[self.key]
del self
del universe.categories[self.category][self.subkey]
del universe.contents[self.key]
del self
- def delete(self, facet):
- """Delete a facet from the element."""
- if universe.files[self.origin].data.has_option(self.key, facet):
- universe.files[self.origin].data.remove_option(self.key, facet)
def facets(self):
"""Return a list of non-inherited facets for this element."""
def facets(self):
"""Return a list of non-inherited facets for this element."""
- if self.key in universe.files[self.origin].data.sections():
- return universe.files[self.origin].data.options(self.key)
+ if self.key in self.origin.data.sections():
+ return self.origin.data.options(self.key)
else: return []
def has_facet(self, facet):
"""Return whether the non-inherited facet exists."""
return facet in self.facets()
def remove_facet(self, facet):
"""Remove a facet from the element."""
else: return []
def has_facet(self, facet):
"""Return whether the non-inherited facet exists."""
return facet in self.facets()
def remove_facet(self, facet):
"""Remove a facet from the element."""
- if self.has_facet(facet): universe.files[self.origin].data.remove_option(self.key, facet)
+ if self.has_facet(facet):
+ self.origin.data.remove_option(self.key, facet)
+ self.origin.modified = True
def ancestry(self):
"""Return a list of the element's inheritance lineage."""
if self.has_facet("inherit"):
def ancestry(self):
"""Return a list of the element's inheritance lineage."""
if self.has_facet("inherit"):
def get(self, facet, default=None):
"""Retrieve values."""
if default is None: 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)
+ if self.origin.data.has_option(self.key, facet):
+ return self.origin.data.get(self.key, facet)
elif self.has_facet("inherit"):
for ancestor in self.ancestry():
if universe.contents[ancestor].has_facet(facet):
elif self.has_facet("inherit"):
for ancestor in self.ancestry():
if universe.contents[ancestor].has_facet(facet):
def getboolean(self, facet, default=None):
"""Retrieve values as boolean type."""
if default is None: 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)
+ if self.origin.data.has_option(self.key, facet):
+ return self.origin.data.getboolean(self.key, facet)
elif self.has_facet("inherit"):
for ancestor in self.ancestry():
if universe.contents[ancestor].has_facet(facet):
elif self.has_facet("inherit"):
for ancestor in self.ancestry():
if universe.contents[ancestor].has_facet(facet):
def getint(self, facet, default=None):
"""Return values as int/long type."""
if default is None: 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)
+ if self.origin.data.has_option(self.key, facet):
+ return self.origin.data.getint(self.key, facet)
elif self.has_facet("inherit"):
for ancestor in self.ancestry():
if universe.contents[ancestor].has_facet(facet):
elif self.has_facet("inherit"):
for ancestor in self.ancestry():
if universe.contents[ancestor].has_facet(facet):
def getfloat(self, facet, default=None):
"""Return values as float type."""
if default is None: 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)
+ if self.origin.data.has_option(self.key, facet):
+ return self.origin.data.getfloat(self.key, facet)
elif self.has_facet("inherit"):
for ancestor in self.ancestry():
if universe.contents[ancestor].has_facet(facet):
elif self.has_facet("inherit"):
for ancestor in self.ancestry():
if universe.contents[ancestor].has_facet(facet):
else: return default
def set(self, facet, value):
"""Set values."""
else: return default
def set(self, facet, value):
"""Set values."""
- 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)
+ if not self.has_facet(facet) or not self.get(facet) == value:
+ if type(value) is long: value = str(value)
+ elif not type(value) is str: value = repr(value)
+ self.origin.data.set(self.key, facet, value)
+ self.origin.modified = True
def append(self, facet, value):
"""Append value tp a list."""
if type(value) is long: value = str(value)
def append(self, facet, value):
"""Append value tp a list."""
if type(value) is long: value = str(value)
class DataFile:
"""A file containing universe elements."""
def __init__(self, filename, universe):
class DataFile:
"""A file containing universe elements."""
def __init__(self, filename, universe):
self.data = RawConfigParser()
if access(filename, R_OK): self.data.read(filename)
self.filename = filename
self.data = RawConfigParser()
if access(filename, R_OK): self.data.read(filename)
self.filename = filename
if not isabs(include_file):
include_file = path_join(dirname(filename), include_file)
DataFile(include_file, universe)
if not isabs(include_file):
include_file = path_join(dirname(filename), include_file)
DataFile(include_file, universe)
+ def is_writeable(self):
+ """Returns True if the __control__ read_only is False."""
+ return not self.data.has_option("__control__", "read_only") or not self.data.getboolean("__control__", "read_only")
def save(self):
"""Write the data, if necessary."""
def save(self):
"""Write the data, if necessary."""
- # when there is content or the file exists, but is not 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") ):
+ # when modified, writeable and has content or the file exists
+ if self.modified and self.is_writeable() and ( self.data.sections() or exists(self.filename) ):
# make parent directories if necessary
if not exists(dirname(self.filename)):
# make parent directories if necessary
if not exists(dirname(self.filename)):
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)
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)
- self.avatar.append("inherit", "template:actor")
+ self.avatar.append("inherit", "archetype:avatar")
self.account.append("avatars", self.avatar.key)
def delete_avatar(self, avatar):
self.account.append("avatars", self.avatar.key)
def delete_avatar(self, avatar):
def command_look(user, parameters):
"""Look around."""
def command_look(user, parameters):
"""Look around."""
- if parameters: user.send("You look at or in anything yet.")
+ if parameters: user.send("You can't look at or in anything yet.")
else: user.avatar.look_at(user.avatar.get("location"))
def command_say(user, parameters):
else: user.avatar.look_at(user.avatar.get("location"))
def command_say(user, parameters):
if element not in universe.contents: message = "The \"" + element + "\" element does not exist."
elif facet not in universe.contents[element].facets(): message = "The \"" + element + "\" element has no \"" + facet + "\" facet."
else:
if element not in universe.contents: message = "The \"" + element + "\" element does not exist."
elif facet not in universe.contents[element].facets(): message = "The \"" + element + "\" element has no \"" + facet + "\" facet."
else:
- universe.contents[element].delete(facet)
+ universe.contents[element].remove_facet(facet)
message = "You have successfully deleted the \"" + facet + "\" facet of element \"" + element + "\". Try \"show element " + element + "\" for verification."
user.send(message)
message = "You have successfully deleted the \"" + facet + "\" facet of element \"" + element + "\". Try \"show element " + element + "\" for verification."
user.send(message)