Implement the 005-set-initiative feature that adds initiative values to combatants with automatic descending sort and active turn preservation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,8 @@ function formatEvent(e: ReturnType<typeof useEncounter>["events"][number]) {
|
||||
return `Removed combatant: ${e.name}`;
|
||||
case "CombatantUpdated":
|
||||
return `Renamed combatant: ${e.oldName} → ${e.newName}`;
|
||||
case "InitiativeSet":
|
||||
return `Initiative: ${e.combatantId} ${e.previousValue ?? "unset"} → ${e.newValue ?? "unset"}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +79,7 @@ export function App() {
|
||||
addCombatant,
|
||||
removeCombatant,
|
||||
editCombatant,
|
||||
setInitiative,
|
||||
} = useEncounter();
|
||||
const activeCombatant = encounter.combatants[encounter.activeIndex];
|
||||
const [nameInput, setNameInput] = useState("");
|
||||
@@ -107,6 +110,23 @@ export function App() {
|
||||
isActive={i === encounter.activeIndex}
|
||||
onRename={editCombatant}
|
||||
/>{" "}
|
||||
<input
|
||||
type="number"
|
||||
value={c.initiative ?? ""}
|
||||
placeholder="Init"
|
||||
style={{ width: "4em" }}
|
||||
onChange={(e) => {
|
||||
const raw = e.target.value;
|
||||
if (raw === "") {
|
||||
setInitiative(c.id, undefined);
|
||||
} else {
|
||||
const n = Number.parseInt(raw, 10);
|
||||
if (!Number.isNaN(n)) {
|
||||
setInitiative(c.id, n);
|
||||
}
|
||||
}
|
||||
}}
|
||||
/>{" "}
|
||||
<button type="button" onClick={() => removeCombatant(c.id)}>
|
||||
Remove
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user