Documentation
¶
Overview ¶
Package rolltables stores each campaign's own rolling tables: named lists of weighted entries a DM rolls on at the table. A campaign has one document holding all its tables, replaced as a unit; Chronicle validates and stores it but never rolls it, so the dice logic stays in the client.
The browser HTTP surface for roll tables. Handlers only bind, call the service and shape the response; the reads are open to scribes and the DM team, writes to the DM team only.
Hand-written SQL for campaign_roll_tables.
SECURITY: every method filters on campaign_id, which is the primary key, so one campaign can never read or replace another's document.
Route registration for roll tables.
Index ¶
Constants ¶
const ( MaxBodyBytes = 512 * 1024 MaxTables = 100 MaxTableNameLen = 120 MaxEntries = 500 MaxEntryNameLen = 200 MaxEntryBriefLen = 1000 MaxWeight = 100 MaxCreditField = 200 MaxCreditNotice = 600 MaxCreditURL = 300 // VisibilityEveryone and VisibilityDMOnly are the two answers to who sees // what a calendar day's roll puts on the day. VisibilityEveryone = "everyone" VisibilityDMOnly = "dm_only" )
Limits keep one campaign's document bounded; it is a DM's working set of tables, not a content store.
const PluginSlug = "rolltables"
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 table is created from the compiled binary regardless of the working directory (same pattern as the other plugins).
Functions ¶
func RegisterRoutes ¶
func RegisterRoutes(e *echo.Echo, h *Handler, campaignSvc campaigns.CampaignService, authSvc auth.AuthService)
RegisterRoutes mounts the browser routes under the campaign group. The tables are a DM's prep and may spoil outcomes, so players never read them; scribes, who can edit pages that hold a roller, may read and roll them, and only the DM team may change them. CSRF is enforced by the global middleware.
Types ¶
type Credit ¶
type Credit struct {
Source string `json:"source"`
Author string `json:"author,omitempty"`
Page string `json:"page,omitempty"`
URL string `json:"url,omitempty"`
Licence string `json:"licence,omitempty"`
LicenceURL string `json:"licenceUrl,omitempty"`
Notice string `json:"notice,omitempty"`
}
Credit says where a table copied from an openly licensed source came from. A copy of a library table carries it, so the licence's attribution travels with the campaign's own version.
type Document ¶
type Document struct {
// Tables is never nil: an empty set marshals as [] so clients can iterate
// without a null check.
Tables []Table `json:"tables"`
}
Document is a campaign's whole set of rolling tables. It is both the wire shape and the stored shape, so what a client reads is what the service normalized on the way in.
type Entry ¶
type Entry struct {
Name string `json:"name"`
Brief string `json:"brief"`
Weight float64 `json:"weight"`
// When limits the days this line can come up on (moon phase, season,
// weekday, month and the engine's other day conditions). It is stored as
// the validated JSON the client's engine reads, so the two never drift
// into different shapes.
When json.RawMessage `json:"when,omitempty"`
}
Entry is one row of a table; Weight is its relative chance of being rolled.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves the roll-table routes.
type Repository ¶
type Repository interface {
// Get returns the stored JSON document, or nil when the campaign has none.
Get(ctx context.Context, campaignID string) ([]byte, error)
// Put stores the document, replacing any existing one. userID is empty
// when there is no acting user.
Put(ctx context.Context, campaignID string, data []byte, userID string) error
}
Repository is the persistence boundary for roll tables.
func NewRepository ¶
func NewRepository(db *sql.DB) Repository
NewRepository creates a MariaDB-backed repository.
type Service ¶
type Service interface {
// Get returns the campaign's document; a campaign with no row reads as an
// empty set of tables.
Get(ctx context.Context, campaignID string) (Document, error)
// Put validates the raw body, replaces the whole document with its
// normalized form and returns what was stored.
Put(ctx context.Context, campaignID string, body []byte, userID string) (Document, error)
}
Service is the business-logic boundary for roll tables.
type Table ¶
type Table struct {
ID string `json:"id"`
Name string `json:"name"`
Credit *Credit `json:"credit,omitempty"`
// Visibility says who sees what a calendar day's Roll one puts on the
// day: "everyone" or "dm_only". Only "dm_only" hides; empty or
// "everyone" leaves it to the roll's own tell-players setting.
Visibility string `json:"visibility,omitempty"`
Entries []Entry `json:"entries"`
}
Table is one rolling table.