dmscreen

package
v0.0.0-...-95891f2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: AGPL-3.0 Imports: 28 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package dmscreen serves the DM Screen: a control panel for the people running a campaign (owners and scribes), opened from the campaign top bar. It owns no tables. Every section is read from another plugin through the source interfaces in sources.go, and a section whose source is missing or fails is left out rather than failing the whole screen.

Index

Constants

View Source
const (
	BoardKindPage = "page"
	BoardKindNote = "note"
)

Board item kinds.

View Source
const (
	RequestMove     = "move"
	RequestPurchase = "purchase"
)

Request kinds, which pick the armory route a button posts to.

View Source
const PluginSlug = "dmscreen"

PluginSlug names this plugin in the registry and the health/migration bookkeeping. Only the Adventures tab needs a table; a failed migration leaves the rest of the screen working and the tab out.

Variables

View Source
var ErrAlreadyPinned = errors.New("page already pinned")

ErrAlreadyPinned is returned by BoardRepository.AddPin when the page is already on the board; the service treats it as success.

View Source
var ErrNoteChanged = apperror.NewConflict("changed elsewhere")

ErrNoteChanged is returned by NotesSource.Save when the note's body no longer matches the version the caller loaded.

View Source
var MigrationsFS embed.FS

MigrationsFS contains the embedded SQL migration files so the table is created from the compiled binary regardless of the working directory (same pattern as the other plugins).

View Source
var TimeSteps = []TimeStep{
	{Key: "1h", Label: "+1 hour", Hours: 1},
	{Key: "8h", Label: "+8 hours", Hours: 8},
	{Key: "1d", Label: "Next day", Days: 1},
}

TimeSteps are the chips, in the order they are drawn.

Functions

func BodyVersion

func BodyVersion(entry string) string

BodyVersion names a stored body for the lost-update check.

func CanOpen

func CanOpen(cc *campaigns.CampaignContext) bool

CanOpen reports who may open the DM Screen: the owner and any member the owner has given DM access (a Co-DM), since that access is for running the game. A Scribe sees what players see. The top-bar button uses the same rule.

func RegisterRoutes

func RegisterRoutes(e *echo.Echo, h *Handler, campaignSvc campaigns.CampaignService, authSvc auth.AuthService)

RegisterRoutes mounts the DM Screen routes behind CanOpen; the service checks the role again so a wiring mistake can't open it to players.

Types

type AdventureItem

type AdventureItem struct {
	ID       string
	Kind     string
	EntityID string
	Kicker   string
	Title    string
	Subtitle string
	Text     string
}

AdventureItem is one card on the tab. For a pin, Kicker/Title/Subtitle name the page; for a note, Text is the note.

type AdventurePage

type AdventurePage struct {
	ID       string
	Name     string
	TypeName string
	// Subtitle is a short line under the name (sessions, status); may be empty.
	Subtitle string
}

AdventurePage is a page of the DM-only Adventures category, as the tab shows it.

type AdventureSource

type AdventureSource interface {
	// Pages returns the requested pages that are live, in the campaign, in the
	// Adventures category and viewable by v; anything else is simply absent.
	Pages(ctx context.Context, campaignID string, ids []string, v Viewer) (map[string]AdventurePage, error)
	// Search lists Adventures pages matching query (all, newest first, when
	// empty). A limit of 0 or less lists every match: the picker feeds a
	// chooser that must offer each adventure. hasCategory is false when the campaign has no Adventures
	// category, so the picker can say where to add it.
	Search(ctx context.Context, campaignID, query string, v Viewer, limit int) (pages []AdventurePage, hasCategory bool, err error)
	// CategoryID is the Adventures category a new page is made in, or 0 when
	// the campaign has none.
	CategoryID(ctx context.Context, campaignID string) (int, error)
}

AdventureSource reads Adventures pages through the entities plugin's own visibility, so the tab can never name a page the viewer could not open.

type AdventuresView

