Fixes to contrib

This commit is contained in:
Wendy Wang 2024-10-08 22:47:49 +02:00
parent 7bf491a517
commit 238a0999d9
3 changed files with 16 additions and 7 deletions

View file

@ -1,5 +1,5 @@
"""
Item storage integration - helpme 2022
Item storage integration - helpme 2024
"""
from .storage import StorageCmdSet # noqa

View file

@ -3,6 +3,8 @@ from evennia.utils import list_to_string
from evennia.utils.search import search_object_by_tag
from evennia.commands.default.muxcommand import MuxCommand
SHARED_TAG_PREFIX = "shared"
class StorageCommand(MuxCommand):
"""
@ -13,20 +15,26 @@ class StorageCommand(MuxCommand):
"""
Check if the current location is tagged as a storage location
Every stored object is tagged on storage, and untagged on retrieval
Returns:
bool: True if the command is to be stopped here
"""
success = super().at_pre_cmd()
if super().at_pre_cmd():
return True
self.storage_location_id = self.caller.location.tags.get(category="storage_location")
if not self.storage_location_id:
self.caller.msg(f"You cannot {self.cmdstring} anything here.")
return True
self.object_tag = (
"shared" if self.storage_location_id.startswith("shared_") else self.caller.pk
SHARED_TAG_PREFIX
if self.storage_location_id.startswith(SHARED_TAG_PREFIX)
else self.caller.pk
)
self.currently_stored = search_object_by_tag(
self.object_tag, category=self.storage_location_id
)
return success
class CmdStore(StorageCommand):
@ -163,7 +171,9 @@ class CmdStorage(MuxCommand):
caller.msg("This is already a storage location: |wstorage/delete|n to remove the tag.")
return
new_storage_id = f"{'shared_' if 'shared' in self.switches else ''}{storage_id}"
new_storage_id = (
f"{SHARED_TAG_PREFIX if SHARED_TAG_PREFIX in self.switches else ''}{storage_id}"
)
location.tags.add(new_storage_id, category="storage_location")
caller.msg(f"This is now a storage location with id: {new_storage_id}.")

View file

@ -7,7 +7,6 @@ from . import storage
class TestStorage(BaseEvenniaCommandTest):
def setUp(self):
super().setUp()
self.char1.location = self.room1
self.obj1.location = self.char1
self.room1.tags.add("storage_1", "storage_location")
self.room2.tags.add("shared_storage_2", "storage_location")
@ -117,6 +116,6 @@ class TestStorage(BaseEvenniaCommandTest):
self.call(
storage.CmdStorage(),
"/shared",
f"This is now a storage location with id: shared_{self.room1.id}.",
f"This is now a storage location with id: shared{self.room1.id}.",
caller=self.char1,
)