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

@ifloom/plugin-wardrobe

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

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

@ifloom/plugin-wardrobe

Closet

Type. Explained in Wardrobe.

The data of the wardrobe/closet trait, which makes a location somewhere the player can change clothes. While the player is there, the room offers a button that opens the wardrobe panel.

The button needs the places plugin, which says where the player is.

import type { Closet } from '@ifloom/plugin-wardrobe'
type Closet = {
  label?: string
}
FieldTypeOptionalDefaultDescription
labelstringyesThe label of the button that opens the wardrobe panel. The wardrobe/open string (Wardrobe) if left out.

ownedHere

Function. Explained in Wardrobe.

Returns how many of a thing a body ('you' if left out) has in its wardrobe, its starts read from wardrobe/owned.

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

Uses: GameState, Game.

Owners

Type. Explained in Wardrobe.

The bodies that own a thing at the start, one body for one of it or a count for each body ({ player: 1, 'character:sam': 1 }).

import type { Owners } from '@ifloom/plugin-wardrobe'
type Owners = EntityRef | typeof PLAYER | Partial<Record<EntityRef | typeof PLAYER, number>>

Uses: EntityRef.

slotsOf

Function. Explained in Wardrobe.

Returns the game's slots in order, from data.wardrobe.slots in its content and packs.

import { slotsOf } from '@ifloom/plugin-wardrobe'
function slotsOf(game: Game): WardrobeSlot[]

Uses: Game, WardrobeSlot.

wardrobe

Function. Explained in Wardrobe.

The wardrobe plugin's factory, with its helpers as properties. wardrobe() returns the plugin for the game's plugins, and content calls helpers such as wardrobe.wearable('coat') and wardrobe.wear('clothing:scarf').

import { wardrobe } from '@ifloom/plugin-wardrobe'
function wardrobe(options?: WardrobeOptions): DefinedPlugin<WardrobeState, WardrobeView>

Uses: WardrobeOptions, DefinedPlugin, WardrobeState, WardrobeView.

HelperSignatureDescription
wardrobe.wearable(slot: string, hooks?: { onWear?: EffectRef[]; onTakeOff?: EffectRef[] }): { 'wardrobe/wearable': Wearable }Returns the wardrobe/wearable trait for a slot, with its onWear and onTakeOff effects, to spread into traits.
wardrobe.owned(owners: Owners): { 'wardrobe/owned': Owners }Returns the wardrobe/owned trait, to spread into an entity's traits, naming whose wardrobe it starts in.
wardrobe.closet(options?: Closet): { 'wardrobe/closet': Closet }Returns the wardrobe/closet trait, to spread into a location's traits, which offers a button that opens the wardrobe panel.
wardrobe.wearing(entity: EntityRef, slot?: string): ConditionReturns the wardrobe/wearing condition, which holds while whoever the player is playing wears the thing, in slot if given.
wardrobe.slotFilled(slot: string): ConditionReturns the wardrobe/wearing condition for a slot, which holds while whoever the player is playing has something in it.
wardrobe.wear(entity: EntityRef): CommandRefReturns the wardrobe/wear command, which puts on a thing the player owns.
wardrobe.takeOff(slot: string): CommandRefReturns the wardrobe/takeOff command, which takes off whatever is in the slot.
wardrobe.store(entity: EntityRef, options?: { at?: Someone; by?: number; via?: string }): EffectRefReturns the wardrobe/store effect, which puts a thing someone carries away in their wardrobe.
wardrobe.takeOut(entity: EntityRef, options?: { at?: Someone; by?: number; via?: string }): EffectRefReturns the wardrobe/takeOut effect, which takes a thing out of someone's wardrobe into the next receiver.

WardrobeOptions

Type. Explained in Wardrobe.

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

import type { WardrobeOptions } from '@ifloom/plugin-wardrobe'
type WardrobeOptions = {
  claims?: boolean
  onWear?: EffectRef[]
  onTakeOff?: EffectRef[]
}
FieldTypeOptionalDefaultDescription
claimsbooleanyesFalse for a game where clothes are carried before they're put away. True if left out. With it false, the wardrobe claims nothing a receive gives, so wearables go to the next receiver, and wardrobe/store puts them away by name.
onWearEffectRef[]yesEffects that run when a body puts on anything, after the thing's own onWear.
onTakeOffEffectRef[]yesEffects that run when a body takes off anything, after the thing's own onTakeOff.

WardrobeSlot

Type. Explained in Wardrobe.

A slot the game declares in data.wardrobe.slots, a part of the body where a thing can be worn.

import type { WardrobeSlot } from '@ifloom/plugin-wardrobe'
type WardrobeSlot = {
  id: string
  label: string
  start?: EntityRef
}
FieldTypeOptionalDefaultDescription
idstringThe slot's id, which a wearable thing's slot names.
labelstringThe slot's label.
startEntityRefyesThe wearable thing in the slot at the start, one the player owns at the start. The slot starts empty if left out.

WardrobeState

Type. Explained in Wardrobe.

The clothes a save keeps for each body. The plugin reads slots and wearable things from content.

import type { WardrobeState } from '@ifloom/plugin-wardrobe'
type WardrobeState = {
  worn: Record<string, Record<string, EntityRef | null>>
  owned: Record<string, Record<string, number>>
}
FieldTypeOptionalDefaultDescription
wornRecord<string, Record<string, EntityRef | null>>The thing worn in each slot, by body ('player' or a protagonist such as 'character:sam') and then by slot id.
ownedRecord<string, Record<string, number>>The counts of clothes in each body's wardrobe that play changed, by body and then thing. A count written once is kept, 0 included. For the rest, the plugin reads each thing's wardrobe/owned trait.

WardrobeView