type AdventuresView struct {
	Items []AdventureItem
	// Full is true when nothing more can be added.
	Full bool
}

AdventuresView is the tab: items in the order they were added.

type BoardItem

type BoardItem struct {
	ID         string
	CampaignID string
	Kind       string
	// EntityID is the pinned page; empty for a note.
	EntityID  string
	Body      string
	CreatedBy string
	CreatedAt time.Time
}

BoardItem is one stored item.

type BoardRepository

type BoardRepository interface {
	// List returns the campaign's items, oldest first.
	List(ctx context.Context, campaignID string) ([]BoardItem, error)
	Count(ctx context.Context, campaignID string) (int, error)
	// Add stores an item; a second pin of the same page returns ErrAlreadyPinned.
	Add(ctx context.Context, it *BoardItem) error
	// Delete removes the item of that campaign and reports whether it existed.
	Delete(ctx context.Context, campaignID, id string) (bool, error)
}

BoardRepository stores the board. It never decides who may see what: the service gates every call and reads pages through AdventureSource.

func NewBoardRepository

func NewBoardRepository(db *sql.DB) BoardRepository

NewBoardRepository returns the MariaDB-backed board store.

type ConditionView

type ConditionView struct {
	Name string `json:"name"`
	Text string `json:"text"`
}

ConditionView is one condition and its rule text, markup flattened.

type DecksSource

type DecksSource interface {
	DecksSection(ctx context.Context, campaignID string, v Viewer) (body templ.Component, summary string, ok bool, err error)
}

DecksSource draws the Card decks section: the decks plugin's own fragment and its one-line summary, so the screen holds no deck data. ok is false when the campaign has the add-on off, so the section is left out.

type DowntimeResult

type DowntimeResult struct {
	Open    bool `json:"open"`
	Applied int  `json:"applied"`
	Failed  int  `json:"failed"`
}

DowntimeResult reports a downtime switch: the new state and how many waiting requests went through or failed when it opened.

type DowntimeSource

type DowntimeSource interface {
	Downtime(ctx context.Context, campaignID string, v Viewer) (open bool, pending int, ok bool, err error)

	// SetDowntime opens or closes downtime; opening applies the requests
	// waiting on it. The armory enforces that only the owner may switch.
	SetDowntime(ctx context.Context, campaignID string, v Viewer, open bool) (applied, failed int, err error)
}

DowntimeSource reads the armory's downtime switch and how many stash moves wait for approval. ok is false when the campaign has no armory.

type DowntimeView

type DowntimeView struct {
	Open      bool `json:"open"`
	CanToggle bool `json:"can_toggle"`
	Pending   int  `json:"pending"`
}

DowntimeView is the downtime switch's state plus requests waiting on the GM.

func (DowntimeView) Confirm

func (d DowntimeView) Confirm() (text, yes string)

Confirm is the question the switch asks before changing anything, and its yes button. Starting downtime puts every waiting request through at once, so a stray click must not do it.

type FieldNarrower

type FieldNarrower func(h Hero) map[string]any

FieldNarrower returns the sheet values of h a reader may see.

type FightSource

type FightSource interface {
	FightMount(campaignID string, conditions []string) templ.Component
	// ReadyCount is how many fights the viewer could start now.
	ReadyCount(ctx context.Context, campaignID string, v Viewer) (int, error)
}

FightSource draws the Fight tab: the encounter tracker's own widget, which reads and saves the fight itself, so the screen holds no fight data. conditions are the game system's condition names, offered when the DM marks a creature.

type FoundrySource

type FoundrySource interface {
	FoundryPresence(campaignID string) (lastSeen *time.Time, connected bool)
}

FoundrySource reports whether the campaign's Foundry world is connected.

type FoundryView

type FoundryView struct {
	Connected bool       `json:"connected"`
	NeverSeen bool       `json:"never_seen"`
	LastSeen  *time.Time `json:"last_seen,omitempty"`
}

