Documentation
¶
Overview ¶
Package decks keeps a campaign's card decks: hero decks, party decks and event decks. A deck has cards, a card has copies (one row per physical card, never a weight), and each copy sits in one zone: the pile, shown to the Directors, a hero's hand, in play, used or gone.
The server draws: a draw picks at random among the pile's copies with crypto randomness, and the pile has no stored order, so there is nothing to leak. Directors and players get different response types with no hidden field on the player ones; a deck, card or copy a player may not see answers exactly like a missing one.
The JSON HTTP surface for decks. Handlers bind, call the service and render; the service owns every rule, so a mis-wired route cannot widen access.
Hand-written SQL for decks, cards, copies and the move log.
SECURITY: every statement filters on campaign_id (directly or through the deck), so an id from another campaign never reads or changes anything here. Every move claims its copy with a conditional update and checks the rows it changed, so two people can never take the same copy.
Route registration for decks.
Index ¶
- Constants
- Variables
- func HeroBlock(ctx context.Context, svc Service, cc *campaigns.CampaignContext, ...) (templ.Component, error)
- func RegisterRoutes(e *echo.Echo, h *Handler, campaignSvc campaigns.CampaignService, ...)
- func ScreenComponent(v *ScreenView) templ.Component
- type AI
- type ActInput
- type ActionResult
- type AskedChange
- type Audience
- type Back
- type BackInput
- type Bell
- type BellEntry
- type Card
- type CardEvent
- type CardOpts
- type CardSize
- type CardState
- type CardTests
- type Copy
- type CreateCardInput
- type CreateDeckInput
- type CreateFromInput
- type DealCardInput
- type Deck
- type DeckListView
- type DeckStyle
- type DeckView
- type DirectorCard
- type DirectorCopy
- type DirectorDeck
- type DirectorList
- type DirectorPlayer
- type DrawInput
- type DrawPlan
- type DrawShown
- type DrawView
- type EventKindOption
- type Face
- type Facts
- type Fit
- type FreshCard
- type FreshRow
- type FromReport
- type HandCard
- type HandDraw
- type HandOther
- type HandParty
- type HandSpot
- type HandView
- type Handler
- func (h *Handler) Act(c *echo.Context) error
- func (h *Handler) Create(c *echo.Context) error
- func (h *Handler) CreateCard(c *echo.Context) error
- func (h *Handler) CreateFrom(c *echo.Context) error
- func (h *Handler) DealCard(c *echo.Context) error
- func (h *Handler) Delete(c *echo.Context) error
- func (h *Handler) DeleteCard(c *echo.Context) error
- func (h *Handler) Draw(c *echo.Context) error
- func (h *Handler) DrawView(c *echo.Context) error
- func (h *Handler) FreshCards(c *echo.Context) error
- func (h *Handler) FreshSeen(c *echo.Context) error
- func (h *Handler) Gather(c *echo.Context) error
- func (h *Handler) Get(c *echo.Context) error
- func (h *Handler) HandFragment(c *echo.Context) error
- func (h *Handler) HeroStripFragment(c *echo.Context) error
- func (h *Handler) List(c *echo.Context) error
- func (h *Handler) MomentAnother(c *echo.Context) error
- func (h *Handler) MomentDeal(c *echo.Context) error
- func (h *Handler) MomentDismiss(c *echo.Context) error
- func (h *Handler) MomentInvite(c *echo.Context) error
- func (h *Handler) Moments(c *echo.Context) error
- func (h *Handler) MomentsPanel(c *echo.Context) error
- func (h *Handler) OpenCardFragment(c *echo.Context) error
- func (h *Handler) Say(c *echo.Context) error
- func (h *Handler) ScreenFragment(c *echo.Context) error
- func (h *Handler) SetPlayers(c *echo.Context) error
- func (h *Handler) SetScreenPicks(c *echo.Context) error
- func (h *Handler) ShownFaceFragment(c *echo.Context) error
- func (h *Handler) Shuffle(c *echo.Context) error
- func (h *Handler) Table(c *echo.Context) error
- func (h *Handler) TurnFaceFragment(c *echo.Context) error
- func (h *Handler) Update(c *echo.Context) error
- func (h *Handler) UpdateCard(c *echo.Context) error
- func (h *Handler) WhenOptions(c *echo.Context) error
- func (h *Handler) WorkshopDeck(c *echo.Context) error
- func (h *Handler) WorkshopList(c *echo.Context) error
- func (h *Handler) WorkshopNew(c *echo.Context) error
- func (h *Handler) WorkshopTab(tab string) echo.HandlerFunc
- func (h *Handler) WorkshopTable(c *echo.Context) error
- type Hero
- type HeroHandView
- type Heroes
- type KeepPlan
- type KindCount
- type KindDef
- type LayerFact
- type LogLine
- type Look
- type LookInput
- type Member
- type Members
- type Moment
- type MomentClaim
- type MomentNotifier
- type MomentRepository
- type MomentView
- type MoonFact
- type Move
- type Notifier
- type NumberField
- type NumberSet
- type OpenedCard
- type Option
- func WithBell(b Bell) Option
- func WithFacts(f Facts) Option
- func WithMomentNotifier(n MomentNotifier) Option
- func WithMoments(m MomentRepository) Option
- func WithNotifier(n Notifier) Option
- func WithPictures(p Pictures) Option
- func WithPoke(p func(campaignID string)) Option
- func WithRandom(pick func(n int) int) Option
- func WithScreen(r ScreenRepository) Option
- func WithStory(st Story) Option
- func WithSwitch(on func(ctx context.Context, campaignID string) bool) Option
- func WithTables(t Tables) Option
- type OptionHero
- type OptionWord
- type OtherHolds
- type PageFinder
- type PickChange
- type PictureUse
- type Pictures
- type Place
- type Player
- type PlayerCopy
- type PlayerDeck
- type PlayerHand
- type PlayerInput
- type PlayerList
- type Reading
- type Repository
- type ResizeResult
- type Roster
- type SayInput
- type ScreenChoice
- type ScreenDeck
- type ScreenRepository
- type ScreenShown
- type ScreenView
- type Service
- type SetPlayersInput
- type Settings
- type SettingsInput
- type Story
- type TableCard
- type TableChoices
- type TableDeck
- type TableLine
- type TableRow
- type TableSummary
- type TableView
- type Tables
- type TagFact
- type TagOption
- type TodayFact
- type TrackerFact
- type TrackerKindOption
- type UpdateCardInput
- type UpdateDeckInput
- type Viewer
- type WhenList
- type WhenOptions
- type WhenOptionsView
- type WhenTest
- type WhenView
- type ZoneCounts
Constants ¶
const ( BellDealt = "deck_card_dealt" BellTakenBack = "deck_card_taken_back" BellAsked = "deck_card_asked" BellAnswered = "deck_ask_answered" )
Bell kinds. The words are the bell's notification types.
const ( KindHero = "hero" KindParty = "party" KindEvent = "event" )
Deck kinds. A kind only sets defaults; every deck is the same thing with settings.
const ( ZonePile = "pile" ZoneShown = "shown" ZoneHand = "hand" ZonePlay = "play" ZoneUsed = "used" ZoneGone = "gone" )
Zones a copy can be in.
const ( FateBack = "back" FateUsed = "used" FateGone = "gone" FatePlay = "play" )
Fates: where a copy goes after it is played, taken off or discarded.
const ( ActDraw = "drawn" ActDeal = "dealt" ActTurn = "turned" ActShow = "shown" ActPlay = "played" ActAsk = "asked" ActApprove = "approved" ActTurnDown = "turned-down" ActTakeOff = "taken-off" ActDiscard = "discarded" ActTakeBack = "taken-back" ActPutBack = "put-back" ActKeep = "kept" ActShuffle = "shuffled" ActGather = "gathered" )
Log actions. The names are stable and plain on purpose: later they become the triggers a rule can listen for, so changing one is a change to those.
const ( MaxDecksPerCampaign = 60 MaxCardsPerDeck = 200 MaxCopiesPerDeck = 600 MaxCopiesPerCard = 20 MaxNameChars = 120 MaxWordsChars = 2000 MaxNoteChars = 2000 MaxKindKeyChars = 32 MaxCornerChars = 12 MaxPictureChars = 255 MaxBackWordsChars = 24 MaxKinds = 12 // MaxShown is how many copies of one deck the shown spot holds at once. MaxShown = 5 // MaxDrawCount is how many cards a Director takes in one draw. MaxDrawCount = 5 MaxKindNameChars = 24 MaxPlayersChosen = 200 MaxDraws = 1000 LogKept = 1000 LogShown = 200 MaxBodyBytes = 256 << 10 )
Limits. They bound what a Director can store; the service enforces them.
const ( AnswerDeal = "deal" AnswerAnother = "another" AnswerInvite = "invite" AnswerDismiss = "dismiss" )
Answers a moment offers a Director.
const ( MomentWaiting = "waiting" MomentInvited = "invited" MomentDealt = "dealt" MomentDrawn = "drawn" MomentDismissed = "dismissed" MomentLapsed = "lapsed" )
States of a moment. A moment is open while waiting or invited.
const ( TestNumber = "number" TestTracker = "tracker" TestTag = "tag" TestLayer = "layer" TestSay = "say" // The calendar tests read the main calendar's current date: a moon's phase, // an event on today's date and the time of day. They name no page. TestMoon = "moon" TestEvent = "event" TestTime = "time" )
Kinds of test.
const ( // WhoHolder is the hero a hero deck is for. WhoHolder = "holder" // WhoAny is any hero of the campaign; every "any" test of one card must hold // for the same hero, which is the moment's subject. WhoAny = "any" )
Who a test is about. Anything else is a page id of the campaign.
const ( MaxTests = 4 MaxLayerNameChars = 80 // MaxCalendarNameChars bounds a moon's, a phase's or an event's name. MaxCalendarNameChars = 80 )
Limits of a card's tests.
const AddonSlug = "decks"
AddonSlug is the campaign switch for card decks. It is off until a campaign turns it on.
const BellInvited = "deck_draw_invited"
BellInvited is the bell entry for an invitation to draw. It rides on the existing card-decks choice.
const BlockType = "hero_cards"
BlockType is the layout block that shows a hero's cards.
const (
// MaxScreenPicks is how many decks a Director may choose for the section.
MaxScreenPicks = 12
)
const PluginSlug = "decks"
PluginSlug names this plugin in the registry and the health/migration bookkeeping, so a failed migration leaves only decks out.
Variables ¶
ErrUnavailable is returned by Facts when the plugin a fact comes from is not running. It is judged as a missing fact without a log line, so a degraded plugin does not fill the log after every page save.
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 Palette = []string{"violet", "indigo", "blue", "cyan", "teal", "moss", "plum", "rose", "umber", "slate"}
Palette is the one list of colour keys. No hex colour is ever stored: the stylesheet resolves a key for light and dark.
var StaticAssetsFS embed.FS
StaticAssetsFS holds the card motion script, served at /static/plugins/decks/ and loaded on sight the first time a page shows a card.
Functions ¶
func HeroBlock ¶
func HeroBlock(ctx context.Context, svc Service, cc *campaigns.CampaignContext, heroID, userID string) (templ.Component, error)
HeroBlock is the Cards part of a hero's page. It reads through the same service call as the strip's own route, so the part shows exactly what that route would answer; a page whose hand the viewer may not read draws nothing, as the route answers 404.
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 Card decks add-on on; the service then decides who may see and do what (the co-Director grant and the per-deck player rules cannot be expressed by a role middleware), so the gate here is not the only one. CSRF is enforced by the global middleware.
func ScreenComponent ¶
func ScreenComponent(v *ScreenView) templ.Component
ScreenComponent is the section body, for a caller (the DM Screen) that draws it inside its own card.
Types ¶
type AI ¶
type AI struct {
// contains filtered or unexported fields
}
AI is the card decks' part of the AI engine (aiplug, ADR-071): the `deck` and `card` blocks an AI can ask to write and the `decks` lookup. Every read and write goes through Service, so the Director-only rules, the sight rules the screens already obey and the one check of a card's tests are the service's own; this file words them for a review screen and decides nothing a screen would not.
func NewAI ¶
NewAI builds the AI part. on reports whether the campaign has the Card decks add-on switched on: the service does not ask, because its routes are gated where they are mounted.
type ActInput ¶
type ActInput struct {
// To is "hand" or "table" for deal. A hand deal on a party deck with no
// HeroID lands in the party's own hand.
To string `json:"to"`
HeroID string `json:"heroId"`
// TargetDeckID is the deck `keep` copies the card into.
TargetDeckID string `json:"targetDeckId"`
}
ActInput carries what a verb needs: where a deal goes, or the deck a card is kept in.
type ActionResult ¶
type ActionResult struct {
CopyID string `json:"copyId,omitempty"`
// CopyIDs lists the copies a draw took, a list even when it holds one. A
// player's draw has the same shape.
CopyIDs []string `json:"copyIds,omitempty"`
Deck DeckView `json:"deck"`
}
ActionResult is what a move returns: the copy it touched and the deck as the same viewer now sees it.
type AskedChange ¶
type AskedChange int
AskedChange says what a move does to a copy's waiting-for-a-Director mark.
const ( // AskedKeep leaves the mark as it is. AskedKeep AskedChange = iota // AskedMark stamps it: a player asked to play an ask-first card. AskedMark // AskedClear removes it. AskedClear )
type Audience ¶
type Audience struct {
// Members is every member of the campaign.
Members bool
// Users are these players, sorted and without repeats.
Users []string
}
Audience is who a live "your decks view changed" message goes to. Directors always get it, so they are not listed. A message with neither Members nor Users is for Directors only.
type Back ¶
type Back struct {
Pattern string `json:"pattern"`
// Colour is a palette key, or "" for the campaign's accent.
Colour string `json:"colour"`
// Picture is "" for now.
Picture string `json:"picture"`
Words string `json:"words"`
Sign string `json:"sign"`
}
Back is the card back.
type BackInput ¶
type BackInput struct {
Pattern *string `json:"pattern"`
Colour *string `json:"colour"`
Picture *string `json:"picture"`
Words *string `json:"words"`
Sign *string `json:"sign"`
}
BackInput is Back with every key optional.
type Bell ¶
Bell writes notices for the bell. A notice to a player may name only the deck, and a card only when it was face up to that player.
type Card ¶
type Card struct {
ID string
DeckID string
CampaignID string
Name string
KindKey string
Words string
DirectorNote string
Picture string
Corner string
// Rare is part of the card's face: it is sent only with a face.
Rare bool
Copies int
// Fate is "" for the deck's default.
Fate string
// When is the card's list of tests, at most MaxTests, all of which must hold
// for the card to come up. WhenOpen is derived from it: true when at least one
// test is printed on the card.
When []WhenTest
WhenOpen bool
// SaidAt is when a Director said so, for the "the Director says so" test.
SaidAt *time.Time
// FitsSince is when the card's tests last started to hold, kept so a moment
// is raised on the rising edge only. Nil while they do not hold.
FitsSince *time.Time
// Printed is the card's printed line as the reader may see it. It is never
// stored; the service fills it where a face is built.
Printed string
AskFirst bool
SortOrder int
CreatedAt time.Time
UpdatedAt time.Time
}
Card is a card definition.
type CardEvent ¶
type CardEvent struct {
DeckID string
DeckName string
CardID string
CardName string
// HeroID is the hero page the card is with after a draw, or was in the
// hand of when played; "" for the table or the party.
HeroID string
// By is whoever made the move: the player who drew or played, or the
// Director who dealt, drew or let a played card through.
By Viewer
}
CardEvent is what a rule may know about a move: names and ids of the deck and card, the hero page the card is with, and who did it. It never carries which copy moved, so a rule cannot tell one face-down copy from another.
type CardOpts ¶
type CardOpts struct {
Size CardSize
// DeckName and Position name which card of which deck a face-down card is,
// for the turn-over button ("card 3 of 5", "Orrin"). Neither is card data.
DeckName string
Position string
// Turnable draws the turn-over button on a face-down card.
Turnable bool
// FaceSrc is the address the widget fetches the face from when the card is
// turned. It is never requested before. It must name a copy, never a card:
// the address sits in the markup of a face-down card, so one that named the
// card (by id, or by anything that identifies it) would tell the page which
// card it is before it is turned.
FaceSrc string
// Foot is a quiet last line on the leaf (a card's fate, say).
Foot string
}
CardOpts are the parts of a card that are not its look or its state.
type CardSize ¶
type CardSize string
CardSize is how big a card is drawn. A smaller size shows fewer lines of words, never smaller type, and the hand size thins every frame.
type CardState ¶
type CardState struct {
// contains filtered or unexported fields
}
CardState is what a card shows. It is built only by FaceDown and FaceUp, so a face-down card cannot carry a name, words, kind, picture or id: FaceDown takes nothing, and the components draw a face only from a FaceUp state.
func FaceDown ¶
func FaceDown() CardState
FaceDown is a card showing its back, drawn from the deck's look alone.
func FaceUp ¶
FaceUp is a card showing its face. picture is an optional picture address; without one the face shows its material and the kind's sign.
func FaceUpDeferred ¶
FaceUpDeferred is FaceUp for the markup a turn-over fetches: the picture is named but loaded by the widget once the turn is under way.
type Copy ¶
type Copy struct {
ID string
DeckID string
CampaignID string
CardID string
Zone string
HolderEntityID string
FaceUp bool
// Open is a face-up card in a hand that its holder has shown to the table.
// It implies FaceUp and is cleared whenever the copy leaves the hand.
Open bool
AskedAt *time.Time
DealtBy string
DealtAt *time.Time
TurnedAt *time.Time
MovedAt time.Time
}
Copy is one physical card.
type CreateCardInput ¶
type CreateCardInput struct {
Name string `json:"name"`
KindKey string `json:"kindKey"`
Words string `json:"words"`
DirectorNote string `json:"directorNote"`
Picture string `json:"picture"`
Corner string `json:"corner"`
Rare bool `json:"rare"`
Copies *int `json:"copies"`
Fate string `json:"fate"`
// When is the card's tests; "", null and [] mean none.
When WhenList `json:"when"`
AskFirst bool `json:"askFirst"`
}
CreateCardInput makes a card; Copies defaults to 1.
type CreateDeckInput ¶
type CreateDeckInput struct {
Name string `json:"name"`
Kind string `json:"kind"`
HolderEntityID string `json:"holderEntityId"`
Settings *SettingsInput `json:"settings"`
Look *LookInput `json:"look"`
}
CreateDeckInput makes a deck. Settings and Look are optional; whatever is left out takes the kind's default.
type CreateFromInput ¶
type CreateFromInput struct {
Name string `json:"name"`
Kind string `json:"kind"`
HolderEntityID string `json:"holderEntityId"`
DeckID string `json:"deckId"`
TableID string `json:"tableId"`
}
CreateFromInput names the new deck and exactly one source: a deck to copy or a rolling table to read.
type DealCardInput ¶
type DealCardInput struct {
CardID string `json:"cardId"`
To string `json:"to"`
HeroID string `json:"heroId"`
}
DealCardInput deals a named card's pile copy.
type Deck ¶
type Deck struct {
ID string
CampaignID string
Name string
Kind string
HolderEntityID string
// NextCardID and LastCardID are the Director's two nudges to the draw: the
// card the next draw takes, and the card left out while anything else is in
// the pile. "" is unset. Players never receive either.
NextCardID string
LastCardID string
Settings Settings
Look Look
Version int
SortOrder int
CreatedAt time.Time
UpdatedAt time.Time
// Players is who a Director chose for the deck. The repository fills it
// on every deck read, so no caller can decide who sees a deck without it.
Players []Player
}
Deck is a stored deck.
type DeckListView ¶
type DeckListView interface {
// contains filtered or unexported methods
}
DeckListView is what List returns: DirectorList or PlayerList.
type DeckStyle ¶
type DeckStyle struct {
Key, Name string
// Line says what the style does, in words, for the picker.
Line string
Border string
Shape string
Window string
Lettering string
Corner string
Marker string
Finish string
// Back is the pattern, palette colour ("" is the campaign's colour) and sign.
Pattern, Colour, Sign string
Turn string
}
DeckStyle is a starting look for a new deck: plain data, one table. Picking one only writes these values into the new deck's look; nothing stays linked to the style afterwards.
func DeckStyles ¶
func DeckStyles() []DeckStyle
DeckStyles returns the styles in picker order. The slice is a copy.
func StyleByKey ¶
StyleByKey finds a style; ok is false for a key the table does not have.
type DeckView ¶
type DeckView interface {
// contains filtered or unexported methods
}
DeckView is what Get and every move return. Only DirectorDeck and PlayerDeck implement it, so a handler cannot send anything else.
type DirectorCard ¶
type DirectorCard struct {
ID string `json:"id"`
Name string `json:"name"`
KindKey string `json:"kindKey"`
Words string `json:"words"`
DirectorNote string `json:"directorNote"`
Picture string `json:"picture"`
Corner string `json:"corner"`
Rare bool `json:"rare"`
Copies int `json:"copies"`
Fate string `json:"fate"`
// When is the card's tests, each with its sentence and whether it still
// resolves. WhenOpen is true when at least one is printed. FitsNow and WhyNot
// are filled for a deck read whole, only for a card that has tests.
When []WhenView `json:"when"`
WhenOpen bool `json:"whenOpen"`
FitsNow bool `json:"fitsNow"`
WhyNot string `json:"whyNot,omitempty"`
SaidAt *time.Time `json:"saidAt,omitempty"`
AskFirst bool `json:"askFirst"`
SortOrder int `json:"sortOrder"`
}
DirectorCard is a card with everything a Director wrote.
type DirectorCopy ¶
type DirectorCopy struct {
ID string `json:"id"`
CardID string `json:"cardId"`
Zone string `json:"zone"`
HolderEntityID string `json:"holderEntityId,omitempty"`
FaceUp bool `json:"faceUp"`
Open bool `json:"open"`
AskedAt *time.Time `json:"askedAt,omitempty"`
DealtBy string `json:"dealtBy,omitempty"`
DealtAt *time.Time `json:"dealtAt,omitempty"`
TurnedAt *time.Time `json:"turnedAt,omitempty"`
MovedAt time.Time `json:"movedAt"`
}
DirectorCopy is one copy wherever it is.
type DirectorDeck ¶
type DirectorDeck struct {
ID string `json:"id"`
Name string `json:"name"`
Kind string `json:"kind"`
HolderEntityID string `json:"holderEntityId,omitempty"`
NextCardID string `json:"nextCardId"`
LastCardID string `json:"lastCardId"`
Settings Settings `json:"settings"`
Look Look `json:"look"`
Version int `json:"version"`
Players []DirectorPlayer `json:"players"`
Counts ZoneCounts `json:"counts"`
Cards []DirectorCard `json:"cards,omitempty"`
Copies []DirectorCopy `json:"copies,omitempty"`
Log []LogLine `json:"log,omitempty"`
}
DirectorDeck is a whole deck for a Director. Cards, Copies and Log are filled for one deck (Get and moves) and left out of the list.
type DirectorList ¶
type DirectorList struct {
Decks []DirectorDeck `json:"decks"`
}
DirectorList is the Director's list of decks.
type DirectorPlayer ¶
DirectorPlayer is a chosen player as a Director sees them.
type DrawInput ¶
DrawInput names the hero a player draws into; a Director's draw goes to the shown spot and names none. Count is how many cards a Director takes, 1 to 5, and 0 means one; a player's draw is always one card.
type DrawPlan ¶
type DrawPlan struct {
CampaignID string
DeckID string
// Count is how many copies to take; 0 is one. A pile that holds fewer
// gives what it has, and only a pile with none is errEmptyPile.
Count int
// To is where each drawn copy lands.
To Place
// DealtBy stamps a copy that lands in a hand or in play.
DealtBy string
// CardID limits the draw to one card's copies in the pile ("deal a named
// card").
CardID string
// PutBackCopyID returns that shown copy to the pile first and never draws
// it again when another copy exists.
PutBackCopyID string
// Reshuffle moves the used pile into the pile when the pile has nothing
// to draw.
Reshuffle bool
// SpendUserID spends one of that player's draws; "" spends nothing.
SpendUserID string
// Restrict limits the draw to the copies of the cards in Allowed: the cards
// whose tests fit (or, for a player, may be pulled). A pile that holds copies
// but none of them allowed is errNoneFit, and nothing is reshuffled: a
// reshuffle is only for a pile that is really empty.
Restrict bool
Allowed map[string]bool
// Moment, when set, is claimed in the same transaction as the draw, so a
// deal and the answer that caused it are one step and two Directors cannot
// both answer.
Moment *MomentClaim
// Pick returns a random index below n; the service supplies crypto
// randomness and tests supply a fixed one.
Pick func(n int) int
Log LogLine
}
DrawPlan is one random draw of Count copies, done in one transaction.
type DrawView ¶
type DrawView struct {
DeckID string
Name string
// Sub is "Events · 9 left".
Sub string
Shape string
Turn string
Look Look
// Pile is the count the viewer may know.
Pile *int
// Fan is how many backs the overlay shows: the pile's count up to seven, or
// seven when the count is not the viewer's to know.
Fan int
CanDraw bool
// Refusal says why a draw would be refused ("" when it would not).
Refusal string
// DrawsLeft is a player's remaining draws; nil is no limit or a Director.
DrawsLeft *int
// HeroID is the hero a player's draw goes to; "" for a Director.
HeroID string
Shown []DrawShown
}
DrawView is what the draw overlay needs to open on a deck, as its viewer may know it. A player's is built from the player deck, so Pile is nil when the deck tells players nothing of its count, and Shown is always empty.
type EventKindOption ¶
EventKindOption is a kind of calendar event a test may name.
type Face ¶
type Face struct {
CardID string `json:"cardId"`
Name string `json:"name"`
KindKey string `json:"kindKey"`
Words string `json:"words"`
Picture string `json:"picture"`
Corner string `json:"corner"`
Rare bool `json:"rare"`
// When is the card's printed line ("When ... and ..."), empty when no test is
// printed. Only tests the Director chose to print are in it.
When string `json:"when,omitempty"`
}
Face is what a player reads on a card that is face up: never the Director's note or a condition. Picture is the card's media file id; the media server decides who may fetch it (ADR-078), and a face-down copy carries none.
type Facts ¶
type Facts interface {
// Numbers reads a page's numbers: its stored sheet values with its layers
// applied.
Numbers(ctx context.Context, campaignID, pageID string) (NumberSet, error)
// Trackers lists the trackers on a page, hidden ones included.
Trackers(ctx context.Context, campaignID, pageID string) ([]TrackerFact, error)
// Tags lists the page's tags, Director-only tags included.
Tags(ctx context.Context, campaignID, pageID string) ([]TagFact, error)
// Layers lists the transformations on a page.
Layers(ctx context.Context, campaignID, pageID string) ([]LayerFact, error)
// Fields lists the number fields a page has: its category's and its own.
Fields(ctx context.Context, campaignID, pageID string) ([]NumberField, error)
// Options says what the editor may offer.
Options(ctx context.Context, campaignID string) (WhenOptions, error)
// Today reads the main calendar's current date as v sees it: a moon hidden
// from v, or an event v may not see, is not in it. It is the one fact read
// for a viewer rather than as a Director, so a player's own draw judges the
// calendar exactly as that player is shown it. A campaign with no main
// calendar v may see, or no current date, is ErrUnavailable.
Today(ctx context.Context, campaignID string, v Viewer) (TodayFact, error)
}
Facts reads what a card's tests are judged on. It is owned here and implemented in internal/app over the entities, trackers, tags, transformations and calendar services, so decks never imports another plugin.
Every method but Today answers as a Director would see it: a Director's own test may name a tag or a layer no player can read. A fact that cannot be read is reported as an error and judged as missing, and a test on a missing fact does not hold, so a failing source can never make a card come up.
type Fit ¶
type Fit struct {
// OK is true when every test holds. A card with no test always fits.
OK bool
// Subject is the hero the "any" tests hold for; "" when the card has none.
Subject string
// Reading says what the first number or tracker test is now.
Reading Reading
// Why is the first test that fails, as a sentence with the current value.
Why string
}
Fit is the verdict on one card.
type FreshCard ¶
FreshCard is a face-down card dealt to one of the viewer's heroes that has not yet been put in front of them. It holds the deck's look and the copy's id, never a card.
type FreshRow ¶
FreshRow is a face-down copy dealt to a hero a player plays, found by the pop-up check. It names the copy and its deck and nothing of the card.
type FromReport ¶
type FromReport struct {
// TestsLeftOff lists the cards whose tests the new deck cannot hold.
TestsLeftOff []CardTests `json:"testsLeftOff"`
// PicturesLeftOff names the cards whose picture can no longer be used.
PicturesLeftOff []string `json:"picturesLeftOff"`
// DayLines counts table lines with day conditions, made into cards without.
DayLines int `json:"dayLines"`
// Skipped counts table lines that could not become a card.
Skipped int `json:"skipped"`
// Merged counts lines whose name an earlier line had, so they added copies.
Merged int `json:"merged"`
// NotMade counts usable lines left out because a deck is full.
NotMade int `json:"notMade"`
// LinesUsed counts the table's usable lines that went into cards, which is
// more than Made when lines of one name became one card.
LinesUsed int `json:"linesUsed"`
// Made is how many cards the new deck has.
Made int `json:"made"`
Notes []string `json:"notes"`
}
FromReport says what a new deck could not take from its source. Notes are the same facts as sentences, ready to show once on the new deck's page.
type HandCard ¶
type HandCard struct {
DeckID string
DeckName string
Look Look
Copy PlayerCopy
}
HandCard is one copy drawn in a hand: the copy as its viewer may know it, and the deck that gives it a look and a name.
type HandDraw ¶
type HandDraw struct {
DeckID string
DeckName string
Look Look
Pile *int
Kinds []KindCount
DrawsLeft *int
CanDraw bool
// Heroes are the viewer's own heroes a draw may go to.
Heroes []Hero
// Invited is set only for the player the Director invited to draw: the draw
// goes into the invited hero's hand and spends no draw, so the count of draws
// left is not shown.
Invited bool
}
HandDraw is a deck opened to the viewer to draw from, with what the deck lets them know of its pile.
type HandOther ¶
type HandOther struct {
HeroID string
HeroName string
DeckID string
DeckName string
Look Look
Count int
Faces []Face
}
HandOther is what one deck lets the viewer see of another hero's hand.
type HandParty ¶
type HandParty struct {
DeckID string
DeckName string
Look Look
Pile *int
Hand []HandCard
Used []HandCard
}
HandParty is a party deck as every member sees it.
type HandSpot ¶
type HandSpot struct {
// HeroID is "" for a party deck's hand.
HeroID string
// Name is the hero's name, or the party deck's.
Name string
// Acts is whether the viewer may turn, play and show these cards.
Acts bool
Hand []HandCard
Play []HandCard
}
HandSpot is one hand: a hero's, or a party deck's own. Hand and Play are the cards held and the cards lying in front of the hero.
type HandView ¶
type HandView struct {
Mine []HandSpot
Party []HandParty
Table []TableDeck
Others []HandOther
Draws []HandDraw
}
HandView is everything the Hand leaf draws.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves the deck routes.
func (*Handler) CreateCard ¶
CreateCard handles POST /campaigns/:id/decks/:did/cards.
func (*Handler) CreateFrom ¶
CreateFrom handles POST /campaigns/:id/decks/from: a deck started from another deck or a rolling table. The Director check comes first, so anyone else is told 404 before the body is read or the service is asked.
func (*Handler) DeleteCard ¶
DeleteCard handles DELETE /campaigns/:id/decks/:did/cards/:cid.
func (*Handler) FreshCards ¶
FreshCards handles GET /campaigns/:id/decks/hand/fresh.
func (*Handler) HandFragment ¶
HandFragment handles GET /campaigns/:id/decks/hand: the Hand leaf.
func (*Handler) HeroStripFragment ¶
HeroStripFragment handles GET /campaigns/:id/decks/hand/hero/:eid: the Cards part of a hero's page.
func (*Handler) MomentAnother ¶
MomentAnother handles POST /campaigns/:id/decks/moments/:mid/another.
func (*Handler) MomentDeal ¶
MomentDeal handles POST /campaigns/:id/decks/moments/:mid/deal.
func (*Handler) MomentDismiss ¶
MomentDismiss handles POST /campaigns/:id/decks/moments/:mid/dismiss.
func (*Handler) MomentInvite ¶
MomentInvite handles POST /campaigns/:id/decks/moments/:mid/invite.
func (*Handler) MomentsPanel ¶
MomentsPanel handles GET /campaigns/:id/decks/moments/panel: the open moments as the Table draws them. ?at= names the moment to show. A non-Director is told the page is not there, before anything is read.
func (*Handler) OpenCardFragment ¶
OpenCardFragment handles GET /campaigns/:id/decks/hand/:did/copies/:copy: a face-up card at full size with its controls.
func (*Handler) ScreenFragment ¶
ScreenFragment handles GET /campaigns/:id/decks/screen: the section body.
func (*Handler) SetPlayers ¶
SetPlayers handles PUT /campaigns/:id/decks/:did/players.
func (*Handler) SetScreenPicks ¶
SetScreenPicks handles PUT /campaigns/:id/decks/screen/picks.
func (*Handler) ShownFaceFragment ¶
ShownFaceFragment handles GET /campaigns/:id/decks/:did/copies/:copy/face.
func (*Handler) TurnFaceFragment ¶
TurnFaceFragment handles POST /campaigns/:id/decks/hand/:did/copies/:copy/turn: it turns the copy over and answers with its face, in one request.
func (*Handler) UpdateCard ¶
UpdateCard handles PUT /campaigns/:id/decks/:did/cards/:cid.
func (*Handler) WhenOptions ¶
WhenOptions handles GET /campaigns/:id/decks/when-options.
func (*Handler) WorkshopDeck ¶
WorkshopDeck handles GET /campaigns/:id/decks/workshop/:did.
func (*Handler) WorkshopList ¶
WorkshopList handles GET /campaigns/:id/decks/workshop: the Decks app page.
func (*Handler) WorkshopNew ¶
WorkshopNew handles GET /campaigns/:id/decks/workshop/new.
func (*Handler) WorkshopTab ¶
func (h *Handler) WorkshopTab(tab string) echo.HandlerFunc
WorkshopTab handles one tab's fragment.
type Hero ¶
type Hero struct {
ID string
Name string
// OwnerUserID is the claimed owner, "" when unclaimed.
OwnerUserID string
}
Hero is a page a hero deck can belong to and a player can own.
type HeroHandView ¶
type HeroHandView struct {
HeroID string
Name string
// Own is the hero's own hand, for the hero's player and for Directors.
Own *HandSpot
// Others is what the viewer may see of the hero's hand, for anyone else.
Others []HandOther
}
HeroHandView is the strip on a hero's page.
func (*HeroHandView) Empty ¶
func (h *HeroHandView) Empty() bool
Empty says the strip has nothing to draw.
func (*HeroHandView) Shown ¶
func (h *HeroHandView) Shown() int
Shown is how many cards the strip draws for this viewer: the cards held and in play for a holder or Director, and for anyone else what each deck lets them see, a face or a back apiece. It counts what the viewer is shown and nothing more, so a caller can offer the strip without reading its fields.
type Heroes ¶
type Heroes interface {
// Owned lists the pages of the campaign the user is the claimed owner of.
Owned(ctx context.Context, campaignID, userID string) ([]Hero, error)
// InCampaign finds a live page of this campaign by id; ok is false when
// it is missing, trashed or in another campaign.
InCampaign(ctx context.Context, campaignID, entityID string) (hero Hero, ok bool, err error)
// Viewable says whether the viewer may open the page by the page's own
// visibility rules, so a hidden hero is never named to a player.
Viewable(ctx context.Context, campaignID, entityID string, v Viewer) (bool, error)
// Party lists the campaign's hero pages (the claimed pages, the party) as
// the viewer may see them, for a Director's hero picker.
Party(ctx context.Context, campaignID string, v Viewer) ([]Hero, error)
}
Heroes is owned by this plugin and implemented in internal/app over the entities service, so decks never imports another plugin.
type KeepPlan ¶
type KeepPlan struct {
CampaignID string
DeckID string
CopyID string
From Place
TargetDeckID string
// TargetKinds is the target deck's kind keys, so the card's kind carries
// over only where the target has one by that key.
TargetKinds map[string]bool
Log LogLine
}
KeepPlan copies one card into another deck and sends the source copy to gone, in one transaction.
type KindDef ¶
type KindDef struct {
Key string `json:"key"`
Name string `json:"name"`
Colour string `json:"colour"`
// Sign is one of signValues; saved empty it is filled in by checkKinds.
Sign string `json:"sign"`
}
KindDef names a card kind, gives it a palette colour and a sign.
type LayerFact ¶
LayerFact is one transformation on a page. Source is the preset it came from ("" for one made by hand).
type LogLine ¶
type LogLine struct {
ID int64 `json:"id"`
DeckID string `json:"deckId"`
CardID string `json:"cardId,omitempty"`
CardName string `json:"cardName"`
CopyID string `json:"copyId,omitempty"`
Action string `json:"action"`
ActorUserID string `json:"actorUserId"`
HolderEntityID string `json:"holderEntityId,omitempty"`
Seen bool `json:"seen"`
CreatedAt time.Time `json:"createdAt"`
}
LogLine is one move, for Directors.
type Look ¶
type Look struct {
Shape string `json:"shape"`
Border string `json:"border"`
Turn string `json:"turn"`
// Window is only drawn on tall cards; it is kept for the others so a change
// of shape does not lose the choice.
Window string `json:"window"`
// Name is where the card's name sits.
Name string `json:"name"`
Lettering string `json:"lettering"`
// Corner is the style of the corner mark, not a card's corner text.
Corner string `json:"corner"`
Marker string `json:"marker"`
Finish string `json:"finish"`
Back Back `json:"back"`
Kinds []KindDef `json:"kinds"`
}
Look is how a deck's cards are drawn. Every value comes from a fixed list. Shape decides the build (tall is the plate and the leaf, the others the compact card), so there is no separate face key to contradict it.
type LookInput ¶
type LookInput struct {
Shape *string `json:"shape"`
Border *string `json:"border"`
Turn *string `json:"turn"`
Window *string `json:"window"`
Name *string `json:"name"`
Lettering *string `json:"lettering"`
Corner *string `json:"corner"`
Marker *string `json:"marker"`
Finish *string `json:"finish"`
Back *BackInput `json:"back"`
Kinds []KindDef `json:"kinds"`
}
LookInput is Look with every key optional: nil keeps what is there. Kinds nil keeps the list and an empty list clears it.
func (*LookInput) UnmarshalJSON ¶
UnmarshalJSON refuses a key the look does not have, naming it, so a typo or a value from a later version is a plain error and never silently dropped.
type Member ¶
type Member struct {
UserID string
// Name is how the person is shown ("" when they have none).
Name string
// Role is the membership role (1 player, 2 scribe, 3 owner).
Role int
// Director is the owner or a co-Director.
Director bool
// JoinedAt is when the member joined; a grant made before it is from an
// earlier stay.
JoinedAt time.Time
}
Member is one person in the campaign.
type Members ¶
Members lists the campaign's members, implemented in internal/app over the campaigns service. It checks the players a Director chooses and drops a grant made before the member's current stay.
type Moment ¶
type Moment struct {
ID string
CampaignID string
DeckID string
CardID string
// SubjectID is the hero the card's "any" tests held for; "" when it has none.
SubjectID string
// FitCount is how many cards with tests fit.
FitCount int
Reading Reading
State string
// Quiet is a moment that follows another too closely to be announced loudly.
Quiet bool
InvitedUserID string
CreatedAt time.Time
ClosedAt *time.Time
ClosedBy string
}
Moment is one waiting notice for one deck: the card the deck picked blind among the cards that fit, remembered and not dealt. Nothing leaves the pile until a Director deals.
type MomentClaim ¶
type MomentClaim struct {
ID string
// From lists the states the moment may be in.
From []string
To string
By string
// InvitedUserID, when set, must be the invited player.
InvitedUserID string
}
MomentClaim is a state change of a moment made inside another transaction, so an answer and the move it causes are one step.
type MomentNotifier ¶
type MomentNotifier interface {
MomentChanged(campaignID string)
}
MomentNotifier tells Directors that a moment opened, changed or closed. It carries nothing but the campaign: the message is Directors-only and the client fetches the moments again.
type MomentRepository ¶
type MomentRepository interface {
// WatchedDecks lists the decks of a campaign that need a look: those with a
// card that has tests and a notice that is not quiet, and those with an open
// moment. It is one indexed question and nothing else, because it runs after
// every page save in every campaign.
WatchedDecks(ctx context.Context, campaignID string) ([]string, error)
// PileCounts is how many copies of each card are in the pile.
PileCounts(ctx context.Context, campaignID, deckID string) (map[string]int, error)
// SetFits starts fits_since on the cards in start (where it is not set) and
// clears it on the cards in stop. started is how many cards it really
// started: a look that read the cards before another look marked them
// starts none, so it raises no second moment.
SetFits(ctx context.Context, campaignID, deckID string, start, stop []string) (started int, err error)
// ClearFits clears fits_since on every card of the deck.
ClearFits(ctx context.Context, campaignID, deckID string) error
// SetSaid sets or clears "the Director says so"; ok is false for a card that
// is not in the deck.
SetSaid(ctx context.Context, campaignID, deckID, cardID string, said bool) (ok bool, err error)
// Open finds the deck's open moment.
Open(ctx context.Context, campaignID, deckID string) (Moment, bool, error)
// ListOpen lists the campaign's open moments, oldest first.
ListOpen(ctx context.Context, campaignID string) ([]Moment, error)
Get(ctx context.Context, campaignID, id string) (Moment, bool, error)
// InvitedFor finds the moment that invites this player to draw from the deck.
InvitedFor(ctx context.Context, campaignID, deckID, userID string) (Moment, bool, error)
// Create stores a moment; created is false when the deck already has an open
// one (the unique key), which is not an error.
Create(ctx context.Context, m Moment) (created bool, err error)
// Repick changes the card of a waiting moment, only while it still waits on
// fromCard.
Repick(ctx context.Context, campaignID, id, fromCard string, to Moment) (bool, error)
// Refresh updates what an open moment says about its card without changing
// the card, only while it still holds forCard: a look that began before the
// moment was picked again must not write the old card's hero onto the new one.
Refresh(ctx context.Context, campaignID, id, forCard string, to Moment) (bool, error)
// Close moves an open moment to a closed state, only from one of from.
Close(ctx context.Context, campaignID, id string, from []string, to, by string) (bool, error)
// Invite moves a waiting moment to invited.
Invite(ctx context.Context, campaignID, id, userID string) (bool, error)
// LastClosed is when the deck's most recent moment closed.
LastClosed(ctx context.Context, campaignID, deckID string) (time.Time, bool, error)
}
MomentRepository is the persistence boundary for moments and for what is remembered about whether a card's tests hold.
func NewMomentRepository ¶
func NewMomentRepository(db *sql.DB) MomentRepository
NewMomentRepository creates the MariaDB-backed moment store.
type MomentView ¶
type MomentView struct {
ID string `json:"id"`
DeckID string `json:"deckId"`
DeckName string `json:"deckName"`
DeckKind string `json:"deckKind"`
// Notice is the deck's own setting for how loudly it tells the Director.
Notice string `json:"notice"`
Card *DirectorCard `json:"card"`
// SubjectID and Subject are the hero the card's "any" tests held for.
SubjectID string `json:"subjectId,omitempty"`
Subject string `json:"subject,omitempty"`
// Hero is the name of the hero the card would go to, "" when it goes to the
// party's hand or the table (or the page cannot be read).
Hero string `json:"hero,omitempty"`
FitCount int `json:"fitCount"`
Reading string `json:"reading,omitempty"`
ReadingSource string `json:"readingSource,omitempty"`
ReadAt *time.Time `json:"readAt,omitempty"`
Quiet bool `json:"quiet"`
State string `json:"state"`
InvitedUserID string `json:"invitedUserId,omitempty"`
InvitedName string `json:"invitedName,omitempty"`
// Answers are the answers this moment can be given right now.
Answers []string `json:"answers"`
CreatedAt time.Time `json:"createdAt"`
}
MomentView is an open moment as a Director reads it.
type MoonFact ¶
MoonFact is one moon on the current date. Day is the day of its cycle, the new moon's day being 1, or 0 for a moon set by hand; Words are the phase words it matches today ("Waning Crescent", "waning", "crescent").
type Move ¶
type Move struct {
CampaignID string
DeckID string
CopyID string
From Place
To Place
// ExpectAsked requires the copy to be waiting for a Director (approve and
// turn down).
ExpectAsked bool
Asked AskedChange
// Turned stamps turned_at.
Turned bool
// DealtBy stamps dealt_by and dealt_at; "" leaves them (and clears them
// when the copy goes back to the pile or the shown spot).
DealtBy string
// Log is written in the same transaction; CardID and CopyID are filled
// from the copy.
Log LogLine
}
Move is one claimed change of a copy. It applies only while the copy is still exactly in From, so a lost race changes nothing.
type Notifier ¶
Notifier carries "your decks view changed" to the people it is for. It is told after every stored move and edit, once, with who to tell and nothing else: no deck, copy, card or holder, so a message cannot say what moved.
type NumberField ¶
type NumberField struct {
Key string `json:"key"`
Label string `json:"label"`
MaxKey string `json:"maxKey,omitempty"`
}
NumberField is a number field a test may name. MaxKey is the field that holds its upper bound, when the game system says so.
type NumberSet ¶
type NumberSet struct {
// Sheet is whether the page has a stored sheet at all. A page with none
// never satisfies a number test.
Sheet bool
// Values is each number field's value by key. A field that is neither
// stored nor set by a layer is absent.
Values map[string]float64
// Sources says where a value came from, by key, only where the adapter
// knows: "layer" for a value a layer set or changed. A stored value has no
// entry, because the store does not say whether a hand or Foundry wrote it.
Sources map[string]string
// ChangedAt is when the page last changed.
ChangedAt time.Time
}
NumberSet is a page's numbers as the server can know them.
The server judges stored values and the page's number layers. A number the sheet only works out in the browser is not here, so a test on it reads as missing.
type OpenedCard ¶
type OpenedCard struct {
DeckID string
DeckName string
Look Look
Copy PlayerCopy
// InHand is a copy in a hand (not on the table or in play).
InHand bool
// CanPlay, CanShow and CanDiscard say which controls are on. They follow
// the rules Act applies, which still decide every request.
CanPlay bool
CanShow bool
CanDiscard bool
// Shown is a card its holder has shown to the table; it cannot be taken back.
Shown bool
}
OpenedCard is one face-up card read at full size, with what its viewer may do with it.
type Option ¶
type Option func(*service)
Option configures the service.
func WithFacts ¶
WithFacts sets what a card's tests are judged on. Without it only "the Director says so" can be used and no other test can be saved.
func WithMomentNotifier ¶
func WithMomentNotifier(n MomentNotifier) Option
WithMomentNotifier sets who carries the Directors-only moment message.
func WithMoments ¶
func WithMoments(m MomentRepository) Option
WithMoments sets where moments and what is remembered about tests are stored. Without it a deck notices nothing, and conditions still gate draws.
func WithNotifier ¶
WithNotifier sets who carries live messages after a move.
func WithPictures ¶
WithPictures sets who may say a media file is usable as a card's picture. Without it no card can have a picture, so a service built without the media side refuses rather than accepting an id nobody checked.
func WithPoke ¶
WithPoke sets what is told that something a card's tests read may have changed in a campaign. It is called after every write the service makes that can change whether a test holds, and does its work later, off the request.
func WithRandom ¶
WithRandom replaces the draw's random pick; tests use it to fix a draw.
func WithScreen ¶
func WithScreen(r ScreenRepository) Option
WithScreen sets where the Card decks section's picks and the shown dealt cards are kept. Without it the section and the pop-up check say nothing.
func WithStory ¶
WithStory sets who is told of draws, deals and plays. Without it, or with nil, nothing is told and moves behave exactly as before.
func WithSwitch ¶
WithSwitch says whether card decks are switched on for a campaign. With it, a campaign that switched them off raises no moments from the cards it still has.
func WithTables ¶
WithTables sets the reader of the campaign's rolling tables. Bound only while that plugin is healthy; without it a deck cannot be made from a table.
type OptionHero ¶
OptionHero is a hero page a test may name.
type OptionWord ¶
OptionWord is a key and the words it is said with.
type OtherHolds ¶
type OtherHolds struct {
HeroID string `json:"heroId"`
Count int `json:"count"`
// Faces are the face-up cards, sent only when others may see faces.
Faces []Face `json:"faces,omitempty"`
}
OtherHolds is what another hero holds, by what the deck lets others see.
type PageFinder ¶
type PageFinder interface {
// FindPage is the page's id and stored name, ok false when there is none.
FindPage(ctx context.Context, campaignID, name string) (id, stored string, ok bool, err error)
}
PageFinder finds a page by the name an AI wrote. It is implemented in internal/app over the entities service, so decks imports no other plugin.
type PickChange ¶
PickChange says which of a deck's two draw nudges an update changes, so a save that names neither never writes them back over a draw that cleared one.
type PictureUse ¶
PictureUse is one card that wears a media file as its picture.
type Pictures ¶
type Pictures interface {
// Usable is true only for an image of this campaign that is neither a page
// file nor in the Trash. A file that is missing, foreign or unusable all
// answer false with no error, so a refusal cannot tell them apart.
Usable(ctx context.Context, campaignID, mediaID string) (bool, error)
}
Pictures decides whether a media file may be a card's picture. It is owned here and implemented in internal/app over the media service, so decks never imports the media plugin.
type Place ¶
Place is where a copy sits: a zone, the hero page holding it (hand or play in front of a hero; "" is nobody, the whole table, or on a party deck the party's own hand) and which way up. Open is a face-up card in a hand shown to the table; every Place that leaves a hand has it false.
type Player ¶
type Player struct {
UserID string
// DrawsLeft is how many draws the player has left; nil is no limit.
DrawsLeft *int
// GrantedAt is when the Director chose the player; a grant older than the
// member's joined_at belongs to an earlier stay and counts for nothing.
GrantedAt time.Time
}
Player is one player a Director chose for a deck.
type PlayerCopy ¶
type PlayerCopy struct {
ID string `json:"id"`
DeckID string `json:"deckId"`
FaceUp bool `json:"faceUp"`
// Waiting is true while a play of this card waits for a Director.
Waiting bool `json:"waiting"`
// Open is true on a face-up card its holder has shown to the table. It is
// never set on a face-down copy, so a face-down entry is always the same
// four keys.
Open bool `json:"open,omitempty"`
// AskFirst is true on a face-up card whose play waits for a Director's
// answer, so the holder's button reads "Ask to play". It is never set on a
// face-down copy.
AskFirst bool `json:"askFirst,omitempty"`
Face *Face `json:"face,omitempty"`
}
PlayerCopy is a copy a player may know about. Face is present only for a copy that is face up; a face-down copy is its id, its deck and that it is face down.
type PlayerDeck ¶
type PlayerDeck struct {
ID string `json:"id"`
Name string `json:"name"`
Kind string `json:"kind"`
Look Look `json:"look"`
CanDraw bool `json:"canDraw"`
DrawsLeft *int `json:"drawsLeft"`
// DrawsOpen is true for a player the deck lets draw for themselves, even
// with no draws left, so the screen can say so.
DrawsOpen bool `json:"drawsOpen"`
Hands []PlayerHand `json:"hands"`
// PartyHand is the party deck's own hand, held by no hero and seen by every
// member of the campaign. Face-down copies are face-down entries.
PartyHand []PlayerCopy `json:"partyHand,omitempty"`
// Pile is the pile's count, present when the deck lets players know it.
Pile *int `json:"pile,omitempty"`
// Kinds is the pile's count per kind, present for "kinds" and "faces".
Kinds []KindCount `json:"kinds,omitempty"`
// Cards is every card's face, present only for "faces".
Cards []Face `json:"cards,omitempty"`
// Others is what other heroes hold, by the deck's othersSee.
Others []OtherHolds `json:"others,omitempty"`
// Used is the used pile of a party deck, visible to every member.
Used []PlayerCopy `json:"used,omitempty"`
// InvitedHeroID is set only for the player a Director invited to draw, and
// names the hero the card will go to. Everyone else's deck omits it.
InvitedHeroID string `json:"invitedHeroId,omitempty"`
}
PlayerDeck is a deck as a listed player sees it.
type PlayerHand ¶
type PlayerHand struct {
HeroID string `json:"heroId"`
Hand []PlayerCopy `json:"hand"`
Play []PlayerCopy `json:"play"`
}
PlayerHand is one of the viewer's own heroes and what they hold of a deck.
type PlayerInput ¶
type PlayerInput struct {
UserID string `json:"userId"`
// DrawsLeft nil is no limit.
DrawsLeft *int `json:"drawsLeft"`
}
PlayerInput chooses one player and how many draws they have.
type PlayerList ¶
type PlayerList struct {
Decks []PlayerDeck `json:"decks"`
}
PlayerList is a player's list of decks.
type Reading ¶
Reading is what a notice says about the first test that names a number or a tracker: the sentence of what it is now, where the value came from when the adapter knows, and when the page last changed.
type Repository ¶
type Repository interface {
CountDecks(ctx context.Context, campaignID string) (int, error)
// ListDecks lists the campaign's decks with their chosen players.
ListDecks(ctx context.Context, campaignID string) ([]Deck, error)
GetDeck(ctx context.Context, campaignID, id string) (Deck, bool, error)
// CreateDeck returns errDuplicate when the name is taken.
CreateDeck(ctx context.Context, d Deck) error
// CreateDeckWithCards stores the deck and every card with its pile copies in
// one transaction: all of it or nothing. errDuplicate when the deck's name is
// taken, errCardDuplicate when two cards share a name, errTargetFull or
// errTargetCopies when the card or copy limit would be passed.
CreateDeckWithCards(ctx context.Context, d Deck, cards []Card) error
// UpdateDeck writes d if its stored version is still expected; ok is
// false on a lost race. errDuplicate when the new name is taken. The draw
// nudges are written only as picks says.
UpdateDeck(ctx context.Context, d Deck, expected int, picks PickChange) (ok bool, err error)
DeleteDeck(ctx context.Context, campaignID, id string) error
// SetPlayers replaces the chosen players if the stored version is still
// expected, and bumps it.
SetPlayers(ctx context.Context, campaignID, deckID string, players []Player, expected int) (ok bool, err error)
ListCards(ctx context.Context, campaignID, deckID string) ([]Card, error)
GetCard(ctx context.Context, campaignID, deckID, id string) (Card, bool, error)
// CreateCard stores the card and its copies, all in the pile, under the
// deck's lock, and sets c.SortOrder. errDuplicate when the name is taken;
// errTargetFull or errTargetCopies, changing nothing, when the deck's
// card or copy limit would be passed.
CreateCard(ctx context.Context, c Card) error
// UpdateCard writes the card. Only when resize is true (the edit carried
// a copies value) does it write copies and bring the copies to c.Copies:
// it adds pile copies, or removes them from the pile, then used, then
// gone, and returns a *heldError, changing nothing, when more would have
// to come out of a hand or out of play, or errTargetCopies when the
// deck's copy limit would be passed. Without resize the stored copies are
// left alone, because a keep may have raised them since the caller read
// the card.
UpdateCard(ctx context.Context, c Card, resize bool) (ResizeResult, error)
// DeleteCard removes the card and its copies, and clears the deck's next
// or last card when it was this one.
DeleteCard(ctx context.Context, campaignID, deckID, id string) error
ListCopies(ctx context.Context, campaignID, deckID string) ([]Copy, error)
GetCopy(ctx context.Context, campaignID, deckID, id string) (Copy, bool, error)
// ListHeldBy lists the copies in hand or in play held by these pages.
ListHeldBy(ctx context.Context, campaignID string, holderIDs []string) ([]Copy, error)
// ZoneCounts counts every deck's copies by zone.
ZoneCounts(ctx context.Context, campaignID string) (map[string]ZoneCounts, error)
// ListTable lists the face-up copies in play in front of nobody, with the
// face of their card and their deck's name and look.
ListTable(ctx context.Context, campaignID string) ([]TableRow, error)
// CardsWithPicture lists the cards of the campaign that wear this media
// file. A campaign whose decks tables never migrated has none.
CardsWithPicture(ctx context.Context, campaignID, mediaID string) ([]PictureUse, error)
// PictureIDs lists the distinct media files any card of the campaign wears.
PictureIDs(ctx context.Context, campaignID string) ([]string, error)
// Draw takes p.Count copies (one by default) or none at all.
Draw(ctx context.Context, p DrawPlan) ([]Copy, error)
Move(ctx context.Context, m Move) error
// Keep returns errLostClaim when the copy moved first, errTargetFull,
// errTargetCopies or errCardCopies, changing nothing, when the target
// deck's limits would be passed, and errDuplicate when a card of that name
// appeared in the target through a writer that did not hold the deck lock.
Keep(ctx context.Context, k KeepPlan) error
// Shuffle moves the used pile back to the pile and returns how many.
Shuffle(ctx context.Context, campaignID, deckID string, log LogLine) (int, error)
// Gather moves every copy to the pile and returns how many moved.
Gather(ctx context.Context, campaignID, deckID string, log LogLine) (int, error)
ListLog(ctx context.Context, campaignID, deckID string, limit int) ([]LogLine, error)
}
Repository is the persistence boundary for decks.
func NewRepository ¶
func NewRepository(db *sql.DB) Repository
NewRepository creates a MariaDB-backed repository.
type ResizeResult ¶
type ResizeResult struct{ Added, Removed int }
ResizeResult reports a copies change.
type Roster ¶
Roster is the campaign's hero pages and people, as a Director picks them on a deck: a hero for a hero deck, and the players a deck may be drawn by.
type SayInput ¶
type SayInput struct {
Said bool `json:"said"`
}
SayInput is the body of the say route.
type ScreenChoice ¶
ScreenChoice is one line of the "Choose decks" list.
type ScreenDeck ¶
ScreenDeck is one deck row of the section.
func (ScreenDeck) Sub ¶
func (d ScreenDeck) Sub() string
Sub is the row's second line: "Events · 9 left · 2 drawn", with no drawn part when nothing is drawn.
type ScreenRepository ¶
type ScreenRepository interface {
// Picks lists the decks a Director chose for the section, in their order.
Picks(ctx context.Context, campaignID, userID string) ([]string, error)
// SetPicks replaces the Director's picks; an empty list clears them.
SetPicks(ctx context.Context, campaignID, userID string, deckIDs []string) error
// LastMoves gives, per deck, the id of its newest log line. A deck with no
// line is absent.
LastMoves(ctx context.Context, campaignID string) (map[string]int64, error)
// Fresh lists, newest deal first and at most limit, the face-down copies in
// hand of these heroes that someone other than userID dealt within the last
// window and that userID has not been shown.
Fresh(ctx context.Context, campaignID, userID string, heroIDs []string, window time.Duration, limit int) ([]FreshRow, error)
// MarkSeen records that userID was shown the copy. Marking twice is fine.
MarkSeen(ctx context.Context, campaignID, userID, copyID string) error
}
ScreenRepository stores what the DM Screen's Card decks section remembers and which dealt cards a player has been shown. It sits beside Repository, as the moments store does, so the decks core does not depend on it.
SECURITY: every statement filters on campaign_id, and a pick is stored only for a deck of that campaign, so an id from another campaign never reads or changes anything here.
func NewScreenRepository ¶
func NewScreenRepository(db *sql.DB) ScreenRepository
NewScreenRepository creates the MariaDB-backed store.
type ScreenShown ¶
ScreenShown is a card a Director has drawn and not dealt, as the section draws it.
type ScreenView ¶
type ScreenView struct {
CampaignID string
// Shown are the decks the section lists: the Director's picks in their
// order, or the decks with the newest moves.
Shown []ScreenDeck
// Rest are the other decks, folded behind "All decks".
Rest []ScreenDeck
// Total is every deck of the campaign.
Total int
Choices []ScreenChoice
// Heroes are the party's heroes, for "Deal to…".
Heroes []Hero
}
ScreenView is the Card decks section, for a Director.
func (*ScreenView) Summary ¶
func (v *ScreenView) Summary() string
Summary is the section's one line on the screen's rail: "3 decks · 2 drawn".
type Service ¶
type Service interface {
// List returns the Directors' list, or the player's own list, by who asks.
List(ctx context.Context, campaignID string, v Viewer) (DeckListView, error)
// Get returns one deck as the viewer may see it; a deck they may not see
// is a 404.
Get(ctx context.Context, campaignID, deckID string, v Viewer) (DeckView, error)
Create(ctx context.Context, campaignID string, v Viewer, in CreateDeckInput) (DeckView, error)
Update(ctx context.Context, campaignID, deckID string, v Viewer, in UpdateDeckInput) (DeckView, error)
Delete(ctx context.Context, campaignID, deckID string, v Viewer) error
SetPlayers(ctx context.Context, campaignID, deckID string, v Viewer, in SetPlayersInput) (DeckView, error)
CreateCard(ctx context.Context, campaignID, deckID string, v Viewer, in CreateCardInput) (DeckView, error)
UpdateCard(ctx context.Context, campaignID, deckID, cardID string, v Viewer, in UpdateCardInput) (DeckView, error)
DeleteCard(ctx context.Context, campaignID, deckID, cardID string, v Viewer) (DeckView, error)
// Draw is a Director's draw to the shown spot, or a player's draw into the
// named hero's hand.
Draw(ctx context.Context, campaignID, deckID string, v Viewer, in DrawInput) (*ActionResult, error)
// Act applies a verb to one copy.
Act(ctx context.Context, campaignID, deckID, copyID, verb string, v Viewer, in ActInput) (*ActionResult, error)
// DealCard deals a random pile copy of a named card.
DealCard(ctx context.Context, campaignID, deckID string, v Viewer, in DealCardInput) (*ActionResult, error)
Shuffle(ctx context.Context, campaignID, deckID string, v Viewer) (*ActionResult, error)
Gather(ctx context.Context, campaignID, deckID string, v Viewer) (*ActionResult, error)
// Say sets or clears "the Director says so" on a card. Directors only.
Say(ctx context.Context, campaignID, deckID, cardID string, v Viewer, said bool) (DeckView, error)
// WhenOptions is what the card editor may offer for a test. Directors only.
WhenOptions(ctx context.Context, campaignID string, v Viewer) (WhenOptionsView, error)
// CreateFrom starts a deck from another deck of the campaign or from one of
// its rolling tables, with every card, in one transaction. Directors only.
CreateFrom(ctx context.Context, campaignID string, v Viewer, in CreateFromInput) (DeckView, FromReport, error)
// RollingTables lists the tables a deck could be made from. Directors only.
RollingTables(ctx context.Context, campaignID string, v Viewer) (TableChoices, error)
// ValidateWhen checks a card's tests against the campaign and returns them
// normalized; every writer of a card's tests calls it.
ValidateWhen(ctx context.Context, campaignID string, d Deck, tests []WhenTest) ([]WhenTest, error)
// BrokenTests says which tests of a stored list name something that no
// longer exists.
BrokenTests(ctx context.Context, campaignID string, d Deck, tests []WhenTest) []bool
// SayWhen says each test in words, with whether every name in it still
// resolves, using the sentence writer the editor and the notice use.
// Directors only: a test may name a tag or layer no player can read.
SayWhen(ctx context.Context, campaignID string, d Deck, v Viewer, tests []WhenTest) ([]WhenView, error)
// Moments lists the campaign's open moments for a Director. It looks again
// first when nothing has looked in the last few seconds.
Moments(ctx context.Context, campaignID string, v Viewer) ([]MomentView, error)
// DealMoment deals the moment's card, an ordinary deal.
DealMoment(ctx context.Context, campaignID, momentID string, v Viewer) (*ActionResult, error)
// AnotherMoment picks again among the other cards that fit.
AnotherMoment(ctx context.Context, campaignID, momentID string, v Viewer) (*MomentView, error)
// InviteMoment lets the hero's player draw.
InviteMoment(ctx context.Context, campaignID, momentID string, v Viewer) (*MomentView, error)
// DismissMoment sets the moment aside, or takes an invitation back.
DismissMoment(ctx context.Context, campaignID, momentID string, v Viewer) (*MomentView, error)
// Recheck looks at every card with tests in the campaign and raises, re-picks
// or lapses moments. It never deals.
Recheck(ctx context.Context, campaignID string) error
// Roster is who a Director can name on a deck: the campaign's hero pages
// and its people. Directors only.
Roster(ctx context.Context, campaignID string, v Viewer) (Roster, error)
// Table returns the cards lying in front of the whole table, from every
// deck, to any member.
Table(ctx context.Context, campaignID string, v Viewer) (*TableView, error)
// Hand reads what the Hand leaf draws, from the player types only.
Hand(ctx context.Context, campaignID string, v Viewer) (*HandView, error)
// HeroHand reads the strip on one hero's page.
HeroHand(ctx context.Context, campaignID, heroID string, v Viewer) (*HeroHandView, error)
// Open reads one face-up card at full size with what its viewer may do.
Open(ctx context.Context, campaignID, deckID, copyID string, v Viewer) (*OpenedCard, error)
// TurnFace turns one face-down copy over and returns its face.
TurnFace(ctx context.Context, campaignID, deckID, copyID string, v Viewer) (*OpenedCard, error)
// Screen reads the DM Screen's Card decks section. Directors only.
Screen(ctx context.Context, campaignID string, v Viewer) (*ScreenView, error)
// SetScreenPicks stores the decks a Director chose for that section.
SetScreenPicks(ctx context.Context, campaignID string, v Viewer, deckIDs []string) error
// DrawView reads a deck for the draw overlay: any deck for a Director, a
// deck open to them to draw from for a player, from the player types only.
DrawView(ctx context.Context, campaignID, deckID string, v Viewer) (*DrawView, error)
// ShownFace reads a shown copy's face for a Director.
ShownFace(ctx context.Context, campaignID, deckID, copyID string, v Viewer) (*OpenedCard, error)
// FreshCards lists dealt face-down cards a player has not been shown yet.
FreshCards(ctx context.Context, campaignID string, v Viewer) ([]FreshCard, error)
// MarkFreshSeen records that a player was shown a dealt card.
MarkFreshSeen(ctx context.Context, campaignID, copyID string, v Viewer) error
// IsCardPicture says whether any card of the campaign wears the media file.
// It answers true on an error, so a caller that ignores the error refuses.
IsCardPicture(ctx context.Context, campaignID, mediaID string) (bool, error)
// CardPictureSeenBy says whether a copy of a card wearing the media file is
// face up to the viewer right now, by the rules that build what they are
// sent. A Director always sees it.
CardPictureSeenBy(ctx context.Context, campaignID, mediaID string, v Viewer) (bool, error)
// CardPictureIDs lists the media files the campaign's cards wear.
CardPictureIDs(ctx context.Context, campaignID string) ([]string, error)
// CardPictureUses names the decks and cards that wear the media file, for
// Directors only.
CardPictureUses(ctx context.Context, campaignID, mediaID string, v Viewer) ([]PictureUse, error)
}
Service owns the deck rules. Handlers only bind and render; every check of who may see or do what is here, so a mis-wired route cannot widen access.
func NewService ¶
func NewService(repo Repository, heroes Heroes, members Members, opts ...Option) Service
NewService builds the service.
type SetPlayersInput ¶
type SetPlayersInput struct {
Version int `json:"version"`
Players []PlayerInput `json:"players"`
}
SetPlayersInput replaces a deck's chosen players.
type Settings ¶
type Settings struct {
// Draws is who draws: "directors" or "players".
Draws string `json:"draws"`
// Knows is what a player who can see the deck may know of it.
Knows string `json:"knows"`
// OthersSee is what other players see of a card dealt to one hero.
OthersSee string `json:"othersSee"`
// Arrives is how a card dealt to a hero lands: "down" or "up".
Arrives string `json:"arrives"`
// Fate is the deck's default after a card is played.
Fate string `json:"fate"`
// Empty is what a draw from an empty pile does.
Empty string `json:"empty"`
// Discard lets players discard from their own hand.
Discard bool `json:"discard"`
// Notice is how a dealt card announces itself. It is stored and checked
// only; nothing reads it yet.
Notice string `json:"notice"`
}
Settings are a deck's rules. They are stored as a re-marshal of this typed struct, so an unknown key in a request never reaches the database.
type SettingsInput ¶
type SettingsInput struct {
Draws *string `json:"draws"`
Knows *string `json:"knows"`
OthersSee *string `json:"othersSee"`
Arrives *string `json:"arrives"`
Fate *string `json:"fate"`
Empty *string `json:"empty"`
Discard *bool `json:"discard"`
Notice *string `json:"notice"`
}
SettingsInput is Settings with every key optional: nil keeps what is there.
type Story ¶
type Story interface {
// CardDrawn is told once per card that arrives where people play it from:
// a hero's hand, the party's hand or the table. A Director's draw to the
// shown spot, "another" and a put back are the Director looking and tell
// nothing; the deal that follows does.
CardDrawn(ctx context.Context, campaignID string, e CardEvent)
// CardPlayed is told when a card is really played: for an "ask first"
// card that is when a Director lets it through, not when the player asks.
CardPlayed(ctx context.Context, campaignID string, e CardEvent)
}
Story hears moves once they are stored. It is told after the move's transaction has committed and the deck's lock is released, so it can neither fail nor hold up the move; whatever it does with the event is its own business, and nothing about the event is sent to any browser from here.
type TableChoices ¶
type TableChoices struct {
// Available is false while the rolling tables plugin cannot be read.
Available bool
Tables []TableSummary
}
TableChoices is what the New deck page offers under "From a rolling table".
type TableDeck ¶
type TableDeck struct {
DeckID string `json:"deckId"`
Name string `json:"name"`
Kind string `json:"kind"`
Look Look `json:"look"`
Cards []TableCard `json:"cards"`
}
TableDeck is one deck's cards on the table.
type TableLine ¶
type TableLine struct {
Name string
Brief string
Weight float64
// HasDays says the line only comes up on certain days.
HasDays bool
}
TableLine is one line of a rolling table.
type TableRow ¶
type TableRow struct {
CopyID string
DeckID string
DeckName string
DeckKind string
Look Look
Face Face
Tests []WhenTest
}
TableRow is a card on the table with what a viewer needs to draw it. It holds no Director's note. Tests are read only so the service can print the ones the Director chose to print; a row is never sent as it is.
type TableSummary ¶
TableSummary is one rolling table in a list.
type TableView ¶
type TableView struct {
Decks []TableDeck `json:"decks"`
}
TableView is every card lying in front of the whole table.
type Tables ¶
type Tables interface {
// List is the campaign's tables, in their own order.
List(ctx context.Context, campaignID string) ([]TableSummary, error)
// Lines reads one table's lines; ok is false when there is no such table.
Lines(ctx context.Context, campaignID, tableID string) (lines []TableLine, name string, ok bool, err error)
}
Tables reads the campaign's rolling tables so a deck can be made from one. It is owned here and implemented in internal/app over the rolling tables service, and bound only while that plugin is healthy, so decks never imports it. Every method answers as a Director would see it: a Director-only table is listed too, because the workshop is the Director's.
type TodayFact ¶
type TodayFact struct {
// Moons are the moons the viewer may see, by lower-cased, trimmed name.
Moons map[string]MoonFact
// Events are the lower-cased names of today's events and the slugs and
// names of their kinds. Nil when they could not be read, which is a
// missing fact, not an empty day.
Events map[string]bool
// DayPart is dawn, day, dusk or night; "" when the calendar can't say.
DayPart string
}
TodayFact is the main calendar's current date as one viewer sees it.
type TrackerFact ¶
TrackerFact is one tracker on a page.
type TrackerKindOption ¶
TrackerKindOption is a tracker kind a test may name.
type UpdateCardInput ¶
type UpdateCardInput struct {
Name patch.Field[string] `json:"name"`
KindKey patch.Field[string] `json:"kindKey"`
Words patch.Field[string] `json:"words"`
DirectorNote patch.Field[string] `json:"directorNote"`
Picture patch.Field[string] `json:"picture"`
Corner patch.Field[string] `json:"corner"`
Rare patch.Field[bool] `json:"rare"`
Copies patch.Field[int] `json:"copies"`
Fate patch.Field[string] `json:"fate"`
// When replaces the whole list of tests; null or [] clears it.
When patch.Field[WhenList] `json:"when"`
AskFirst patch.Field[bool] `json:"askFirst"`
}
UpdateCardInput is a partial update of a card.
type UpdateDeckInput ¶
type UpdateDeckInput struct {
Version patch.Field[int] `json:"version"`
Name patch.Field[string] `json:"name"`
Kind patch.Field[string] `json:"kind"`
HolderEntityID patch.Field[string] `json:"holderEntityId"`
Settings patch.Field[SettingsInput] `json:"settings"`
Look patch.Field[LookInput] `json:"look"`
// NextCardID and LastCardID are Director-only: absent keeps, null or ""
// clears, a card id of this deck sets.
NextCardID patch.Field[string] `json:"nextCardId"`
LastCardID patch.Field[string] `json:"lastCardId"`
}
UpdateDeckInput is a partial update: an absent key keeps the stored value, an explicit null clears the hero page, a value replaces. Version is required and is the version the editor loaded.
type Viewer ¶
type Viewer struct {
UserID string
// MemberRole is the real membership role (0 none/guest .. 3 owner). A
// player rule needs at least RolePlayer, so a former member or a visitor
// to a public campaign never matches.
MemberRole int
// VisibilityRole decides what the viewer may see on a hero page.
VisibilityRole int
// Director is the owner or a co-Director.
Director bool
}
Viewer is who is asking, taken from the campaign context in the handler.
type WhenList ¶
type WhenList []WhenTest
WhenList is a card's tests as they arrive in a request. Its decoder refuses an unknown key or kind by name, so a typo is never stored as a test that quietly does nothing.
func (*WhenList) UnmarshalJSON ¶
UnmarshalJSON accepts a list of tests, and "", null or [] for none.
type WhenOptions ¶
type WhenOptions struct {
Heroes []OptionHero `json:"heroes"`
Fields []NumberField `json:"fields"`
Trackers []TrackerKindOption `json:"trackers"`
Tags []TagOption `json:"tags"`
// Layers are the transformation names now on any hero, for the editor to
// offer; a test may still name one that is not on a page yet.
Layers []string `json:"layers"`
// Calendar is whether the campaign's main calendar could be read; without
// it no moon, event or time test can hold.
Calendar bool `json:"hasCalendar"`
// Moons are the main calendar's moons by name, hidden ones included.
Moons []string `json:"moons"`
// EventKinds are the campaign's kinds of event, for the editor to offer; an
// event test may also name an event.
EventKinds []EventKindOption `json:"eventKinds"`
}
WhenOptions is what the editor may offer for a campaign: the party, the number fields of hero pages, and the tracker kinds and tags that exist.
type WhenOptionsView ¶
type WhenOptionsView struct {
WhenOptions
// Available is false when no facts are wired, so only "the Director says
// so" can be used.
Available bool `json:"available"`
Ops []OptionWord `json:"ops"`
TestKinds []OptionWord `json:"testKinds"`
// DayParts and MoonPhases are what a time and a moon test may name.
DayParts []OptionWord `json:"dayParts"`
MoonPhases []OptionWord `json:"moonPhases"`
MaxTests int `json:"maxTests"`
}
WhenOptionsView is what the options route returns: Options plus the words the editor needs to say a test in a sentence.
type WhenTest ¶
type WhenTest struct {
Test string `json:"test"`
// Open says the test is printed on the card.
Open bool `json:"open"`
Who string `json:"who,omitempty"`
// Field, Op, Value, Of and Share are a number test; a tracker test uses Op and
// Value too.
Field string `json:"field,omitempty"`
Op string `json:"op,omitempty"`
Value *float64 `json:"value,omitempty"`
Of string `json:"of,omitempty"`
// Kind is a tracker kind id.
Kind string `json:"kind,omitempty"`
// Tag is a tag id and Has whether the page has it.
Tag *int `json:"tag,omitempty"`
Has *bool `json:"has,omitempty"`
// Name is a layer's name or source and On whether it is on the page. A
// moon test names the moon and an event test the event or kind of event.
Name string `json:"name,omitempty"`
On *bool `json:"on,omitempty"`
// Phase is a moon's phase word, or From and To a range of days of its
// cycle (the new moon's day is 1; a range may wrap, 23 to 1).
Phase string `json:"phase,omitempty"`
From *int `json:"from,omitempty"`
To *int `json:"to,omitempty"`
// Time is a part of the day.
Time string `json:"time,omitempty"`
// Is says whether the moon or the time of day is so, for the "not" form.
Is *bool `json:"is,omitempty"`
}
WhenTest is one test. Only the keys of its kind are used; ParseWhen refuses any other.
type WhenView ¶
type WhenView struct {
WhenTest
Sentence string `json:"sentence"`
// Broken is true when a hero, field, tracker kind, tag or moon the test
// names no longer exists; such a test can never hold.
Broken bool `json:"broken"`
}
WhenView is a test as a Director reads it back: the test, its sentence and whether every name in it still resolves.
Source Files
¶
- ai.go
- ai_card.go
- ai_lookup.go
- audience.go
- block.go
- card_look.go
- create_from.go
- directory.go
- doc.go
- embed.go
- errors.go
- facts.go
- fits.go
- hand.go
- hand_handlers.go
- hand_page.go
- handler.go
- model.go
- moment_handlers.go
- moment_panel.go
- moments.go
- moments_repo.go
- moves.go
- notify.go
- repository.go
- roster.go
- routes.go
- say.go
- screen.go
- screen_handlers.go
- screen_repo.go
- service.go
- settings.go
- story.go
- styles.go
- when.go
- workshop.go
- workshop_look.go
- workshop_rules.go