* Add RevealAction/UnrevealAction for revealing/hiding items in a room * Add a lot of checks for items being revealed when it's attempted to be triggered * Implement TeleportAction (mostly) * For all Check* family of actions, the `yes` and `no` values may be just be a single action instead of an array of actions * Change up how room descriptions and stuff work, mostly so that you can specify multiple lines in an array so you can preserve paragraph breaks when displayed. * Example game has some more content Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
import dataclasses
|
|
from typing import MutableMapping, Optional, Sequence, Union, TYPE_CHECKING
|
|
from agame.item import ItemInst
|
|
from agame.util import search_item_name
|
|
|
|
|
|
__all__ = ("Room",)
|
|
|
|
|
|
@dataclasses.dataclass
|
|
class Room:
|
|
id: str
|
|
name: str
|
|
desc: Union[str, Sequence[str]]
|
|
items: MutableMapping[str, ItemInst]
|
|
|
|
def __init__(
|
|
self,
|
|
id: str,
|
|
name: str,
|
|
desc: Union[str, Sequence[str]],
|
|
items: Union[Sequence[ItemInst], MutableMapping[str, ItemInst]],
|
|
):
|
|
self.id = id
|
|
self.name = name
|
|
self.desc = desc
|
|
if isinstance(items, MutableMapping):
|
|
self.items = items
|
|
else:
|
|
self.items = {item.id: item for item in items}
|
|
|
|
def search_item_name(self, item_name: str) -> Optional[ItemInst]:
|
|
"""
|
|
Searches all item instances in the room for the given item name, also
|
|
checking synonyms. Returns the first item instance found, or none if no
|
|
synonyms or names were found to match.
|
|
"""
|
|
return search_item_name(self.items.values(), item_name)
|
|
|
|
def remove(self, item_id: str) -> Optional[ItemInst]:
|
|
"""
|
|
Removes an item with the given ID from the room, returning it.
|
|
|
|
If it's not present in the room, `None` is returned.
|
|
"""
|
|
return self.items.pop(item_id, None)
|