Documentation
¶
Overview ¶
Package encounters stores the fights a DM plans on a page (an Adventures trial, a location, any page) so Foundry can load one on game night.
An encounter belongs to one page. It names the heroes it was built for and one row per creature: which creature page, how many, its initiative group and how it starts the fight (seen, hidden or arriving later). A scene is an encounter with things to show instead of creatures. Planning is the DM's: no planning route answers a viewer below Owner visibility, so a planned ambush never reaches a player. What a running scene shows is the one thing that does, and only once the DM presses Show.
The browser HTTP surface for encounters. Handlers bind, call the service and shape the response; the service owns every rule, so a mis-wired route cannot widen access.
Hand-written SQL for the encounters table.
SECURITY: every statement filters on campaign_id, so an encounter id from another campaign never reads, changes or deletes a row here.
Route registration for encounters.
Hand-written SQL for the encounter_runs table.
SECURITY: the campaign id is the key, so a run is only ever read, changed or ended for the campaign the route resolved.
Index ¶
- Constants
- Variables
- func RegisterRoutes(e *echo.Echo, h *Handler, campaignSvc campaigns.CampaignService, ...)
- func RegisterRunRoutes(e *echo.Echo, h *RunHandler, campaignSvc campaigns.CampaignService, ...)
- type CountChange
- type Creature
- type Encounter
- type EndReport
- type EndedCreature
- type EndedFight
- type FightListener
- type Handler
- type Hero
- type HeroPage
- type Page
- type PageAccess
- type PageDirectory
- type PageList
- type Pick
- type Picked
- type PickerTypes
- type Player
- type Repository
- type ResultDirectory
- type Row
- type Run
- type RunHandler
- type RunLine
- type RunRepository
- type RunRow
- type RunSave
- type RunService
- type RunShow
- type RunShowInput
- type RunStart
- type RunView
- type SaveInput
- type SceneDirectory
- type Service
- type Show
- type ShowPublisher
- type ShownItem
- type ShownRepository
- type Stage
- type StageForm
- type StageWhen
- type StatBlock
- type Summary
- type TestOutcome
- type Version
- type Viewer
Constants ¶
const ( StartSeen = "seen" StartHidden = "hidden" StartLater = "later" )
How a creature starts the fight. Foundry places a "hidden" creature with its token hidden and leaves a "later" one off the scene until the DM places it; nothing is ever revealed without the DM pressing Show.
const ( KindFight = "fight" KindScene = "scene" )
What an encounter is. A fight has creature rows; a scene has things to show the players instead, run from the same DM Screen card.
const ( ShowPage = "page" ShowReveal = "reveal" ShowNote = "note" )
What a scene's row shows. A page row points players at a page they may already open; a reveal row un-hides an NPC or creature page and points at it; a note row carries the DM's own words.
const ( HowReveal = "reveal" HowQuiet = "quiet" )
How a form change is shown to players. "reveal" tells them; "quiet" swaps the token without announcing it.
const ( WhenManual = "manual" WhenStamina = "stamina" WhenRound = "round" )
When a stage is due. Only the DM presses Start; the kind just tells the DM Screen when to say a stage is waiting.
const ( LineHero = "hero" LineCreature = "creature" )
Kinds of line in a run.
const ( MaxRunLines = 60 MaxRunConds = 12 MaxCondChars = 40 MaxLineNameChars = 80 MaxRound = 9999 MinInit, MaxInit = -99, 999 MaxHitPoints = 99999 // MaxRunBodyBytes is well above the largest legal run. MaxRunBodyBytes = 128 << 10 )
Run limits. They bound the stored document; the widget keeps to them too.
const ( DefaultSearchLimit = 50 MaxSearchLimit = 100 )
Search limits: the default fills Foundry's list, the cap bounds one call.
const ( MaxNameChars = 120 MaxHeroes = 12 MaxCreatureRows = 30 MaxCreatureCount = 40 MaxRowIDChars = 64 MaxStages = 8 MaxStageForms = 10 MaxStageArrive = 30 MaxNoteChars = 200 MaxFormNameChars = 80 MaxVersions = 6 MaxVersionAdds = 10 MaxShows = 30 MaxShowLabel = 120 MaxShowText = 500 // MaxPerPage keeps one page's widget a list a DM can scan; a campaign // can still hold any number of encounters across its pages. MaxPerPage = 50 // MaxBodyBytes is well above the largest legal encounter and low enough // that a junk body is refused. MaxBodyBytes = 64 << 10 )
Limits. They bound the stored document and so a request body; the widget enforces the same numbers as a courtesy.
const BlockType = "page_encounters"
BlockType is the layout block that shows a page's encounters.
const MaxShownList = 200
MaxShownList bounds one read of the shown log.
const PluginSlug = "encounters"
PluginSlug names this plugin in the registry and the health/migration bookkeeping.
const TonightWindow = 12 * time.Hour
TonightWindow is how far back a player's Table lists what was shown: long enough for one evening's session, short enough that last week's is gone.
Variables ¶
var MigrationsFS embed.FS
MigrationsFS contains the embedded SQL migration files so the table is created from the compiled binary regardless of the working directory.
var StaticAssetsFS embed.FS
StaticAssetsFS holds the Encounters widget script, served at /static/plugins/encounters/ and loaded only on pages that show the block.
Functions ¶
func RegisterRoutes ¶
func RegisterRoutes(e *echo.Echo, h *Handler, campaignSvc campaigns.CampaignService, authSvc auth.AuthService)
RegisterRoutes mounts the routes under the campaign group. Every route needs a signed-in member; the service then refuses anyone below Owner visibility, so the gate here is not the only one. CSRF is enforced by the global middleware.
func RegisterRunRoutes ¶
func RegisterRunRoutes(e *echo.Echo, h *RunHandler, campaignSvc campaigns.CampaignService, authSvc auth.AuthService)
RegisterRunRoutes mounts the Fight tab's routes, with the same gates as RegisterRoutes; the run service refuses anyone below Owner visibility on every route but the Table's shown list.
Types ¶
type CountChange ¶
CountChange is a base row played with another count in a version.
type Creature ¶
type Creature struct {
ID string `json:"id"`
// EntityID is the creature's page, which Foundry maps to its actor.
// Empty for a creature typed by name that has no page yet.
EntityID string `json:"entityId"`
// Name is kept with the row so the encounter still reads correctly when
// the page is renamed or removed.
Name string `json:"name"`
Count int `json:"count"`
Group string `json:"group"`
Start string `json:"start"`
}
Creature is one row of an encounter: Count copies of one creature.
type Encounter ¶
type Encounter struct {
ID string `json:"id"`
Page Page `json:"page"`
Name string `json:"name"`
Kind string `json:"kind"`
Ready bool `json:"ready"`
Heroes []Hero `json:"heroes"`
Creatures []Creature `json:"creatures"`
Stages []Stage `json:"stages"`
Versions []Version `json:"versions"`
Shows []Show `json:"shows"`
// Picked is set only for an encounter that has versions, and only
// while the tests that pick them can be read.
Picked *Picked `json:"picked,omitempty"`
Version int `json:"version"`
UpdatedAt time.Time `json:"updatedAt"`
}
Encounter is one planned fight as the API returns it.
type EndReport ¶
type EndReport struct {
Name string `json:"name"`
Lines []string `json:"lines"`
Link string `json:"link,omitempty"`
LinkText string `json:"linkText,omitempty"`
Note string `json:"note,omitempty"`
}
EndReport is what the Fight tab shows once a fight is over: a line per creature from the fight listener, and where to go to see what was left.
type EndedCreature ¶
EndedCreature is one creature row of an ended fight: its page ("" for a row with none), how many copies it had and how many were at 0 hit points or less, read as the Fight tab draws a box down (an untouched copy is at its full hit points). A creature still waiting to come in was never down.
type EndedFight ¶
type EndedFight struct {
Name string
Creatures []EndedCreature
}
EndedFight is a fight as it stood when the DM ended it.
type FightListener ¶
type FightListener interface {
// Leaves gives a short note per page, nil when there is nothing to
// say. A note beginning "No " says the page leaves nothing, and the tab
// draws it plain rather than marked.
Leaves(ctx context.Context, campaignID string, v Viewer, pageIDs []string) (map[string]string, error)
FightEnded(ctx context.Context, campaignID string, v Viewer, f EndedFight) (*EndReport, error)
}
FightListener hears about fights for another app: what each creature's page will leave, and a fight that ended. It is implemented in internal/app, so encounters never imports the app that listens.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves the encounter routes.
type PageAccess ¶
PageAccess is one viewer's standing on one page.
type PageDirectory ¶
type PageDirectory interface {
// Access answers what the viewer may do with a page, using the page's
// own rules. A page that is missing or in another campaign comes back
// with Exists false.
Access(ctx context.Context, campaignID, entityID string, v Viewer) (PageAccess, error)
// Names returns the names of the pages among ids that are live pages of
// campaignID the viewer may see, keyed by id. Every other id is absent.
Names(ctx context.Context, campaignID string, ids []string, v Viewer) (map[string]string, error)
// PickerTypes returns the page types the builder offers: heroes from
// the campaign's character list, creatures from its creature types and
// NPC list. Sub-types are included.
PickerTypes(ctx context.Context, campaignID string) (PickerTypes, error)
// Heroes lists the hero pages of typeIDs the viewer may see, by name:
// a player has the page, it is marked playable, or it names a class or
// hero choice. NPCs on the same types are left out.
Heroes(ctx context.Context, campaignID string, typeIDs []int, v Viewer) ([]HeroPage, error)
}
PageDirectory is owned by this plugin and implemented in internal/app over the entities service, so encounters never imports another plugin.
type PageList ¶
type PageList struct {
Encounters []Encounter `json:"encounters"`
CanEdit bool `json:"canEdit"`
// Heroes is what the hero picker offers: the hero pages of the
// campaign's characters list, NPCs left out.
Heroes []HeroPage `json:"heroes"`
// The page types the creature picker searches, so the widget uses the
// campaign's own choice instead of guessing from presets.
CreatureTypeIDs []int `json:"creatureTypeIds"`
// The game system's stat block widgets, for the creature fold-out.
StatBlocks []StatBlock `json:"statBlocks"`
// Players a scene row can be shown to alone; empty without a scene
// directory.
Players []Player `json:"players"`
}
PageList is what the page's widget receives.
type Pick ¶
type Pick struct {
Test string `json:"test"`
Result string `json:"result"`
TestName string `json:"testName,omitempty"`
ResultLabel string `json:"resultLabel,omitempty"`
}
Pick is a test on any page of the campaign and one of its results. TestName and ResultLabel are filled on read so the builder and Foundry can say what picks a version; a save ignores them.
type Picked ¶
type Picked struct {
Version string `json:"version"`
Test string `json:"test"`
Result string `json:"result"`
Open []string `json:"open"`
}
Picked is which version the recorded results choose. Version is empty when none does, and the base rows are played; Open names the tests that pick a version and have no result yet. Test, Result and Open carry names and labels for display, not ids; the ids are on each version's Pick. Nothing is ever loaded on its own: Foundry shows the choice and the DM sets up the fight.
type PickerTypes ¶
PickerTypes is which page types the builder's pickers search, and the game system's stat blocks for creature pages.
type Repository ¶
type Repository interface {
// ListForPage returns a page's encounters, oldest first.
ListForPage(ctx context.Context, campaignID, entityID string) ([]Row, error)
// Get returns one encounter; found is false when there is none.
Get(ctx context.Context, campaignID, id string) (r Row, found bool, err error)
// Create inserts a new encounter at version 1.
Create(ctx context.Context, r Row, userID string) error
// Update writes the encounter if the stored version is still expected
// and bumps it. ok is false on a lost race or a missing row.
Update(ctx context.Context, campaignID, id, name string, ready bool, data []byte, expected int, userID string) (ok bool, err error)
// Delete removes one encounter; ok is false when there was none.
Delete(ctx context.Context, campaignID, id string) (ok bool, err error)
// Search lists the campaign's encounters on live pages, ready ones
// first, then the most recently changed. q, when set, matches the
// encounter's or its page's name. total counts every match.
Search(ctx context.Context, campaignID, q string, limit int) (rows []Row, total int, err error)
}
Repository is the persistence boundary for encounters.
func NewRepository ¶
func NewRepository(db *sql.DB) Repository
NewRepository creates a MariaDB-backed repository.
type ResultDirectory ¶
type ResultDirectory interface {
// Outcomes returns, for the tests among ids the viewer may see, their
// name, results (id to label) and recorded result id, keyed by id.
Outcomes(ctx context.Context, campaignID string, ids []string, v Viewer) (map[string]TestOutcome, error)
}
ResultDirectory is how an encounter reads the tests that pick its versions. It is implemented in internal/app over the Tests block, so encounters never imports that plugin; it is nil when the Tests block is unavailable, and every pick then reads as unknown.
type Row ¶
type Row struct {
ID string
CampaignID string
EntityID string
PageName string
Name string
Ready bool
Data []byte
Version int
UpdatedAt time.Time
}
Row is one stored encounter. PageName is filled only by Search, which joins the page.
type Run ¶
type Run struct {
EncounterID string `json:"encounterId"`
// Name is the encounter's name when the fight started.
Name string `json:"name"`
Round int `json:"round"`
// Turn is the id of the line whose turn it is; empty before the first
// turn, while the DM types initiative.
Turn string `json:"turn"`
Lines []RunLine `json:"lines"`
// Kind is "scene" for a scene, empty for a fight. A scene has no lines;
// its Shows are copied from the encounter when it starts.
Kind string `json:"kind,omitempty"`
Shows []RunShow `json:"shows,omitempty"`
}
Run is the fight as stored and as the Fight tab edits it.
type RunHandler ¶
type RunHandler struct {
// contains filtered or unexported fields
}
RunHandler serves the Fight tab's routes.
func NewRunHandler ¶
func NewRunHandler(svc RunService) *RunHandler
NewRunHandler builds the run handler.
func (*RunHandler) Current ¶
func (h *RunHandler) Current(c *echo.Context) error
Current handles GET /campaigns/:id/encounter-run.
func (*RunHandler) End ¶
func (h *RunHandler) End(c *echo.Context) error
End handles DELETE /campaigns/:id/encounter-run, answering with what the fight left.
func (*RunHandler) Save ¶
func (h *RunHandler) Save(c *echo.Context) error
Save handles PUT /campaigns/:id/encounter-run.
func (*RunHandler) Show ¶
func (h *RunHandler) Show(c *echo.Context) error
Show handles POST /campaigns/:id/encounter-run/show.
type RunLine ¶
type RunLine struct {
ID string `json:"id"`
Kind string `json:"kind"`
Name string `json:"name"`
// EntityID is the line's page, kept from the encounter. The service
// never takes one from a save, so a run can't be made to point at a page
// the encounter didn't name.
EntityID string `json:"entityId"`
Group string `json:"group"`
// Init is the initiative the DM typed; nil until then.
Init *int `json:"init"`
// Max is the line's full hit points; nil until the DM types it.
Max *int `json:"max"`
// HP holds each copy's current hit points; nil means full.
HP []*int `json:"hp"`
// Conds are the line's conditions, by name.
Conds []string `json:"conds"`
// Waiting is a creature that starts "later": listed, but out of the
// turn order until the DM brings it in.
Waiting bool `json:"waiting"`
}
RunLine is one hero, or one creature row with a box of hit points for each copy.
type RunRepository ¶
type RunRepository interface {
// GetRun returns the campaign's run; found is false when none is on.
GetRun(ctx context.Context, campaignID string) (r RunRow, found bool, err error)
// CreateRun stores a new run at version 1. ok is false when the
// campaign already has one.
CreateRun(ctx context.Context, campaignID string, data []byte, userID string) (ok bool, err error)
// UpdateRun writes the run if the stored version is still expected and
// bumps it. ok is false on a lost race or when the run has ended.
UpdateRun(ctx context.Context, campaignID string, data []byte, expected int, userID string) (ok bool, err error)
// EndRun deletes the campaign's run and returns it as it was. ended is
// false when none was on, so of two ends at once only one gets the run;
// ending none is not an error.
EndRun(ctx context.Context, campaignID string) (r RunRow, ended bool, err error)
}
RunRepository is the persistence boundary for runs.
func NewRunRepository ¶
func NewRunRepository(db *sql.DB) RunRepository
NewRunRepository creates a MariaDB-backed run repository.
type RunService ¶
type RunService interface {
// Current returns the fight that is on, or the Ready encounters that can
// be started when none is.
Current(ctx context.Context, campaignID string, v Viewer) (*RunView, error)
// Start lays out a fight from an encounter. It refuses while a fight is on.
Start(ctx context.Context, campaignID string, v Viewer, in RunStart) (*RunView, error)
// Save replaces the fight; in.Version must be the stored version.
Save(ctx context.Context, campaignID string, v Viewer, in RunSave) (*RunView, error)
// End ends the fight and says what it left, as the fight listener
// tells it; ending no fight reports nothing.
End(ctx context.Context, campaignID string, v Viewer) (*EndReport, error)
// Show shows one row of the running scene to its players.
Show(ctx context.Context, campaignID string, v Viewer, in RunShowInput) (*RunView, error)
// Shown lists what scenes showed since, as this viewer may see it: the
// DM team sees every row, a player the rows for everyone or for them.
// Unlike every other method it answers any member.
Shown(ctx context.Context, campaignID string, v Viewer, since time.Time) ([]ShownItem, error)
}
RunService owns the Fight tab's rules. Like the encounter service it is for the DM only: anyone below Owner visibility is refused before anything is read.
func NewRunService ¶
func NewRunService(repo RunRepository, enc Service, pages PageDirectory) RunService
NewRunService builds the run service over the encounter service, which decides which encounters the viewer may start.
type RunShowInput ¶
type RunShowInput struct {
ShowID string `json:"showId"`
}
RunShowInput names the scene row to show.
type RunStart ¶
type RunStart struct {
EncounterID string `json:"encounterId"`
}
RunStart is a start body.
type RunView ¶
type RunView struct {
Run *Run `json:"run"`
Version int `json:"version"`
Ready []Summary `json:"ready"`
Planned []Summary `json:"planned"`
PlannedTotal int `json:"plannedTotal"`
StatBlocks []StatBlock `json:"statBlocks"`
// Leaves says, by page, what a creature will leave when the fight ends
// ("Has a drop list"), as the fight listener tells it; empty without one.
Leaves map[string]string `json:"leaves,omitempty"`
// Players names who a scene row goes to; set only while a scene runs.
Players []Player `json:"players,omitempty"`
}
RunView is what the Fight tab receives. Run is nil when no fight is on; Ready lists the encounters the DM can start; Planned lists every other one, newest change first, up to the search cap, and PlannedTotal counts them all so the card can say how many more there are.
type SaveInput ¶
type SaveInput struct {
Name string `json:"name"`
Kind string `json:"kind"`
Ready bool `json:"ready"`
Heroes []string `json:"heroes"`
Creatures []Creature `json:"creatures"`
Stages []Stage `json:"stages"`
Versions []Version `json:"versions"`
Shows []Show `json:"shows"`
Version *int `json:"version"`
}
SaveInput is a create or update body. The builder always sends the whole encounter. Version is a pointer so a missing one is refused on update rather than read as "no row yet".
type SceneDirectory ¶
type SceneDirectory interface {
// Players lists the campaign's members who play (not the DM team).
Players(ctx context.Context, campaignID string) ([]Player, error)
// PlayerCanView reports whether a player may open the page. userID ""
// asks about a player with no access granted to them by name.
PlayerCanView(ctx context.Context, campaignID, entityID, userID string) (bool, error)
// Reveal un-hides an NPC or creature page of the campaign and returns
// its name; any other page is not found.
Reveal(ctx context.Context, campaignID, entityID string) (string, error)
}
SceneDirectory is what a scene needs beyond pages: the campaign's players, whether a player may open a page, and un-hiding an NPC or creature page. It is implemented in internal/app; while it is nil a scene can show notes to everyone but nothing that needs a page or a player.
type Service ¶
type Service interface {
// ListForPage returns a page's encounters for its widget.
ListForPage(ctx context.Context, campaignID, entityID string, v Viewer) (*PageList, error)
// Get returns one encounter.
Get(ctx context.Context, campaignID, id string, v Viewer) (*Encounter, error)
// Create adds an encounter to a page.
Create(ctx context.Context, campaignID, entityID string, v Viewer, in SaveInput) (*Encounter, error)
// Update replaces an encounter; in.Version must be the stored version.
Update(ctx context.Context, campaignID, id string, v Viewer, in SaveInput) (*Encounter, error)
// Delete removes an encounter.
Delete(ctx context.Context, campaignID, id string, v Viewer) error
// Search lists the campaign's encounters for Foundry: ready ones first,
// then the most recently changed, optionally matching q.
Search(ctx context.Context, campaignID, q string, limit int, v Viewer) (items []Summary, total int, err error)
}
Service owns the encounter rules. Every method is for the DM: a viewer below Owner visibility is refused before anything is read, so a planned fight never reaches a player through any route.
func NewService ¶
func NewService(repo Repository, pages PageDirectory, results ResultDirectory) Service
NewService builds the service. results may be nil when the Tests block is unavailable: versions still save and play, but none can be picked by a result.
type Show ¶
type Show struct {
ID string `json:"id"`
Kind string `json:"kind"`
EntityID string `json:"entityId"`
Label string `json:"label"`
Text string `json:"text"`
To string `json:"to"`
}
Show is one thing a scene can show. To is empty for everyone, or the user id of the one player who gets it.
type ShowPublisher ¶
ShowPublisher sends a shown item to the players' live connections: everyone, or only item.To (and the DM team). It is implemented in internal/app over the WebSocket hub.
type ShownItem ¶
type ShownItem struct {
ID string `json:"id"`
Kind string `json:"kind"`
Label string `json:"label"`
Text string `json:"text,omitempty"`
EntityID string `json:"entityId,omitempty"`
To string `json:"to,omitempty"`
Scene string `json:"scene"`
ShownAt time.Time `json:"shownAt"`
}
ShownItem is one thing shown to players, as the shown log keeps it and as a player's Table receives it. Scene is the scene's name; To is empty for everyone.
type ShownRepository ¶
type ShownRepository interface {
// AddShown records one shown item.
AddShown(ctx context.Context, campaignID string, item ShownItem, userID string) error
// ListShown returns the campaign's items shown since, oldest first, at
// most limit of the newest.
ListShown(ctx context.Context, campaignID string, since time.Time, limit int) ([]ShownItem, error)
}
ShownRepository keeps what scenes showed to players, for the players' Table and the night's record.
func NewShownRepository ¶
func NewShownRepository(db *sql.DB) ShownRepository
NewShownRepository creates a MariaDB-backed shown log.
type Stage ¶
type Stage struct {
ID string `json:"id"`
When StageWhen `json:"when"`
Forms []StageForm `json:"forms"`
Arrive []string `json:"arrive"`
How string `json:"how"`
// Note is the DM's reminder, plain text.
Note string `json:"note"`
}
Stage says when something changes mid-fight: creatures take another form and/or "later" rows arrive. It never fires on its own.
func CarryStages ¶
readStages drops what a stage points at that is gone, the way an unlinked row keeps its name: a form change needs a row with a page, an arrival needs a row, and a Stamina trigger on a missing row falls back to manual. A stage emptied this way is kept so the DM sees it and decides. CarryStages keeps an encounter's stages across a save that replaces its rows: references to rows that are gone are dropped, and a stage left with nothing to do is dropped too, since a save would refuse it.
type StageForm ¶
type StageForm struct {
Row string `json:"row"`
// Form is the game system's form id, or empty for the creature's first.
Form string `json:"form"`
// FormName is kept so the stage reads right if the system's forms change.
FormName string `json:"formName"`
}
StageForm is one creature changing form.
type StageWhen ¶
type StageWhen struct {
Kind string `json:"kind"`
// Row is the creature row whose Stamina is watched (stamina).
Row string `json:"row"`
// Percent is due at or below this share of Stamina, 1 to 99 (stamina).
Percent int `json:"percent"`
// Round is due at the start of this round, 2 to 99 (round).
Round int `json:"round"`
}
StageWhen is what makes a stage due. Row, Percent and Round are read only for the kind that uses them.
type StatBlock ¶
type StatBlock struct {
Widget string `json:"widget"`
SystemID string `json:"systemId"`
TypeIDs []int `json:"typeIds"`
}
StatBlock is a game-system widget that draws a creature's stat block, and the page types it draws for. A creature row folds it out in place; a page of no listed type folds out its own fields instead.
type Summary ¶
type Summary struct {
ID string `json:"id"`
Page Page `json:"page"`
Name string `json:"name"`
Kind string `json:"kind"`
Ready bool `json:"ready"`
CreatureCount int `json:"creatureCount"`
ShowCount int `json:"showCount"`
UpdatedAt time.Time `json:"updatedAt"`
}
Summary is one line of the Foundry list.
type TestOutcome ¶
TestOutcome is one test as a version's pick needs it.
type Version ¶
type Version struct {
ID string `json:"id"`
Name string `json:"name"`
// Pick names the test result that chooses this version; nil when only
// the DM chooses it.
Pick *Pick `json:"pick"`
Add []Creature `json:"add"`
Remove []string `json:"remove"`
Counts []CountChange `json:"counts"`
}
Version is the same fight played another way: the base creature rows with some rows added, some removed and some counts changed. Only the changes are stored, so a change to a shared row is made once and every version follows.
func CarryVersions ¶
CarryVersions keeps an encounter's versions across a save that replaces its base rows: a removal or count change of a row that is gone is dropped, and the rest of the version, its added rows and its pick, is kept.