Wardrobe
The wardrobe plugin keeps track of what the player and each protagonist has on, in slots the game declares.
@ifloom/plugin-wardrobe keeps track of what the player has on. The game declares the slots, such as a coat and a scarf, and anything the player can wear is a thing with the wardrobe/wearable trait, which names its slot. The plugin keeps each body's clothes and what each has on, the player's and each protagonist's the you effect switches to.
The wardrobe is an optional shortcut. A game in the Twine style keeps an outfit in kv keys and gates scenes on them, and the wardrobe saves writing that: slots, wear and take-off buttons, a body that can wear only what it owns, and effects when a thing goes on or comes off.
It's a receiver: it claims the wearable things a receive gives, so a shirt bought from the shop goes straight into the wardrobe. A game where clothes are carried home first sets claims: false, and wearables fall through to the next receiver, such as the inventory. The wardrobe names no other plugin to do either. It needs no other plugin, and it cooperates with places for a location where the player changes. Entities, things and traits explains traits, Add a plugin installs it, and Let the player get dressed builds a wardrobe with it.
In the showcase: examples/showcase/src/world/things.ts, which declares the raincoat, the scarf and the coat and neck slots. The flat in examples/showcase/src/story/flat.ts is a closet, and the café's body in examples/showcase/src/story/cafe.ts reads wardrobe.wearing('clothing:raincoat').
import {
wardrobe,
slotsOf,
wearableOf,
ownedHere,
type Closet,
type Owners,
type Wearable,
type WardrobeOptions,
type WardrobeSlot,
type WardrobeState,
type WardrobeView,
} from '@ifloom/plugin-wardrobe'wardrobe
The plugin's factory, which returns the plugin with the id wardrobe. It takes WardrobeOptions. The slots and the wearable things are content a mod can change. Every field of its result is in wardrobe, and its helpers are listed under Functions.
A new game dresses the player from each slot's start. Putting a thing on takes off whatever was in its slot, and the thing taken off stays owned. A body wears what it owns in any receiver, its wardrobe or, with claims: false, what it carries. After each command that goes through, the plugin's onCommand hook takes off each thing a body no longer owns anywhere, whether it was sold, used up, given away or taken by an effect, and runs its onTakeOff.
In a game with the inventory too, list the wardrobe first in the game's receivers, receivers: ['wardrobe', 'inventory'], so clothes go to the wardrobe and the rest to the inventory.
import { loadGame, type Content } from '@ifloom/engine'
import { places } from '@ifloom/plugin-places'
import { wardrobe } from '@ifloom/plugin-wardrobe'
declare const town: Content
export const { game } = loadGame([town], { id: 'small-town', title: 'Small Town', plugins: [places({ start: 'flat' }), wardrobe()] })WardrobeOptions
The plugin's settings. Every field is in WardrobeOptions.
claims: false makes the wardrobe claim nothing a receive gives, so wearables go to the next receiver and the player carries them, and wardrobe/store puts them away by name. onWear and onTakeOff run when a body puts on or takes off anything, after the thing's own.
wardrobe({ claims: false, onWear: [{ kv: 'outfitChanged', to: true }] })Content
WardrobeSlot
A slot the game declares in data.wardrobe.slots, a part of the body where a thing is worn. Every field is in WardrobeSlot.
The loader merges slots by id, so a mod adds a slot, and the view lists them in order. label is the word the player reads. start is the thing the player wears in the slot in a new game, and the slot starts empty if it's left out. The player must start owning that thing, so it needs wardrobe.owned('player').
import type { Content } from '@ifloom/engine'
import { wardrobe } from '@ifloom/plugin-wardrobe'
export const town: Content = {
kinds: [{ id: 'clothing', label: 'Clothing', unique: true, listed: false }],
entities: [
{ id: 'raincoat', of: 'clothing', name: 'raincoat', description: 'Yellow, a size too big.', traits: { ...wardrobe.wearable('coat'), ...wardrobe.owned('player') } },
{ id: 'scarf', of: 'clothing', name: 'scarf', description: 'Knitted by someone who loved you.', traits: { ...wardrobe.wearable('neck') } },
],
data: {
wardrobe: {
slots: [
{ id: 'coat', label: 'Coat', start: 'clothing:raincoat' },
{ id: 'neck', label: 'Neck' },
],
},
},
}The clothing kind is unique because each coat is one particular coat. A stackable kind works too, for three identical socks.
Traits
Wearable
The data of the wardrobe/wearable trait, which makes a thing wearable in one slot. Every field is in Wearable.
slot is the slot it goes in. onWear runs when a body puts the thing on and onTakeOff when it comes off, before the game-wide ones, such as a uniform that sets a kv key while it's on:
import type { EntityDef } from '@ifloom/engine'
import { wardrobe } from '@ifloom/plugin-wardrobe'
export const uniform: EntityDef = {
id: 'uniform',
of: 'clothing',
name: 'uniform',
traits: { ...wardrobe.wearable('body', { onWear: [{ kv: 'onDuty', to: true }], onTakeOff: [{ kv: 'onDuty', to: false }] }) },
}wardrobe.wearable(slot, { onWear, onTakeOff }?) writes the trait, to spread into traits beside other plugins' traits, such as the shop's sellable. The trait goes on a kind as a default, on an entity, or in content's traits table, where a mod can move a thing to another slot. A thing made in play like a wearable one is wearable too.
Owners
The data of the wardrobe/owned trait, whose wardrobe a thing starts in: one body, 'player' or a protagonist, or a count for each body. wardrobe.owned(owners) writes it. Its type is in Owners.
Closet
The data of the wardrobe/closet trait, which makes a location somewhere the player changes clothes. Every field is in Closet.
While the player is at a location with the trait, the plugin's actions provider offers a button with the id open and the command { type: 'action', id: 'wardrobe/open' }, which opens the wardrobe panel with { panel: 'wardrobe' }. The button's label is the trait's label, or the wardrobe/open string (Wardrobe) if left out. Any choice or action can open the same panel with { panel: 'wardrobe' }. The plugin finds the location through the places/here query, so the trait does nothing in a game without places.
import { places } from '@ifloom/plugin-places'
import { wardrobe } from '@ifloom/plugin-wardrobe'
export const flat = places.location({
id: 'flat',
name: 'Your flat',
description: 'Home',
exits: ['high-street'],
body: [{ text: 'A sofa, a radiator that knocks, and a coat rack by the door.' }],
traits: { ...wardrobe.closet({ label: 'Open the wardrobe' }) },
})Conditions
wardrobe/wearing
Holds while a thing is on, or while a slot has something in it. It's a plugin call, and works anywhere a condition goes, such as a block's when, a choice, a blocked entry or a lock.
| Kind | Meaning |
|---|---|
{ entity } | Holds while the thing is on, in any slot the game declares. wardrobe.wearing(entity) writes it. |
{ entity, slot } | Holds while that thing is in that slot. wardrobe.wearing(entity, slot) writes it. |
{ slot } | Holds while something is in that slot. wardrobe.slotFilled(slot) writes it. |
{ entity, at } | Holds while the thing is on at's body, 'player' or a protagonist such as 'character:sam', whoever is played. It has no helper. |
Without at, it asks about whoever the player is playing now, 'you'. With neither entity nor slot it's false, and so is an unknown thing or a slot the save has nothing in. To ask whether the player owns a thing, worn or not, use the engine's owned condition.
{ 'wardrobe/wearing': { entity: 'clothing:scarf' } } // wardrobe.wearing('clothing:scarf')Receiving
As a receiver, the wardrobe claims things with the wardrobe/wearable trait, unless claims is false. receive adds the count to to's wardrobe, owned counts what of has there, and release takes from from's. Each left out is whoever the player is playing now.
Effects
Content uses receive and release to give and take clothes whichever plugin keeps them. These effects target the wardrobe by name. at is whose wardrobe, whoever is played if left out, and by is how many, 1 if left out.
wardrobe/add
Puts by of the thing entity in the wardrobe of at.
{ 'wardrobe/add': { entity: 'clothing:scarf' } }wardrobe/remove
Takes by of the thing entity out of the wardrobe of at.
wardrobe/store
Puts a thing away: it takes by of it from the game's other receivers in order, or the one via names, with release, and adds what it took to the wardrobe of at. A game with claims: false uses it for putting carried clothes away.
{ 'wardrobe/store': { entity: 'clothing:scarf' } } // wardrobe.store('clothing:scarf')wardrobe/takeOut
Takes by of the thing out of the wardrobe of at and gives it to the first other receiver that claims it, or the one via names, with receive.
{ 'wardrobe/takeOut': { entity: 'clothing:scarf' } } // wardrobe.takeOut('clothing:scarf')Values
wardrobe/owns is how many of a thing someone has in their wardrobe, at them (whoever is played if left out), so 0 or 1 for a unique thing. The value condition reads it.
Commands
Both commands act on whoever the player is playing now, and both go through locks, which name them wardrobe/wear and wardrobe/takeOff, or both as wardrobe/*. Neither checks where the player is or what's on screen, so both work with a scene open and at any location.
wardrobe/wear
Puts the thing id on, in its slot, in place of whatever was there. The plugin refuses it in this order:
- With
There is no such thing.(noSuchThing) when the thing isn't in the game. - With
The <name> is not something you wear.(wardrobe/notClothing) when it has nowardrobe/wearabletrait. - With
You are already wearing the <name>.(wardrobe/alreadyWearing). - With
You have no <name>.(wardrobe/haveNone) when the player owns none, in any receiver.
{ 'wardrobe/wear': { id: 'clothing:scarf' } } // wardrobe.wear('clothing:scarf')wardrobe/takeOff
Empties the slot id. The plugin refuses it with There is nothing to take off. (wardrobe/nothingToTakeOff) when the save has nothing in that slot, which includes a slot the game doesn't have.
{ 'wardrobe/takeOff': { id: 'coat' } } // wardrobe.takeOff('coat')State
WardrobeState
The clothes a save keeps at state.plugins.wardrobe. worn holds, for each body that has worn something, 'player' or a protagonist's reference, the thing in each slot or null. owned holds the counts in each body's wardrobe that play changed, 0 included, and the plugin reads the rest from each thing's wardrobe/owned trait. Every field is in WardrobeState.
Each body keeps its own slots, and the view and wardrobe/wearing read the slots of whoever is played. A protagonist starts with nothing on until they put something on, whatever the slots' start, which is the player's. The onCommand hook checks every body, so giving the player's scarf to Sam takes it off the player even while Sam is played. A UI reads WardrobeView instead.
import { apply, applyEffects, holds, type Game, type GameState } from '@ifloom/engine'
import { wardrobe } from '@ifloom/plugin-wardrobe'
declare const game: Game
declare const state: GameState // the player in the raincoat, and Sam owning a scarf
const asSam = applyEffects(state, game, [{ you: 'character:sam' }])
const dressed = apply(asSam, game, wardrobe.wear('clothing:scarf')).state
holds(dressed, game, wardrobe.wearing('clothing:raincoat')) // false, because Sam isn't wearing it
const back = applyEffects(dressed, game, [{ you: 'player' }])
holds(back, game, wardrobe.wearing('clothing:raincoat')) // true
holds(back, game, { 'wardrobe/wearing': { entity: 'clothing:scarf', at: 'character:sam' } }) // trueView
WardrobeView
The wardrobe of whoever the player is playing, in view.plugins.wardrobe. Every field is in WardrobeView.
slots lists every slot the game declares, in order, with the thing in it and its name, both null for an empty slot. Each slot's takeOff is a RenderedChoice labelled with the wardrobe/takeOff string, or null for an empty slot. spare lists the wearable things the player owns and isn't wearing, in the game's order of its entities, each with its slot and a wear button labelled with the wardrobe/wear string. Each button carries the engine's refusal in disabled when it can't be pressed now, such as a lock's.
{
slots: [{ id: 'coat', label: 'Coat', entity: 'clothing:raincoat', name: 'raincoat', takeOff: { label: 'Take off', … } }, { id: 'neck', label: 'Neck', entity: null, name: null, takeOff: null }],
spare: [{ entity: 'clothing:scarf', name: 'scarf', slot: 'neck', wear: { label: 'Wear scarf', … } }],
}With claims: false, the things worn are in the inventory's view too, since the player still carries them. A UI that lists the bag without the clothes leaves out the references in slots.
Render what the player wears renders this view in Plain JS, React and Vue.
React UI
The React UI is optional: the @ifloom/plugin-wardrobe/react subpath renders the wardrobe for a game that uses @ifloom/react, and a game rendered another way never loads it. Show plugins in the React UI adds it to a game.
wardrobeUi
The plugin's PluginUi, listed in mountGame's plugins. It renders WardrobeCard as the wardrobe panel, in a dialog titled ui.wardrobe, which a closet's button or any { panel: 'wardrobe' } opens. It adds nothing to the side column. Its type is in wardrobeUi.
WARDROBE_WORDS
The words the wardrobe UI uses, by key, which a game rewords as ui.<key> in its strings as it does the React UI's own. Its value is in WARDROBE_WORDS. The buttons use the plugin's own strings.
| Key | Meaning |
|---|---|
ui.nothingOn | Nothing, the line for an empty slot. |
ui.wardrobe | Wearing, the title of the card, its dialog and its section. |
WardrobeSection
Renders a folding Section with the id wardrobe and the title ui.wardrobe, holding the WardrobeCard. Its type is in WardrobeSection.
wardrobeUi doesn't place it, so a layout puts it in its Sidebar to keep what the player wears on screen. A game with no closet location, no { panel: 'wardrobe' } and no WardrobeSection gives the player no way to change. For a section that shows only at some locations, a layout puts its own Section with when round a WardrobeCard, as the showcase does.
import { Sidebar, Title } from '@ifloom/react'
import { WardrobeSection } from '@ifloom/plugin-wardrobe/react'
// What the player wears, kept in view in the side column.
export function SidebarWithWardrobe() {
return (
<Sidebar>
<Title />
<WardrobeSection />
</Sidebar>
)
}
WardrobeCard
Renders view.plugins.wardrobe: each slot with its label and the thing in it or ui.nothingOn, the slot's Take off button while something is in it, and a Wear … button for each spare thing for that slot. Its props are in WardrobeCard.
A button that can't be pressed now is disabled, with whyNot's reason in its title, shown on hover rather than printed. The heading is ui.wardrobe, or title, and false leaves it out. It renders nothing in a game without the plugin. A game replaces it as WardrobeCard in components. Its parts are wardrobe, wardrobe-title, wardrobe-slot (with data-slot-id, and data-worn holding the reference of the thing in it), wardrobe-slot-name, wardrobe-worn and button.
useWardrobe
Returns the wardrobe view from the running game, slot by slot with its buttons, and a wear and a takeOff that send the commands, or null in a game without the plugin. It re-renders when the view changes. Its signature is in useWardrobe.
WardrobeControls
The value useWardrobe returns: the view's spare, its slots as WardrobeSlotControls, and wear(entity) and takeOff(slot). Every field is in WardrobeControls. Each function returns the runner's Result, so a refusal comes back with its reason.
WardrobeSlotControls
One slot as useWardrobe returns it: the view's slot with wear, the wear buttons of the spare things for that slot. Every field is in WardrobeSlotControls.
Functions
The helpers are properties of wardrobe and write its traits and calls, typed:
wardrobe.wearable(slot, { onWear, onTakeOff }?)returns thewardrobe/wearabletrait,wardrobe.owned(owners)thewardrobe/ownedtrait, andwardrobe.closet(options?)thewardrobe/closettrait, to spread intotraits.wardrobe.wearing(entity, slot?)andwardrobe.slotFilled(slot)return thewardrobe/wearingcondition.wardrobe.store(entity, { at, by, via }?)andwardrobe.takeOut(entity, { at, by, via }?)return the effects.wardrobe.wear(entity)andwardrobe.takeOff(slot)return the commands as aCommandRef.
The bench by the river is too cold without a scarf:
import { need, type ActionDef } from '@ifloom/engine'
import { wardrobe } from '@ifloom/plugin-wardrobe'
export const bench: ActionDef = {
id: 'bench',
label: 'Sit on the bench by the river',
blocked: [need('Too cold without a scarf.', wardrobe.wearing('clothing:scarf'))],
effects: [{ stat: 'energy', by: 5 }],
}slotsOf
Returns the game's slots from data.wardrobe.slots, merged from its content and packs, in order. Its signature is in slotsOf.
ownedHere
Returns how many of a thing a body ('you' if left out) has in its wardrobe, its starts read from wardrobe/owned. It counts the wardrobe only; the engine's owned condition counts every receiver. Its signature is in ownedHere.
wearableOf
Returns the thing's wardrobe/wearable trait, read through the thing it was made like, or undefined for a thing that can't be worn. Its signature is in wearableOf.
import { wearableOf } from '@ifloom/plugin-wardrobe'
wearableOf(state, game, 'clothing:scarf')?.slot // 'neck'Checks
When the game loads, the plugin reports problems with each slot and each trait against the content or pack that brought it:
| Problem | Cause |
|---|---|
trait wardrobe/wearable on clothing:gloves · unknown slot "hands" | A wearable thing names a slot the game doesn't have. |
a wearable thing needs a slot: { slot: "coat" } | A wardrobe/wearable trait has no slot. |
a closet’s label must be words: { label: "Wardrobe" } | A wardrobe/closet trait isn't an object, or its label isn't a string. |
slots coat · unknown entity "clothing:anorak" | A slot's start names a thing the game doesn't have. |
starts with "clothing:scarf", which is not worn in this slot | A slot's start names a thing whose trait names another slot. |
starts with "clothing:raincoat", which the player does not own at the start: … | A slot's start names a thing without wardrobe.owned('player'). Not checked with claims: false. |
wardrobe/owned can't be "you" where a thing starts: … | A wardrobe/owned names 'you'. |
wardrobe/owned gives "…" 2.5: a count is a whole number above 0 | A start count isn't a whole number above 0. |
a unique thing starts in one place, one of it | A unique thing starts in more than one wardrobe, or more than one of it. |
A wardrobe/wearing condition or a wardrobe/wear command naming a thing the game doesn't have gives unknown entity "…" where it's written.
mod:winter · trait wardrobe/wearable on clothing:gloves · unknown slot "hands"
town · slots coat · starts with "clothing:raincoat", which the player does not own at the start: give it wardrobe.owned('player')Strings
A game, a pack or a translation rewords these by their full key in its strings. {thing} is the thing's name. wardrobe/wear also uses the engine's noSuchThing.
| Key | Meaning |
|---|---|
wardrobe/notClothing | The {thing} is not something you wear., the refusal of a thing with no wardrobe/wearable trait. |
wardrobe/alreadyWearing | You are already wearing the {thing}. |
wardrobe/haveNone | You have no {thing}., the refusal of a thing the player doesn't own. |
wardrobe/nothingToTakeOff | There is nothing to take off., the refusal of an empty slot. |
wardrobe/takeOff | Take off, the label of a slot's takeOff button. |
wardrobe/wear | Wear {thing}, the label of a spare thing's wear button. |
wardrobe/open | Wardrobe, the label of a closet's button when its trait gives none. |
Caveats
- Within the command that loses a thing,
wardrobe/wearingstill holds, because the plugin takes the thing off after the command.applyEffectsruns no hooks, so a state made with it can show something on that the player no longer owns. - A worn thing is still owned, so
{ owned: 'clothing:raincoat' }holds while the raincoat is on. - The wardrobe marks one thing as on, never a count. A player with two of a stackable thing wears one, and selling one leaves it on.
- A save made while the game had a slot it has since dropped keeps that slot.
wardrobe.wearing(entity)and the view read only the slots the game declares now, butwardrobe.slotFilledreads the save, so it still holds for the dropped slot, andwardrobe.takeOffempties it.
Last updated on