FoundryView says whether the campaign's Foundry world is connected.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler serves the DM Screen fragment and its reveal action.

func NewHandler

func NewHandler(svc Service) *Handler

NewHandler returns a Handler backed by svc.

func (*Handler) AddBoardNote

func (h *Handler) AddBoardNote(c *echo.Context) error

AddBoardNote handles POST /campaigns/:id/dm-screen/adventures/notes.

func (*Handler) PickPages

func (h *Handler) PickPages(c *echo.Context) error

PickPages handles GET /campaigns/:id/dm-screen/adventures/pages?q=.

func (*Handler) PinPage

func (h *Handler) PinPage(c *echo.Context) error

PinPage handles POST /campaigns/:id/dm-screen/adventures/pins.

func (*Handler) RemoveBoardItem

func (h *Handler) RemoveBoardItem(c *echo.Context) error

RemoveBoardItem handles DELETE /campaigns/:id/dm-screen/adventures/items/:itemID.

func (*Handler) Reveal

func (h *Handler) Reveal(c *echo.Context) error

Reveal handles POST /campaigns/:id/dm-screen/reveal/:eid and returns the row redrawn as revealed.

func (*Handler) SaveNote

func (h *Handler) SaveNote(c *echo.Context) error

SaveNote handles PUT /campaigns/:id/dm-screen/notes.

func (*Handler) Show

func (h *Handler) Show(c *echo.Context) error

Show handles GET /campaigns/:id/dm-screen and returns the panel fragment the top-bar widget mounts.

func (*Handler) ShowNote

func (h *Handler) ShowNote(c *echo.Context) error

ShowNote handles GET /campaigns/:id/dm-screen/notes.

func (*Handler) StepTime

func (h *Handler) StepTime(c *echo.Context) error

StepTime handles POST /campaigns/:id/dm-screen/time. The panel listens for the dms-refresh trigger and redraws itself with the new date.

func (*Handler) UndoReveal

func (h *Handler) UndoReveal(c *echo.Context) error

UndoReveal handles POST /campaigns/:id/dm-screen/hide/:eid and returns the row redrawn hidden, with its Reveal button back.

type Hero

type Hero struct {
	ID           string
	TypeID       int // the hero's category, which says which sheet values are restricted
	Name         string
	PlayerName   string
	PlayerUserID string
	Fields       map[string]any
	// PageRestricted names the fields added to just this hero's page that
	// are GM-only or owner-only; a narrower withholds them along with the
	// category's restricted fields.
	PageRestricted []string
}

Hero is a claimed player character with its raw sheet fields.

type HeroView

type HeroView struct {
	ID         string `json:"id"`
	Name       string `json:"name"`
	PlayerName string `json:"player_name"`
	// PlayerUserID and PlayerHere are additive: the dot after "Played by"
	// needs to know whether that player is here right now.
	PlayerUserID string `json:"player_user_id,omitempty"`
	PlayerHere   bool   `json:"player_here,omitempty"`
	// Subtitle and Conditions come from the sheet fields the system's
	// manifest names; either may be empty.
	Subtitle string `json:"subtitle"`
	// Level is the sheet's `level` value when the hero has one, so a reader
	// that is not the screen (the AI's players lookup) can say it. It is read
	// from the same narrowed values as the meters.
	Level      string      `json:"level,omitempty"`
	Conditions []string    `json:"conditions,omitempty"`
	Meters     []MeterView `json:"meters,omitempty"`
}

HeroView is one player character with the meters the system declares.

func (HeroView) Folded

func (h HeroView) Folded() (bar *MeterView, chips, rest []MeterView)

Folded splits a hero's meters for the one-line folded row: the first meter with a max becomes the bar, and every meter without a max (a class resource, an armour class) becomes a chip. Rest is what folds open.

type Hidden

type Hidden struct {
	ID       string
	Name     string
	TypeName string
}

Hidden is a character entity players can't see.

type HiddenSource

