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 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.utils.search import search_object_by_tag
from evennia.commands.default.muxcommand import MuxCommand from evennia.commands.default.muxcommand import MuxCommand
SHARED_TAG_PREFIX = "shared"
class StorageCommand(MuxCommand): class StorageCommand(MuxCommand):
""" """
@ -13,20 +15,26 @@ class StorageCommand(MuxCommand):
""" """
Check if the current location is tagged as a storage location Check if the current location is tagged as a storage location
Every stored object is tagged on storage, and untagged on retrieval 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") self.storage_location_id = self.caller.location.tags.get(category="storage_location")
if not self.storage_location_id: if not self.storage_location_id:
self.caller.msg(f"You cannot {self.cmdstring} anything here.") self.caller.msg(f"You cannot {self.cmdstring} anything here.")
return True return True
self.object_tag = ( 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.currently_stored = search_object_by_tag(
self.object_tag, category=self.storage_location_id self.object_tag, category=self.storage_location_id
) )
return success
class CmdStore(StorageCommand): 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.") caller.msg("This is already a storage location: |wstorage/delete|n to remove the tag.")
return 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") location.tags.add(new_storage_id, category="storage_location")
caller.msg(f"This is now a storage location with id: {new_storage_id}.") 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): class TestStorage(BaseEvenniaCommandTest):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
self.char1.location = self.room1
self.obj1.location = self.char1 self.obj1.location = self.char1
self.room1.tags.add("storage_1", "storage_location") self.room1.tags.add("storage_1", "storage_location")
self.room2.tags.add("shared_storage_2", "storage_location") self.room2.tags.add("shared_storage_2", "storage_location")
@ -117,6 +116,6 @@ class TestStorage(BaseEvenniaCommandTest):
self.call( self.call(
storage.CmdStorage(), storage.CmdStorage(),
"/shared", "/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, caller=self.char1,
) )