Show toast when roll-all-initiative skips combatants without loaded sources
Previously the button silently did nothing for creatures whose bestiary source wasn't loaded. Now it reports how many were skipped and why. Also keeps the roll-all button visible (but disabled) when there's nothing left to roll, and moves toasts to the bottom-left corner. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,10 @@ export type {
|
||||
} from "./ports.js";
|
||||
export { removeCombatantUseCase } from "./remove-combatant-use-case.js";
|
||||
export { retreatTurnUseCase } from "./retreat-turn-use-case.js";
|
||||
export { rollAllInitiativeUseCase } from "./roll-all-initiative-use-case.js";
|
||||
export {
|
||||
type RollAllResult,
|
||||
rollAllInitiativeUseCase,
|
||||
} from "./roll-all-initiative-use-case.js";
|
||||
export { rollInitiativeUseCase } from "./roll-initiative-use-case.js";
|
||||
export { setAcUseCase } from "./set-ac-use-case.js";
|
||||
export { setHpUseCase } from "./set-hp-use-case.js";
|
||||
|
||||
@@ -10,20 +10,29 @@ import {
|
||||
} from "@initiative/domain";
|
||||
import type { EncounterStore } from "./ports.js";
|
||||
|
||||
export interface RollAllResult {
|
||||
events: DomainEvent[];
|
||||
skippedNoSource: number;
|
||||
}
|
||||
|
||||
export function rollAllInitiativeUseCase(
|
||||
store: EncounterStore,
|
||||
rollDice: () => number,
|
||||
getCreature: (id: CreatureId) => Creature | undefined,
|
||||
): DomainEvent[] | DomainError {
|
||||
): RollAllResult | DomainError {
|
||||
let encounter = store.get();
|
||||
const allEvents: DomainEvent[] = [];
|
||||
let skippedNoSource = 0;
|
||||
|
||||
for (const combatant of encounter.combatants) {
|
||||
if (!combatant.creatureId) continue;
|
||||
if (combatant.initiative !== undefined) continue;
|
||||
|
||||
const creature = getCreature(combatant.creatureId);
|
||||
if (!creature) continue;
|
||||
if (!creature) {
|
||||
skippedNoSource++;
|
||||
continue;
|
||||
}
|
||||
|
||||
const { modifier } = calculateInitiative({
|
||||
dexScore: creature.abilities.dex,
|
||||
@@ -47,5 +56,5 @@ export function rollAllInitiativeUseCase(
|
||||
}
|
||||
|
||||
store.save(encounter);
|
||||
return allEvents;
|
||||
return { events: allEvents, skippedNoSource };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user