Documentation
¶
Overview ¶
Package cutscenes keeps a campaign's cut scenes: short full-screen moments the Director pushes onto chosen players' screens, in Chronicle and in Foundry. A scene is three separate layers (the background, what is drawn on top, the words) and an ending; one play of it to named people is a showing, which keeps a copy of the scene as shown so the people it was for can watch it again for a while even after the scene changes or is deleted.
The scene is data, never markup: every kind, colour and number is checked and clamped here before it is stored, and the browser engine draws words with textContent. Showing is a live act of the Director's; the AI may write scenes through review but can never show one.
The HTTP surface for cut scenes. Handlers bind, call the service and render; the service owns every rule, so a mis-wired route cannot widen access.
Hand-written SQL for cut scenes and their showings.
SECURITY: every statement filters on campaign_id (directly, or through the showing for its viewers), so an id from another campaign never reads or changes anything here.
Route registration for cut scenes.
Index ¶
- Constants
- Variables
- func Ago(t, now time.Time) string
- func BackgroundWords(b Background) string
- func ColorName(hex string) string
- func EndingWords(e Ending) string
- func LookKey(kind, key string) string
- func LookWords(kind, key string) string
- func OverlayWords(o Overlay) string
- func PupilKey(key string) string
- func PupilWords(o Overlay) string
- func RegisterRoutes(e *echo.Echo, h *Handler, campaignSvc campaigns.CampaignService, ...)
- func SceneBlock(s Scene) string
- func SceneWords(s Scene) string
- func Secs(v float64) string
- func TextWords(t TextLine) string
- func Until(end, now time.Time) string
- type AI
- type AudienceRow
- type Background
- type Ending
- type Handler
- func (h *Handler) Create(c *echo.Context) error
- func (h *Handler) Delete(c *echo.Context) error
- func (h *Handler) Editor(c *echo.Context) error
- func (h *Handler) List(c *echo.Context) error
- func (h *Handler) Mine(c *echo.Context) error
- func (h *Handler) New(c *echo.Context) error
- func (h *Handler) Preview(c *echo.Context) error
- func (h *Handler) ReadShowing(c *echo.Context) error
- func (h *Handler) Save(c *echo.Context) error
- func (h *Handler) Show(c *echo.Context) error
- func (h *Handler) ShowSheet(c *echo.Context) error
- func (h *Handler) Showings(c *echo.Context) error
- func (h *Handler) Stop(c *echo.Context) error
- func (h *Handler) Watched(c *echo.Context) error
- type Kind
- type Look
- type Member
- type MemberShowing
- type Members
- type MineItem
- type Option
- type Overlay
- type Params
- type Place
- type Presence
- type Publisher
- type ReportViewer
- type Repository
- type Scene
- type Service
- type ShowInput
- type Showing
- type ShowingRead
- type ShowingReport
- type ShowingViewer
- type TextLine
- type Viewer
Constants ¶
const ( BackgroundFallAsleep = "fall-asleep" BackgroundBlack = "black" BackgroundFadeToBlack = "fade-to-black" BackgroundNone = "none" OverlayEye = "eye" OverlayEmbers = "embers" StyleWhisper = "whisper" StyleTitle = "title" StylePlain = "plain" EndingTap = "tap" EndingAuto = "auto" )
The kinds a scene may use. The browser engine (static/js/cutscene_engine.js) draws each of these; a Go test greps the engine for every one so the two lists cannot drift apart. The engine draws nothing for a kind it does not know, so an older client never breaks on a newer scene.
const ( PupilRound = "round" PupilSlit = "slit" )
Pupils an eye can be drawn with, whatever its look. Ids and names mirror the engine's ChronicleCutscene.pupils table, in its order; a Go test reads the engine to keep them equal. A layer naming none gets its look's own.
const ( MaxNameChars = 120 MaxOverlays = 8 MaxTextLines = 12 MaxSayChars = 280 MinSeconds = 0.5 MaxSeconds = 60.0 MaxAt = 120.0 MaxAfter = 60.0 DefaultAfter = 3.0 DefaultSeconds = 5.0 // MaxBodyBytes caps a scene sent as JSON or a form; a full scene is a few // kilobytes. MaxBodyBytes = 64 << 10 )
Limits on a scene. Numbers outside them are clamped, never refused; counts and text lengths over them are refused with a plain sentence.
const ( DefaultEyeColor = "#3dff7a" DefaultEmbersColor = "#ff9a3c" )
Default colours, used when a layer comes without one.
const AddonSlug = "cutscenes"
AddonSlug is the campaign switch for cut scenes. It is off until a campaign turns it on.
const DefaultRewatch = "12h"
DefaultRewatch is the Show sheet's preselected window.
const EngineSrc = "/static/js/cutscene_engine.js"
EngineSrc is where the cut scene engine is loaded from; the workshop script loads it the first time Preview is pressed.
const KindName = "cut-scene"
KindName is the block's front-matter kind.
const LiveFor = 5 * time.Minute
LiveFor is how long after it starts a showing that was not stopped still counts as playing: longer than the longest scene the limits allow.
const MaxViewers = 100
MaxViewers caps how many people one showing names.
const PluginSlug = "cutscenes"
PluginSlug names this plugin in the registry and the health/migration bookkeeping, so a failed migration leaves only cut scenes out.
Variables ¶
var ( BackgroundKinds = []Kind{ {BackgroundFallAsleep, "Falling asleep", "darkness creeps in from the edges in soft, blurred patches until the screen is black, like eyes closing"}, {BackgroundFadeToBlack, "Fade to black", "the whole screen dims evenly to black"}, {BackgroundBlack, "Black", "the screen is black at once"}, {BackgroundNone, "Nothing", "no background of its own; only the layers on top and the words are drawn"}, } OverlayKinds = []Kind{ {OverlayEye, "An eye opens", "a single eye opens in the middle of the screen, burning with light in its colour, with fire blooming round it"}, {OverlayEmbers, "Embers", "glowing sparks drift up from the bottom of the screen in its colour"}, } TextStyles = []Kind{ {StyleWhisper, "Whisper", "small, spaced italic letters that fade in softly"}, {StyleTitle, "Title", "large display letters, like a chapter heading"}, {StylePlain, "Plain", "ordinary reading text"}, } EndingKinds = []Kind{ {EndingTap, "When they tap", "a quiet Close appears once the last layer has finished; a tap, click or Esc closes it"}, {EndingAuto, "By itself", "it closes on its own a few seconds after the last layer has finished"}, } )
BackgroundKinds, OverlayKinds and TextStyles are every choice in the order the editor offers them; the first background and style are the defaults.
var Looks = map[string][]Look{ BackgroundFallAsleep: { {"ink", "Ink in water", "darkness bleeds in from the edges like ink spreading through water, in curling soft tendrils that meet in the middle", ""}, {"eyelids", "Heavy eyelids", "soft dark patches breathe in from the edges while eyelids droop and flutter open twice before they give in", ""}, {"drift", "The page drifts off", "the screen itself blurs, loses its colour and sinks while darkness closes in like tunnel vision and soft dark spots float across it", ""}, }, OverlayEye: { {"rift", "Burning seam", "a line of fire burns across the dark and tears open into a ragged eye with a round pupil that narrows onto you; as it opens, fire blooms around it in the eye's colour and a haze of heat veils the eye", PupilRound}, {"almond", "Lids part", "a thin seam of light cracks, hesitates, then the lids part on a burning iris with a slit pupil; as they open, fire blooms around the eye and a haze of heat veils it", PupilSlit}, {"gather", "Sparks gather", "sparks drift out of the dark into a ring of fire; lines of light draw the eye around it, the pupil splits open and fire blooms around it under a haze of heat", PupilSlit}, }, }
Looks lists the looks of each kind that has them. A look on any other kind, or one not listed here, is dropped, and the engine plays the default.
var MigrationsFS embed.FS
MigrationsFS contains the embedded SQL migration files so the tables are created from the compiled binary regardless of the working directory.
var Pupils = []Kind{ {PupilRound, "Round", "a round black pupil that widens and narrows"}, {PupilSlit, "Dragon slit", "a tall reptilian slit that narrows and flares with the fire, in a scaled, veined iris"}, }
var RewatchChoices = []struct { Key string Name string Hours int }{ {"1h", "1 hour", 1}, {"12h", "Tonight (12 hours)", 12}, {"72h", "3 days", 72}, }
Rewatch windows the Show sheet offers, by their form value.
var StaticAssetsFS embed.FS
StaticAssetsFS holds the Director's workshop script and stylesheet, served at /static/plugins/cutscenes/.
Functions ¶
func BackgroundWords ¶
func BackgroundWords(b Background) string
BackgroundWords says the background: "falling asleep over 7 s".
func ColorName ¶
ColorName names a #rrggbb colour in a plain word ("green", "deep red"), for review lines; "" for an empty or malformed colour.
func LookKey ¶
LookKey is the look the editor's picker shows selected: the layer's own, or the default when it has none.
func LookWords ¶
LookWords names a layer's look for a kind that has several, saying when it is the default because none was picked: `, look "Heavy eyelids"`. It is empty for a kind with one way of being drawn.
func OverlayWords ¶
OverlayWords says one layer on top: "green eye at 7.5 s".
func PupilKey ¶
PupilKey is the pupil the editor's picker shows selected: the layer's own, or "" (the look's own) when it names none or an unknown one.
func PupilWords ¶
PupilWords names an eye's pupil, saying when it is the look's own because none was picked: `, pupil "Dragon slit"`. It is empty for anything but an eye.
func RegisterRoutes ¶
func RegisterRoutes(e *echo.Echo, h *Handler, campaignSvc campaigns.CampaignService, authSvc auth.AuthService, addonSvc addons.AddonService)
RegisterRoutes mounts the routes under the campaign group. Every route needs a signed-in member of at least Player role and the Cut scenes add-on on. The Director routes then turn anyone who is not the owner or a co-DM away with a 404 (the co-DM grant cannot be expressed by a role middleware), and the service decides again; a showing is readable only by the people it was for. CSRF is enforced by the global middleware.
func SceneBlock ¶
SceneBlock is the scene's front matter in the cut-scene block's format.
func SceneWords ¶
SceneWords is the one-line summary under a scene's name on the list page.
Types ¶
type AI ¶
type AI struct {
// contains filtered or unexported fields
}
AI is the cut scenes' part of the AI engine (aiplug, ADR-071): the `cut-scene` block an AI can ask to write and the `cut-scenes` lookup. Every read and write goes through Service, so the Director-only rule and the one check of a scene (Normalize) are the service's own; this file words them for the review screen. Showing a scene is never something the AI can ask for: it is a live act of the Director's, on the Cut scenes page.
type AudienceRow ¶
AudienceRow is one person on the Show sheet.
type Background ¶
type Background struct {
Kind string `json:"kind"`
Seconds float64 `json:"seconds"`
Params Params `json:"params"`
}
Background is the bottom layer: how the screen goes dark.
type Ending ¶
Ending says how the scene closes. After (auto only) is seconds after the last layer has finished.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves the cut scene routes.
func (*Handler) Delete ¶
Delete handles POST /campaigns/:id/cutscenes/:sid/delete. Showings keep their copy of the scene, so people can still watch it again.
func (*Handler) Mine ¶
Mine handles GET /campaigns/:id/cutscenes/mine: the caller's showings still inside their window, newest first.
func (*Handler) Preview ¶
Preview handles POST /campaigns/:id/cutscenes/preview: the editor's form as the scene JSON the engine plays, checked exactly as a save would be, so Preview shows unsaved changes and never something a save would refuse.
func (*Handler) ReadShowing ¶
ReadShowing handles GET /campaigns/:id/cutscenes/showings/:shid.
func (*Handler) Save ¶
Save handles POST /campaigns/:id/cutscenes/:sid. The editor posts the whole scene; an HTMX save answers with the form redrawn as stored.
func (*Handler) Show ¶
Show handles POST /campaigns/:id/cutscenes/:sid/show. It answers with the live row; a refusal redraws the sheet with the reason in it.
func (*Handler) ShowSheet ¶
ShowSheet handles GET /campaigns/:id/cutscenes/:sid/show, the "Show to…" sheet (an HTMX fragment).
func (*Handler) Showings ¶
Showings handles GET /campaigns/:id/cutscenes/showings, the Director's recent showings: a fragment for HTMX, JSON otherwise.
type Kind ¶
type Kind struct {
Key string
Name string // what the editor's picker says
Looks string // what it looks like on screen, for the AI and the editor's hint
}
Kind is one choice a layer offers, with the plain words the editor and the AI use for it.
type Look ¶
type Look struct {
Key string
Name string
Looks string
Pupil string // an eye look's own pupil, drawn when the layer names none
}
Look is one way a kind can be drawn. The ids and names mirror the engine's ChronicleCutscene.looks table, in its order, the first being the one the engine plays when a scene names none; a Go test reads the engine to keep them equal.
type MemberShowing ¶
type MemberShowing struct {
ShowingID string `json:"showingId"`
Name string `json:"name"`
ShownAt time.Time `json:"shownAt"`
RewatchUntil time.Time `json:"rewatchUntil"`
Scene Scene `json:"scene"`
}
MemberShowing is one showing as the sync API hands it to the Foundry GM client, with the scene to play.
type Members ¶
Members lists the campaign's people; implemented in internal/app over the campaigns service.
type MineItem ¶
type MineItem struct {
ShowingID string `json:"showingId"`
Name string `json:"name"`
ShownAt time.Time `json:"shownAt"`
RewatchUntil time.Time `json:"rewatchUntil"`
Watched bool `json:"watched"`
Stopped bool `json:"stopped"`
}
MineItem is one of the caller's own showings still inside its window, in the shape GET /cutscenes/mine sends. Stopped tells the stage not to play a showing the Director called off when the page opens; it can still be watched again by choice.
type Option ¶
type Option func(*service)
Option configures the service.
func WithPresence ¶
WithPresence adds the "where are they" signal to the Show sheet; without it everyone reads as away.
func WithPublisher ¶
WithPublisher wires the live channel; without it a showing is only stored, and players find it in their Watch again list.
type Overlay ¶
type Overlay struct {
Kind string `json:"kind"`
At float64 `json:"at"`
Seconds float64 `json:"seconds"`
Params Params `json:"params"`
}
Overlay is one animation drawn on top of the background, in list order.
type Params ¶
type Params struct {
Color string `json:"color,omitempty"`
Look string `json:"look,omitempty"`
Pupil string `json:"pupil,omitempty"` // eye only; empty draws its look's own
}
Params are a layer's settings beyond kind and timing: an overlay's colour, and the look of a kind that has several (falling asleep, the eye). An unknown param is dropped when the layer is read.
type Place ¶
Place says where a member is now. Both false is away.
type Presence ¶
type Presence interface {
Places(ctx context.Context, campaignID string) (map[string]Place, error)
}
Presence says where each member is now; implemented in internal/app over the websocket hub and the Foundry players report, so this plugin imports neither. A member missing from the map is away.
type Publisher ¶
Publisher puts a showing on screens and takes it off; implemented in internal/app over the websocket bus. It is told after the database has the showing, so a screen that asks right away can read it.
type ReportViewer ¶
type ReportViewer struct {
UserID string `json:"userId"`
Name string `json:"name"`
Watched bool `json:"watched"`
}
ReportViewer is one person on a showing report.
type Repository ¶
type Repository interface {
ListScenes(ctx context.Context, campaignID string) ([]Scene, error)
// GetScene answers NotFound for a scene that is not in the campaign.
GetScene(ctx context.Context, campaignID, id string) (*Scene, error)
// CreateScene answers Conflict when the campaign has a scene of that name.
CreateScene(ctx context.Context, campaignID, createdBy string, s Scene) error
// UpdateScene answers NotFound for a missing scene and Conflict for a
// name another scene has.
UpdateScene(ctx context.Context, campaignID string, s Scene) error
DeleteScene(ctx context.Context, campaignID, id string) error
// CreateShowing stores the showing and its viewers in one transaction.
CreateShowing(ctx context.Context, s Showing) error
// GetShowing answers NotFound for a showing that is not in the campaign.
GetShowing(ctx context.Context, campaignID, id string) (*Showing, error)
// StopShowing stamps stopped_at once; a second stop changes nothing.
StopShowing(ctx context.Context, campaignID, id string, at time.Time) error
// RecentShowings lists the campaign's newest showings, viewers included.
RecentShowings(ctx context.Context, campaignID string, limit int) ([]Showing, error)
// ViewerShowings lists the showings userID is a viewer of whose window
// is still open at now, newest first, each with only that viewer.
ViewerShowings(ctx context.Context, campaignID, userID string, now time.Time) ([]Showing, error)
// MarkWatched stamps watched_at the first time only.
MarkWatched(ctx context.Context, campaignID, showingID, userID string, at time.Time) error
}
Repository is the store behind the service.
func NewRepository ¶
func NewRepository(db *sql.DB) Repository
NewRepository creates a MariaDB-backed repository.
type Scene ¶
type Scene struct {
ID string `json:"id"`
Name string `json:"name"`
Background Background `json:"background"`
Overlays []Overlay `json:"overlays"`
Text []TextLine `json:"text"`
Ending Ending `json:"ending"`
UpdatedAt time.Time `json:"-"`
}
Scene is a cut scene, in the shape the engine reads and the database keeps (one JSON column per layer).
func NewScene ¶
func NewScene() Scene
NewScene is the scene a "New scene" page starts from: the first built-in animation, the screen falling asleep and a green eye opening, with one whispered line under it.
func Normalize ¶
Normalize checks a scene and returns it clamped: every number brought into its range and rounded to a tenth of a second, colours lower-cased and filled with the layer's default, words trimmed of control characters. An unknown kind or style, a malformed colour, a missing name or words, too many layers and words over the limit are refused with a sentence the editor can show as it is. The ID is kept as given; the caller decides it.
func SceneFromForm ¶
SceneFromForm reads the editor's form into a scene. It only reads: every rule (kinds, ranges, limits) is Normalize's, applied by the service. A number that is not a number is refused here, because "abc seconds" has no clamped meaning.
type Service ¶
type Service interface {
List(ctx context.Context, campaignID string, v Viewer) ([]Scene, error)
Get(ctx context.Context, campaignID, sceneID string, v Viewer) (*Scene, error)
Create(ctx context.Context, campaignID string, v Viewer, in Scene) (*Scene, error)
// Save replaces the whole scene: the editor posts every layer.
Save(ctx context.Context, campaignID, sceneID string, v Viewer, in Scene) (*Scene, error)
Delete(ctx context.Context, campaignID, sceneID string, v Viewer) error
// Check returns the scene as Save would store it, for the editor's
// Preview, without storing anything.
Check(ctx context.Context, campaignID string, v Viewer, in Scene) (Scene, error)
// Audience lists every member with where they are now, for the Show sheet.
Audience(ctx context.Context, campaignID string, v Viewer) ([]AudienceRow, error)
// Show makes a showing of the scene as it is now and puts it on the
// chosen people's screens.
Show(ctx context.Context, campaignID, sceneID string, v Viewer, in ShowInput) (*Showing, error)
// Stop pulls a showing off every screen; its rewatch window stays.
Stop(ctx context.Context, campaignID, showingID string, v Viewer) (*Showing, error)
// Recent lists the campaign's newest showings with who watched.
Recent(ctx context.Context, campaignID string, v Viewer) ([]ShowingReport, error)
// LiveFor lists a scene's showings that may still be on screens.
LiveFor(ctx context.Context, campaignID, sceneID string, v Viewer) ([]Showing, error)
// Mine lists the caller's own showings still inside their window.
Mine(ctx context.Context, campaignID string, v Viewer) ([]MineItem, error)
// Read returns one showing's scene for the caller to play.
Read(ctx context.Context, campaignID, showingID string, v Viewer) (*ShowingRead, error)
// Watched marks the caller's first play of a showing.
Watched(ctx context.Context, campaignID, showingID string, v Viewer) error
// MemberShowings lists one member's showings still inside their window,
// with the scenes, for the Foundry GM client. The sync API checks the
// caller is a Director before it asks.
MemberShowings(ctx context.Context, campaignID, userID string) ([]MemberShowing, error)
}
Service owns every rule about scenes and showings. It never imports Echo: the handlers bind and render, the service decides.
Two sight rules hold everywhere: only a Director (owner or co-DM) reads, writes or shows scenes, and a showing is readable only by the people it was for while its window is open, or by a Director. Anyone else is told it does not exist (404), never that it is not theirs.
func NewService ¶
func NewService(repo Repository, members Members, opts ...Option) Service
NewService builds the service.
type ShowInput ¶
ShowInput is what the Show sheet posts.
func ShowFromForm ¶
ShowFromForm reads the Show sheet: to (repeated) and rewatch.
type Showing ¶
type Showing struct {
ID string
CampaignID string
SceneID string // "" once the scene is deleted
Scene Scene // the scene as it was shown
ShownBy string
ShownAt time.Time
RewatchUntil time.Time
StoppedAt *time.Time
Viewers []ShowingViewer
}
Showing is one play of a scene to named people.
func (Showing) Live ¶
Live reports whether the showing was put on screens moments ago, which is when the editor lists it as showing.
type ShowingRead ¶
type ShowingRead struct {
ShowingID string `json:"showingId"`
RewatchUntil time.Time `json:"rewatchUntil"`
Scene Scene `json:"scene"`
}
ShowingRead is one showing as a viewer reads it to play it.
type ShowingReport ¶
type ShowingReport struct {
ShowingID string `json:"showingId"`
SceneID string `json:"sceneId,omitempty"`
Name string `json:"name"`
ShownAt time.Time `json:"shownAt"`
RewatchUntil time.Time `json:"rewatchUntil"`
Stopped bool `json:"stopped"`
Live bool `json:"live"`
CanStop bool `json:"canStop"`
Viewers []ReportViewer `json:"viewers"`
}
ShowingReport is one showing on the Director's recent list.
type ShowingViewer ¶
type ShowingViewer struct {
UserID string
Name string // filled by the service from the member list
WatchedAt *time.Time
}
ShowingViewer is one person a showing was for.