Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .ai/rules/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 3 additions & 0 deletions .ai/rules/table.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/Actions/Campaigns/ExportCampaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
Expand Down
21 changes: 21 additions & 0 deletions app/Actions/Campaigns/ImportCampaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<string, mixed> $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
Expand Down
21 changes: 21 additions & 0 deletions app/Actions/Campaigns/ReadCampaignFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
];
Expand Down Expand Up @@ -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<string, mixed> $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.
Expand Down Expand Up @@ -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']}\"");
Expand Down
8 changes: 8 additions & 0 deletions app/Actions/Entities/DeleteEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Actions\Entities;

use App\Models\Campaign;
use App\Models\Entity;
use Illuminate\Support\Facades\DB;

Expand All @@ -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();
});
}
Expand Down
80 changes: 80 additions & 0 deletions app/Actions/Table/SetScreen.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

namespace App\Actions\Table;

use App\Actions\Handouts\RevealHandout;
use App\Enums\ScreenFocus;
use App\Enums\Visibility;
use App\Events\ScreenChanged;
use App\Models\Campaign;
use App\Models\Entity;
use App\Models\User;
use InvalidArgumentException;

/**
* Writes what the television at the end of the table shows.
*
* Two columns on the campaign and one event. A hidden handout is revealed on the way
* through RevealHandout, so it lands on every player's own device the same moment it
* lands on the wall: "on the screen" means the party can see it, and there is no
* second switch that could say otherwise. A map is not revealed on the way, because a
* map's visibility is a form decision, so a map the party may not see is refused.
*/
class SetScreen
{
public function __construct(private readonly RevealHandout $revealHandout) {}

/**
* A handout or a map, on the screen.
*
* @throws InvalidArgumentException when the page is not a handout or a map, is
* not this campaign's, or is a map the party may
* not see.
*/
public function show(Campaign $campaign, Entity $page, User $actor): void
{
$focus = ScreenFocus::forPage($page->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);
}
}
46 changes: 46 additions & 0 deletions app/Enums/ScreenFocus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace App\Enums;

/**
* What the television at the end of the table is showing.
*
* Two of these stand on their own and two name a page: a handout or a map carries
* campaigns.screen_entity_id beside it, and the fight and the clocks carry nothing.
* Campaign::screen() is where a focus that needs a page and has none resolves to
* null, so the Blade never has to ask.
*/
enum ScreenFocus: string
{
case Fight = 'fight';
case Clocks = 'clocks';
case Handout = 'handout';
case Map = 'map';

public function label(): string
{
return match ($this) {
self::Fight => '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,
};
}
}
51 changes: 51 additions & 0 deletions app/Events/ScreenChanged.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace App\Events;

use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Contracts\Broadcasting\ShouldRescue;
use Illuminate\Foundation\Events\Dispatchable;

/**
* The GM changed what the screen shows. Not to what.
*
* One ULID, and it is in the channel name already, so the payload is empty. Every
* listener is a Livewire component that re-renders on the server and reads the two
* columns through the party's gate, so a GM who put up a page the party may not see
* has changed nothing on the wall. There is no payload to filter and none to leak.
*
* ShouldRescue, because a GM pressing "On the screen" must never see an error from a
* websocket server that happens to be down. The screen's own sixty-second poll is the
* backstop.
*/
class ScreenChanged implements ShouldBroadcast, ShouldRescue
{
use Dispatchable, InteractsWithSockets;

public function __construct(
public readonly string $campaignId,
) {}

/**
* @return array<int, PresenceChannel>
*/
public function broadcastOn(): array
{
return [new PresenceChannel('campaign.'.$this->campaignId)];
}

public function broadcastAs(): string
{
return 'screen.changed';
}

/**
* @return array{}
*/
public function broadcastWith(): array
{
return [];
}
}
Loading
Loading