diff --git a/.ai/rules/models.md b/.ai/rules/models.md index 95560a1..c06e498 100644 --- a/.ai/rules/models.md +++ b/.ai/rules/models.md @@ -81,3 +81,6 @@ Every in-game date is three integer columns (year, month, day) read through Game ## The ledger is ungated, append-only, and summed on every read `ledger_entries` has no visibility column and no `scopeVisibleTo()`: the purse is the party's, every member reads and writes it. Rows are never edited; a mistake is deleted (author or GM) and written again, so there is no update action. The balance is `sum(amount)` over coin rows and the inventory is `LedgerEntry::inventory()` over item rows, grouped by the linked Item page or the case-folded name, computed on every read and never stored. The two links on a row, the session and the Item page, are loaded through `GameSession::visibleTo()` and `Entity::visibleTo()` keyed by id, the clock's way; a member who posts a page id the picker never offered gets the row without the link, silently. The unit is `campaigns.currency`, one label, no rate. + +## The screen is two columns on the campaign, resolved through the strictest gate +campaigns.screen_focus (ScreenFocus) and campaigns.screen_entity_id are scalars on the campaign, not a table: one screen, one thing on it. Campaign::screen() is the one reader: it loads the page through Entity::visibleToParty() (Players only, no Selected, no own-character) and resolves a focus that needs a page and gets none back to null. So a handout the GM took back comes off the wall on the next render with the columns left alone; nothing else writes them, and SetScreen is the one writer. DeleteEntity clears both columns itself, because an entity soft-deletes and nullOnDelete never fires. The export carries both keys and the importer remaps the id after the entities, like active_combatant_id after the combatants. diff --git a/.ai/rules/table.md b/.ai/rules/table.md index db9b120..79dbc44 100644 --- a/.ai/rules/table.md +++ b/.ai/rules/table.md @@ -18,3 +18,6 @@ A player gets a word, never a number — except death saves. A dying character's The exception is to what a visible row CARRIES, never to the gate. Combatant::deathSavesVisibleToPlayers() asks player_visible first, so a hidden row's death saves reach nothing exactly as its hit points do not. healthWord() is untouched: a player still reads "Down", with the pips beside it. A lair action reaches the party as a marker with the count and no words, the way a hidden combatant's turn reaches them without a name. The marker is not a combatants row: it has no hit points, cannot be targeted, and a fake row would reach RollInitiative, ApplyDamage and the export. Encounter::lairMarkerIndex() places it where it would fall if position and initiative were sorted together. + +## The screen reads under the party's gate, whoever opened it +Table\Screen is the page on the television at the end of the table. The GM opens it on the laptop that feeds the wall, so the viewer is a GM and the page must still show only what the whole party may see. Every read there goes through a gate that takes no user and no role: Combatant::visibleToPlayers(), Clock::visibleTo(Player), Entity::visibleToParty(), MapMarker::visibleToParty(). There is no isDm() branch in the component or the Blade, and the snapshot test holds that a hidden handout the columns name never reaches the payload. A new thing on the screen gets a user-free gate first, or it does not go on the screen. diff --git a/README.md b/README.md index 47c2460..bd0b6d4 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,8 @@ Slice 22 adds **Continue with Discord**. A button on the login and register page Slice 23 adds **a ceiling on a campaign's files**. `CAMPAIGN_STORAGE_MB`, 500 by default, is one limit for every campaign on the install, over its cover, every image, and every handout file. An upload that would cross it is refused on the form with the numbers in the sentence, an archive import stops attaching files at the ceiling and says how many it left before the GM commits, and campaign settings shows a bar of what is used. Zero turns it off. +Slice 24 adds **the player screen**, for the television at the end of the table. `/screen` is one page with no sidebar and no controls that shows what the whole party may see and nothing else, whoever opened it: the turn order with health as a word, a handout full size, a map with the pins the party found, or the revealed clocks, with the clocks in a strip along the bottom the rest of the time. The GM chooses from a card on the Run screen, and putting a hidden handout up shows the party on the way. It changes on every open screen at once over the same channel as the table, and it falls back on its own: to the fight while one runs, then to the campaign's name and the party. + Your creatures travel in your export with the prose you wrote. A shipped creature never does — it is named in the file and nothing more, exactly as before. The CC BY notice follows the words rather than the table: a creature you wrote carries none, and a copy of a shipped one keeps the source and licence it came from, so the credit travels with the text. ## Local setup diff --git a/app/Actions/Campaigns/ExportCampaign.php b/app/Actions/Campaigns/ExportCampaign.php index 56cc7d1..9ac22be 100644 --- a/app/Actions/Campaigns/ExportCampaign.php +++ b/app/Actions/Campaigns/ExportCampaign.php @@ -219,6 +219,8 @@ private function campaign(Campaign $campaign): array 'session_length_minutes' => $campaign->session_length_minutes, 'reminder_lead_hours' => $campaign->reminder_lead_hours, 'currency' => $campaign->currency, + 'screen_focus' => $campaign->screen_focus?->value, + 'screen_entity_id' => $campaign->screen_entity_id, 'created_at' => $campaign->created_at?->toIso8601String(), 'updated_at' => $campaign->updated_at?->toIso8601String(), 'cover' => $this->media($campaign->getFirstMedia('cover')), diff --git a/app/Actions/Campaigns/ImportCampaign.php b/app/Actions/Campaigns/ImportCampaign.php index d3a02a1..70d00bd 100644 --- a/app/Actions/Campaigns/ImportCampaign.php +++ b/app/Actions/Campaigns/ImportCampaign.php @@ -93,6 +93,7 @@ public function handle(array $document, User $importer, array $restored = []): C $this->decisions($document, $campaign, $importer, $ids); $this->ledger($document, $campaign, $importer, $ids); $this->reputation($document, $campaign, $importer, $ids); + $this->screen($document, $campaign, $ids); }); // One index at the end rather than a write per entity. Chunked, so a @@ -505,6 +506,26 @@ private function prepped(array $document, IdMap $ids): void } } + /** + * What the screen on the wall shows, written after the page it names exists. The + * focus travels as it is; the page is remapped like every other id. + * + * @param array $document + */ + private function screen(array $document, Campaign $campaign, IdMap $ids): void + { + $attributes = $document['campaign']; + + if ($attributes['screen_focus'] === null && $attributes['screen_entity_id'] === null) { + return; + } + + $campaign->forceFill([ + 'screen_focus' => $attributes['screen_focus'], + 'screen_entity_id' => $ids->newForNullable($attributes['screen_entity_id']), + ])->save(); + } + /** * Encounters, their combatants, and then whose turn it is. active_combatant_id * carries no foreign key and is filled last, because it points at a row this same diff --git a/app/Actions/Campaigns/ReadCampaignFile.php b/app/Actions/Campaigns/ReadCampaignFile.php index f50d519..85b4868 100644 --- a/app/Actions/Campaigns/ReadCampaignFile.php +++ b/app/Actions/Campaigns/ReadCampaignFile.php @@ -10,6 +10,7 @@ use App\Enums\PrepRole; use App\Enums\QuestStatus; use App\Enums\Ruleset; +use App\Enums\ScreenFocus; use App\Enums\SessionStatus; use App\Enums\Visibility; use App\Models\Calendar; @@ -159,6 +160,8 @@ private function campaign(array $row): array 'session_length_minutes' => min(720, max(30, $this->integer($row, 'session_length_minutes') ?? 240)), 'reminder_lead_hours' => $this->reminderLead($row), 'currency' => $this->text($row, 'currency', Campaign::MAX_CURRENCY_LENGTH) ?? 'gp', + 'screen_focus' => $this->screenFocus($row), + 'screen_entity_id' => $this->reference($row, 'screen_entity_id'), 'cover' => $this->mediaReference($row['cover'] ?? null), 'calendar' => $this->calendar($row['calendar'] ?? null), ]; @@ -288,6 +291,22 @@ private function calendar(mixed $value): ?array ]; } + /** + * What the screen on the wall shows, or null. Absent from a file older than slice + * 24, and null is what that means; a value this demgem does not know is an error, + * as every other enum in the file is. + * + * @param array $row + */ + private function screenFocus(array $row): ?ScreenFocus + { + if (! isset($row['screen_focus'])) { + return null; + } + + return $this->enum(ScreenFocus::class, $row, 'screen_focus', 'the screen'); + } + /** * Only the values the settings screen offers. Anything else means off, which is * the hidden direction for a feature that sends email. @@ -1036,6 +1055,8 @@ private function checkReferences(array $document): void } } + $this->mustResolve($document['campaign']['screen_entity_id'], $this->entityIds, 'page', 'the screen'); + foreach ($entities as $entity) { $this->mustResolve($entity['parent_id'], $this->entityIds, 'entity', "the parent of \"{$entity['name']}\""); $this->mustResolve($entity['giver_entity_id'], $this->entityIds, 'entity', "the giver of \"{$entity['name']}\""); diff --git a/app/Actions/Entities/DeleteEntity.php b/app/Actions/Entities/DeleteEntity.php index c51f7eb..0d9e66d 100644 --- a/app/Actions/Entities/DeleteEntity.php +++ b/app/Actions/Entities/DeleteEntity.php @@ -2,6 +2,7 @@ namespace App\Actions\Entities; +use App\Models\Campaign; use App\Models\Entity; use Illuminate\Support\Facades\DB; @@ -24,6 +25,13 @@ public function handle(Entity $entity): void $entity->sessionsInArc()->update(['arc_id' => null]); } + // The screen on the wall. nullOnDelete never fires for a soft delete, so the + // columns are cleared here, the way an arc's quests are unfiled above. + Campaign::query() + ->whereKey($entity->campaign_id) + ->where('screen_entity_id', $entity->id) + ->update(['screen_focus' => null, 'screen_entity_id' => null]); + $entity->delete(); }); } diff --git a/app/Actions/Table/SetScreen.php b/app/Actions/Table/SetScreen.php new file mode 100644 index 0000000..e2778ec --- /dev/null +++ b/app/Actions/Table/SetScreen.php @@ -0,0 +1,80 @@ +type); + + if ($focus === null) { + throw new InvalidArgumentException('Only a handout or a map goes on the screen.'); + } + + if ($page->campaign_id !== $campaign->id) { + throw new InvalidArgumentException('That page belongs to another campaign.'); + } + + if ($page->isHandout()) { + if ($page->visibility === Visibility::Dm) { + $page = $this->revealHandout->show($page, $actor); + } + } elseif ($page->visibility !== Visibility::Players) { + throw new InvalidArgumentException('The party cannot see that map.'); + } + + $this->write($campaign, $focus, $page->id); + } + + /** + * The fight, the clocks, or nothing. Any page on the screen comes down. + * + * @throws InvalidArgumentException for a focus that needs a page; that is show(). + */ + public function focus(Campaign $campaign, ?ScreenFocus $focus): void + { + if ($focus?->needsPage()) { + throw new InvalidArgumentException('A handout or a map goes on the screen through show().'); + } + + $this->write($campaign, $focus, null); + } + + private function write(Campaign $campaign, ?ScreenFocus $focus, ?string $entityId): void + { + $campaign->forceFill([ + 'screen_focus' => $focus, + 'screen_entity_id' => $entityId, + ])->save(); + + ScreenChanged::dispatch($campaign->id); + } +} diff --git a/app/Enums/ScreenFocus.php b/app/Enums/ScreenFocus.php new file mode 100644 index 0000000..d53be0a --- /dev/null +++ b/app/Enums/ScreenFocus.php @@ -0,0 +1,46 @@ + 'The fight', + self::Clocks => 'The clocks', + self::Handout => 'A handout', + self::Map => 'A map', + }; + } + + public function needsPage(): bool + { + return match ($this) { + self::Handout, self::Map => true, + self::Fight, self::Clocks => false, + }; + } + + public static function forPage(EntityType $type): ?self + { + return match ($type) { + EntityType::Handout => self::Handout, + EntityType::Map => self::Map, + default => null, + }; + } +} diff --git a/app/Events/ScreenChanged.php b/app/Events/ScreenChanged.php new file mode 100644 index 0000000..8267008 --- /dev/null +++ b/app/Events/ScreenChanged.php @@ -0,0 +1,51 @@ + + */ + public function broadcastOn(): array + { + return [new PresenceChannel('campaign.'.$this->campaignId)]; + } + + public function broadcastAs(): string + { + return 'screen.changed'; + } + + /** + * @return array{} + */ + public function broadcastWith(): array + { + return []; + } +} diff --git a/app/Livewire/Table/Screen.php b/app/Livewire/Table/Screen.php new file mode 100644 index 0000000..6d7da8a --- /dev/null +++ b/app/Livewire/Table/Screen.php @@ -0,0 +1,159 @@ +enterCampaign($campaign); + } + + #[On('echo-presence:campaign.{campaign.id},.screen.changed')] + public function screenChanged(): void + { + // Deliberately empty. The re-render is the point, and it reads the columns + // through the party's gate. + } + + #[On('echo-presence:campaign.{campaign.id},.encounter.changed')] + public function encounterChanged(): void + { + // Deliberately empty. The re-render is the point. + } + + #[On('echo-presence:campaign.{campaign.id},.clock.changed')] + public function clockChanged(): void + { + // Deliberately empty. The re-render is the point. + } + + #[On('echo-presence:campaign.{campaign.id},.handout.revealed')] + public function handoutRevealed(): void + { + // Deliberately empty. The re-render is the point. + } + + #[On('echo-presence:campaign.{campaign.id},.map.changed')] + public function mapChanged(): void + { + // Deliberately empty. The re-render is the point. + } + + public function render(): View + { + $state = $this->campaign->screen(); + $focus = $state->focus; + $page = $state->entity; + + // A focus of the fight with no fight, and no focus at all, both fall to + // whatever is true: the fight while one runs, then the idle state. + $fight = null; + + if ($focus === null || $focus === ScreenFocus::Fight) { + $fight = $this->activeEncounter(); + $focus = $fight === null ? null : ScreenFocus::Fight; + } + + $clocks = $this->campaign->clocks()->visibleTo(CampaignRole::Player)->get(); + + return view('livewire.table.screen', [ + 'focus' => $focus, + 'page' => $page, + 'fight' => $fight, + 'combatants' => $fight === null ? new Collection : $this->combatants($fight), + 'file' => $focus === ScreenFocus::Handout ? $page?->files()->first() : null, + 'markers' => $focus === ScreenFocus::Map && $page !== null ? $this->markers($page) : new Collection, + 'clocks' => $clocks, + 'party' => $focus === null ? $this->party() : new Collection, + 'deathSaves' => Combatant::DEATH_SAVES, + 'pollSeconds' => self::POLL_SECONDS, + ])->title('The screen'); + } + + /** + * The fight on the table right now, as Table\Show finds it. + */ + private function activeEncounter(): ?Encounter + { + return Encounter::query() + ->where('status', EncounterStatus::Active) + ->orderByDesc('updated_at') + ->first(); + } + + /** + * The party's rows and nothing else, whoever is looking. There is no GM branch. + * + * @return Collection + */ + private function combatants(Encounter $encounter): Collection + { + return $encounter->combatants()->visibleToPlayers()->get(); + } + + /** + * The pins the party found, with a target the whole party may see. + * + * @return Collection + */ + private function markers(Entity $map): Collection + { + return MapMarker::query() + ->where('entity_id', $map->id) + ->visibleToParty() + ->with('target') + ->get(); + } + + /** + * @return Collection + */ + private function party(): Collection + { + return Entity::query() + ->ofType(EntityType::Character) + ->visibleToParty() + ->where('is_pc', true) + ->orderBy('name') + ->get(); + } +} diff --git a/app/Livewire/Table/ScreenControls.php b/app/Livewire/Table/ScreenControls.php new file mode 100644 index 0000000..4cecf23 --- /dev/null +++ b/app/Livewire/Table/ScreenControls.php @@ -0,0 +1,154 @@ +enterCampaign($campaign); + } + + #[On('echo-presence:campaign.{campaign.id},.screen.changed')] + public function screenChanged(): void + { + // Deliberately empty. A co-GM on a second device changed it; re-render. + } + + #[On('echo-presence:campaign.{campaign.id},.handout.revealed')] + public function handoutRevealed(): void + { + // Deliberately empty. The labels say which handouts are hidden. + } + + #[On('echo-presence:campaign.{campaign.id},.encounter.changed')] + public function encounterChanged(): void + { + // Deliberately empty. Whether "The fight" is offered depends on it. + } + + /** + * A handout or a map. A hidden map is a 404 here, the way a hidden page is + * everywhere: the query never offered it, so a posted id for one is a guess. + */ + public function showPage(string $pageId, SetScreen $setScreen): void + { + $this->authorize('useGmTools', $this->campaign); + + $page = Entity::query() + ->whereKey($pageId) + ->where(function (Builder $query): void { + $query->where(fn (Builder $handout) => $handout->ofType(EntityType::Handout)) + ->orWhere(fn (Builder $map) => $map->ofType(EntityType::Map)->visibleToParty()); + }) + ->first(); + + abort_if($page === null, 404); + + $setScreen->show($this->campaign, $page, $this->user()); + } + + public function focus(string $focus, SetScreen $setScreen): void + { + $this->authorize('useGmTools', $this->campaign); + + $case = ScreenFocus::tryFrom($focus); + + abort_if($case === null || $case->needsPage(), 404); + + $setScreen->focus($this->campaign, $case); + } + + public function clear(SetScreen $setScreen): void + { + $this->authorize('useGmTools', $this->campaign); + + $setScreen->focus($this->campaign, null); + } + + public function render(): View + { + $canManage = $this->isDm(); + $state = $this->campaign->screen(); + + return view('livewire.table.screen-controls', [ + 'canManage' => $canManage, + 'focus' => $state->focus, + 'page' => $state->entity, + 'handouts' => $canManage ? $this->handouts() : new Collection, + 'maps' => $canManage ? $this->maps() : new Collection, + 'hasFight' => Encounter::query()->where('status', EncounterStatus::Active)->exists(), + 'hasClocks' => $this->campaign->clocks()->visibleTo(CampaignRole::Player)->exists(), + // The backstop the panels keep: a handout taken back from the panel beside + // this card changes what this card says, and without a socket the poll + // is what catches it. + 'pollSeconds' => self::POLL_SECONDS, + ]); + } + + /** + * @return Collection + */ + private function handouts(): Collection + { + return Entity::query()->ofType(EntityType::Handout)->orderBy('name')->get(); + } + + /** + * The maps with a picture the party may see. The picture check is in PHP over a + * short list: a campaign has a handful of maps, not a thousand. + * + * @return Collection + */ + private function maps(): Collection + { + return Entity::query() + ->ofType(EntityType::Map) + ->visibleToParty() + ->with('media') + ->orderBy('name') + ->get() + ->filter(fn (Entity $map) => $map->imageUrl() !== null) + ->values(); + } + + private function user(): User + { + /** @var User $user */ + $user = auth()->user(); + + return $user; + } +} diff --git a/app/Models/Campaign.php b/app/Models/Campaign.php index 156ef0f..c5ff29e 100644 --- a/app/Models/Campaign.php +++ b/app/Models/Campaign.php @@ -4,6 +4,8 @@ use App\Enums\CampaignRole; use App\Enums\Ruleset; +use App\Enums\ScreenFocus; +use App\Support\Table\ScreenState; use Database\Factories\CampaignFactory; use Illuminate\Database\Eloquent\Attributes\Fillable; use Illuminate\Database\Eloquent\Concerns\HasUlids; @@ -20,7 +22,9 @@ use Spatie\MediaLibrary\MediaCollections\Models\Media; /** - * @property string $id + * @property string|null $discord_webhook_url Decrypted on read. Never exported. + * @property ScreenFocus|null $screen_focus + * @property string|null $screen_entity_id * @property string $name * @property string|null $description * @property Ruleset $ruleset @@ -61,6 +65,7 @@ protected function casts(): array { return [ 'ruleset' => Ruleset::class, + 'screen_focus' => ScreenFocus::class, 'session_length_minutes' => 'integer', 'reminder_lead_hours' => 'integer', 'discord_webhook_url' => 'encrypted', @@ -172,6 +177,37 @@ public function calendar(): HasOne return $this->hasOne(Calendar::class); } + /** + * What the television at the end of the table shows, resolved through the party's + * gate. The page is read with Entity::visibleToParty(), the strictest gate in the + * app, whoever is asking: a GM who opens the screen on the laptop that feeds the + * wall reads exactly what a player reads. A focus that needs a page and gets none + * back resolves to null, so a handout the GM took back comes off the wall on the + * next render with the columns left as they are. + */ + public function screen(): ScreenState + { + $focus = $this->screen_focus; + + if ($focus === null) { + return ScreenState::nothing(); + } + + if (! $focus->needsPage()) { + return new ScreenState($focus, null); + } + + $page = $this->screen_entity_id === null + ? null + : Entity::query()->visibleToParty()->whereKey($this->screen_entity_id)->first(); + + if ($page === null || ScreenFocus::forPage($page->type) !== $focus) { + return ScreenState::nothing(); + } + + return new ScreenState($focus, $page); + } + public function registerMediaCollections(): void { $this->addMediaCollection('cover')->singleFile()->useDisk(config('media-library.disk_name')); diff --git a/app/Models/Entity.php b/app/Models/Entity.php index eb7ff41..d79fa0d 100644 --- a/app/Models/Entity.php +++ b/app/Models/Entity.php @@ -520,6 +520,20 @@ public function scopeVisibleTo(Builder $query, User $user, CampaignRole $role): }); } + /** + * The strictest gate in the app: what the whole party may see, with no user in + * the question. Players only. Not Selected, which names some of the party, and + * not "my own character", which names one. It is the gate for the screen on the + * wall, where the viewer is whoever plugged the laptop in. + * + * @param Builder $query + * @return Builder + */ + public function scopeVisibleToParty(Builder $query): Builder + { + return $query->where($query->qualifyColumn('visibility'), Visibility::Players->value); + } + public function isVisibleTo(User $user, CampaignRole $role): bool { if ($role->isDm() || $this->player_user_id === $user->id) { diff --git a/app/Models/MapMarker.php b/app/Models/MapMarker.php index 434d821..e0a596d 100644 --- a/app/Models/MapMarker.php +++ b/app/Models/MapMarker.php @@ -113,6 +113,27 @@ public function scopeVisibleTo(Builder $query, User $user, CampaignRole $role): }); } + /** + * The party's map with no player in the question: the GM's eye, and a target the + * whole party may see. The same two gates as scopeVisibleTo() for a player, with + * Entity::visibleToParty() as the second. For the screen on the wall. + * + * @param Builder $query + * @return Builder + */ + public function scopeVisibleToParty(Builder $query): Builder + { + return $query + ->where($query->qualifyColumn('player_visible'), true) + ->where(function (Builder $gate): void { + $gate->whereNull($gate->qualifyColumn('target_entity_id')) + ->orWhereIn( + $gate->qualifyColumn('target_entity_id'), + Entity::query()->visibleToParty()->select('entities.id'), + ); + }); + } + /** * Whether the party sees this pin at all, before the target's own rule applies. */ diff --git a/app/Support/Table/ScreenState.php b/app/Support/Table/ScreenState.php new file mode 100644 index 0000000..29847ff --- /dev/null +++ b/app/Support/Table/ScreenState.php @@ -0,0 +1,27 @@ +string('screen_focus', 16)->nullable()->after('currency'); + $table->foreignUlid('screen_entity_id')->nullable()->after('screen_focus') + ->constrained('entities')->nullOnDelete(); + }); + } + + public function down(): void + { + Schema::table('campaigns', function (Blueprint $table) { + $table->dropConstrainedForeignId('screen_entity_id'); + $table->dropColumn('screen_focus'); + }); + } +}; diff --git a/database/seeders/DemoCampaignSeeder.php b/database/seeders/DemoCampaignSeeder.php index 5522f87..6f4b670 100644 --- a/database/seeders/DemoCampaignSeeder.php +++ b/database/seeders/DemoCampaignSeeder.php @@ -39,6 +39,7 @@ use App\Actions\Sessions\RecordAttendance; use App\Actions\Sessions\RespondToSession; use App\Actions\Sessions\ToggleDateVote; +use App\Actions\Table\SetScreen; use App\Enums\CampaignRole; use App\Enums\EntityType; use App\Enums\PrepRole; @@ -837,6 +838,10 @@ private function seedHandouts(Campaign $campaign, User $dm): void $this->attachPlaceholderScan($letter, "The duke's letter", 900, 1200); $this->attachPlaceholderScan($orders, 'The sealed orders', 900, 1200); + + // The letter is on the television, so /screen has something on it on the + // first run. It is already revealed, so nothing changes hands here. + app(SetScreen::class)->show($campaign, $letter, $dm); } /** diff --git a/docs/plans/2026-09-13-feat-player-screen-plan.md b/docs/plans/2026-09-13-feat-player-screen-plan.md new file mode 100644 index 0000000..d43acd4 --- /dev/null +++ b/docs/plans/2026-09-13-feat-player-screen-plan.md @@ -0,0 +1,174 @@ +--- +title: "feat: The player screen, for the television at the end of the table" +type: feat +date: 2026-09-13 +status: implemented +brainstorm: docs/brainstorms/2026-09-02-demgem-campaign-manager-brainstorm.md +follows: docs/plans/2026-09-11-feat-storage-quotas-plan.md +--- + +# feat: The player screen, for the television at the end of the table + +## Overview + +The brainstorm's GM table has one P3 row about a second display: "push an image or map to a second display". Slice 5 built `/table`, the page a player keeps open on their own device. This slice builds the page a GM puts on the television: what the whole party may see, nothing else, chosen from the Run screen and changed on every screen at once. + +| Feature | What it adds | +|---|---| +| `/screen` | One route, one page, no sidebar. It shows the fight as the party sees it, a handout, a map with the pins the party found, or the revealed clocks. Every member may open it. | +| The GM's choice | A card on the Run screen: put a handout or a map on the screen, show the fight, show the clocks, or clear it. One press. | +| The live part | A new event, `ScreenChanged`, on the campaign's presence channel, with the four events the table already has. The screen re-renders on each and polls as a backstop. | +| The round trip | The two columns travel in the campaign section of the export, and the importer remaps the one that is an id. | + +When this slice is done a GM running session 3 presses "On the screen" beside the duke's letter, and the television at the end of the table shows the letter, full size, with its name under it. The GM presses "The fight" and the television shows the turn order with health as a word. A player who opens `/screen` on a tablet sees exactly the same page. + +**On scope.** Phase 0 is the state: the two columns, the action, the event. Phase 1 is the screen. Phase 2 is the card on the Run screen. Phase 3 is the export, the seeder, the rules, and the pass. + +## Problem Statement + +**`/table` is a page for one person's hands, not a wall.** It carries the dice tray, the party list, and the last recap, in the type size of a form. A television across a room needs one thing at a time, large, with no controls on it. A GM who plugs a laptop into a screen today shows the party the Run screen, which is the one page they must never see. + +**A handout has a gallery, and a gallery is not a display.** "Show the party" puts the letter on every player's own device inside a card of ten. At a physical table the players are looking at one wall, and the GM wants the letter on it, alone. + +**The turn order the party may read already exists, and nobody can see it from six feet.** `Table\Fight` renders the party's view under a query gate. The television needs that same query and a different sheet of Blade. + +## Proposed Solution + +**The screen is two columns on the campaign, and both are scalars.** `campaigns.screen_focus` says what kind of thing is up: the fight, the clocks, a handout, or a map. `campaigns.screen_entity_id` names the handout or map. A campaign has one screen, one focus, one page on it, so by the models rule these are columns and not a table. The importer remaps the id and the export carries both. + +**What the screen shows is decided in the query, under the party's gate, whoever opened it.** The GM opens `/screen` on the laptop that feeds the television, so the GM is the viewer, and the page must still show what the party may see. Every read on the screen goes through a gate that takes no user and no role: combatants through `Combatant::visibleToPlayers()`, clocks through `Clock::visibleTo(Player)`, the handout and the map through a new `Entity::visibleToParty()`, and the pins through a new `MapMarker::visibleToParty()`. That last gate is the strictest one in the app: `Players` only, no `Selected`, no "my own character". A television is not one player. When a GM takes a handout back, the column still names it and the screen shows nothing, because the gate said so. + +**The choice reuses "Show the party".** Putting a hidden handout on the screen goes through `RevealHandout::show()` first, so it is revealed on every player's device the same moment it lands on the wall. A map is offered only when the party may already see it and it has an image. + +**The event carries nothing.** `ScreenChanged` broadcasts the campaign id on the campaign's presence channel and no payload at all. The screen re-renders and reads its own state. It also listens to `encounter.changed`, `clock.changed`, `handout.revealed`, and `map.changed`, because each of those changes what the wall should say. + +**Focus falls back on its own.** A focus of the fight with no fight running shows the idle state: the campaign's name and the party. A focus of a handout whose row is gone, or hidden, shows the same. A null focus shows the fight while one is active, then the idle state. The revealed clocks sit in a strip at the bottom whenever the focus is not the clocks and at least one is revealed. + +## Technical Approach + +### No new dependency + +Reverb, Echo, Livewire, and Alpine are all installed. The map viewer's pan and zoom is `resources/js/map.js`, and the screen reuses it with `canEdit: false`. + +### What slices 1 to 23 give us for free + +| Piece | Reuse | +|---|---| +| `Table\Show` and `Table\Fight` | The listener shape, the sixty-second poll, and the query gates. | +| `RevealHandout` | The reveal, through `UpdateEntity` so the observers run. | +| `Combatant::healthWord()`, `Encounter::lairMarkerIndex()` | The party's reading of a row and where the lair marker sits. | +| `mapViewer()` and `x-ui.map-pin` | The image, the transform, and the pins. | +| `x-ui.clock` | The dial. | +| `EncounterChanged`, `MapChanged`, `ClockChanged`, `HandoutRevealed` | The four events the screen listens to beside its own. | +| `DeleteEntity` | Already nulls an arc's columns on soft delete. It nulls the screen's the same way. | + +### The data + +``` +campaigns + screen_focus string(16) nullable fight | clocks | handout | map + screen_entity_id ulid nullable -> entities, nullOnDelete, indexed +``` + +`ScreenFocus` is a backed enum with four cases. `Campaign::screen()` returns a `ScreenState`: the focus as stored, the entity read through the party gate, and the focus resolved to null when the focus needs an entity and the gate returned none. + +### Scope and decisions + +| Question | Decision | +|---|---| +| Who may open `/screen` | Every member, as `/table`. A non-member gets 404. | +| Whose gate | The party's, always. The viewer's role never widens what the screen shows. A GM who opens it reads exactly what a player reads. | +| `Selected` | Never on the screen. A handout shared with two players is not on the wall. | +| A hidden handout put on the screen | Revealed first, through `RevealHandout`. Taking it back later hides it from the screen through the gate, and the columns are left alone. | +| A map put on the screen | Only a map the party may see, with an image. The pins are the ones the party found. No reveal on the way, because a map's visibility is a form decision. | +| The fight | The active encounter, as `Table\Show` finds it. No "You" badge, no numbers, no names for hidden turns. Death saves show, by the table rule. | +| The clocks | The revealed ones, in a strip when something else is up, large when they are the focus. | +| Deleting the page on the screen | `DeleteEntity` nulls both columns. Soft delete never fires `nullOnDelete`. | +| The layout | A new `layouts::screen`: no sidebar, no header, no search. The theme script and the Echo settings stay, because the page is live. | +| The poll | Sixty seconds, `wire:poll.visible`, the table's backstop. | +| The payload | `ScreenChanged` carries no keys. The listener reads the row. | +| Who may set the screen | `useGmTools`, the existing gate for the tracker and the tables. | +| The API | None. Like a clock. | +| The vault | Nothing. The screen is state, not lore. | + +### Actions + +| Action | Does | +|---|---| +| `Table\SetScreen::show(Campaign, Entity)` | A handout or a map. Reveals a hidden handout. Writes both columns. Dispatches the event. | +| `Table\SetScreen::focus(Campaign, ?ScreenFocus)` | The fight, the clocks, or null. Clears the entity. Dispatches the event. | + +### Screens + +- **`/screen`** is `Table\Screen`, on the new layout. The campaign's name in the corner, the focus in the middle, the clock strip at the bottom. Type sizes are for a wall. +- **The Run screen** gains an "On the screen" card, `Table\ScreenControls`: what is up now, four buttons, every handout with "On the screen", every party-visible map with an image with "On the screen", and a link that opens the screen in a new tab. +- **`/table`** gains a link to the screen in its header. + +### The round trip + +- The campaign section gains `screen_focus` and `screen_entity_id`. The reader accepts absent keys from an older file, refuses a focus it does not know, and refuses an entity the file does not carry. The importer writes both after the entities, the way `active_combatant_id` is written after the combatants. +- `RoundTripTest` drops `screen_entity_id` with the other remapped ids and compares `screen_focus` in full. +- No version bump. + +## Verification + + php artisan test --compact tests/Feature/Table + php artisan test --compact --filter=Screen + php artisan test --compact --filter=RoundTrip + php artisan test --compact --filter=DemoSeeder + vendor/bin/pint --dirty --format agent + vendor/bin/phpstan analyse + +Then the full suite with `memory_limit=1G`, and a browser pass: open the Run screen for session 3 as the GM and `/screen` in a second tab; put the duke's letter up and read it on the screen; show the fight and read the party's turn order with no numbers; open `/screen` as the player and read the same page; take the letter back and watch the screen fall to the idle state. + +## Open Questions + +1. **Should the screen carry the dice log?** A wall that shows every roll is a nice thing at some tables. Recommendation: not now. The focus list is four things, and a roll is a moment rather than a state. +2. **Should a handout with several files page through them on the screen?** Recommendation: the first file, full size, this slice. A second press for the next file is a small follow-up. +3. **Should the screen have a "session" line?** Recommendation: no. The screen is the campaign's, and a session's name is often a spoiler. + +## References + +- `.ai/rules/table.md` — the gate is in the query, never the Blade. The screen adds the strictest form of that gate. +- `.ai/rules/events.md` — broadcast the fact, never the data, and always `ShouldRescue`. +- `.ai/rules/models.md` — a handout is revealed by its visibility column and nothing else; the screen reads that column and adds no second switch. +- `.ai/rules/routes.md` — `/screen` is singular and sits above the `{type}` routes, like `/table`. +- `.ai/rules/campaigns.md` — an added key does not bump the export version. + +## Implementation Results — 2026-09-13 + +Implemented in full. 28 new tests; the suite is 1422 tests, 1421 passing, 1 skipped, with Larastan clean and Pint clean. + +### What shipped, against the plan + +| Planned | Shipped | +|---|---| +| Two columns on the campaign | As planned: `screen_focus` and `screen_entity_id`, with `ScreenFocus` as a backed enum and `Campaign::screen()` returning a `ScreenState` resolved through the party's gate. | +| The party's gate, whoever opened it | `Entity::visibleToParty()` and `MapMarker::visibleToParty()`, both user-free. `Table\Screen` has no `isDm()` branch at all, and the snapshot test holds that a hidden handout the columns name never reaches the payload. | +| `SetScreen` | As planned. `show()` reveals a hidden handout through `RevealHandout` and refuses a map the party may not see; `focus()` refuses a focus that needs a page. | +| `ScreenChanged` | As planned, with an empty payload. | +| `/screen` on its own layout | `layouts::screen`: no sidebar, no header, no search. The four focuses, the idle state, and the clock strip. | +| The card on the Run screen | `Table\ScreenControls`, at the top of the aside beside the secrets. Every handout, every party-visible map with a picture, the two focus buttons, clear, and a link that opens the screen in a new tab. | +| The round trip | Both keys in the campaign section; the reader accepts absent keys and refuses an unknown focus or a page the file does not carry; the importer writes both after the entities. | +| The demo world | The duke's letter is on the screen on first run, and the seeder test opens `/screen` and `/table`. | + +### Deviations + +| Planned | Shipped | Why | +|---|---|---| +| No poll on the controls card | A sixty-second poll, like every panel | The browser pass took a handout back from the panel beside the card, and with no socket the card kept saying the letter was up. The poll is the same backstop the panels keep. | +| The handout at 78vh, the map at 82vh | 62vh and 68vh | At 1024×768 the clock strip fell below the fold. The strip is the part a table glances at, so it has to be on the screen. | + +### Not done + +- The `public/storage` link was missing on this machine, so the first screenshot showed a broken image. `php artisan storage:link` fixed it. That is the environment, not the slice, and nothing in the repo changed for it. + +### Browser checks + +Driven end to end on the seeded world at 1400px as the GM and 1024px as the player, with `BROADCAST_CONNECTION=null`, so every change was read on the next load rather than pushed: + +- The Run screen for session 3 shows the "On the screen" card with the two handouts, the two maps, "The fight", "The clocks", and the link. +- "On the screen" beside the duke's letter puts the letter on `/screen`, full size with its name under it and the two revealed clocks in the strip. The player's `/screen` shows the same page. +- "The fight" puts the turn order up: round, whose turn, four rows the party may see, health as words, the hidden thralls absent, no numbers anywhere, read from the GM's own session. +- The Duchy of Vell on the screen shows the four pins the party found and neither of the two hidden ones, which the GM's own map page shows in purple. +- "Take it back" on the letter while it is up drops the screen to the fight on the next load, with the columns still naming the letter. diff --git a/resources/views/components/ui/icon.blade.php b/resources/views/components/ui/icon.blade.php index 2e96085..381af14 100644 --- a/resources/views/components/ui/icon.blade.php +++ b/resources/views/components/ui/icon.blade.php @@ -2,6 +2,7 @@ @props(['name']) + + + + + {{ isset($title) ? $title.' · '.config('app.name') : config('app.name') }} + + + + + + @vite(['resources/css/app.css', 'resources/js/app.js']) + @livewireStyles + + + {{ $slot }} + + @livewireScripts + + diff --git a/resources/views/livewire/sessions/run.blade.php b/resources/views/livewire/sessions/run.blade.php index 73e41d4..8714752 100644 --- a/resources/views/livewire/sessions/run.blade.php +++ b/resources/views/livewire/sessions/run.blade.php @@ -148,6 +148,12 @@