feat: rule-pack contract v2 (params + summary) and registry listing
This commit is contained in:
@@ -11,6 +11,7 @@ export class DiceTray extends HTMLElement {
|
||||
this._systemId = 'year-zero';
|
||||
this.rng = Math.random;
|
||||
this.last = null;
|
||||
this.params = {};
|
||||
}
|
||||
get sides() { return this._sides; }
|
||||
set sides(v) { this._sides = Number(v); this.render(); }
|
||||
@@ -24,7 +25,7 @@ export class DiceTray extends HTMLElement {
|
||||
roll() {
|
||||
const { results, total } = rollPool([{ sides: this._sides, count: this._count }], this.rng);
|
||||
const pack = getRulePack(this._systemId);
|
||||
const verdict = pack ? pack.interpret(results) : null;
|
||||
const verdict = pack ? pack.interpret(results, this.params) : null;
|
||||
this.last = { results, total, verdict };
|
||||
this.render();
|
||||
this.dispatchEvent(new CustomEvent('rolled', { detail: this.last, bubbles: true }));
|
||||
@@ -36,9 +37,9 @@ export class DiceTray extends HTMLElement {
|
||||
const felt = this.last
|
||||
? this.last.results.map((r) => `<span class="rolled" data-value="${r.value}">${r.value}</span>`).join('')
|
||||
: '<span class="hint">Tap Roll</span>';
|
||||
const pack = getRulePack(this._systemId);
|
||||
const verdict = this.last?.verdict
|
||||
? `${this.last.verdict.successes} success${this.last.verdict.successes === 1 ? '' : 'es'}` +
|
||||
(this.last.verdict.ones ? ` · ${this.last.verdict.ones} stress` : '')
|
||||
? (pack && pack.summary ? pack.summary(this.last.verdict) : '')
|
||||
: '';
|
||||
|
||||
this.innerHTML = `
|
||||
|
||||
@@ -4,3 +4,6 @@ const packs = new Map([[yearZero.id, yearZero]]);
|
||||
|
||||
export function getRulePack(id) { return packs.get(id) || null; }
|
||||
export function registerRulePack(pack) { packs.set(pack.id, pack); }
|
||||
export function listRulePacks() {
|
||||
return [...packs.values()].map((p) => ({ id: p.id, label: p.label }));
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
export const yearZero = {
|
||||
id: 'year-zero',
|
||||
label: 'Year-Zero',
|
||||
interpret(results) {
|
||||
params: [],
|
||||
interpret(results, params = {}) {
|
||||
let successes = 0, ones = 0;
|
||||
for (const r of results) {
|
||||
if (r.value >= 10) successes += 2;
|
||||
@@ -10,4 +11,8 @@ export const yearZero = {
|
||||
}
|
||||
return { successes, ones, canPush: true, isCritical: successes >= 2 };
|
||||
},
|
||||
summary(v) {
|
||||
const base = `${v.successes} success${v.successes === 1 ? '' : 'es'}`;
|
||||
return v.ones ? `${base} · ${v.ones} stress` : base;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user