feat(events): the step editor reworked, and event templates (MODULE_API 1.13.0)
Rust PLAN_REDESIGNS §2 (U-3-U-6, F11; D192, D334), core half. Game-agnostic:
Module-uo's steps get the new controls and nothing else.
Contract (MODULE_API 1.12.0 -> 1.13.0, four optional additions):
- api.registerEventTemplates([{ id, label, description, inputs, build }]):
inputs are params (<= 8); core checks them, calls build() (10 s), validates
the result as a spec and answers an unsaved draft.
POST /admin/events/catalog/templates/:templateId (admin, editor).
- a param's duration: 'minutes' (int/float only); core.lease's minutes has it.
- a lease's example for its value.
- an option row's note (<= 300 chars), shown under the chosen field.
Editor:
- no type tags or bare asterisks; a required field says so in words once a
save has been tried with it empty (and the save stops before the round trip).
- boolean: toggle when required, [Not set] [Yes] [No] when optional (D334).
- a choice of two or three is a row of buttons (lease values, small sources).
- core.lease drawn as the chosen lease: picked by label; value by the lease's
type, range, values and example; target picker over target.source (F11);
minutes with the lease's longest hold.
- a timed step keeps its run open: a phase with no advance rule gets
after: <longest hold> when a timed step is added; a sentence under any phase
whose run can end sooner (U-6).
- Start asks "Publish and start" or "Start version N" when the working copy is
ahead of the published version (draftAhead on GET/PUT/publish; U-5).
- New event can start from a module's template.
- core's own examples name no game (§0.9).
Swagger, routes.manifest/guards and engagement-triggers.json regenerated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E14m6SuuY6i1vASFeGDBeY
This commit is contained in:
@@ -78,6 +78,16 @@ const shapeDefinition = (d) => ({
|
||||
updatedAt: d.updated_at,
|
||||
})
|
||||
|
||||
/**
|
||||
* The definition as the EDITOR reads it: the shape above, and whether the working
|
||||
* copy has moved on from the published version (Rust PLAN_REDESIGNS §2.3). One
|
||||
* extra read, so only the three routes the editor loads from carry it.
|
||||
*/
|
||||
const shapeEditable = async (row) => ({
|
||||
...shapeDefinition(row),
|
||||
draftAhead: await definitions.draftAhead(row),
|
||||
})
|
||||
|
||||
const shapeRun = (r) => ({
|
||||
id: r.id,
|
||||
definitionId: r.definition_id,
|
||||
@@ -203,6 +213,9 @@ exports.catalog = (_req, res) => {
|
||||
budgets: registries.allEventBudgets(),
|
||||
leases: registries.allEventLeases(),
|
||||
optionSources: registries.allEventOptionSources(),
|
||||
// MODULE_API 1.13.0 (Rust PLAN_REDESIGNS §2.5). Without `build`, like every
|
||||
// callable above; filling one in is its own request.
|
||||
templates: registries.allEventTemplates(),
|
||||
limits: {
|
||||
maxPhases: spec.MAX_PHASES,
|
||||
maxStepsPerPhase: spec.MAX_STEPS_PER_PHASE,
|
||||
@@ -363,7 +376,7 @@ exports.get = async (req, res) => {
|
||||
if (!id) return res.status(400).json({ error: 'bad event id' })
|
||||
const row = await definitionsDb.getById(id)
|
||||
if (!row) return res.status(404).json({ error: 'no such event definition' })
|
||||
return res.json({ event: shapeDefinition(row) })
|
||||
return res.json({ event: await shapeEditable(row) })
|
||||
}
|
||||
|
||||
/** GET /api/v1/admin/events/:id/versions */
|
||||
@@ -408,7 +421,7 @@ exports.update = async (req, res) => {
|
||||
action: 'event.definition.updated',
|
||||
detail: { id, title: result.definition.title },
|
||||
})
|
||||
return res.json({ event: shapeDefinition(result.definition) })
|
||||
return res.json({ event: await shapeEditable(result.definition) })
|
||||
}
|
||||
|
||||
/** POST /api/v1/admin/events/:id/publish */
|
||||
@@ -423,7 +436,7 @@ exports.publish = async (req, res) => {
|
||||
detail: { id, version: result.version, versionId: result.versionId, repinned: result.repinned },
|
||||
})
|
||||
return res.json({
|
||||
event: shapeDefinition(result.definition),
|
||||
event: await shapeEditable(result.definition),
|
||||
version: result.version,
|
||||
versionId: result.versionId,
|
||||
// How many already-materialised occurrences moved to this version. The
|
||||
@@ -585,6 +598,19 @@ exports.options = async (req, res) => {
|
||||
return res.json(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/v1/admin/events/catalog/templates/:templateId — fill a template in.
|
||||
*
|
||||
* MODULE_API 1.13.0 (Rust PLAN_REDESIGNS §2.5). Answers a draft and writes
|
||||
* nothing, so there is nothing to put in the activity log: the definition the
|
||||
* draft becomes is logged when it is created, by the route that creates it.
|
||||
*/
|
||||
exports.buildTemplate = async (req, res) => {
|
||||
const result = await definitions.buildFromTemplate(req.params.templateId, req.body?.inputs)
|
||||
if (!result.ok) return res.status(result.status || 400).json({ errors: result.errors })
|
||||
return res.json({ draft: result.draft })
|
||||
}
|
||||
|
||||
/**
|
||||
* PUT /api/v1/admin/events/actions — set one action's switch and caps.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user