Search by

tilttek / character-sheet

phil

Keep a character sheet that knows its game system: attributes within its bounds, values computed by bounded formulas, equipment, charges, campaign fields.

Package info

github.com/TiltTek/character-sheet

Homepage

pkg:composer/tilttek/character-sheet

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0-alpha 2026-11-29 22:00 UTC

This package is auto-updated.

Last update: 2026-11-30 02:53:28 UTC


README

Character sheets that know their game system: attributes within its bounds, values computed by bounded formulas, equipment, charges, and fields of their own for each campaign.

tilttek/character-sheet keeps a character the way its game system describes it. The system comes from tilttek/rpg-systems: the sheet holds a value for each of its attributes, within the bounds the system sets — Strength from 1 to 20 —, and the rules of the system say what is computed from them.

  • Computed values. The rules of a system derive values by formulas — (str - 10) / 2, 10 + dex_mod + gear.armour, max(1, (8 + con_mod) * level) —: whole numbers, +, -, *, / rounded down, parentheses, abs, min, max and clamp. A formula holds no loop and no call beyond those, so it always ends; it is bounded in length, depth and values, and the rules refuse a formula that reads a name they do not hold or that depends on itself.
  • Equipment. Items with a quantity, equipped or not; an equipped item gives to the stats the formulas read as gear.armour, gear.stealth.
  • Charges. A derived value can be a pool a character spends from — the uses of an ability, spell slots, hit points —, spent and restored, never below 0 left.
  • Portable. A sheet belongs to its owner outside any campaign; it joins campaigns, each of which keeps fields of its own on it — a faction, a downtime count —, erased when the sheet leaves the campaign.
  • Adjustments. A sheet is computed with adjustments to its attributes — what a condition or a spell changes for a while — counted before anything is derived. tilttek/conditions reads the computed values as the statistics of a character, and an inventory's carrying capacity reads them too.

The facts of a sheet — created, changed, joined to a campaign, left, erased — go to an observer, each once, by identifiers only.

It is a plain PHP library: one service, value objects, ports and a store kept in memory for tests. Its one dependency is tilttek/rpg-systems, which describes the game systems.

Status

Part State
Formula: the bounded formulas of the rules, read, computed and written back canonically Implemented and tested
SheetRules, Rules\StaticRuleBook: the derived values and pools of a system, ordered so each comes after what it reads Implemented and tested
CharacterSheet, Item: a sheet, its equipment, its charges spent and its campaign fields, bounded and checked Implemented and tested
SheetCalculator, View\ComputedSheet, View\Pool: a sheet computed by its rules, with adjustments Implemented and tested
CharacterSheets: create, rename, set attributes and level, equipment, charges, campaigns and their fields, erase Implemented and tested
Store\InMemorySheetStore: the store of the tests Implemented and tested
Guided creation and level-up step by step, a Symfony bundle with its Doctrine store and forms Not started

Documentation

Document What it covers
Installation Requirements, installing and wiring.
Sheets Sheets, their rules, equipment, charges, campaigns, adjustments, and reading them from other tools.
Formulas What a formula holds, how it computes, its bounds, and its canonical text.
Extension points The store, the rule book, the observer and its events, and who may do what.
Exceptions CharacterSheetException and its exceptions.
Testing The library's tests, its fuzz target and its benchmarks.
Reference Every type of the library, with its role.

Quick start

use Tilttek\CharacterSheet\CharacterSheets;
use Tilttek\CharacterSheet\Item;
use Tilttek\CharacterSheet\Rules\StaticRuleBook;
use Tilttek\CharacterSheet\SheetRules;

$rules = new SheetRules($lanterns, [                       // a GameSystem of tilttek/rpg-systems
    'str_mod' => '(str - 10) / 2',
    'dex_mod' => '(dex - 10) / 2',
    'defence' => '10 + dex_mod + gear.armour',
    'ki' => 'level',
], pools: ['ki'], maxLevel: 10);

$sheets = new CharacterSheets($store, new StaticRuleBook($rules), $observer);

$sheets->create('sheet-1', 'member-1', 'lanterns', 'Wren', ['str' => 14, 'dex' => 12, 'con' => 10], level: 3);
$sheets->putItem('sheet-1', new Item('mail', 'Chain mail', equipped: true, bonuses: ['armour' => 5]));
$sheets->spend('sheet-1', 'ki');
$sheets->join('sheet-1', 'campaign-7');
$sheets->setField('sheet-1', 'campaign-7', 'faction', 'Lamplighters');

$sheets->compute('sheet-1')->toArray();                    // defence 16, ki 2 of 3 left

Requirements

PHP 8.5 or later, with tilttek/rpg-systems 0.1.

Contributing

Contributions are welcome on the PHIL monorepo: read the contribution guide and the code of conduct. Report a vulnerability privately, as the security policy explains, never in a public issue.

License

MIT, © Philippe Gamache, doing business as Le Gnome Archiviste; a Tilttek project. See LICENSE.