Switch internal counters to new-style Element
[mudpy.git] / mudpy / misc.py
index 7478f3f..202b6b2 100644 (file)
@@ -91,8 +91,8 @@ class Element:
         if self.old_style:
             del self.origin.data[self.key]
         else:
-            for facet in self.facethash:
-                del self.origin.data[".".join((self.key, facet))]
+            for facet in dict(self.facethash):
+                self.remove_facet(facet)
         del self.universe.categories[self.category][self.subkey]
         del self.universe.contents[self.key]
         del self
@@ -113,9 +113,13 @@ class Element:
 
     def remove_facet(self, facet):
         """Remove a facet from the element."""
-        if self.has_facet(facet):
-            del(self.origin.data[self.key][facet])
-            self.origin.modified = True
+        if self.old_style and self.has_facet(facet):
+            del self.origin.data[self.key][facet]
+        elif ".".join((self.key, facet)) in self.origin.data:
+            del self.origin.data[".".join((self.key, facet))]
+        if facet in self.facethash:
+            del self.facethash[facet]
+        self.origin.modified = True
 
     def ancestry(self):
         """Return a list of the element's inheritance lineage."""
@@ -940,16 +944,12 @@ class User:
     def new_avatar(self):
         """Instantiate a new, unconfigured avatar for this user."""
         counter = 0
-        while "avatar:" + self.account.get("name") + ":" + str(
-            counter
-        ) in universe.categories.get("actor", {}).keys():
+        while ("avatar_%s_%s" % (self.account.get("name"), counter)
+                in universe.categories.get("actor", {}).keys()):
             counter += 1
         self.avatar = Element(
-            "actor:avatar:" + self.account.get("name") + ":" + str(
-                counter
-            ),
-            universe, old_style=True
-        )
+            "actor.avatar_%s_%s" % (self.account.get("name"), counter),
+            universe)
         self.avatar.append("inherit", "archetype:avatar")
         self.account.append("avatars", self.avatar.key)
 
@@ -1401,7 +1401,7 @@ def on_pulse():
 
     # add an element for counters if it doesn't exist
     if "counters" not in universe.categories.get("internal", {}):
-        Element("internal:counters", universe, old_style=True)
+        Element("internal.counters", universe)
 
     # update the log every now and then
     if not universe.categories["internal"]["counters"].get("mark"):