Extension points
tilttek/player-knowledgeThe 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 secrets and their revelations | Implement Contract\KnowledgeStoreInterface, and pass it to Knowledge. |
| Act on what happened | Implement Contract\KnowledgeObserverInterface, and pass it to Knowledge. |
| Hide the entries of a page from those who do not know | Read a KnowledgeSnapshot once, and call filter() or knowsAll() for each entry. |
| Say who may reveal, share or read | Check it in the application before calling Knowledge. |
The store
Contract\KnowledgeStoreInterface keeps the secrets, each at a version, and their revelations:
secret()gives one by its identifier, or null;secrets()gives those of a campaign, in the order they were first kept;countSecrets()says how many a campaign holds;save()keeps a secret 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, andKnowledgeConflictis raised otherwise, nothing kept;delete()erases a secret with every revelation of it, when the store holds it at its version, and raisesKnowledgeConflictotherwise, nothing erased;revelationsOf()gives the revelations of a secret, andrevelationsIn()those of a campaign, to the knowers given or to anyone, each in the order they were kept;add()keeps revelations, all or none: one of a secret the store does not hold, or to a knower who holds a revelation of it already, raisesKnowledgeConflict, nothing kept;remove()erases one revelation, and says whether there was one;forget()erases every revelation to a knower, in every campaign, and says how many there were.
Two game masters reveal the same secret to the same character at once: the first add() keeps it, and the second is
refused with KnowledgeConflict. A database store holds a unique key on the secret and the knower's key for this.
Store\InMemoryKnowledgeStore keeps them in memory, as long as the object lasts: it is for tests. An application
keeps them in its database. A secret holds strings, an integer version and its origin, two strings; a revelation holds
strings, a knower — its key — and a moment. revelationsIn() is read at each page: a database store indexes the
revelations by campaign and knower.
The observer and its events
Contract\KnowledgeObserverInterface::notify() is told each fact once it is kept, by identifiers only:
| Event | When | Carries |
|---|---|---|
Event\SecretRecorded | A secret was recorded. | the secret, the campaign |
Event\SecretChanged | Its title or its origin changed. | the secret, the campaign |
Event\SecretRemoved | A secret was erased, with its revelations. | the secret, the campaign |
Event\SecretRevealed | A secret was revealed to knowers who did not know it. | the secret, the campaign, the knowers' keys, the Means |
Event\RevelationRetracted | A revelation was taken back. | the secret, the campaign, the knower's key |
Event\KnowerForgotten | Every revelation to a knower was erased. | the knower's key, how many |
Every event implements Event\KnowledgeEventInterface. 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 push the
revelation to the player's screen, to add it to a session's draft summary —, and the handler reads the rest from the
store.
Who may do what
Knowledge does not know who calls it. The application checks before each call that the member may: the game master
of the campaign records, retitles, removes, reveals, retracts, and reads whoKnows() and the game master's
perspective; the player of a character shares what it knows and reads its perspective; nobody reads the perspective of
another character, by default.