Skip to content

The format

tilttek/random-character

A document of creation rules is a YAML or JSON mapping that names the format tilttek-random-character/1. Format\RulesReader reads it into a RulesCatalogue:

use Tilttek\RandomCharacter\Format\RulesReader;
use Tilttek\RandomCharacter\Format\Syntax;

$catalogue = new RulesReader()->load('rules/lanterns.yaml');          // .yaml, .yml or .json
$catalogue = new RulesReader()->parse($text, Syntax::Json);
$catalogue = new RulesReader()->catalogue($decodedDocument);
format: tilttek-random-character/1
system: lanterns
rules:
  - key: lanterns.wanderer
    stats:
      method: rolled-array
      roll: 1d4+1
      attributes: [grit, wits, glow]
    fields:
      - { key: lineage, generator: lanterns.lineage }
      - { key: name, generator: 'lanterns.name.{lineage}' }
      - { key: traits, generator: lanterns.trait, count: 2, unique: true }
      - { key: age, roll: 2d10+14 }

The document

FieldRequiredHolds
formatYestilttek-random-character/1.
systemNoThe system of the rules that do not name theirs.
rulesYesA list of 1 to 1,000 rules.

Rules

FieldRequiredHolds
keyYesThe key of the rules.
systemWhen the document names noneThe key of the system in tilttek/rpg-systems.
statsWhen there are no fieldsThe stats, below.
fieldsWhen there are no statsA list of 1 to 64 fields, below, in the order they are rolled.

Stats

FieldRequiredHolds
methodYeseach, rolled-array or array.
attributesYesA list of 1 to 32 attribute keys of the system.
rollFor each and rolled-arrayThe roll of each value, in a notation of tilttek/dice.
valuesFor arrayOne whole number per attribute.

Fields

FieldRequiredHolds
keyYesThe key of the field.
generatorEither this or rollThe name of the generator, with its placeholders: names.{lineage}.
rollEither this or generatorThe roll, in a notation of tilttek/dice.
countNoHow many values, 1 to 16; 1 by default.
uniqueNoFor a generated field, true for different results; false by default.

Refusals and bounds

Every refusal is an InvalidDocument whose message starts with the place of the field: rules[0].fields[2].count: a whole number is expected., rules[1].stats: the stats of a fixed array have no roll, and one value per attribute. A mapping holds only the fields of its table; YAML tags that build objects and JSON nested 64 levels deep are refused. A document is read up to 1 MiB by default, RulesReader::MAX_BYTES; the constructor takes another bound.

The reader checks what a document says, not what it names: whether the system has the attributes, and whether the generators exist, is checked by CharacterRoller::check() against the application's systems and generators.