mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Merge 4690dfaf20 into 3761a7cb21
This commit is contained in:
commit
f0aa5ef83f
2 changed files with 46 additions and 6 deletions
|
|
@ -1506,15 +1506,20 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
|
|||
Append 01, 02 etc to obj.key. Checks next higher number in the
|
||||
same location, then adds the next number available
|
||||
|
||||
returns the new clone name on the form keyXX
|
||||
Returns the new clone name on the form keyXX
|
||||
"""
|
||||
key = self.key
|
||||
num = sum(
|
||||
1
|
||||
if not self.location:
|
||||
# no location means no clone numbering
|
||||
return key
|
||||
suffixes = [
|
||||
obj.key.removeprefix(key)
|
||||
for obj in self.location.contents
|
||||
if obj.key.startswith(key) and obj.key.lstrip(key).isdigit()
|
||||
)
|
||||
return "%s%03i" % (key, num)
|
||||
]
|
||||
num = 1
|
||||
if nums := [int(suffix) for suffix in suffixes if suffix.isdigit()]:
|
||||
num = max(nums) + 1
|
||||
return f"{key}{num:02d}"
|
||||
|
||||
new_key = new_key or find_clone_key()
|
||||
new_obj = ObjectDB.objects.copy_object(self, new_key=new_key, **kwargs)
|
||||
|
|
|
|||
|
|
@ -393,6 +393,41 @@ class TestObjectManager(BaseEvenniaTest):
|
|||
self.assertEqual(self.obj1.attributes.get(key="phrase", category="adventure"), "plugh")
|
||||
self.assertEqual(obj2.attributes.get(key="phrase", category="adventure"), "plugh")
|
||||
|
||||
def test_copy_object_clone_key(self):
|
||||
# reset key to avoid overlap with other tests
|
||||
self.obj1.key = "CopyMe"
|
||||
copied = self.obj1.copy()
|
||||
self.assertEqual(copied.key, "CopyMe01")
|
||||
copied2 = self.obj1.copy()
|
||||
self.assertEqual(copied2.key, "CopyMe02")
|
||||
# verify that it increments based on max existing identifier
|
||||
# both for skipped numbers...
|
||||
copied.key = "CopyMe03"
|
||||
copied3 = self.obj1.copy()
|
||||
self.assertEqual(copied3.key, "CopyMe04")
|
||||
copied3.delete()
|
||||
# ...and for duplicate numbers
|
||||
copied.key = "CopyMe01"
|
||||
copied2.key = "CopyMe01"
|
||||
copied3 = self.obj1.copy()
|
||||
self.assertEqual(copied3.key, "CopyMe02")
|
||||
# and that sharing a partial prefix doesn't count
|
||||
copied3.delete()
|
||||
copied.key = "CopyMeMe02"
|
||||
copied2.key = "CopyMe01"
|
||||
copied3 = self.obj1.copy()
|
||||
self.assertEqual(copied3.key, "CopyMe02")
|
||||
# and that nothing breaks if something in the room doesn't share the prefix
|
||||
copied3.key = "NotACopy"
|
||||
copied4 = self.obj1.copy()
|
||||
self.assertEqual(copied4.key, "CopyMe02")
|
||||
|
||||
|
||||
def test_copy_object_no_location(self):
|
||||
self.obj1.location = None
|
||||
# we just want to make sure this doesn't error
|
||||
self.assertIsNotNone(self.obj1.copy())
|
||||
|
||||
|
||||
class TestContentHandler(BaseEvenniaTest):
|
||||
"Test the ContentHandler (obj.contents)"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue