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

@ifloom/plugin-inventory

Every export of @ifloom/plugin-inventory and its /react subpath: its signature and its fields.

Generated from the source of @ifloom/plugin-inventory and @ifloom/plugin-inventory/react and its TSDoc by npm run api-docs. Each export links to the page that explains it, where one does.

@ifloom/plugin-inventory

canHold

Function. Explained in Inventory.

Returns true when holder can hold things now. The player always can, and a unique entity can while it is in the game.

import { canHold } from '@ifloom/plugin-inventory'
function canHold(state: GameState, game: Game, holder: string): boolean

Uses: GameState, Game.

heldBy

Function. Explained in Inventory.

Returns the things a holder holds, 'you' if left out, each with its count, in the game's order of its entities.

import { heldBy } from '@ifloom/plugin-inventory'
function heldBy(state: GameState, game: Game, at?: string): { ref: EntityRef; count: number }[]

Uses: GameState, Game, EntityRef.

heldCount

Function. Explained in Inventory.

Returns the count of a thing a holder holds, 'you' if left out. Returns 0 for a thing not held there or not in the game.

import { heldCount } from '@ifloom/plugin-inventory'
function heldCount(state: GameState, game: Game, ref: string, at?: string): number

Uses: GameState, Game.

Holder

Type. Explained in Inventory.

A holder of things, 'player', a unique entity ('character:ava') or 'you', whoever the player is playing now.

import type { Holder } from '@ifloom/plugin-inventory'
type Holder = EntityRef | typeof PLAYER | typeof YOU

Uses: EntityRef.

holderOf

Function. Explained in Inventory.

Returns the holder of a thing when one holder has it, as always for a unique thing. Undefined when no one holds it.

import { holderOf } from '@ifloom/plugin-inventory'
function holderOf(state: GameState, game: Game, ref: string): Holder | undefined

Uses: GameState, Game, Holder.

holdersOf

Function. Explained in Inventory.

Returns each holder of a thing with its count, in no set order.

import { holdersOf } from '@ifloom/plugin-inventory'
function holdersOf(state: GameState, game: Game, ref: string): { holder: Holder; count: number }[]

Uses: GameState, Game, Holder.

inventory

Function. Explained in Inventory.

The inventory plugin's factory, with its helpers as properties. inventory() returns the plugin for the game's plugins, and content calls helpers such as inventory.usable('Eat', effects) and inventory.use('food:apple').

import { inventory } from '@ifloom/plugin-inventory'
function inventory(options?: InventoryOptions): DefinedPlugin<InventoryState, InventoryView>

Uses: InventoryOptions, DefinedPlugin, InventoryState, InventoryView.

HelperSignatureDescription
inventory.usable(label: string, effects: EffectRef[], options?: { keep?: boolean }): { 'inventory/usable': Usable }Returns the inventory/usable trait, to spread into an entity's or a kind's traits. Using the thing spends one unless keep is true.
inventory.at(placement: Placement): { 'inventory/at': Placement }Returns the inventory/at trait, to spread into an entity's traits, naming who holds it at the start.
inventory.use(ref: EntityRef): CommandRefReturns the inventory/use command, which uses one of a thing the player holds.
inventory.drop(ref: EntityRef): CommandRefReturns the inventory/drop command, which drops one of a thing the player holds.
inventory.give(ref: EntityRef, to: Holder): CommandRefReturns the inventory/give command, which gives one of a thing the player holds to someone.
inventory.move(entity: EntityRef, to: Holder, options?: { from?: Holder; by?: number }): EffectRefReturns the inventory/move effect, which moves a thing from one holder to another, from 'you' if from is left out.
inventory.set(entity: EntityRef, to: number, holder?: Holder): EffectRefReturns the inventory/set effect, which sets how many of a thing a holder ('you' if left out) holds.

InventoryData

Type. Explained in Inventory.

The inventory plugin's content, which the game declares in data.inventory.

import type { InventoryData } from '@ifloom/plugin-inventory'
type InventoryData = {
  kinds?: { id: string }[]
}
FieldTypeOptionalDefaultDescription
kinds{ id: string }[]yesThe kinds whose things the inventory shows in InventoryView, each an entry with the kind's id ({ id: 'food' }), so a mod can add one. Every kind if left out.

inventoryKindsOf

Function. Explained in Inventory.

Returns the kinds the inventory shows, from data.inventory.kinds in the game's content and packs. Returns undefined when every kind is shown.

import { inventoryKindsOf } from '@ifloom/plugin-inventory'
function inventoryKindsOf(game: Game): { id: string }[] | undefined

Uses: Game.

InventoryOptions

Type. Explained in Inventory.

The inventory plugin's settings, which the game passes to inventory().

import type { InventoryOptions } from '@ifloom/plugin-inventory'
type InventoryOptions = {
  carryOver?: readonly string[] | 'all'
}
FieldTypeOptionalDefaultDescription
carryOverreadonly string[] | 'all'yesThe things a New Game+ keeps in the player's own inventory, by reference ('food:apple'), or 'all' for everything the player holds, things made in play included. Nothing if left out.

InventoryState

Type. Explained in Inventory.

The inventory's state, the counts play changed.

import type { InventoryState } from '@ifloom/plugin-inventory'
type InventoryState = {
  held: Record<string, Record<string, number>>
}
FieldTypeOptionalDefaultDescription
heldRecord<string, Record<string, number>>The counts play changed, by holder and then thing. A count stays once written, 0 included.

InventoryThing

Type. Explained in Inventory.

A thing someone holds as the player sees it, in view.plugins.inventory.things.

