Skip to content

Extension points

tilttek/player-knowledge

The 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.

ToDo
Keep the secrets and their revelationsImplement Contract\KnowledgeStoreInterface, and pass it to Knowledge.
Act on what happenedImplement Contract\KnowledgeObserverInterface, and pass it to Knowledge.
Hide the entries of a page from those who do not knowRead a KnowledgeSnapshot once, and call filter() or knowsAll() for each entry.
Say who may reveal, share or readCheck 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, and KnowledgeConflict is raised otherwise, nothing kept;
  • delete() erases a secret with every revelation of it, when the store holds it at its version, and raises KnowledgeConflict otherwise, nothing erased;
  • revelationsOf() gives the revelations of a secret, and revelationsIn() 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, raises KnowledgeConflict, 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:

EventWhenCarries
Event\SecretRecordedA secret was recorded.the secret, the campaign
Event\SecretChangedIts title or its origin changed.the secret, the campaign
Event\SecretRemovedA secret was erased, with its revelations.the secret, the campaign
Event\SecretRevealedA secret was revealed to knowers who did not know it.the secret, the campaign, the knowers' keys, the Means
Event\RevelationRetractedA revelation was taken back.the secret, the campaign, the knower's key
Event\KnowerForgottenEvery 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.