#3660 bugfix old name saved in alias
This commit is contained in:
parent
f007199878
commit
2e47c98175
2 changed files with 33 additions and 8 deletions
|
|
@ -1267,6 +1267,15 @@ class TestBuilding(BaseEvenniaCommandTest):
|
||||||
)
|
)
|
||||||
self.call(building.CmdName(), "Obj4=", "No names or aliases defined!")
|
self.call(building.CmdName(), "Obj4=", "No names or aliases defined!")
|
||||||
|
|
||||||
|
def test_name_clears_plural(self):
|
||||||
|
box, _ = DefaultObject.create("Opened Box", location=self.char1)
|
||||||
|
|
||||||
|
# Force update of plural aliases (set in get_numbered_name)
|
||||||
|
self.char1.execute_cmd("inventory")
|
||||||
|
self.assertIn("one opened box", box.aliases.get(category=box.plural_category))
|
||||||
|
self.char1.execute_cmd("@name box=closed box")
|
||||||
|
self.assertIsNone(box.aliases.get(category=box.plural_category))
|
||||||
|
|
||||||
def test_desc(self):
|
def test_desc(self):
|
||||||
oid = self.obj2.id
|
oid = self.obj2.id
|
||||||
self.call(building.CmdDesc(), "Obj2=TestDesc", "The description was set on Obj2.")
|
self.call(building.CmdDesc(), "Obj2=TestDesc", "The description was set on Obj2.")
|
||||||
|
|
|
||||||
|
|
@ -231,6 +231,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
has_account (bool, read-only) - True is this object has an associated account.
|
has_account (bool, read-only) - True is this object has an associated account.
|
||||||
is_superuser (bool, read-only): True if this object has an account and that
|
is_superuser (bool, read-only): True if this object has an account and that
|
||||||
account is a superuser.
|
account is a superuser.
|
||||||
|
plural_category (string) - Alias category for the plural strings of this object
|
||||||
|
|
||||||
* Handlers available
|
* Handlers available
|
||||||
|
|
||||||
|
|
@ -382,6 +383,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
|
|
||||||
at_look(target, **kwargs)
|
at_look(target, **kwargs)
|
||||||
at_desc(looker=None)
|
at_desc(looker=None)
|
||||||
|
at_rename(oldname, newname)
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
@ -407,6 +409,8 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
{things}
|
{things}
|
||||||
{footer}
|
{footer}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
plural_category = "plural_key"
|
||||||
# on-object properties
|
# on-object properties
|
||||||
|
|
||||||
@lazy_property
|
@lazy_property
|
||||||
|
|
@ -1693,7 +1697,6 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
obj.get_numbered_name(1, looker, key="Foobert", return_string=True, no_article=True)
|
obj.get_numbered_name(1, looker, key="Foobert", return_string=True, no_article=True)
|
||||||
-> "Foobert"
|
-> "Foobert"
|
||||||
"""
|
"""
|
||||||
plural_category = "plural_key"
|
|
||||||
key = kwargs.get("key", self.get_display_name(looker))
|
key = kwargs.get("key", self.get_display_name(looker))
|
||||||
raw_key = self.name
|
raw_key = self.name
|
||||||
key = ansi.ANSIString(key) # this is needed to allow inflection of colored names
|
key = ansi.ANSIString(key) # this is needed to allow inflection of colored names
|
||||||
|
|
@ -1704,13 +1707,13 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
# this is raised by inflect if the input is not a proper noun
|
# this is raised by inflect if the input is not a proper noun
|
||||||
plural = key
|
plural = key
|
||||||
singular = _INFLECT.an(key)
|
singular = _INFLECT.an(key)
|
||||||
if not self.aliases.get(plural, category=plural_category):
|
if not self.aliases.get(plural, category=self.plural_category):
|
||||||
# we need to wipe any old plurals/an/a in case key changed in the interrim
|
# we need to wipe any old plurals/an/a in case key changed in the interrim
|
||||||
self.aliases.clear(category=plural_category)
|
self.aliases.clear(category=self.plural_category)
|
||||||
self.aliases.add(plural, category=plural_category)
|
self.aliases.add(plural, category=self.plural_category)
|
||||||
# save the singular form as an alias here too so we can display "an egg" and also
|
# save the singular form as an alias here too so we can display "an egg" and also
|
||||||
# look at 'an egg'.
|
# look at 'an egg'.
|
||||||
self.aliases.add(singular, category=plural_category)
|
self.aliases.add(singular, category=self.plural_category)
|
||||||
|
|
||||||
if kwargs.get("no_article") and count == 1:
|
if kwargs.get("no_article") and count == 1:
|
||||||
if kwargs.get("return_string"):
|
if kwargs.get("return_string"):
|
||||||
|
|
@ -1928,7 +1931,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
|
|
||||||
if hasattr(self, "_createdict"):
|
if hasattr(self, "_createdict"):
|
||||||
# this will be set if the object was created by the utils.create function
|
# this will be set if the object was created by the utils.create function
|
||||||
# or the spawner. We want these kwargs to override the values set by
|
# or the spawner. We want these kwargs to override the values set by
|
||||||
# the initial hooks.
|
# the initial hooks.
|
||||||
cdict = self._createdict
|
cdict = self._createdict
|
||||||
updates = []
|
updates = []
|
||||||
|
|
@ -1972,7 +1975,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
self.nattributes.add(key, value)
|
self.nattributes.add(key, value)
|
||||||
|
|
||||||
del self._createdict
|
del self._createdict
|
||||||
|
|
||||||
# run the post-setup hook
|
# run the post-setup hook
|
||||||
self.at_object_post_creation()
|
self.at_object_post_creation()
|
||||||
|
|
||||||
|
|
@ -2055,7 +2058,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
"""
|
"""
|
||||||
Called when this object is spawned or updated from a prototype, after all other
|
Called when this object is spawned or updated from a prototype, after all other
|
||||||
hooks have been run.
|
hooks have been run.
|
||||||
|
|
||||||
Keyword Args:
|
Keyword Args:
|
||||||
prototype (dict): The prototype that was used to spawn or update this object.
|
prototype (dict): The prototype that was used to spawn or update this object.
|
||||||
"""
|
"""
|
||||||
|
|
@ -2980,6 +2983,19 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
||||||
mapping=location_mapping,
|
mapping=location_mapping,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def at_rename(self, oldname, newname):
|
||||||
|
"""
|
||||||
|
This Hook is called by @name on a successful rename.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
oldname (str): The instance's original name.
|
||||||
|
newname (str): The new name for the instance.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Clear plural aliases set by DefaultObject.get_numbered_name
|
||||||
|
self.aliases.clear(category=self.plural_category)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Base Character object
|
# Base Character object
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue