Implement the 026-roll-initiative feature that adds d20 roll buttons for bestiary combatants' initiative using a click-to-edit pattern (d20 icon when empty, plain text when set), plus a Roll All button in the top bar that batch-rolls for all unrolled bestiary combatants, with randomness confined to the adapter layer and the domain receiving pre-resolved dice values

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Lukas
2026-03-10 16:29:09 +01:00
parent 5b0bac880d
commit d5f7b6ee36
20 changed files with 926 additions and 27 deletions

View File

@@ -0,0 +1,21 @@
import type { DomainError } from "./types.js";
/**
* Pure function that computes initiative from a resolved dice roll and modifier.
* The dice roll must be an integer in [1, 20].
* Returns the sum (diceRoll + modifier) or a DomainError for invalid inputs.
*/
export function rollInitiative(
diceRoll: number,
modifier: number,
): number | DomainError {
if (!Number.isInteger(diceRoll) || diceRoll < 1 || diceRoll > 20) {
return {
kind: "domain-error",
code: "invalid-dice-roll",
message: `Dice roll must be an integer between 1 and 20, got ${diceRoll}`,
};
}
return diceRoll + modifier;
}