Documentation
¶
Overview ¶
Hand-written SQL for the notice-board tables.
SECURITY: every statement filters on campaign_id, and board and item lookups also on the owning home (page or category) / board, so an id from another campaign, home or board is simply not found (no cross-tenant or cross-home access).
Package quests holds the quest sheet behind a page's Quest board block and the notice boards that place pages (taverns, temples) pin quests, notes, pages and maps to. Chronicle validates, stores and gates the data; the pinboard drawing lives in the widgets.
Everything the service returns is already filtered for the viewer: the widgets never receive a hidden step, a DM-only item or the name of a page the viewer cannot open, so a client bug cannot leak them.
The browser HTTP surface for quests and notice boards. Handlers bind, call the service and shape the response; the services own every rule, so a mis-wired route cannot widen access.
Hand-written SQL for the quests table.
SECURITY: every statement filters on campaign_id as well as the page id, so a page id from another campaign never reads or overwrites a sheet here.
Route registration for quests and notice boards.
Index ¶
- Constants
- Variables
- func RegisterRoutes(e *echo.Echo, h *Handler, campaignSvc campaigns.CampaignService, ...)
- func WithAnnouncer(q QuestService, b BoardService, entities EntityDirectory, types TypeDirectory, ...) (QuestService, BoardService)
- type AIQuests
- type Announcer
- type Archive
- type ArchivedQuest
- type Board
- type BoardPatch
- type BoardRepository
- type BoardService
- type BoardSummary
- type BoardView
- type BoardsView
- type CalendarDirectory
- type CalendarMonth
- type CalendarView
- type CharacterDirectory
- type CharacterInfo
- type DMQuestView
- type DayView
- type DigestQuest
- type DueDay
- type DueEvent
- type DueView
- type EntityDirectory
- type EntityInfo
- type Foe
- type FoeView
- type Handler
- func (h *Handler) ClearPlayerItems(c *echo.Context) error
- func (h *Handler) CreateBoard(c *echo.Context) error
- func (h *Handler) CreateItem(c *echo.Context) error
- func (h *Handler) DeleteBoard(c *echo.Context) error
- func (h *Handler) DeleteItem(c *echo.Context) error
- func (h *Handler) GetBoards(c *echo.Context) error
- func (h *Handler) GetQuest(c *echo.Context) error
- func (h *Handler) OpenQuestsBlock(c *echo.Context) error
- func (h *Handler) PatchBoard(c *echo.Context) error
- func (h *Handler) PatchItem(c *echo.Context) error
- func (h *Handler) Picker(c *echo.Context) error
- func (h *Handler) PutQuest(c *echo.Context) error
- func (h *Handler) SetLooks(c *echo.Context) error
- func (h *Handler) SetOrder(c *echo.Context) error
- func (h *Handler) SetPlacementChecker(p campaigns.BlockPlacementChecker)
- type Home
- type HomeView
- type Item
- type ItemInput
- type ItemPatch
- type ItemView
- type Layout
- type LayoutPatch
- type Link
- type LinkView
- type Looks
- type LooksPatch
- type MapDirectory
- type MapInfo
- type MapRef
- type Me
- type MemberNames
- type Notice
- type PickerItem
- type PickerService
- type PlayerQuestView
- type PlayerStep
- type Quest
- type QuestCalendar
- type QuestChange
- type QuestChanges
- type QuestDigest
- type QuestEntry
- type QuestPatch
- type QuestRepository
- type QuestService
- type Rect
- type Remap
- type Reward
- type RewardView
- type StampedSheet
- type Step
- type TypeDirectory
- type Viewer
Constants ¶
const ( MaxBoardsPerPage = 12 MaxItemsPerBoard = 60 )
Caps keep one page's boards bounded; they are abuse limits, so the small race between counting and inserting is accepted.
const ( StatusNotStarted = "not_started" StatusActive = "active" StatusDone = "done" StatusFailed = "failed" LookLit = "lit" LookPlain = "plain" LookParchment = "parchment" LookMidnight = "midnight" WhoDM = "dm" WhoScribe = "scribe" WhoAll = "all" KindNotice = "notice" KindNote = "note" KindPage = "page" KindMap = "map" KindString = "string" )
Allowed enums.
const ( PickPage = "page" PickQuest = "quest" PickMap = "map" // PickCharacter lists who rewards can be handed to: DM only. PickCharacter = "character" )
Picker kinds. A quest is any page, since any page can hold a quest sheet.
const (
MaxBodyBytes = 256 * 1024
)
Limits keep one page's sheet bounded; it is prep notes, not a content store.
const MaxPickerResults = 25
MaxPickerResults caps a picker answer.
const PluginSlug = "quests"
PluginSlug names this plugin in the registry and the health/migration bookkeeping.
Variables ¶
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 (same pattern as the other plugins).
var StaticAssetsFS embed.FS
StaticAssetsFS holds the quest board and notice board scripts, served at /static/plugins/quests/ and loaded only on pages that show a board.
Functions ¶
func RegisterRoutes ¶
func RegisterRoutes(e *echo.Echo, h *Handler, campaignSvc campaigns.CampaignService, authSvc auth.AuthService)
RegisterRoutes mounts the routes under the campaign group. Reads follow the page: anyone who can view the page (a public-campaign guest included) may read, and the service hides what the viewer must not see. Writes need a signed-in member; the service then decides per board and per item. CSRF is enforced by the global middleware.
func WithAnnouncer ¶
func WithAnnouncer(q QuestService, b BoardService, entities EntityDirectory, types TypeDirectory, a Announcer) (QuestService, BoardService)
WithAnnouncer wraps the services so every successful change is announced. A nil announcer returns them unchanged.
Types ¶
type AIQuests ¶
type AIQuests struct {
// contains filtered or unexported fields
}
AIQuests is the quests' part of the AI engine (aiplug): the `quests` lookup, every quest with its status and the notice board it is pinned on. It reads through the two services with a Viewer built from the asker, so each reader gets what the Quests screens give them: the Director team the whole list, anyone else (Safe privacy, a player's key) only the notices a board they may open shows, with the services' own rules for hidden items and pages they cannot open.
func NewAIQuests ¶
func NewAIQuests(q QuestService, b BoardService) *AIQuests
NewAIQuests builds the lookup over the quests plugin's services.
func (*AIQuests) Answer ¶
func (l *AIQuests) Answer(ctx context.Context, campaignID string, a aiplug.Actor, _ aiplug.Record) (string, string, error)
Answer lists the quests the Actor may see.
func (*AIQuests) LookupInfo ¶
func (*AIQuests) LookupInfo() aiplug.LookupInfo
LookupInfo describes `what: quests` and its tool. It is not owner-only: a player's key gets the notices on boards a player can see.
type Announcer ¶
type Announcer interface {
// QuestChanged says a quest sheet was saved at version.
QuestChanged(campaignID, entityID string, version int, dmOnly bool)
// BoardsChanged says a home's boards, items or looks changed.
BoardsChanged(campaignID string, h Home, dmOnly bool)
}
Announcer tells open quest boards and notice boards that something they show has changed. It carries ids only: each browser fetches again through its own route, so what anyone sees is still decided by the services. It is implemented in internal/app over the websocket hub.
type Archive ¶
type Archive interface {
// Export returns every stored sheet, ordered by page id.
Export(ctx context.Context, campaignID string) ([]ArchivedQuest, error)
// Import validates a sheet and stores it on the page entityID, with every
// reference already pointed at the new campaign by remap. It returns what
// it had to leave out, in plain words.
Import(ctx context.Context, campaignID, entityID, userID string, data []byte, remap Remap) ([]string, error)
}
Archive moves quest sheets in and out of a campaign export. It is separate from QuestService because an export is the owner's whole copy (DM-only ledger included) and an import writes straight to storage: it must not create due-date calendar events, which the imported calendar already holds.
func NewArchive ¶
func NewArchive(repo QuestRepository, entities EntityDirectory, maps MapDirectory, cal CalendarDirectory) Archive
NewArchive builds the archive over the same stores the quest service uses.
type ArchivedQuest ¶
type ArchivedQuest struct {
EntityID string
// Name is the page's name, for naming a sheet in an import report.
Name string
Data []byte
}
ArchivedQuest is one stored sheet and the page it belongs to.
type Board ¶
type Board struct {
ID string
CampaignID string
Home Home
Name string
Who string
// Fill lists the quest statuses the board shows by itself; empty means
// every notice is pinned by hand.
Fill []string
SortOrder int
}
Board is a stored board.
type BoardPatch ¶
type BoardPatch struct {
Name patch.Field[string] `json:"name"`
Who patch.Field[string] `json:"who"`
Fill patch.Field[[]string] `json:"fill"`
}
BoardPatch renames a board, changes who may pin to it, or sets which quest statuses it fills itself with (an empty list or null stops filling).
type BoardRepository ¶
type BoardRepository interface {
GetLooks(ctx context.Context, campaignID string, h Home) (Looks, error)
SetLooks(ctx context.Context, campaignID string, h Home, l Looks) error
ListBoards(ctx context.Context, campaignID string, h Home) ([]Board, error)
// ListFillBoards returns every board in the campaign that fills itself
// with quests, whatever its home.
ListFillBoards(ctx context.Context, campaignID string) ([]Board, error)
// ListHomes returns every home in the campaign with at least one board.
ListHomes(ctx context.Context, campaignID string) ([]Home, error)
// GetBoard returns NotFound unless the board belongs to the home and campaign.
GetBoard(ctx context.Context, campaignID string, h Home, boardID string) (*Board, error)
InsertBoard(ctx context.Context, b Board) error
UpdateBoard(ctx context.Context, b Board) error
DeleteBoard(ctx context.Context, campaignID string, h Home, boardID string) error
// SetOrder writes sort_order by position, atomically.
SetOrder(ctx context.Context, campaignID string, h Home, ids []string) error
ListItems(ctx context.Context, campaignID string, boardIDs []string) ([]Item, error)
// GetItem returns NotFound unless the item is on that board and campaign.
GetItem(ctx context.Context, campaignID, boardID, itemID string) (*Item, error)
CountItems(ctx context.Context, campaignID, boardID string) (int, error)
InsertItem(ctx context.Context, it Item) error
// InsertAutoItem pins a notice the board placed itself; a second one for
// the same quest on the same board is silently skipped.
InsertAutoItem(ctx context.Context, it Item) error
UpdateItem(ctx context.Context, it Item) error
DeleteItems(ctx context.Context, campaignID, boardID string, ids []string) error
}
BoardRepository is the persistence boundary for boards and their items.
func NewBoardRepository ¶
func NewBoardRepository(db *sql.DB) BoardRepository
NewBoardRepository creates a MariaDB-backed repository.
type BoardService ¶
type BoardService interface {
// View returns the home's boards as v may see them.
View(ctx context.Context, campaignID string, h Home, v Viewer) (*BoardsView, error)
// Homes lists the places with boards that v may open: categories first,
// then pages by name.
Homes(ctx context.Context, campaignID string, v Viewer) ([]HomeView, error)
CreateBoard(ctx context.Context, campaignID string, h Home, v Viewer, name, who string) (*BoardView, error)
PatchBoard(ctx context.Context, campaignID string, h Home, boardID string, v Viewer, p BoardPatch) (*BoardSummary, error)
DeleteBoard(ctx context.Context, campaignID string, h Home, boardID string, v Viewer) error
SetOrder(ctx context.Context, campaignID string, h Home, v Viewer, ids []string) error
SetLooks(ctx context.Context, campaignID string, h Home, v Viewer, p LooksPatch) (Looks, error)
// ClearPlayerItems removes everything players pinned (not the DM's own
// pieces, and never notices) and returns how many items went.
ClearPlayerItems(ctx context.Context, campaignID string, h Home, boardID string, v Viewer) (int, error)
CreateItem(ctx context.Context, campaignID string, h Home, boardID string, v Viewer, in ItemInput) (*ItemView, error)
PatchItem(ctx context.Context, campaignID string, h Home, boardID, itemID string, v Viewer, p ItemPatch) (*ItemView, error)
DeleteItem(ctx context.Context, campaignID string, h Home, boardID, itemID string, v Viewer) error
// FillQuest brings one quest's notice in line with every board that fills
// itself: pinned where its status matches, taken down where it no longer
// does. It runs after a quest is saved, so it takes no viewer, and returns
// the homes whose boards changed.
FillQuest(ctx context.Context, campaignID, questID string) ([]Home, error)
}
BoardService owns the notice-board rules: who may change which board, what each viewer may see, and the caps.
func NewBoardService ¶
func NewBoardService(repo BoardRepository, quests QuestRepository, entities EntityDirectory, types TypeDirectory, maps MapDirectory, members MemberNames, cal CalendarDirectory) BoardService
NewBoardService builds the service.
type BoardSummary ¶
type BoardSummary struct {
ID string `json:"id"`
Name string `json:"name"`
Who string `json:"who"`
CanChange bool `json:"canChange"`
// Fill is the quest statuses the board shows by itself, never null.
Fill []string `json:"fill"`
// Full says a board that fills itself has reached the item cap, so a
// matching quest may be missing from it. Absent otherwise.
Full bool `json:"full,omitempty"`
}
BoardSummary is a board without its items.
type BoardView ¶
type BoardView struct {
BoardSummary
Items []ItemView `json:"items"`
}
BoardView is a board with the items the viewer may see.
type BoardsView ¶
type BoardsView struct {
CanManage bool `json:"canManage"`
Me Me `json:"me"`
Looks Looks `json:"looks"`
Boards []BoardView `json:"boards"`
// MapsOn is false when the maps addon is off, so map choices are hidden.
MapsOn bool `json:"mapsOn"`
}
BoardsView is the GET response for a place page.
type CalendarDirectory ¶
type CalendarDirectory interface {
// Calendar returns the campaign's primary calendar, or nil (and no
// error) when there is none or the calendar addon is off.
Calendar(ctx context.Context, campaignID string) (QuestCalendar, error)
// SaveDueEvent updates the event eventID, or creates one when eventID is
// empty or the event is gone, and returns the event's id.
SaveDueEvent(ctx context.Context, campaignID string, cal QuestCalendar, eventID string, ev DueEvent) (string, error)
// SetDueEventVisibility changes only the event's visibility, and only
// when it differs. A missing event is not an error.
SetDueEventVisibility(ctx context.Context, campaignID string, cal QuestCalendar, eventID string, dmOnly bool) error
// DeleteDueEvent removes the event; a missing event is not an error.
DeleteDueEvent(ctx context.Context, campaignID string, cal QuestCalendar, eventID string) error
}
CalendarDirectory is the quests plugin's view of the campaign calendar. It is implemented in internal/app over the calendar service.
type CalendarMonth ¶
type CalendarMonth struct {
Name string `json:"name"`
Days int `json:"days"`
LeapDays int `json:"leapDays"`
}
CalendarMonth is one month of the calendar, as the due-date picker needs it.
type CalendarView ¶
type CalendarView struct {
Name string `json:"name"`
Today DayView `json:"today"`
Months []CalendarMonth `json:"months"`
LeapEvery int `json:"leapEvery"`
LeapOffset int `json:"leapOffset"`
}
CalendarView is what the DM's due-date picker needs to draw the calendar.
type CharacterDirectory ¶
type CharacterDirectory interface {
// ListCharacters returns the character pages the viewer may see.
ListCharacters(ctx context.Context, campaignID string, role int, userID string) ([]CharacterInfo, error)
}
CharacterDirectory lists the campaign's characters for handing out rewards.
type CharacterInfo ¶
CharacterInfo is a character page and the display name of the member who claimed it ("" when unclaimed).
type DMQuestView ¶
type DMQuestView struct {
CanEdit bool `json:"canEdit"`
Version int `json:"version"`
Notice Notice `json:"notice"`
Status string `json:"status"`
HandedOut bool `json:"handedOut"`
Steps []Step `json:"steps"`
Rewards []RewardView `json:"rewards"`
Foes []FoeView `json:"foes"`
Links []LinkView `json:"links"`
MapID string `json:"mapId"`
MapName string `json:"mapName"`
Layout Layout `json:"layout"`
Looks Looks `json:"looks"`
// MapsOn is false when the maps addon is off, so map choices are hidden.
MapsOn bool `json:"mapsOn"`
// Calendar is null when the campaign has no usable calendar; the DM
// view alone carries it. Due is null without a due date or a calendar.
Calendar *CalendarView `json:"dueCalendar"`
Due *DueView `json:"due"`
}
DMQuestView is everything, for the DM team.
type DayView ¶
type DayView struct {
Year int `json:"year"`
Month int `json:"month"`
Day int `json:"day"`
Label string `json:"label"`
}
DayView is a calendar day with its label in the calendar's own style.
type DigestQuest ¶
type DigestQuest struct {
EntityID string
Title string
Status string
// DaysLeft is nil without a due date or a calendar to count on; negative
// when late.
DaysLeft *int
// Saved is when the sheet was last saved; it stands in for "newest".
Saved time.Time
}
DigestQuest is one open quest in the campaign home's digest. Title is the notice's own title, which is what a player is shown of the quest.
type DueEvent ¶
type DueEvent struct {
EntityID string
Title string
Day DueDay
// DMOnly keeps the event off players' calendars; it is set whenever a
// plain player may not open the quest page, so a hidden quest's title
// never reaches them.
DMOnly bool
// CreatedBy is the acting user; only used when the event is created.
CreatedBy string
}
DueEvent is the calendar event that mirrors a quest's due date.
type EntityDirectory ¶
type EntityDirectory interface {
// Entities returns the requested pages that exist IN the campaign; a
// missing id or one in another campaign is simply absent.
Entities(ctx context.Context, campaignID string, ids []string) (map[string]EntityInfo, error)
// FilterViewable returns the subset of ids the viewer may open, using
// the entities plugin's own visibility rules.
FilterViewable(ctx context.Context, campaignID string, ids []string, role int, userID string) (map[string]bool, error)
// Search finds pages by name for the picker, already limited to what
// the viewer may see.
Search(ctx context.Context, campaignID, query string, role int, userID string, limit int) ([]EntityInfo, error)
}
EntityDirectory answers questions about pages.
type EntityInfo ¶
EntityInfo is the little this plugin needs to know about a page.
type Foe ¶
type Foe struct {
ID string `json:"id"`
Text string `json:"text"`
Note string `json:"note"`
EntityID string `json:"entityId"`
}
Foe is a DM-only ledger entry.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves the quest, notice-board and picker routes.
func NewHandler ¶
func NewHandler(q QuestService, b BoardService, p PickerService) *Handler
NewHandler builds the handler.
func (*Handler) ClearPlayerItems ¶
ClearPlayerItems handles DELETE .../boards/:bid/player-items.
func (*Handler) CreateBoard ¶
CreateBoard handles POST .../notice-boards/:eid/boards.
func (*Handler) CreateItem ¶
CreateItem handles POST .../boards/:bid/items.
func (*Handler) DeleteBoard ¶
DeleteBoard handles DELETE .../boards/:bid.
func (*Handler) DeleteItem ¶
DeleteItem handles DELETE .../boards/:bid/items/:iid.
func (*Handler) GetBoards ¶
GetBoards handles GET /campaigns/:id/notice-boards/:eid and /campaigns/:id/category-boards/:tid.
func (*Handler) OpenQuestsBlock ¶
OpenQuestsBlock draws the block. A guest of a public campaign gets it only where the owner placed it on the Guests home, and then only the quests an anonymous viewer may already open. An owner viewing as a player is read as a player. GET /campaigns/:id/open-quests
func (*Handler) PatchBoard ¶
PatchBoard handles PATCH .../boards/:bid.
func (*Handler) SetPlacementChecker ¶
func (h *Handler) SetPlacementChecker(p campaigns.BlockPlacementChecker)
SetPlacementChecker wires the check a guest-facing block asks for a page placement.
type Home ¶
Home is where a set of boards lives: on one page (EntityID) or on a category's dashboard (TypeID, an entity type). Exactly one is set; the repository refuses anything else, so a mix-up cannot widen a query.
type HomeView ¶
type HomeView struct {
Kind string `json:"kind"`
ID string `json:"id"`
Name string `json:"name,omitempty"`
}
HomeView names one place that has boards. Kind is "category" or "page"; ID is the entity type id as a string for a category. Name is the page's title; a category's name comes from the caller's own type list.
type Item ¶
type Item struct {
ID string
BoardID string
CampaignID string
Kind string
X, Y, W, R float64
OwnerUserID string
// ByDM records the poster's DM capability at creation, so a later role
// change cannot turn a player's pin into a DM piece or the reverse.
ByDM bool
Hidden bool
Text string
RefID string
FromID string
ToID string
// Auto marks a notice the board placed itself because the quest's status
// is one the board fills with.
Auto bool
}
Item is a stored board item. Empty strings stand for NULL.
type ItemInput ¶
type ItemInput struct {
Kind string `json:"kind"`
X float64 `json:"x"`
Y float64 `json:"y"`
W float64 `json:"w"`
R float64 `json:"r"`
Text string `json:"text"`
RefID string `json:"refId"`
From string `json:"from"`
To string `json:"to"`
}
ItemInput creates an item.
type ItemPatch ¶
type ItemPatch struct {
X patch.Field[float64] `json:"x"`
Y patch.Field[float64] `json:"y"`
W patch.Field[float64] `json:"w"`
R patch.Field[float64] `json:"r"`
Text patch.Field[string] `json:"text"`
Hidden patch.Field[bool] `json:"hidden"`
}
ItemPatch moves or edits an item; absent preserves. Text and Hidden have no cleared state, so null preserves them.
type ItemView ¶
type ItemView struct {
ID string `json:"id"`
Kind string `json:"kind"`
X float64 `json:"x"`
Y float64 `json:"y"`
W float64 `json:"w"`
R float64 `json:"r"`
Mine bool `json:"mine"`
ByDM bool `json:"byDm"`
OwnerName string `json:"ownerName"`
OwnerInitial string `json:"ownerInitial"`
Hidden *bool `json:"hidden,omitempty"` // DM only
// Auto is a notice the board placed itself; it leaves when the quest's
// status no longer matches.
Auto bool `json:"auto,omitempty"`
// notice
QuestID string `json:"questId,omitempty"`
Title string `json:"title,omitempty"`
Kicker string `json:"kicker,omitempty"`
Blurb string `json:"blurb,omitempty"`
Reward string `json:"reward,omitempty"`
Status string `json:"status,omitempty"`
HasSheet bool `json:"hasSheet,omitempty"`
// DaysLeft is a pointer so that 0 (due today) is not dropped; it is
// absent when the quest has no due date.
DaysLeft *int `json:"daysLeft,omitempty"`
// page / map
EntityID string `json:"entityId,omitempty"`
MapID string `json:"mapId,omitempty"`
Name string `json:"name,omitempty"`
TypeName string `json:"typeName,omitempty"`
URL string `json:"url,omitempty"`
Concealed bool `json:"concealed,omitempty"`
// ImagePath is resolved to ImageURL by the handler, which owns the signed
// media URL helpers.
ImagePath string `json:"-"`
ImageURL string `json:"imageUrl,omitempty"`
// note
Text string `json:"text,omitempty"`
// string
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
}
ItemView is one item as a viewer sees it. One flat shape for every kind; the fields of other kinds are omitted. Concealed pages carry no name or id.
type LayoutPatch ¶
type LayoutPatch struct {
Notice *Rect `json:"notice"`
Map *Rect `json:"map"`
Tag *Rect `json:"tag"`
}
LayoutPatch replaces whichever pieces it carries and keeps the rest.
type Link ¶
type Link struct {
ID string `json:"id"`
Kind string `json:"kind"`
RefID string `json:"refId"`
Label string `json:"label"`
}
Link is a DM-only ledger link to a page or a map.
type LooksPatch ¶
type LooksPatch struct {
Board patch.Field[string] `json:"board"`
Ledger patch.Field[string] `json:"ledger"`
}
LooksPatch changes a page's board and ledger themes.
type MapDirectory ¶
type MapDirectory interface {
// Maps returns the requested maps that exist in the campaign.
Maps(ctx context.Context, campaignID string, ids []string) (map[string]MapInfo, error)
// ListMaps returns every map of the campaign.
ListMaps(ctx context.Context, campaignID string) ([]MapInfo, error)
// Enabled reports whether the campaign has the maps addon on. When it is
// off, Maps and ListMaps find nothing, so map pins and links are refused.
Enabled(ctx context.Context, campaignID string) (bool, error)
}
MapDirectory answers questions about maps.
type MemberNames ¶
type MemberNames interface {
DisplayNames(ctx context.Context, campaignID string, userIDs []string) (map[string]string, error)
}
MemberNames resolves campaign members' display names.
type Notice ¶
type Notice struct {
Plate string `json:"plate"`
Kicker string `json:"kicker"`
Title string `json:"title"`
Blurb string `json:"blurb"`
Body []string `json:"body"`
PostedBy string `json:"postedBy"`
Reward string `json:"reward"`
Due string `json:"due"`
}
Notice is the posting on the board. Plain text only: the widgets render it as text, never HTML.
type PickerItem ¶
type PickerItem struct {
ID string `json:"id"`
Name string `json:"name"`
TypeName string `json:"typeName,omitempty"`
Player string `json:"player,omitempty"`
ImagePath string `json:"-"`
ImageURL string `json:"imageUrl,omitempty"`
}
PickerItem is one search hit for the pinning picker; maps carry only id and name.
type PickerService ¶
type PickerService interface {
Search(ctx context.Context, campaignID string, v Viewer, kind, q string) ([]PickerItem, error)
}
PickerService searches what a viewer may pin.
func NewPickerService ¶
func NewPickerService(entities EntityDirectory, maps MapDirectory, characters CharacterDirectory) PickerService
NewPickerService builds the service. characters may be nil, in which case the character kind answers an empty list.
type PlayerQuestView ¶
type PlayerQuestView struct {
CanEdit bool `json:"canEdit"`
Notice *Notice `json:"notice"`
Status string `json:"status"`
HandedOut bool `json:"handedOut"`
Steps []PlayerStep `json:"steps"`
HiddenSteps bool `json:"hiddenSteps"`
ShowTag bool `json:"showTag"`
Layout Layout `json:"layout"`
Looks Looks `json:"looks"`
Map *MapRef `json:"map"`
// Due is null without a due date, or while the DM hides the notice.
Due *DueView `json:"due"`
}
PlayerQuestView is all a non-DM viewer receives: no reward list, foes, links, hidden steps or the ids of anything hidden. Notice and Map are null when the DM hid that piece.
type PlayerStep ¶
PlayerStep is a shown step without its id.
type Quest ¶
type Quest struct {
Notice Notice `json:"notice"`
Status string `json:"status"`
HandedOut bool `json:"handedOut"`
Steps []Step `json:"steps"`
Rewards []Reward `json:"rewards"`
Foes []Foe `json:"foes"`
Links []Link `json:"links"`
MapID string `json:"mapId"`
Layout Layout `json:"layout"`
Looks Looks `json:"looks"`
// DueDate is a day on the campaign calendar; nil means none. DueEventID
// is the calendar event that mirrors it, so a later change can update
// that event instead of adding another.
DueDate *DueDay `json:"dueDate,omitempty"`
DueEventID string `json:"dueEventId,omitempty"`
}
Quest is the whole stored document.
type QuestCalendar ¶
type QuestCalendar interface {
ID() string
Name() string
// Today is the calendar's current in-world date.
Today() DueDay
Months() []CalendarMonth
// Leap is the leap-year interval and offset (0 every = no leap years).
Leap() (every, offset int)
// Valid reports whether d is a real day of this calendar.
Valid(d DueDay) bool
// Label formats d in the calendar's own style.
Label(d DueDay) string
// DaysFromToday is d minus today in days; negative when d is past.
DaysFromToday(d DueDay) int
}
QuestCalendar is the campaign calendar reduced to what a due date needs. All date arithmetic lives behind it, in the calendar plugin's own methods, so the quests plugin never second-guesses leap rules or month lengths.
type QuestChange ¶
QuestChange is one quest the viewer may see that was saved after a time.
type QuestChanges ¶
type QuestChanges struct {
New []QuestChange
Finished []QuestChange
TypeSlug string
}
QuestChanges is what the campaign home's "Since you were last here" reads: the quests the viewer may see that were made, or last saved as finished, after a time. TypeSlug is the category most visible quests are pages of, for a link to the board; empty when none.
type QuestDigest ¶
type QuestDigest struct {
Open []DigestQuest
Total int
// TypeSlug is the category most of the visible quests are pages of, so a
// link to the quest board needs no id.
TypeSlug string
}
QuestDigest is what the campaign home reads: the open quests the viewer may see, most pressing first (due soonest, then most recently saved), and how many quests of any status the viewer may see.
type QuestEntry ¶
QuestEntry is one saved sheet in a campaign's list, with its page's name.
type QuestPatch ¶
type QuestPatch struct {
Version patch.Field[int] `json:"version"`
Notice patch.Field[Notice] `json:"notice"`
Status patch.Field[string] `json:"status"`
HandedOut patch.Field[bool] `json:"handedOut"`
Steps patch.Field[[]Step] `json:"steps"`
Rewards patch.Field[[]Reward] `json:"rewards"`
Foes patch.Field[[]Foe] `json:"foes"`
Links patch.Field[[]Link] `json:"links"`
MapID patch.Field[string] `json:"mapId"`
Layout patch.Field[LayoutPatch] `json:"layout"`
Looks patch.Field[LooksPatch] `json:"looks"`
DueDate patch.Field[DueDay] `json:"dueDate"`
}
QuestPatch is the PUT body. Absent key preserves, present replaces; an explicit null clears mapId and dueDate (every other field has no "cleared" state and preserves, as patch.Field.Val does). Version is required: it is the version the editor loaded.
func DecodePatch ¶
func DecodePatch(raw []byte) (QuestPatch, error)
DecodePatch reads a quest PUT body. The sync API decodes through here too, so both routes accept exactly the same patch.
type QuestRepository ¶
type QuestRepository interface {
// Get returns the stored document and its version; found is false when
// the page has no sheet yet.
Get(ctx context.Context, campaignID, entityID string) (data []byte, version int, found bool, err error)
// GetMany returns the stored documents of the given pages, keyed by id.
GetMany(ctx context.Context, campaignID string, entityIDs []string) (map[string][]byte, error)
// ListAll returns every stored sheet in the campaign, keyed by page id.
ListAll(ctx context.Context, campaignID string) (map[string][]byte, error)
// ListAllStamped is ListAll with each sheet's last-saved time, so a
// caller can say which quest is newest.
ListAllStamped(ctx context.Context, campaignID string) (map[string]StampedSheet, error)
// ListStampedSince is ListAllStamped limited to the sheets saved after
// since, so a caller asking what changed reads only those.
ListStampedSince(ctx context.Context, campaignID string, since time.Time) (map[string]StampedSheet, error)
// Save writes the document if the stored version is still expectedVersion
// (0 means "no row yet") and bumps it. ok is false on a lost race.
Save(ctx context.Context, campaignID, entityID string, data []byte, expectedVersion int, userID string) (ok bool, err error)
}
QuestRepository is the persistence boundary for quest sheets.
func NewQuestRepository ¶
func NewQuestRepository(db *sql.DB) QuestRepository
NewQuestRepository creates a MariaDB-backed repository.
type QuestService ¶
type QuestService interface {
// Get returns the DM view (*DMQuestView) for the DM team and the filtered
// *PlayerQuestView for everyone else. A page that is missing or hidden
// from the viewer is NotFound.
Get(ctx context.Context, campaignID, entityID string, v Viewer) (any, error)
// Put applies a partial update and returns the DM view. DM team only.
Put(ctx context.Context, campaignID, entityID string, v Viewer, p QuestPatch) (*DMQuestView, error)
// List returns every saved sheet in the campaign whose page v may open,
// by page name. DM team only: it is how the AI tool reads the quests.
List(ctx context.Context, campaignID string, v Viewer) ([]QuestEntry, error)
// Digest reads the viewer's quests for the campaign home: every saved
// sheet whose page v may open, as v sees it (see QuestDigest).
Digest(ctx context.Context, campaignID string, v Viewer) (*QuestDigest, error)
// ChangesSince reads the sheets saved after since that v may see, as the
// digest does, and sorts them into new quests and finished ones.
ChangesSince(ctx context.Context, campaignID string, v Viewer, since time.Time) (*QuestChanges, error)
// SyncDueEvent re-derives the visibility of the page's due-date calendar
// event after the page's own visibility changed. It touches nothing when
// the page has no sheet or no due date.
SyncDueEvent(ctx context.Context, campaignID, entityID string) error
// RemoveDueEvent deletes the page's due-date calendar event, for a page
// that was deleted. The sheet itself is left as it is.
RemoveDueEvent(ctx context.Context, campaignID, entityID string) error
}
QuestService owns the quest sheet rules.
func NewQuestService ¶
func NewQuestService(repo QuestRepository, entities EntityDirectory, maps MapDirectory, cal CalendarDirectory) QuestService
NewQuestService builds the service. cal may be nil.
func WithBoardFill ¶
func WithBoardFill(q QuestService, b BoardService) QuestService
WithBoardFill wraps the quest service so every saved quest is put on, or taken off, the boards that fill themselves. Pass the board service that announces changes, so open boards redraw. A failure here is logged and never undoes the save: the quest is right, and the board catches up on the quest's next save or when its fill list is set again.
type Rect ¶
type Rect struct {
X float64 `json:"x"`
Y float64 `json:"y"`
W float64 `json:"w"`
R float64 `json:"r"`
Hidden bool `json:"hidden"`
}
Rect places a piece on the cork board, in percent of the board.
type Remap ¶
type Remap struct {
Entity func(string) (string, bool)
Map func(string) (string, bool)
Event func(string) (string, bool)
}
Remap turns ids from an export into ids in the new campaign. Each returns false when the original did not come back.
type Reward ¶
type Reward struct {
ID string `json:"id"`
Kind string `json:"kind"`
Text string `json:"text"`
Amount *float64 `json:"amount"`
EntityID string `json:"entityId"`
}
Reward is a DM-only ledger entry (the player-facing line is Notice.Reward).
type RewardView ¶
RewardView is a Reward with the linked page's name resolved.
type StampedSheet ¶
StampedSheet is a stored sheet and when it was last saved. Version is 1 until the sheet's second save, so a sheet still at 1 was saved only when it was made.
type Step ¶
type Step struct {
ID string `json:"id"`
Text string `json:"text"`
Done bool `json:"done"`
Shown bool `json:"shown"`
}
Step is one ledger step; only shown steps reach players.
type TypeDirectory ¶
type TypeDirectory interface {
// TypeInCampaign is false for a missing type and for one of another
// campaign. It is also false for a DM-only category unless dmTeam is set,
// so a player cannot learn that category exists through its boards.
TypeInCampaign(ctx context.Context, campaignID string, typeID int, dmTeam bool) (bool, error)
}
TypeDirectory answers whether a category (entity type) belongs to a campaign, so a category id from another campaign can never be used as a board home.
type Viewer ¶
type Viewer struct {
UserID string
// MemberRole is the real membership role (0 guest .. 3 owner); it decides
// who may change a board.
MemberRole int
// VisibilityRole is the role used for page visibility; a co-DM counts as
// an owner there.
VisibilityRole int
// IsDM is the owner or a member with DM access.
IsDM bool
}
Viewer is who is asking, reduced to plain values so services never see Echo or campaign types. The handler builds it from the campaign context.
func PlainPlayer ¶
func PlainPlayer() Viewer
PlainPlayer is a member with the player role and no named-player rules: what every player may see. Callers that show one view to a whole table (the Foundry module's player copy) read as this viewer, so a page shown to named players only stays out, the same rule live updates follow.