V1.26.0: dice that tumble, rolled by the server, seen by the DM

- Each die is drawn as its own shape, tumbles in and lands on its result;
  a natural 20 glows, a natural 1 shakes; respects reduced motion
- In a campaign the server makes every digital roll and keeps it
- The DM sees each roll as it lands: an "Everyone's rolls" tab in the
  roller, a pop-up beside the dice button, and a list on the encounter page
- Players see everyone's rolls or only their own, by the campaign setting;
  the DM can roll hidden
- Physical dice are typed in, one box per die, and checked; with "both",
  each person chooses in the roller
- game/dice.js: parsing, rolling, checking typed dice, critical damage

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-12 08:46:22 +02:00
co-authored by Claude Opus 5.5
parent c3f2b0dfa7
commit 8811f14732
22 changed files with 1345 additions and 167 deletions
+24
View File
@@ -9,6 +9,7 @@ import type {
CharacterDetail,
CharacterSummary,
Currency,
DiceRollRecord,
DiceMode,
Encounter,
EncounterMode,
@@ -28,6 +29,7 @@ import type {
QuickStats,
RestResult,
RestType,
RollSpec,
Spell,
Weapon,
} from './types';
@@ -380,6 +382,28 @@ export function useBuildOptions() {
});
}
// The latest rolls at the table that this member may see, newest first.
export function useRolls(campaignId: string | null | undefined) {
return useQuery({
queryKey: ['campaign', campaignId, 'rolls'],
enabled: Boolean(campaignId),
queryFn: async () => (await apiClient.get<{ rolls: DiceRollRecord[] }>(`/campaigns/${campaignId}/rolls`, { params: { limit: 40 } })).data.rolls,
});
}
// Makes a roll at the table: the server rolls it (or checks dice typed in),
// keeps it and tells the table.
export function useRoll(campaignId: string | null | undefined) {
const qc = useQueryClient();
return useMutation({
mutationFn: async (spec: RollSpec) => (await apiClient.post<{ roll: DiceRollRecord }>(`/campaigns/${campaignId}/rolls`, spec)).data.roll,
onSuccess: (roll) => {
// Shown at once in the feed, without waiting for the server to say so.
qc.setQueryData<DiceRollRecord[]>(['campaign', campaignId, 'rolls'], (rolls) => (rolls && !rolls.some((r) => r.id === roll.id) ? [roll, ...rolls] : rolls));
},
});
}
// Multiclassing requirements and the suggested routes.
export function useMulticlassReference(enabled: boolean) {
return useQuery({