import type { InventoryThing } from '@ifloom/plugin-inventory'
type InventoryThing = {
  ref: EntityRef
  name: string
  description: string | null
  image: string | null
  count: number
  at: Holder
  use: RenderedChoice | null
  drop: RenderedChoice
}
FieldTypeOptionalDefaultDescription
refEntityRefThe thing's entity reference, such as 'food:apple'.
namestringThe thing's name.
descriptionstring | nullThe thing's description, with its tokens filled, or null when it has none.
imagestring | nullThe path of the thing's picture through artSrc, or null when it has none.
countnumberThe number of this thing the holder holds.
atHolderThe thing's holder, the protagonist being played or 'player'.
useRenderedChoice | nullThe button that uses one, labelled by its trait, or null for a thing with no use. Its command is the one to send.
dropRenderedChoiceThe button that drops one.

InventoryView

Type. Explained in Inventory.

The inventory as the player sees it, in view.plugins.inventory.

import type { InventoryView } from '@ifloom/plugin-inventory'
type InventoryView = {
  things: InventoryThing[]
}
FieldTypeOptionalDefaultDescription
thingsInventoryThing[]The things the inventory shows, the played protagonist's first and then the player's.

Placement

Type. Explained in Inventory.

A thing's starting place, one holder for one of it or a count for each holder ({ player: 2, 'place:larder': 6 }).

import type { Placement } from '@ifloom/plugin-inventory'
type Placement = Holder | Partial<Record<Holder, number>>

Uses: Holder.

Usable

Type. Explained in Inventory.

The data of the inventory/usable trait, which makes a thing usable. It gives the button's label, the effects of using one and whether one is kept.

import type { Usable } from '@ifloom/plugin-inventory'
type Usable = {
  label: string
  effects: EffectRef[]
  keep?: boolean
}
FieldTypeOptionalDefaultDescription
labelstringThe label of the button that uses one, such as "Eat the sandwich".
effectsEffectRef[]The effects of using one. They read the state as it was before one was spent.
keepbooleanyesTrue when using one doesn't spend it, as for a book read or a torch switched on. One is spent if left out.

usableOf

Function. Explained in Inventory.

Returns a thing's inventory/usable trait, read through the entity it was made like. Returns undefined for a thing with no use.

import { usableOf, type Usable } from '@ifloom/plugin-inventory'
function usableOf(state: GameState, game: Game, ref: EntityRef): Usable | undefined

Uses: GameState, Game, EntityRef, Usable.

@ifloom/plugin-inventory/react

INVENTORY_WORDS

Const. Explained in Inventory.

The inventory plugin's UI words, in English. A game rewords any of them with ui.<key> in its strings.

import { INVENTORY_WORDS } from '@ifloom/plugin-inventory/react'
const INVENTORY_WORDS: {
  inventory: 'Carrying'
  heldCount: '×{n}'
  drop: 'Drop'
}
FieldTypeOptionalDefaultDescription
inventory'Carrying'The heading over the things the player carries.
heldCount'×{n}'The count beside a thing held more than once, with {n} for the number.
drop'Drop'The label of the button that drops one.

InventoryCard

Const. Explained in Inventory.

Renders the things the player holds from view.plugins.inventory, each usable one with a button. It renders nothing while they hold nothing, or in a game without the plugin.

A button that can't be used now is disabled with the engine's reason, and the drop prop adds a button that drops one. A preset can style the parts inventory, inventory-title, thing, thing-name, thing-count, thing-text and thing-drop.

import { InventoryCard } from '@ifloom/plugin-inventory/react'
const InventoryCard: ComponentType<InventoryProps>

Uses: InventoryProps.

InventoryControls

Type. Explained in Inventory.

The inventory plugin's view with functions that send its commands, as useInventory returns it.

import type { InventoryControls } from '@ifloom/plugin-inventory/react'
type InventoryControls = {
  things: InventoryThing[]
  use: (ref: EntityRef) => Result<GameState>
  drop: (ref: EntityRef) => Result<GameState>
  give: (ref: EntityRef, to: Holder) => Result<GameState>
}
FieldTypeOptionalDefaultDescription
thingsInventoryThing[]The things the inventory shows, the played protagonist's first and then the player's.
use(ref: EntityRef) => Result<GameState>Sends inventory/use for one of a thing the player holds. A refusal carries the same reason the button shows.
drop(ref: EntityRef) => Result<GameState>Sends inventory/drop for one of a thing the player holds.
give(ref: EntityRef, to: Holder) => Result<GameState>Sends inventory/give, which gives one of a thing the player holds to someone.

InventoryProps

Type. Explained in Inventory.

The props of InventoryCard.

import type { InventoryProps } from '@ifloom/plugin-inventory/react'
type InventoryProps = {
  className?: string
  title?: string | false
  drop?: boolean
}
FieldTypeOptionalDefaultDescription
classNamestringyesClasses added to the inventory part's own.
titlestring | falseyesThe heading, the inventory word if left out. false leaves it out, as under a section's title.
dropbooleanyesTrue to give each thing a button that drops one.

InventorySection

Component. Explained in Inventory.

Renders InventoryCard in a folding sidebar section titled with the inventory word. It hides itself while nothing is held.

import { InventorySection } from '@ifloom/plugin-inventory/react'
function InventorySection(): JSX.Element

inventoryUi

Const. Explained in Inventory.

The inventory plugin's React UI, for plugins on mountGame or GameProvider. It adds InventorySection to the sidebar and an inventory panel, and the plugin's words.

import { inventoryUi } from '@ifloom/plugin-inventory/react'
const inventoryUi: PluginUi

Uses: PluginUi.

useInventory

Function. Explained in Inventory.

Returns the inventory 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 { useInventory } from '@ifloom/plugin-inventory/react'
function useInventory(): InventoryControls | null

Uses: InventoryControls.

Last updated on

On this page