@ifloom/plugin-places
Every export of @ifloom/plugin-places and its /react subpath: its signature and its fields.
Generated from the source of @ifloom/plugin-places and @ifloom/plugin-places/react and its TSDoc by npm run api-docs. Each export links to the page that explains it, where one does.
@ifloom/plugin-places
- Functions:
locationOf,locationsOf,lyingCount,places - Constants:
LOCATION - Types:
Arrival,ExitView,Lies,LyingView,Place,PlaceDef,PlacesOptions,PlacesState,PlacesView,PlaceView
Arrival
Type. Explained in Places.
The effects that run as the player walks into a location by an exit, in a Place's arrive.
import type { Arrival } from '@ifloom/plugin-places'
type Arrival = {
when?: Condition
effects: EffectRef[]
}| Field | Type | Optional | Default | Description |
|---|---|---|---|---|
when | Condition | yes | The condition that must hold for the effects to run. They always run if left out. | |
effects | EffectRef[] | The effects that run on arrival. |
ExitView
Type. Explained in Places.
An exit from the location the player is at as the player sees it, in view.plugins.places.exits. It is a
RenderedChoice labelled with the destination's name, so its command takes the exit.
Its disabled gives the reason the exit is refused, warning a plugin's soft refusal and price the cost of
going. The other fields describe the destination.
import type { ExitView } from '@ifloom/plugin-places'
type ExitView = {
tags: string[]
ref: EntityRef
description: string | null
image: string | null
// …
}Plugins add fields of their own to it, which their pages list.
| Field | Type | Optional | Default | Description |
|---|---|---|---|---|
tags | string[] | The choice's or action's tags, for a UI to style or filter it by. The destination's tags. | ||
ref | EntityRef | The destination's entity reference, such as 'location:park'. | ||
description | string | null | The destination's description, the line under its name, or null when it has none. | ||
image | string | null | The path of the destination's picture, its image through artSrc, or null when it has none. |
Lies
Type. Explained in Places.
The data of the places/lies trait, which starts a thing lying in a location.
It's the location's id, or the full form with a condition to find it and effects.
import type { Lies } from '@ifloom/plugin-places'
type Lies = string | { at: string; count?: number; when?: Condition; onFind?: EffectRef[]; onPickUp?: EffectRef[] }LOCATION
Const. Explained in Places.
The id of the kind the plugin brings for its locations, location, as in 'location:park'. The kind is unique: each location is one place.
import { LOCATION } from '@ifloom/plugin-places'
const LOCATION: 'location'locationOf
Function. Explained in Places.
Returns the places/location trait of a location, named by its id ('park') or reference, read through the
entity it was made like. Returns undefined for anything that isn't a location.
import { locationOf } from '@ifloom/plugin-places'
function locationOf(state: GameState, game: Game, ref: string | null | undefined): Place | undefinedlocationsOf
Function. Explained in Places.
Returns the references of every location in the game now, each entity with the places/location trait. Those
content declares come first in its order, then those made in play.
import { locationsOf } from '@ifloom/plugin-places'
function locationsOf(state: GameState, game: Game): EntityRef[]Uses: GameState, Game, EntityRef.
lyingCount
Function. Explained in Places.
Returns how many of a thing lie in a location now, whether or not the player can see them.
import { lyingCount } from '@ifloom/plugin-places'
function lyingCount(state: GameState, game: Game, ref: string, at: string): numberLyingView
Type. Explained in Places.
A thing lying at the location the player is at as the player sees it, in view.plugins.places.things.
import type { LyingView } from '@ifloom/plugin-places'
type LyingView = {
ref: EntityRef
name: string
image: string | null
count: number
pickUp: RenderedChoice
}| Field | Type | Optional | Default | Description |
|---|---|---|---|---|
ref | EntityRef | The thing's entity reference, such as 'note:paper'. | ||
name | string | The thing's name. | ||
image | string | null | The path of the thing's picture through artSrc, or null when it has none. | ||
count | number | The number of this thing lying here. | ||
pickUp | RenderedChoice | The button that picks one up. Its command is the one to send. |
Place
Type. Explained in Places.
The data of the places/location trait, which makes an entity a location the player can be at. The location's
name, description, image and tags are the entity's.
import type { Place, Arrival } from '@ifloom/plugin-places'
type Place = {
parent?: string
exits: readonly string[]
picture?: PictureDef
blocked?: Blocked[]
body: Block[]
actions?: ActionDef[]
audio?: Record<string, string | null>
ui?: Ui<SceneUi>
arrive?: Arrival
}| Field | Type | Optional | Default | Description |
|---|---|---|---|---|
parent | string | yes | The id of the location this one is inside, such as the building a shop is in. places/within follows it. | |
exits | readonly string[] | The ids of the locations one step away. | ||
picture | PictureDef | yes | The location's layered picture with hotspots, rendered with the room. A hotspot here sends a command, since a location has no choices. | |
blocked | Blocked[] | yes | The reasons travel here is refused, such as a door shut for the night. With hide, the exit is left out of the view instead of disabled. | |
body | Block[] | The location's body, the blocks the player reads here while no scene is open. | ||
actions | ActionDef[] | yes | The location's actions, offered as buttons in the room. | |
audio | Record<string, string | null> | yes | The audio that plays while the player is here, by channel, such as { ambience: 'cafe.murmur' }. Null silences a channel, and an open scene's audio and an audio effect's override it. | |
ui | Ui<SceneUi> | yes | The room's presentation hints while no scene is open, carried to view.scene.ui as a scene's are, such as the React UI's { transition: 'slide-left' }. The engine gives them no meaning. | |
arrive | Arrival | yes | The effects that run after the player walks in by an exit, such as someone catching them on the way in. A places/move doesn't run them. |
PlaceDef
Type. Explained in Places.
A location the game declares in entities with places.location(). It has an entity's fields and the
places/location trait's side by side, and its ui is the trait's room hints.
import type { PlaceDef, Arrival } from '@ifloom/plugin-places'
type PlaceDef = {
parent?: string
exits: readonly string[]
picture?: PictureDef
blocked?: Blocked[]
body: Block[]
actions?: ActionDef[]
audio?: Record<string, string | null>
ui?: Ui<SceneUi>
arrive?: Arrival
of?: string
// …
}Plugins add fields of their own to it, which their pages list.
| Field | Type | Optional | Default | Description |
|---|---|---|---|---|
parent | string | yes | The id of the location this one is inside, such as the building a shop is in. places/within follows it. | |
exits | readonly string[] | The ids of the locations one step away. | ||
picture | PictureDef | yes | The location's layered picture with hotspots, rendered with the room. A hotspot here sends a command, since a location has no choices. | |
blocked | Blocked[] | yes | The reasons travel here is refused, such as a door shut for the night. With hide, the exit is left out of the view instead of disabled. | |
body | Block[] | The location's body, the blocks the player reads here while no scene is open. | ||
actions | ActionDef[] | yes | The location's actions, offered as buttons in the room. | |
audio | Record<string, string | null> | yes | The audio that plays while the player is here, by channel, such as { ambience: 'cafe.murmur' }. Null silences a channel, and an open scene's audio and an audio effect's override it. | |
ui | Ui<SceneUi> | yes | The room's presentation hints while no scene is open, carried to view.scene.ui as a scene's are, such as the React UI's { transition: 'slide-left' }. The engine gives them no meaning. | |
arrive | Arrival | yes | The effects that run after the player walks in by an exit, such as someone catching them on the way in. A places/move doesn't run them. | |
of | string | yes | The location's kind. The plugin's own kind, location, if left out. |
places
Function. Explained in Places.
The places plugin's factory, with its helpers as properties. places(options) returns the plugin for the game's
plugins, and content calls helpers such as places.location({ ... }), places.go('park') and places.at('cafe').
import { places } from '@ifloom/plugin-places'
function places(options?: PlacesOptions): DefinedPlugin<PlacesState, PlacesView>Uses: PlacesOptions, DefinedPlugin, PlacesState, PlacesView.
| Helper | Signature | Description |
|---|---|---|
places.location | (def: PlaceDef): EntityDef | Returns a location for content's entities, an entity with the places/location trait, from the entity's fields and the trait's. |
places.locationRef | (id: string): EntityRef | Returns the entity reference of a location; a bare id is one of the location kind. |
places.lies | (at: string, more?: Omit<Exclude<Lies, string>, 'at'>): { 'places/lies': Lies } | Returns the places/lies trait, to spread into an entity's traits, naming where it starts lying and any when to find it. |
places.put | (entity: EntityRef, options?: { at?: string; by?: number }): EffectRef | Returns the places/put effect, which puts a thing down where the player is, or at a location. |
places.pickUp | (ref: EntityRef): CommandRef | Returns the places/pickUp command, which picks up one of a thing lying where the player is. |
places.go | (id: string): CommandRef | Returns the places/go command, which walks to a location by an exit. |
places.at | (...places: string[]): Condition | Returns the places/at condition, which holds while the player is at any of these locations. |
places.within | (...places: string[]): Condition | Returns the places/within condition, which holds while the player is at any of these locations or anywhere inside one. |
places.away | (...places: string[]): Condition | Returns the places/away condition, which holds while the player is at none of these locations or at no location. |
places.move | (place: string): EffectRef | Returns the places/move effect, which puts the player at the location at once, closing any scene. |
places.onlyAt | (places: string[], reason?: Reason, options?: { hide?: boolean }): Blocked | Returns a blocked entry that refuses anywhere but these locations, with reason or the places/notHere string. |
places.where | (state: GameState, game: Game): string | null | Returns the id of the location the player is at, from the places/here query, or null. |
PlacesOptions
Type. Explained in Places.
Settings for places().
import type { PlacesOptions } from '@ifloom/plugin-places'
type PlacesOptions = {
start?: string
onPickUp?: EffectRef[]
}| Field | Type | Optional | Default | Description |
|---|---|---|---|---|
start | string | yes | The id of the location a new game starts at. The player is at no location if left out. | |
onPickUp | EffectRef[] | yes | The effects that run each time the player picks anything up, after the thing's own onPickUp, with '$' as the thing. |
PlacesState
Type. Explained in Places.
The location a save keeps for the player. The plugin reads the locations from content.
import type { PlacesState } from '@ifloom/plugin-places'
type PlacesState = {
at: string | null
floor: Record<string, Record<string, number>>
found: string[]
}| Field | Type | Optional | Default | Description |
|---|---|---|---|---|
at | string | null | The id of the location the player is at, its full reference for a location of another kind, or null when at none. | ||
floor | Record<string, Record<string, number>> | The counts of things lying in each location that play changed, by location id and then thing. A count stays once written, 0 included. For a count play hasn't changed, the plugin reads the thing's places/lies. | ||
found | string[] | The things with a when the player has found, by reference. |
PlacesView
Type. Explained in Places.
The player's location, its exits and the things lying there as the player sees them, in view.plugins.places.
import type { PlacesView } from '@ifloom/plugin-places'
type PlacesView = {
location: PlaceView | null
exits: ExitView[]
things: LyingView[]
}| Field | Type | Optional | Default | Description |
|---|---|---|---|---|
location | PlaceView | null | The location the player is at, or null when at none. | ||
exits | ExitView[] | The location's exits in the order it lists them. It is empty while a scene is open or a lock holds everything. | ||
things | LyingView[] | The things lying in the location that the player can see, such as a thing they dropped. It is empty while a scene is open or a lock holds everything. |
PlaceView
Type. Explained in Places.
The location the player is at as the player sees it, in view.plugins.places.location.
import type { PlaceView } from '@ifloom/plugin-places'
type PlaceView = {
id: string
ref: EntityRef
name: string
description: string | null
tags: string[]
image: string | null
picture: PictureView | null
}| Field | Type | Optional | Default | Description |
|---|---|---|---|---|
id | string | The location's id, as places.go names it. | ||
ref | EntityRef | The location's entity reference, such as 'location:park'. | ||
name | string | The location's name. | ||
description | string | null | The location's description, the line under its name, or null when it has none. | ||
tags | string[] | The location's tags, which a UI can style it by. | ||
image | string | null | The path of the location's picture, its image through artSrc, or null when it has none. | ||
picture | PictureView | null | The location's layered picture, rendered by the engine's pictureView, or null when it has none. Its hotspots are left out while a scene is open or a lock holds everything, as the exits are. |
@ifloom/plugin-places/react
- Functions:
usePlaces - Constants:
Exits,LocationCard,placesUi - Types:
PlacesControls
Exits
Const. Explained in Places.
Renders the exits from view.plugins.places.exits, each a button that is disabled with its reason when refused. It
renders nothing without the places plugin, and a preset can style the parts exits and exit.
import { Exits } from '@ifloom/plugin-places/react'
const Exits: ComponentType<{ className?: string; }>LocationCard
Const. Explained in Places.
Renders the player's location from view.plugins.places.location, its name and description under its layered
picture, with the things lying there and a button to pick each up. Exits renders the exits.
A preset can style the parts location, location-name, location-text, location-things, location-thing,
location-thing-name and location-thing-pick.
import { LocationCard } from '@ifloom/plugin-places/react'
const LocationCard: ComponentType<object>PlacesControls
Type. Explained in Places.
The places plugin's view with functions that take an exit and pick up a thing, as usePlaces returns it.
import type { PlacesControls } from '@ifloom/plugin-places/react'
type PlacesControls = {
location: PlaceView | null
exits: ExitView[]
things: LyingView[]
go: (exit: string) => Result<GameState>
pickUp: (thing: EntityRef) => Result<GameState>
}| Field | Type | Optional | Default | Description |
|---|---|---|---|---|
location | PlaceView | null | The location the player is at, or null when at none. | ||
exits | ExitView[] | The location's exits in the order it lists them. It is empty while a scene is open or a lock holds everything. | ||
things | LyingView[] | The things lying in the location that the player can see, such as a thing they dropped. It is empty while a scene is open or a lock holds everything. | ||
go | (exit: string) => Result<GameState> | Sends the command of the exit to the location with this id. The engine refuses it, as any command, when the exit is disabled or missing. | ||
pickUp | (thing: EntityRef) => Result<GameState> | Sends the pickUp command for one of the thing lying here with this reference, such as 'note:paper'. |
placesUi
Const. Explained in Places.
The places plugin's React UI, for plugins on mountGame or GameProvider. It renders the LocationCard and
the Exits in the room, before the room's actions.
import { placesUi } from '@ifloom/plugin-places/react'
const placesUi: PluginUiUses: PluginUi.
usePlaces
Function. Explained in Places.
Returns the places plugin's view and commands from the running game, or null in a game without the plugin. It re-renders when the view changes.
import { usePlaces } from '@ifloom/plugin-places/react'
function usePlaces(): PlacesControls | nullUses: PlacesControls.
Last updated on