Fix unit tests. Make TagCategoryProperty return tags set by other means.

This commit is contained in:
Griatch 2023-06-04 22:19:57 +02:00
parent 615b98c171
commit f78d4abcdd
8 changed files with 399 additions and 147 deletions

View file

@ -1,15 +1,19 @@
# Extended Room
Contribution - Griatch 2012, vincent-lg 2019
Contribution - Griatch 2012, vincent-lg 2019, Griatch 2023
This extends the normal `Room` typeclass to allow its description to change
with time-of-day and/or season. It also adds 'details' for the player to look at
in the room (without having to create a new in-game object for each). The room is
supported by new `look` and `desc` commands.
This extends the normal `Room` typeclass to allow its description to change with
time-of-day and/or season as well as any other state (like flooded or dark).
Embedding `$state(burning, This place is on fire!)` in the description will
allow for changing the description based on room state. The room also supports
`details` for the player to look at in the room (without having to create a new
in-game object for each), as well as support for random echoes. The room
comes with a set of alternate commands for `look` and `@desc`, as well as new
commands `detail`, `roomstate` and `time`.
## Installation/testing:
## Installation
Adding the `ExtendedRoomCmdset` to the default character cmdset will add all
Add the `ExtendedRoomCmdset` to the default character cmdset will add all
new commands for use.
In more detail, in `mygame/commands/default_cmdsets.py`:
@ -30,55 +34,160 @@ class CharacterCmdset(default_cmds.CharacterCmdSet):
Then reload to make the new commands available. Note that they only work
on rooms with the typeclass `ExtendedRoom`. Create new rooms with the right
typeclass or use the `typeclass` command to swap existing rooms. Note that since
this contrib overrides the `look` command, you will need to add the
this contrib overrides the `look` and `@desc` commands, you will need to add the
`extended_room.ExtendedRoomCmdSet` to the default character cmdset *after*
super().at_cmdset_creation(), or it will be overridden by the default look.
`super().at_cmdset_creation()`, or they will be overridden by the default look.
To dig a new extended room:
dig myroom:evennia.contrib.grid.extended_room.ExtendedRoom = north,south
To make all new rooms ExtendedRooms without having to specify it, make your
`Room` typeclass inherit from the `ExtendedRoom` and then reload:
```python
# in mygame/typeclasses/rooms.py
from evennia.contrib.grid.extended_room import ExtendedRoom
# ...
class Room(ObjectParent, ExtendedRoom):
# ...
```
## Features
### Time-changing description slots
### State-dependent description slots
This allows to change the full description text the room shows
depending on larger time variations. Four seasons (spring, summer,
autumn and winter) are used by default. The season is calculated
on-demand (no Script or timer needed) and updates the full text block.
By default, the normal `room.db.desc` description is used. You can however
add new state-ful descriptions with `room.add_desc(description,
room_state=roomstate)` or with the in-game command
There is also a general description which is used as fallback if
one or more of the seasonal descriptions are not set when their
time comes.
```
@desc/roomstate [<description>]
```
An updated `desc` command allows for setting seasonal descriptions.
For example
The room uses the `evennia.utils.gametime.GameTime` global script. This is
started by default, but if you have deactivated it, you need to
supply your own time keeping mechanism.
```
@desc/dark This room is pitch black.`.
### In-description changing tags
```
Within each seasonal (or general) description text, you can also embed
time-of-day dependent sections. Text inside such a tag will only show
during that particular time of day. The tags looks like `<timeslot> ...
</timeslot>`. By default there are four timeslots per day - morning,
afternoon, evening and night.
These will be stored in Attributes `desc_<roomstate>`. To set the default,
fallback description, just use `@desc <description>`.
To activate a state on the room, use `room.add/remove_state(*roomstate)` or the in-game
command
```
roomstate <state> (use it again to toggle the state off)
```
For example
```
roomstate dark
```
There is one in-built, time-based state `season`. By default these are 'spring',
'summer', 'autumn' and 'winter'. The `room.get_season()` method returns the
current season based on the in-game time. By default they change with a 12-month
in-game time schedule. You can control them with
```
ExtendedRoom.months_per_year # default 12
ExtendedRoom.seasons_per year # a dict of {"season": (start, end), ...} where
# start/end are given in fractions of the whole year
```
To set a seasonal description, just set it as normal, with `room.add_desc` or
in-game with
```
@desc/winter This room is filled with snow.
@desc/autumn Red and yellow leaves cover the ground.
```
Normally the season changes with the in-game time, you can also 'force' a given
season by setting its state
```
roomstate winter
```
If you set the season manually like this, it won't change automatically again
until you unset it.
You can get the stateful description from the room with `room.get_stateful_desc()`.
### Changing parts of description based on state
All descriptions can have embedded `$state(roomstate, description)`
[FuncParser tags](../Components/FuncParser.md) embedded in them. Here is an example:
```py
room.add_desc("This a nice beach. "
"$state(empty, It is completely empty)"
"$state(full, It is full of people).", room_state="summer")
```
This is a summer-description with special embedded strings. If you set the room
with
> room.add_room_state("summer", "empty")
> room.get_stateful_desc()
This is a nice beach. It is completely empty
> room.remove_room_state("empty")
> room.add_room_state("full")
> room.get_stateful_desc()
This is a nice beach. It is full of people.
There are four time-of-day states that are meant to be used with these tags. The
room tracks and changes these automatically. By default they are 'morning',
'afternoon', 'evening' and 'night'. You can get the current time-slot with
`room.get_time_of_day`. You can control them with
```
ExtendedRoom.hours_per_day # default 24
ExtendedRoom.times_of_day # dict of {season: (start, end), ...} where
# the start/end are given as fractions of the day
```
You use these inside descriptions as normal:
"A glade. $(morning, The morning sun shines down through the branches)."
### Details
The Extended Room can be "detailed" with special keywords. This makes
use of a special `Look` command. Details are "virtual" targets to look
at, without there having to be a database object created for it. The
Details are simply stored in a dictionary on the room and if the look
command cannot find an object match for a `look <target>` command it
will also look through the available details at the current location
if applicable. The `detail` command is used to change details.
_Details_ are "virtual" targets to look at in a room, without having to create a
new database instance for every thing. It's good to add more information to a
location. The details are stored as strings in a dictionary.
detail window = There is a window leading out.
detail rock = The rock has a text written on it: 'Do not dare lift me'.
When you are in the room you can then do `look window` or `look rock` and get
the matching detail-description. This requires the new custom `look` command.
### Random echoes
The `ExtendedRoom` supports random echoes. Just set them as an Attribute list
`room_messages`:
```
room.room_message_rate = 120 # in seconds. 0 to disable
room.db.room_messages = ["A car passes by.", "You hear the sound of car horns."]
room.start_repeat_broadcast_messages() # also a server reload works
```
These will start randomly echoing to the room every 120s.
### Extra commands
- `CmdExtendedRoomLook` - look command supporting room details
- `CmdExtendedRoomDesc` - desc command allowing to add seasonal descs,
- `CmdExtendedRoomDetail` - command allowing to manipulate details in this room
as well as listing them
- `CmdExtendedRoomGameTime` - A simple `time` command, displaying the current
time and season.
- `CmdExtendedRoomLook` (`look`) - look command supporting room details
- `CmdExtendedRoomDesc` (`@desc`) - desc command allowing to add stateful descs,
- `CmdExtendeRoomState` (`roomstate`) - toggle room states
- `CmdExtendedRoomDetail` (`detail`) - list and manipulate room details
- `CmdExtendedRoomGameTime` (`time`) - Shows the current time and season in the room.
----

View file

@ -441,12 +441,16 @@ Contrib-XYZGrid.md
### `extended_room`
_Contribution - Griatch 2012, vincent-lg 2019_
_Contribution - Griatch 2012, vincent-lg 2019, Griatch 2023_
This extends the normal `Room` typeclass to allow its description to change
with time-of-day and/or season. It also adds 'details' for the player to look at
in the room (without having to create a new in-game object for each). The room is
supported by new `look` and `desc` commands.
This extends the normal `Room` typeclass to allow its description to change with
time-of-day and/or season as well as any other state (like flooded or dark).
Embedding `$state(burning, This place is on fire!)` in the description will
allow for changing the description based on room state. The room also supports
`details` for the player to look at in the room (without having to create a new
in-game object for each), as well as support for random echoes. The room
comes with a set of alternate commands for `look` and `@desc`, as well as new
commands `detail`, `roomstate` and `time`.
[Read the documentation](./Contrib-Extended-Room.md) - [Browse the Code](evennia.contrib.grid.extended_room)