Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

## [Unreleased]

### Added

- [`PlayerView.valuable_phrases`][osrlib.crawl.views.PlayerView.valuable_phrases] gives what to call each piece in `valuable_names` in the middle of a sentence, with its article and its case, such as `"a silver altar candlestick"` or `"Ossor's Eye"`, keyed by the same instance id (#354). Use `valuable_names` in a list and `valuable_phrases` in a sentence. The phrase is the piece's [`phrase`][osrlib.core.items.ValuableInstance.phrase], which the session copies from the [`ValuableSpec.phrase`][osrlib.crawl.dungeon.ValuableSpec.phrase] that placed it. When that's empty or only whitespace, osrlib makes the phrase from the name: a name whose first word is "the", "a", or "an" has that word in lowercase, and any other name has its first character in lowercase and "an" or "a" in front, by its first letter. Set `phrase` when the piece has a proper name, takes "the", or has a first letter that doesn't give its article. A piece from a 2.9.0 save has no `phrase`, so the view makes its phrase from its name, and a `PlayerView` that osrlib 2.9.0 built validates with `valuable_phrases` empty.

### Fixed

- A gem or piece of jewellery whose `name` is only whitespace has no name of its own (#355). It isn't a key in [`PlayerView.valuable_names`][osrlib.crawl.views.PlayerView.valuable_names] or `valuable_phrases`, and a pile's [`items`][osrlib.crawl.views.PileView.items] show its kind. Before, it was a key in `valuable_names` with the blank name, and the pile's `items` showed the blank string. Spaces around a name don't count either: `valuable_names` and the pile's `items` show the name without them, and a gem named `" Gem "` has no name of its own.

## [2.9.0] - 2026-11-26

### Added
Expand Down
2 changes: 1 addition & 1 deletion docs/front-ends/fastapi-pattern.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ except SaveVersionError:
--8<-- "examples/fastapi_crawler/app.py:player-view"
```

[`PlayerView`][osrlib.crawl.views.PlayerView] allowlists only fields safe for an untrusted client: explored and lit dungeon cells, entered areas, known features and transitions, public character sheets, including whether each caster can prepare spells now (`MemberView.can_prepare_now`), masked descriptions for unidentified magic items, display names for every item the view shows (`item_names` and `item_names_plural`) and the own name of each named gem and piece of jewellery (`valuable_names`), the id and count of each thing in a known pile (`PileView.contents`), encounter groups without monster hit points, `journal` entries, and active `quests` with their revealed objectives. Pass each known [`MapFeatureView.id`][osrlib.crawl.views.MapFeatureView.id] back in a treasure command's `feature_id`. [`PlayerView.features_here`][osrlib.crawl.views.PlayerView.features_here] lists the handles the treasure commands accept from where the party stands, and [`MapFeatureView.emptied`][osrlib.crawl.views.MapFeatureView.emptied] marks an authored cache the party has emptied, so the client can draw that cache opened and stop offering it. Unexplored geometry, raw ids in the feature list, cache contents, undiscovered secret doors and traps, transition destinations, monster stats, `flags`, narrator `guidance`, the player-handle key, and RNG state are excluded from the model (see [Views and visibility](../guides/views-and-visibility.md)). `PlayerView.emptied_caches` can contain a fully qualified raw feature id after the party empties that cache.
[`PlayerView`][osrlib.crawl.views.PlayerView] allowlists only fields safe for an untrusted client: explored and lit dungeon cells, entered areas, known features and transitions, public character sheets, including whether each caster can prepare spells now (`MemberView.can_prepare_now`), masked descriptions for unidentified magic items, display names for every item the view shows (`item_names` and `item_names_plural`) and the own name of each named gem and piece of jewellery (`valuable_names`) with the phrase that puts it in a sentence (`valuable_phrases`), the id and count of each thing in a known pile (`PileView.contents`), encounter groups without monster hit points, `journal` entries, and active `quests` with their revealed objectives. Pass each known [`MapFeatureView.id`][osrlib.crawl.views.MapFeatureView.id] back in a treasure command's `feature_id`. [`PlayerView.features_here`][osrlib.crawl.views.PlayerView.features_here] lists the handles the treasure commands accept from where the party stands, and [`MapFeatureView.emptied`][osrlib.crawl.views.MapFeatureView.emptied] marks an authored cache the party has emptied, so the client can draw that cache opened and stop offering it. Unexplored geometry, raw ids in the feature list, cache contents, undiscovered secret doors and traps, transition destinations, monster stats, `flags`, narrator `guidance`, the player-handle key, and RNG state are excluded from the model (see [Views and visibility](../guides/views-and-visibility.md)). `PlayerView.emptied_caches` can contain a fully qualified raw feature id after the party empties that cache.

Authored narrative also reaches web clients through `POST /sessions/{session_id}/commands` responses in two places:

Expand Down
14 changes: 14 additions & 0 deletions docs/guides/authoring-custom-content.md
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,20 @@ assert feature.description == COFFER.description
assert COFFER.referee_notes not in view.model_dump_json()
```

### Name a gem or piece of jewellery

A [`ValuableSpec`][osrlib.crawl.dungeon.ValuableSpec] with a `name` places a piece that the players know by that name. [`PlayerView.valuable_names`][osrlib.crawl.views.PlayerView.valuable_names] gives that name, which a client shows in a list, such as an inventory row. A client also puts the piece in a sentence, such as "Hild takes a silver censer on a chain.", and [`PlayerView.valuable_phrases`][osrlib.crawl.views.PlayerView.valuable_phrases] gives the phrase to use there, with the article and the case. You can write that phrase yourself in the spec's [`phrase`][osrlib.crawl.dungeon.ValuableSpec.phrase].

When `phrase` is empty or only whitespace, osrlib makes the phrase from the name, as for a common noun. A name whose first word is "the", "a", or "an" has that word in lowercase, so the censer above, "A silver censer on a chain", reads "a silver censer on a chain". Any other name has its first character in lowercase and an article in front, "an" before `a`, `e`, `i`, `o`, or `u`, with or without an accent, and "a" otherwise, so "Silver altar candlestick" reads "a silver altar candlestick". Only the first character changes case, so "Eye of Ossor" reads "an eye of Ossor". The view leaves out any spaces around a name or a phrase.

Set `phrase` yourself when the piece isn't a common noun whose first letter gives its article:

- For a proper name, such as "Ossor's Eye", set `phrase="Ossor's Eye"`.
- For a piece that takes the definite article, such as "Prior's chain of office", set `phrase="the Prior's chain of office"`.
- For a name whose first letter doesn't give its article, such as "Unicorn-horn cup" or "Hourglass of smoked crystal", set `phrase="a unicorn-horn cup"` or `phrase="an hourglass of smoked crystal"`.

A piece with no name of its own never has a phrase in the view, whatever `phrase` holds. That's a piece whose `name` is empty, is only whitespace, or is the name treasure generation gives its kind, `"Gem"` for a gem or `"Jewellery"` for a piece of jewellery. The view names such a piece by its kind in [`PlayerView.item_names`][osrlib.crawl.views.PlayerView.item_names], and a client puts it in a sentence with an article, as in "Hild takes a gem."

## Scope and cross-adventure limits

- **Read-only built-in loaders**: `load_classes`, `load_spells`, `load_monsters`, and `load_equipment` return cached, immutable SRD catalogs and provide no global registration or mutation API. Pass extended catalogs explicitly to kernel functions or bundle custom spells, monsters, and items on `Adventure`.
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/views-and-visibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Use three more fields of the member view to decide when to offer the dialog and

A spell id appears in five places in the view: in a member's `spell_book`, `preparable_spells`, `learnable_spells`, and `memorized_spells`, and as the `kind` of a spell's effect in `PlayerView.effects`. Show the names in [`PlayerView.spell_names`][osrlib.crawl.views.PlayerView.spell_names], keyed by those ids, and the names of reversed forms, like *darkness* for *light*, in [`PlayerView.reversed_spell_names`][osrlib.crawl.views.PlayerView.reversed_spell_names]. Group spells by the level in [`PlayerView.spell_levels`][osrlib.crawl.views.PlayerView.spell_levels]. The view reads all three from the session's catalog, so a spell the adventure bundles has its name and level there too. They name only the spells whose ids the view shows. A spell the adventure bundles for a list that the party's classes don't cast from stays hidden. So does a spell at a spell level where the members can neither prepare nor learn it. A spell on a scroll is named only when the view shows its id in one of the five places: in a member's book, either list, or memorized copies, or as the kind of an effect on a member.

Items work the same way. An inventory identifies a mundane stack by its template's catalog id, like `"holy_water"`, and a magic item or a gem or piece of jewellery by its instance id, like `"magic-item-0003"`, and the item events use the same ids. Show the names in [`PlayerView.item_names`][osrlib.crawl.views.PlayerView.item_names], a noun phrase for one with no article, like `"vial of holy water"`, and in [`PlayerView.item_names_plural`][osrlib.crawl.views.PlayerView.item_names_plural] for a count, so you can word "The party finds 2 vials of holy water". Both have a key for each item id that the inventories and the known piles show, and only for those ids. A stack in a pile is named from the session's catalog, and a stack a member carries from the template it embeds, so an item the adventure bundles has its name in both places. The session gives the template each carried stack embeds the catalog's display names when it starts, when a save loads, and when [`AddMember`][osrlib.crawl.commands.AddMember] adds a member, so a stack from a 2.7.0 save, whose template has no display names, shows the catalog's names in `inventory` too, and the next save writes them. A carried stack whose id the catalog lacks, such as an item another adventure bundled, keeps the names its template has. A valuable is named by its kind, `"gem"` or `"piece of jewellery"`, whereas the inventory's `valuables` contain the piece's name and value. A gem or piece of jewellery that an adventure author named, such as one a [`ValuableSpec`][osrlib.crawl.dungeon.ValuableSpec] with a `name` places in a cache, also has that name in [`PlayerView.valuable_names`][osrlib.crawl.views.PlayerView.valuable_names], keyed by the same instance id, for a member's inventory and for a known pile. Show it as written, with no article, so you can word "Sam takes Prior's chain of office." For an id that isn't a key, such as a piece rolled on the treasure tables, use the kind in `item_names` with an article: "Sam takes a gem." A potion drunk before the party knew what it was is identified and used up in one command, so no view contains its name, and the [`ItemIdentifiedEvent`][osrlib.crawl.events.ItemIdentifiedEvent] contains its names instead.
Items work the same way. An inventory identifies a mundane stack by its template's catalog id, like `"holy_water"`, and a magic item or a gem or piece of jewellery by its instance id, like `"magic-item-0003"`, and the item events use the same ids. Show the names in [`PlayerView.item_names`][osrlib.crawl.views.PlayerView.item_names], a noun phrase for one with no article, like `"vial of holy water"`, and in [`PlayerView.item_names_plural`][osrlib.crawl.views.PlayerView.item_names_plural] for a count, so you can word "The party finds 2 vials of holy water". Both have a key for each item id that the inventories and the known piles show, and only for those ids. A stack in a pile is named from the session's catalog, and a stack a member carries from the template it embeds, so an item the adventure bundles has its name in both places. The session gives the template each carried stack embeds the catalog's display names when it starts, when a save loads, and when [`AddMember`][osrlib.crawl.commands.AddMember] adds a member, so a stack from a 2.7.0 save, whose template has no display names, shows the catalog's names in `inventory` too, and the next save writes them. A carried stack whose id the catalog lacks, such as an item another adventure bundled, keeps the names its template has. A valuable is named by its kind, `"gem"` or `"piece of jewellery"`, whereas the inventory's `valuables` contain the piece's name and value. A gem or piece of jewellery that an adventure author named, such as one a [`ValuableSpec`][osrlib.crawl.dungeon.ValuableSpec] with a `name` places in a cache, also has that name in [`PlayerView.valuable_names`][osrlib.crawl.views.PlayerView.valuable_names], keyed by the same instance id, for a member's inventory and for a known pile. Show it as written in a list, such as an inventory row. To put the piece in a sentence, use [`PlayerView.valuable_phrases`][osrlib.crawl.views.PlayerView.valuable_phrases], which has the same keys and gives each piece's phrase with its article and its case, like `"the Prior's chain of office"`, so you can word "Sam takes the Prior's chain of office." The phrase is the one the author set in the `ValuableSpec`'s `phrase`, or one osrlib makes from the name, as [Name a gem or piece of jewellery](authoring-custom-content.md#name-a-gem-or-piece-of-jewellery) describes. For an id that isn't a key, such as a piece rolled on the treasure tables, use the kind in `item_names` with an article: "Sam takes a gem." A potion drunk before the party knew what it was is identified and used up in one command, so no view contains its name, and the [`ItemIdentifiedEvent`][osrlib.crawl.events.ItemIdentifiedEvent] contains its names instead.

Derived combat and exploration stats include bonuses from worn equipment (such as armour, a shield, or a ring of protection), even before the party identifies a magic item:

Expand Down
Loading
Loading