type HiddenSource interface {
	HiddenCharacters(ctx context.Context, campaignID string, v Viewer, limit int) (hidden []Hidden, more bool, err error)
	Reveal(ctx context.Context, entityID, campaignID string) (name string, err error)
	Hide(ctx context.Context, entityID, campaignID string) (name string, err error)
}

HiddenSource lists hidden characters and reveals one, returning its name. HiddenCharacters returns at most limit of the newest and reports whether more exist beyond them, so the panel can point at the full list. Reveal must only ever make an entity visible, never hide it, and must refuse an entity outside campaignID. Hide is Reveal's undo: it only ever hides, and only the entities Reveal could show.

type HiddenView

type HiddenView struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	TypeName string `json:"type_name"`
	Revealed bool   `json:"revealed"`
	// CanUndo offers the revealed row's Undo, which is for the DM team only.
	CanUndo bool `json:"-"`
}

HiddenView is a character the GM can reveal from the screen.

type HomebrewSource

type HomebrewSource interface {
	DrawerMount(campaignID string, canPlace bool) templ.Component
}

HomebrewSource draws what fills the Homebrew drawer: its stylesheets and the widget that reads the campaign's homebrew itself, so the screen holds no homebrew data of its own. canPlace offers placing a Trackers block, which only the campaign's owner may do.

type MeterView

type MeterView struct {
	Label   string `json:"label"`
	Current string `json:"current"`
	Max     string `json:"max"`
	HasMax  bool   `json:"has_max"`
	// Percent is 0-100 for the bar width.
	Percent int  `json:"percent"`
	Low     bool `json:"low"`
}

MeterView is one number on a hero. HasMax draws it as a bar.

type NightSource

type NightSource interface {
	NextNight(ctx context.Context, campaignID string, v Viewer) (*NightView, error)
}

NightSource returns the next game night that hasn't happened, or nil.

type NightView

type NightView struct {
	// Key identifies this night for keeping things with it: the session id,
	// plus the date when the session repeats so each occurrence is its own.
	// Not on the wire.
	Key      string `json:"-"`
	Name     string `json:"name"`
	When     string `json:"when"`
	Going    int    `json:"going"`
	Maybe    int    `json:"maybe"`
	Cant     int    `json:"cant"`
	NoAnswer int    `json:"no_answer"`
}

NightView is the next game night and its answers so far.

type NotesSource

type NotesSource interface {
	Find(ctx context.Context, campaignID, nightKey string, v Viewer) (*ScreenNote, error)
	Save(ctx context.Context, campaignID, nightKey string, v Viewer, title, entry, entryHTML, version string) (*ScreenNote, error)
}

NotesSource keeps the screen's note in the notes widget. nightKey names the game night the note is kept with (NightView.Key); empty means the campaign's standing note. The note's id is derived from the campaign and key, so nothing here owns a table. Find returns nil, nil before the first save. Save creates the note (shared with the GM side, titled title) or, when it exists, replaces only its body; it never retitles. version is the body version the caller loaded ("" for no note yet) and a mismatch returns ErrNoteChanged.

type NotesView

type NotesView struct {
	// Label reads "Kept with <game night>" or "Not tied to a game night".
	Label string `json:"label"`
	// Text is the note as plain lines; empty before anything is saved.
	Text string `json:"text"`
	// NoteID is empty until the first save creates the note.
	NoteID string `json:"note_id,omitempty"`
	// Link opens the note in the Journal; empty until it exists.
	Link string `json:"link,omitempty"`
	// ReadOnly is true when the note holds more than plain paragraphs
	// (headings, lists, marks, images, mentions); the tab shows its text and
	// never saves, so formatting made in the full editor cannot be flattened.
	ReadOnly bool `json:"read_only,omitempty"`
	// Version names the stored body. A save sends it back and is refused (409)
	// if the note changed since, so a stale tab cannot overwrite newer text.
	Version string `json:"version"`
}