Type. Explained in Wardrobe.

The wardrobe of whoever the player is playing as the player sees it, in view.plugins.wardrobe.

import type { WardrobeView } from '@ifloom/plugin-wardrobe'
type WardrobeView = {
  slots: { id: string; label: string; entity: EntityRef | null; name: string | null; takeOff: RenderedChoice | null }[]
  spare: { entity: EntityRef; name: string; slot: string; wear: RenderedChoice }[]
}
FieldTypeOptionalDefaultDescription
slots{ id: string; label: string; entity: EntityRef | null; name: string | null; takeOff:…The game's slots in order, each with the thing in it.
spare{ entity: EntityRef; name: string; slot: string; wear: RenderedChoice }[]The wearable things whoever is played owns and isn't wearing, in the order of the game's entities. Each has its slot and the button that puts it on, labelled with the wardrobe/wear string (Wear {thing}).

Wearable

Type. Explained in Wardrobe.

The data of the wardrobe/wearable trait, which makes a thing wearable in one slot.

import type { Wearable } from '@ifloom/plugin-wardrobe'
type Wearable = {
  slot: string
  onWear?: EffectRef[]
  onTakeOff?: EffectRef[]
}
FieldTypeOptionalDefaultDescription
slotstringThe id of the slot the thing goes in, such as 'coat'.
onWearEffectRef[]yesEffects that run when a body puts the thing on, such as [{ kv: 'onDuty', to: true }], before the game-wide ones.
onTakeOffEffectRef[]yesEffects that run when a body takes the thing off, or it comes off by itself, before the game-wide ones.

wearableOf

Function. Explained in Wardrobe.

Returns a thing's wardrobe/wearable trait, read through the entity it was made like. Returns undefined for a thing that can't be worn.

import { wearableOf } from '@ifloom/plugin-wardrobe'
function wearableOf(state: GameState, game: Game, ref: string): Wearable | undefined

Uses: GameState, Game, Wearable.

@ifloom/plugin-wardrobe/react

useWardrobe

Function. Explained in Wardrobe.

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

Uses: WardrobeControls.

WARDROBE_WORDS

Const. Explained in Wardrobe.

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

import { WARDROBE_WORDS } from '@ifloom/plugin-wardrobe/react'
const WARDROBE_WORDS: { readonly nothingOn: 'Nothing'; readonly wardrobe: 'Wearing'; }

WardrobeCard

Const. Explained in Wardrobe.

Renders what the player has on from view.plugins.wardrobe, slot by slot, with the other things they could wear. It renders nothing without the plugin.

A button that can't be used now is disabled with the engine's reason.

A preset can style the parts wardrobe, wardrobe-title, wardrobe-slot, wardrobe-slot-name and wardrobe-worn.

import { WardrobeCard } from '@ifloom/plugin-wardrobe/react'
const WardrobeCard: ComponentType<{ className?: string; title?: string | false; }>

WardrobeControls

Type. Explained in Wardrobe.

The wardrobe plugin's view, slot by slot with its buttons, and functions that send its commands, as useWardrobe returns it.

import type { WardrobeControls } from '@ifloom/plugin-wardrobe/react'
type WardrobeControls = {
  spare: { entity: EntityRef; name: string; slot: string; wear: RenderedChoice }[]
  slots: WardrobeSlotControls[]
  wear: (entity: EntityRef) => Result<GameState>
  takeOff: (slot: string) => Result<GameState>
}
FieldTypeOptionalDefaultDescription
spare{ entity: EntityRef; name: string; slot: string; wear: RenderedChoice }[]The wearable things whoever is played owns and isn't wearing, in the order of the game's entities. Each has its slot and the button that puts it on, labelled with the wardrobe/wear string (Wear {thing}).
slotsWardrobeSlotControls[]The game's slots in order, each with the thing in it and its buttons.
wear(entity: EntityRef) => Result<GameState>Sends wardrobe/wear for a thing the player holds, by its reference, such as 'clothing:scarf'.
takeOff(slot: string) => Result<GameState>Sends wardrobe/takeOff, which empties the slot with this id.

WardrobeSection

Component. Explained in Wardrobe.

Renders a Wearing section that folds, holding the WardrobeCard. wardrobeUi doesn't place it, so put it in your layout's <Sidebar> to keep what the player wears on screen.

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

WardrobeSlotControls

Type. Explained in Wardrobe.

A slot as useWardrobe returns it, with the thing in it and the buttons that take it off or put another thing on.

import type { WardrobeSlotControls } from '@ifloom/plugin-wardrobe/react'
type WardrobeSlotControls = {
  id: string
  label: string
  entity: EntityRef | null
  name: string | null
  takeOff: RenderedChoice | null
  wear: RenderedChoice[]
}
FieldTypeOptionalDefaultDescription
idstringThe slot's id.
labelstringThe slot's label.
entityEntityRef | nullThe thing in the slot, or null while the slot is empty.
namestring | nullThe name of the thing in the slot, or null while the slot is empty.
takeOffRenderedChoice | nullThe button that takes the thing off, labelled with the wardrobe/takeOff string, or null while the slot is empty.
wearRenderedChoice[]The wear buttons of the spare things for this slot, from the view's spare.

wardrobeUi

Const. Explained in Wardrobe.

The wardrobe plugin's React UI, for plugins on mountGame or GameProvider. It renders the wardrobe panel, which a closet's button or any { panel: 'wardrobe' } opens, as a WardrobeCard, and adds the plugin's words.

It adds nothing to the sidebar, where a layout can place WardrobeSection.

import { wardrobeUi } from '@ifloom/plugin-wardrobe/react'
const wardrobeUi: PluginUi

Uses: PluginUi.

Last updated on

On this page