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');
$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
Rules
Stats
Fields
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.