NotesView is the screen's note: one per campaign, shared with the GM side, kept with the next game night.

type PartySource

type PartySource interface {
	Heroes(ctx context.Context, campaignID string, v Viewer) ([]Hero, error)
}

PartySource lists the campaign's player characters.

type PickPage

type PickPage struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	TypeName string `json:"type_name"`
	// Pinned is true for a page already on the board.
	Pinned bool `json:"pinned"`
}

PickPage is one choice in the pin picker.

type PickResult

type PickResult struct {
	Pages []PickPage `json:"pages"`
	// HasCategory is false when the campaign has no Adventures category.
	HasCategory bool `json:"has_category"`
	// NewTypeID is the category "A new adventure" is made in; 0 when none.
	NewTypeID int `json:"new_type_id,omitempty"`
}

PickResult is the picker's answer.

type PlayerPresence

type PlayerPresence struct {
	UserID string
	Name   string
	Here   bool
}

PlayerPresence is one player of the campaign and whether they are here now.

type PresenceSource

type PresenceSource interface {
	Players(ctx context.Context, campaignID string) ([]PlayerPresence, error)
}

PresenceSource lists the campaign's players (members with the Player role, not the owner, co-DMs or scribes) with whether each is here. A campaign with no players returns an empty list.

type PresenceView

type PresenceView struct {
	Here  int `json:"here"`
	Total int `json:"total"`
	// HereNames and AwayNames are display names, sorted, for the strip's tooltip.
	HereNames []string `json:"here_names,omitempty"`
	AwayNames []string `json:"away_names,omitempty"`
}

PresenceView counts the campaign's players who are here right now. A player is a member with the Player role; the owner, co-DMs and scribes run the game and are not counted.

func (PresenceView) Label

func (p PresenceView) Label() string

Label is the strip text: "3 of 4 players here".

func (PresenceView) Title

func (p PresenceView) Title() string

Title is the strip's tooltip: "Here: a, b. Not here: c."

type Request

type Request struct {
	Kind      string
	ID        int64
	Text      string
	CreatedAt time.Time
}

Request is one request waiting on the owner, in the armory's wording.

type RequestSource

type RequestSource interface {
	WaitingRequests(ctx context.Context, campaignID string, v Viewer) (reqs []Request, ok bool, err error)
}

RequestSource lists every request waiting on the viewer, in any order; the service sorts oldest first and trims. ok is false when the campaign has no armory.

type RequestView

type RequestView struct {
	Kind string `json:"kind"`
	ID   int64  `json:"id"`
	// Text is one plain line: "Bren: move 2 × Healing potion from A to B".
	Text      string    `json:"text"`
	CreatedAt time.Time `json:"created_at"`
}

RequestView is one stash move or ask-to-buy request waiting on the owner.

func (RequestView) ApprovePath

func (r RequestView) ApprovePath(campaignID string) string

ApprovePath and DeclinePath are the armory routes the buttons post to.

func (RequestView) DeclinePath

func (r RequestView) DeclinePath(campaignID string) string

type RequestsView

type RequestsView struct {
	Items []RequestView `json:"items"`
	More  int           `json:"more,omitempty"`
}

RequestsView is the "Waiting on you" block: the oldest few requests, and how many more sit on the Stashes page.

type ScreenNote

type ScreenNote struct {
	ID    string
	Title string
	// Entry is the note's ProseMirror JSON as stored.
	Entry string
	// Legacy is the text of an old block-style note with no Entry; such a note
	// is shown read-only.
	Legacy string
}

ScreenNote is the stored note behind the Notes tab.

type SectionView

type SectionView struct {
	ID      string
	Title   string
	Icon    string // Font Awesome solid icon name, without the fa- prefix
	Summary string
	Badge   int
}

SectionView is one section of the docked screen: an icon on the rail and a card in the column. Summary is the one line a folded card and the icon's peek show; Badge is a count drawn on the icon (zero draws none).

