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

@ifloom/plugin-generators

Every export of @ifloom/plugin-generators: its signature and its fields.

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

drawEntity

Function. Explained in Generators.

Returns the values a template draws for the nth entity of its kind made in play in this save. The same save, template and n always draw the same values.

The generators/generate effect passes the number the engine's create gives the next entity, so each new entity differs and a replay makes the same ones.

import { drawEntity } from '@ifloom/plugin-generators'
function drawEntity(state: GameState, game: Game, template: TemplateDef, n: number): GeneratedEntity

Uses: GameState, Game, TemplateDef, GeneratedEntity.

FieldDef

Type. Explained in Generators.

A field of a template, which gives one value of a new entity. Each form is told apart by its shape.

The forms are:

  • a fixed value, as written, such as 'visitor', 3 or true
  • { pool: 'first-names' }, one value drawn from a pool by weight
  • { between: [1, 5] }, a whole number from the first to the second, both included
  • { join: [...], with?: ' ' }, several fields drawn and joined into one string, with a space if with is left out
import type { FieldDef } from '@ifloom/plugin-generators'
type FieldDef = KvValue | { pool: string } | { between: [ number, number ] } | { join: FieldDef[]; with?: string }

Uses: KvValue.

GeneratedEntity

Type. Explained in Generators.

The values a template draws for one entity, as drawEntity returns them. They're the fields of the engine's create effect that come from pools and ranges.

import type { GeneratedEntity } from '@ifloom/plugin-generators'
type GeneratedEntity = {
  name?: string
  description?: string
  image?: string
  stats: Record<string, number>
  kv: Record<string, KvValue>
}
FieldTypeOptionalDefaultDescription
namestringyesThe drawn name, left out when the template gives none.
descriptionstringyesThe drawn description, left out when the template gives none.
imagestringyesThe drawn picture's path, left out when the template gives none.
statsRecord<string, number>The drawn stats by id. A field that draws no finite number is left out.
kvRecord<string, KvValue>The drawn kv values by key.

generators

Function. Explained in Generators.

Returns the generators plugin, for the game's plugins. Content declares pools and templates in data.generators.pools and data.generators.templates.

Its helper writes its effect, such as generators.generate('regular').

import { generators } from '@ifloom/plugin-generators'
function generators(): DefinedPlugin<null>

Uses: DefinedPlugin.

HelperSignatureDescription
generators.generate(template: string, count?: number): EffectRefReturns the generators/generate effect, which makes count new entities from the template, 1 if left out.

PoolDef

Type. Explained in Generators.

A pool the game declares in data.generators.pools, a named list of values a template picks from. At least one entry must weigh more than 0.

import type { PoolDef } from '@ifloom/plugin-generators'
type PoolDef = {
  id: string
  values: PoolEntry[]
}
FieldTypeOptionalDefaultDescription
idstringThe pool's id, which a field's { pool } names.
valuesPoolEntry[]The pool's entries, each picked by its weight.

PoolEntry

Type. Explained in Generators.

An entry of a pool, a value or a value with a weight. A bare value, or a weight left out, weighs 1.

import type { PoolEntry } from '@ifloom/plugin-generators'
type PoolEntry = KvValue | { value: KvValue; weight?: number }

Uses: KvValue.

poolsOf

Function. Explained in Generators.

Returns the game's pools, data.generators.pools from its content and packs, in declared order.

import { poolsOf } from '@ifloom/plugin-generators'
function poolsOf(game: Game): PoolDef[]

Uses: Game, PoolDef.

TemplateDef

Type. Explained in Generators.

A template the game declares in data.generators.templates, which makes entities of one kind through the engine's create effect. It needs an of or a like, and a name or a like.

import type { TemplateDef } from '@ifloom/plugin-generators'
type TemplateDef = {
  id: string
  of?: string
  like?: EntityRef
  name?: FieldDef
  description?: FieldDef
  image?: FieldDef
  tags?: string[]
  traits?: Record<string, unknown>
  effects?: EffectRef[]
  stats?: Record<string, FieldDef>
  kv?: Record<string, FieldDef>
}
FieldTypeOptionalDefaultDescription
idstringThe template's id, which generators/generate names.
ofstringyesThe kind of entity the template makes. The like's kind if left out.
likeEntityRefyesThe entity the new ones are made like. The engine reads from it the fields the template doesn't give, such as the name, picture, traits and stats.
nameFieldDefyesThe new entity's name. The like's name if left out.
descriptionFieldDefyesThe new entity's description, drawn as the name is.
imageFieldDefyesThe new entity's picture, a path in the game's art/ folder, drawn as the name is, such as { pool: 'faces' }.
tagsstring[]yesThe new entity's tags, added after its kind's and its like's.
traitsRecord<string, unknown>yesThe new entity's trait data by trait id, over its like's or its kind's, such as { 'cast/person': { home: 'park' } }.
effectsEffectRef[]yesThe effects that run once the new entity is made, with '$' as it, such as [{ receive: '$' }] to hand it to whichever plugin keeps things. Nothing more happens if left out.
statsRecord<string, FieldDef>yesThe new entity's stats by id, each a stat the game declares for the kind. A stat left out reads the like's value, else its start.
kvRecord<string, FieldDef>yesThe new entity's kv keys by name.

templateKind

Function. Explained in Generators.

Returns the kind a template makes, its of, else its like's kind. It's undefined when the template has neither.

import { templateKind } from '@ifloom/plugin-generators'
function templateKind(template: TemplateDef): string | undefined

Uses: TemplateDef.

templatesOf

Function. Explained in Generators.

Returns the game's templates, data.generators.templates from its content and packs, in declared order.

import { templatesOf } from '@ifloom/plugin-generators'
function templatesOf(game: Game): TemplateDef[]

Uses: Game, TemplateDef.

Last updated on

On this page