Extension points
tilttek/journalThe 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 entries | Implement Contract\JournalStoreInterface, and pass it to Journal. |
| Link names to the campaign's world | Implement Contract\PageDirectoryInterface, and pass it to Journal. |
| Draft summaries from the session | Implement Contract\SessionEventSourceInterface, and pass it to Journal. |
| Act on what happened | Implement Contract\JournalObserverInterface, and pass it to Journal. |
| Show an entry | Render the Segments of each BlockView of an EntryView, each block by its kind. |
| Say who may write or read | Check it in the application before calling Journal. |
The store
Contract\JournalStoreInterface keeps the entries, each at a version:
entry()gives one by its identifier, or null;entries()gives those of a journal, in the order they were first kept;countEntries()says how many a journal holds;save()keeps an entry 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, in the same journal.JournalConflictis raised otherwise, nothing kept;delete()erases an entry when the store holds it at its version, and raisesJournalConflictotherwise, nothing erased.
A database store holds the entries in a table indexed on the journal and the order they were first kept, the version
compared in the UPDATE itself, and the blocks with the entry, as JSON or in their own table, each with its
identifier, text, kind, audience, secret, origin and source.
Store\InMemoryJournalStore keeps them in memory, as long as the object lasts: it is for tests.
The directory
Contract\PageDirectoryInterface::resolve() is given a journal, the names the blocks a reader sees mention, each once
as typed, and the reader's snapshot. It returns the identifier of the page of each name the reader sees, by name, and
leaves out the others: a name no page holds and a name whose page the reader may not know read alike. An adapter over
tilttek/campaign-wiki calls Wiki::resolve() for each name with the same snapshot.
The source of events
Contract\SessionEventSourceInterface::events() gives the SessionEvents of a session of a journal, in any order: the
rolls of tilttek/dice, the cards drawn, the quests of tilttek/quests, the loot, the notes taken during the session,
each summed up in one line of text. It gives 200 at most; more are refused. Each event carries the audience and the
secret its block takes.
The observer and its events
Contract\JournalObserverInterface::notify() is told each fact once it is kept, by identifiers only:
| Event | When | Carries |
|---|---|---|
Event\EntryDrafted | An entry was drafted, by hand or assembled from a session. | the entry, the journal |
Event\EntryChanged | Its title, audience, subject or blocks changed, or a block was accepted. | the entry, the journal |
Event\EntryPublished | An entry was published. | the entry, the journal, the genre, the author |
Event\EntryWithdrawn | A published entry went back to a draft. | the entry, the journal |
Event\EntryRemoved | An entry was erased. | the entry, the journal |
Every event implements Event\JournalEventInterface. A change that changes nothing keeps nothing and tells nothing.
No event carries a title or a text: an application sends a message with the identifiers alone — to reward the writer
of a session's summary, to note the pages an entry mentions, to tell the table a summary is out —, and the handler
reads the rest from the store.
Who may do what
Journal does not know who calls it. The application checks before each call that the member may: the author of an
entry and the game master of the campaign write it, accept its blocks, publish, withdraw and remove it, and read
entry() and entries(); every other reader reads through read() and timeline() with their own snapshot. An
application never lets a player hide a block behind a secret they do not know, nor read the entries of another
journal.