type Service

type Service interface {
	Build(ctx context.Context, campaignID string, v Viewer) (*View, error)
	// Party is the screen's party panel on its own, each hero's sheet values
	// first passed through narrow (nil keeps them as stored), so a reader who
	// may not see some fields gets meters, subtitle and conditions built only
	// from the rest. Owner and Co-DM only, like Build.
	Party(ctx context.Context, campaignID string, v Viewer, narrow FieldNarrower) ([]HeroView, error)
	Reveal(ctx context.Context, entityID, campaignID string, v Viewer) (string, error)
	// UndoReveal hides again a character Reveal showed, for the owner and
	// co-DMs, who can hide any page from its visibility control anyway.
	UndoReveal(ctx context.Context, entityID, campaignID string, v Viewer) (string, error)
	SetDowntime(ctx context.Context, campaignID string, v Viewer, open bool) (DowntimeResult, error)

	// StepTime moves the world's date forward by one of the TimeSteps.
	StepTime(ctx context.Context, campaignID string, v Viewer, stepKey string) error

	// Note reads the screen's note; SaveNote replaces its text.
	Note(ctx context.Context, campaignID string, v Viewer) (*NotesView, error)
	SaveNote(ctx context.Context, campaignID string, v Viewer, text, version string) (*NotesView, error)

	// The Adventures tab: pin an Adventures page, add a loose note, remove
	// either, and list the pages the picker offers.
	PinPage(ctx context.Context, campaignID string, v Viewer, entityID string) error
	AddNote(ctx context.Context, campaignID string, v Viewer, text string) error
	RemoveItem(ctx context.Context, campaignID string, v Viewer, itemID string) error
	PickPages(ctx context.Context, campaignID string, v Viewer, query string) (*PickResult, error)
}

Service builds the DM Screen and performs its few actions.

func NewService

func NewService(src Sources) Service

NewService returns a Service reading from src.

type Sources

type Sources struct {
	Downtime DowntimeSource
	Requests RequestSource
	Notes    NotesSource
	World    WorldSource
	Nights   NightSource
	Foundry  FoundrySource
	Presence PresenceSource
	Party    PartySource
	Hidden   HiddenSource
	System   SystemSource
	Homebrew HomebrewSource
	Fight    FightSource
	Decks    DecksSource

	// Board and Adventures together feed the Adventures tab; with either
	// missing (the table failed to migrate) the tab is left out.
	Board      BoardRepository
	Adventures AdventureSource
}

Sources groups the screen's inputs. Any of them may be nil, which leaves that section out.

type SystemSource

type SystemSource interface {
	EnabledSystem(ctx context.Context, campaignID string) systems.System
}

SystemSource returns the game system enabled for the campaign, or nil.

type TimeStep

type TimeStep struct {
	// Key is the wire value the chip posts.
	Key   string
	Label string
	// Hours and Days are in the calendar's own units; a day is the calendar's
	// hours per day, not 24.
	Hours, Days int
}

TimeStep is one of the three chips under the date: how far to move it.

type View

