Extension points
tilttek/character-sheetThe package is at 0.x: its extension points are stable only from its 1.0 release. Until then, a minor version may
change them, and its CHANGELOG says how.
| To | Do |
|---|---|
| Keep the sheets | Implement Contract\SheetStore, and pass it to CharacterSheets. |
| Give the rules of each system | Implement Contract\RuleBook, or pass a Rules\StaticRuleBook, to CharacterSheets. |
| Act on what happened | Implement Contract\SheetObserver, and pass it to CharacterSheets. |
| Compute a sheet without the service | Call SheetCalculator::compute() with the sheet and its rules. |
| Say who may change a sheet | Check it in the application before calling CharacterSheets. |
The store
Contract\SheetStore keeps the sheets, each at a version:
sheet()gives one by its identifier, or null;save()keeps one at the next version and returns it. One at version 0 is new, and the store has none of its identifier; any other is kept only when the store holds it at that version, andSheetConflictis raised otherwise, nothing kept;delete()erases one when the store holds it at its version, and raisesSheetConflictotherwise, nothing erased.
Two tabs change the same sheet and both read version 7: the first save keeps version 8, and the second is refused with
SheetConflict. The change is made again on what is read anew.
Store\InMemorySheetStore keeps them in memory, as long as the object lasts: it is for tests. An application keeps
them in its database. A sheet holds strings, integers and its items — each strings, integers, a boolean and a map of
integers by stat —, its charges spent, a map of integers by pool, and its campaign fields, a map by campaign of maps of
strings, integers and booleans by key. delete() erases the sheet with everything it holds: an application keeps no
copy of it elsewhere, so that a member who asks to erase a character is answered.
The rule book
Contract\RuleBook::rules() gives the SheetRules of a system, or null when the application knows none; a sheet of a
system without rules can be neither created nor computed. The rules hold the system and its parsed formulas: an
application builds them once — from the systems tilttek/rpg-systems reads, and the formulas it keeps in its
configuration — and keeps no state between requests beside them.
The observer and its events
Contract\SheetObserver::notify() is told each fact once the sheet is kept, by identifiers only:
| Event | When | Carries |
|---|---|---|
Event\SheetCreated | A sheet was created. | the owner |
Event\SheetChanged | Its name, an attribute, its level, its equipment, its charges or a campaign field changed. | the Change |
Event\CampaignJoined | The sheet joined a campaign. | the campaign |
Event\CampaignLeft | The sheet left a campaign, whose fields were erased. | the campaign |
Event\SheetDeleted | The sheet was erased. |
Every event implements Event\SheetEvent, whose sheet is an identifier. A change that changes nothing keeps nothing
and tells nothing. SheetChanged says what changed, never its value: an application sends a message with the
identifiers alone, and the handler reads the sheet from the store.
Who may do what
CharacterSheets does not know who calls it. The application checks before each call that the member may: the owner
changes their sheet; the game master of a campaign the sheet joined sets that campaign's fields, and reads the sheet
computed; nobody else does, by default.