Skip to content

Extension points

tilttek/spotlight

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 tablesImplement Contract\TableStore, and pass it to Spotlight.
Act on what happenedImplement Contract\SpotlightObserver, and pass it to Spotlight.
Give the timePass a PSR-20 ClockInterface.
Say when a player is behindPass a FairnessPolicy to Spotlight::open().
Say who may give the scene, pause, close, or raise a handCheck it in the application before calling Spotlight.

The store

Contract\TableStore keeps the tables, each at a version:

  • table() 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, and SpotlightConflict is raised otherwise, nothing kept.

Two game masters give the scene at once and both read version 7: the first save keeps version 8, and the second is refused with SpotlightConflict; read anew, the scene is given already.

Store\InMemoryTableStore keeps them in memory, as long as the object lasts: it is for tests. An application keeps them in its database. A table holds strings, integers, booleans, moments, its visibility — an enumeration whose value is its string case — its fairness policy — two integers — its queue of identifiers, and its players, each strings, integers and up to two moments.

The observer and its events

Contract\SpotlightObserver::notify() is told each fact once the table is kept, by identifiers only:

EventWhenCarries
Event\TableOpenedA table was opened.
Event\SceneGivenA player was given the scene.the player
Event\SceneEndedA player's scene ended.the player, the milliseconds counted
Event\HandRaisedA player raised their hand.the player
Event\HandLoweredA player lowered their hand.the player
Event\SpotlightPausedA table was paused.
Event\SpotlightResumedA table counts again.
Event\PlayerJoinedA player joined the table.the player
Event\PlayerLeftA player left the table.the player
Event\TableClosedA table was closed.

Every event implements Event\SpotlightEvent, whose table is an identifier; the events of one player implement Event\PlayerEvent, which adds player. When the scene passes, SceneEnded comes first, then SceneGiven; when the holder leaves, SceneEnded then PlayerLeft; when a table closes, SceneEnded then TableClosed. A call that changes nothing tells nothing. An application sends a message from them — through Messenger, with the identifiers alone — and reads the rest from the store: a push of the view to the game master and of the table's view to the players.

The clock

Spotlight reads the time from the PSR-20 ClockInterface it is given, and from nothing else. Between two calls, nothing happens on its own: the time of the scene in progress is counted when it is read. A clock that goes back counts nothing more, never a negative time.