type View struct {
	CampaignID string `json:"campaign_id"`

	// Downtime is nil when the campaign has no armory (no downtime switch).
	Downtime *DowntimeView `json:"downtime,omitempty"`

	// World is nil when the campaign has no calendar the viewer can see.
	World *WorldView `json:"world,omitempty"`

	// Night is nil when no game night is coming up.
	Night *NightView `json:"night,omitempty"`

	Foundry FoundryView `json:"foundry"`

	// Notes is nil when notes are unavailable; the Notes tab is then hidden.
	Notes *NotesView `json:"notes,omitempty"`

	// Requests is nil when the campaign has no armory or nothing waits.
	Requests *RequestsView `json:"requests,omitempty"`

	// Presence is nil when the campaign has no players or the source is not
	// wired; the strip then says nothing about who is here.
	Presence *PresenceView `json:"presence,omitempty"`

	// SystemName is the enabled game system, empty when none.
	SystemName string `json:"system_name"`

	// PartyFilled is true when the game system declares party meters; when
	// false the party panel lists names only and says why.
	PartyFilled bool       `json:"party_filled"`
	Party       []HeroView `json:"party,omitempty"`

	// Hidden lists characters players can't see yet, newest first.
	Hidden []HiddenView `json:"hidden,omitempty"`

	// HiddenMore is true when more are hidden than Hidden lists.
	HiddenMore bool `json:"hidden_more,omitempty"`

	// Conditions is empty when the system declares none; the tab is hidden.
	Conditions []ConditionView `json:"conditions,omitempty"`

	// Adventures is the Adventures tab, nil when the board is unavailable. It
	// is not on the wire: the Foundry module has no use for it and the sync
	// contract stays as it was.
	Adventures *AdventuresView `json:"-"`

	// Homebrew fills the Homebrew drawer; nil leaves the drawer and its
	// button out. Only the owner and co-DMs get it, since a recipe's rules
	// are theirs to run. Not on the wire, for the same reason as Adventures.
	Homebrew templ.Component `json:"-"`

	// Fight fills the Fight tab; nil leaves the tab out. Only the owner and
	// co-DMs get it, since the encounters behind it are theirs. Not on the
	// wire, for the same reason as Adventures.
	Fight templ.Component `json:"-"`

	// Decks fills the Card decks section; nil leaves it out. Only the owner and
	// co-DMs get it, and only with the Card decks add-on on. DecksSummary is its
	// one line on the rail. Neither is on the wire.
	Decks        templ.Component `json:"-"`
	DecksSummary string          `json:"-"`

	// FightReady is how many fights are marked Ready; FightCounted is false
	// when that could not be read, so the summary stays a plain line rather
	// than a made-up count. Neither is on the wire.
	FightReady   int  `json:"-"`
	FightCounted bool `json:"-"`
}

View is everything the panel template draws. The Foundry module gets the same data as JSON from the sync API, so the field tags are a wire contract.

func (*View) Sections

func (v *View) Sections() []SectionView

Sections lists the rail's sections in rail order. A section whose source is missing is left out, so the rail never offers an empty card.

func (*View) Waiting

func (v *View) Waiting() int

Waiting counts the requests waiting on the viewer: the listed ones plus those past the list, or the armory's pending count when no list is shown.

type Viewer

type Viewer struct {
	UserID string
	// Role is the campaign visibility role (3 owner or co-DM, 2 scribe).
	Role int
	// Layouts is true for the campaign's owner, who alone may change a
	// category's page layout; a co-DM sees the owner's view but not that.
	Layouts bool
}

Viewer is the person opening the screen.

func (Viewer) IsOwner

func (v Viewer) IsOwner() bool

IsOwner reports whether the viewer is the owner or a Co-DM, who alone may open the screen and change game state such as the downtime switch.

type WorldSource

type WorldSource interface {
	World(ctx context.Context, campaignID string, v Viewer) (*WorldView, error)

	// Advance moves the default calendar forward by hours and whole days of
	// its own length. The calendar refuses a real-time calendar.
	Advance(ctx context.Context, campaignID string, v Viewer, hours, days int) error
}

WorldSource reads the default calendar's current date and today's weather. It returns nil, nil when there is no calendar the viewer can see. It sets WorldView.CanStep only for what the calendar allows (not a real-time calendar); the service adds the role check.

type WorldView

type WorldView struct {
	CalendarID string `json:"calendar_id"`
	DateLabel  string `json:"date_label"`
	TimeLabel  string `json:"time_label"`
	// Weather is a one-line description, empty when none is set for today.
	Weather string `json:"weather"`
	// CanStep is true when the viewer may move the date forward by hand and
	// the calendar lets them: not a real-time calendar, and not a scribe.
	CanStep bool `json:"can_step"`
}

WorldView is the in-world date and today's weather.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL