Early development: IFLoom can change until 1.0. What's stable
IFLoom

@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

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[]
}
FieldTypeOptionalDefaultDescription
whenConditionyesThe condition that must hold for the effects to run. They always run if left out.
effectsEffectRef[]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.

FieldTypeOptionalDefaultDescription
tagsstring[]The choice's or action's tags, for a UI to style or filter it by. The destination's tags.
refEntityRefThe destination's entity reference, such as 'location:park'.
descriptionstring | nullThe destination's description, the line under its name, or null when it has none.
imagestring | nullThe 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[] }

Uses: Condition, 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 | undefined

Uses: GameState, Game, Place.

locationsOf

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): number

Uses: GameState, Game.

LyingView

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
}
FieldTypeOptionalDefaultDescription
refEntityRefThe thing's entity reference, such as 'note:paper'.
namestringThe thing's name.
imagestring | nullThe path of the thing's picture through artSrc, or null when it has none.
countnumberThe number of this thing lying here.
pickUpRenderedChoiceThe 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
}
FieldTypeOptionalDefaultDescription
parentstringyesThe id of the location this one is inside, such as the building a shop is in. places/within follows it.
exitsreadonly string[]The ids of the locations one step away.
picturePictureDefyesThe location's layered picture with hotspots, rendered with the room. A hotspot here sends a command, since a location has no choices.
blockedBlocked[]yesThe 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.
bodyBlock[]The location's body, the blocks the player reads here while no scene is open.
actionsActionDef[]yesThe location's actions, offered as buttons in the room.
audioRecord<string, string | null>yesThe 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.
uiUi<SceneUi>yesThe 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.
arriveArrivalyesThe 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.

FieldTypeOptionalDefaultDescription
parentstringyesThe id of the location this one is inside, such as the building a shop is in. places/within follows it.
exitsreadonly string[]The ids of the locations one step away.
picturePictureDefyesThe location's layered picture with hotspots, rendered with the room. A hotspot here sends a command, since a location has no choices.
blockedBlocked[]yesThe 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.
bodyBlock[]The location's body, the blocks the player reads here while no scene is open.
actionsActionDef[]yesThe location's actions, offered as buttons in the room.
audioRecord<string, string | null>yesThe 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.
uiUi<SceneUi>yesThe 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.
arriveArrivalyesThe 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.
ofstringyesThe 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.

HelperSignatureDescription
places.location(def: PlaceDef): EntityDefReturns 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): EntityRefReturns 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 }): EffectRefReturns the places/put effect, which puts a thing down where the player is, or at a location.
places.pickUp(ref: EntityRef): CommandRefReturns the places/pickUp command, which picks up one of a thing lying where the player is.
places.go(id: string): CommandRefReturns the places/go command, which walks to a location by an exit.
places.at(...places: string[]): ConditionReturns the places/at condition, which holds while the player is at any of these locations.
places.within(...places: string[]): ConditionReturns the places/within condition, which holds while the player is at any of these locations or anywhere inside one.
places.away(...places: string[]): ConditionReturns the places/away condition, which holds while the player is at none of these locations or at no location.
places.move(place: string): EffectRefReturns 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 }): BlockedReturns a blocked entry that refuses anywhere but these locations, with reason or the places/notHere string.
places.where(state: GameState, game: Game): string | nullReturns 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[]
}
FieldTypeOptionalDefaultDescription
startstringyesThe id of the location a new game starts at. The player is at no location if left out.
onPickUpEffectRef[]yesThe 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[]
}
FieldTypeOptionalDefaultDescription
atstring | nullThe id of the location the player is at, its full reference for a location of another kind, or null when at none.
floorRecord<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.
foundstring[]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[]
}
FieldTypeOptionalDefaultDescription
locationPlaceView | nullThe location the player is at, or null when at none.
exitsExitView[]The location's exits in the order it lists them. It is empty while a scene is open or a lock holds everything.
thingsLyingView[]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
}
FieldTypeOptionalDefaultDescription
idstringThe location's id, as places.go names it.
refEntityRefThe location's entity reference, such as 'location:park'.
namestringThe location's name.
descriptionstring | nullThe location's description, the line under its name, or null when it has none.
tagsstring[]The location's tags, which a UI can style it by.
imagestring | nullThe path of the location's picture, its image through artSrc, or null when it has none.
picturePictureView | nullThe 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

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>
}
FieldTypeOptionalDefaultDescription
locationPlaceView | nullThe location the player is at, or null when at none.
exitsExitView[]The location's exits in the order it lists them. It is empty while a scene is open or a lock holds everything.
thingsLyingView[]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: PluginUi

Uses: 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 | null

Uses: PlacesControls.

Last updated on

On this page