Skip to content

Commit

Permalink
feat(DiceTool): Resolve Kruptein#1327, Kruptein#1328
Browse files Browse the repository at this point in the history
  • Loading branch information
SuikaXhq committed Jan 15, 2024
1 parent 076e05d commit 0422034
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ tech changes will usually be stripped from release notes for the public
- If the text area of a note is still in focus after 5 seconds and an edit was made, a server save is done
- _see the release notes for all the changes_
- [tech] ModalStack now supports dynamically inserted modals
- Dice history now contains user and details

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion client/src/apiTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ export interface Viewport {
export interface DiceRollResult {
player: string;
roll: string;
result: number;
result: string;
shareWithAll: boolean;
}
export interface FloorBackgroundSet {
Expand Down
20 changes: 20 additions & 0 deletions client/src/game/dice/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ class DiceStore extends Store<DiceState> {
return result;
}

getResultString(key: string): string {
const result = this._state.results.get(key)?.results[0];
if (result === undefined) {
return "";
}
return (
"(" +
result.details
.map((part) =>
part.type === "dice"
? part.output.join("+")
: part.type === "fixed"
? part.output
: `) ${part.value} (`,
)
.join("") +
`) = ${result.total}`
);
}

setResults(key: string, results: DndResult[], position?: [number, number]): void {
this._state.results.set(key, { position, results });
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/game/tools/variants/dice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DiceTool extends Tool implements ITool {
state = reactive<{
shareWithAll: boolean;
autoRoll: boolean;
history: { roll: string; result: number; player: string }[];
history: { roll: string; result: string; player: string }[];
timeouts: Record<string, number>;
}>({
shareWithAll: false,
Expand Down
15 changes: 11 additions & 4 deletions client/src/game/ui/tools/DiceTool.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const diceText = computed(() => {
async function reroll(roll: string): Promise<void> {
const key = await diceTool.roll(roll);
const result = diceStore.getTotal(key);
const result = diceStore.getResultString(key);
diceTool.state.history.push({ roll, result, player: coreStore.state.username });
sendDiceRollResult({
player: coreStore.state.username,
Expand All @@ -70,7 +70,7 @@ async function go(): Promise<void> {
button.value?.classList.remove("transition");
const roll = diceText.value;
const key = await diceTool.roll(roll);
const result = diceStore.getTotal(key);
const result = diceStore.getResultString(key);
diceTool.state.history.push({ roll, result, player: coreStore.state.username });
sendDiceRollResult({
player: coreStore.state.username,
Expand All @@ -86,7 +86,14 @@ async function go(): Promise<void> {
<div id="dice" class="tool-detail">
<div id="dice-history" ref="historyDiv">
<template v-for="r of diceTool.state.history" :key="r.roll">
<div class="roll" :title="r.player" @click="reroll(r.roll)">{{ r.roll }}</div>
<div
class="player"
:title="r.player"
style="margin-right: 1em; overflow: hidden; text-overflow: ellipsis"
>
{{ r.player }}
</div>
<div class="roll" :title="r.player" style="margin-right: 1em" @click="reroll(r.roll)">{{ r.roll }}</div>
<div class="result" :title="r.player">{{ r.result }}</div>
</template>
</div>
Expand Down Expand Up @@ -128,7 +135,7 @@ async function go(): Promise<void> {
#dice-history {
display: grid;
grid-template-columns: 1fr 2em;
grid-template-columns: 1fr 2fr 2fr;
max-height: 3em;
overflow-y: auto;
Expand Down
2 changes: 1 addition & 1 deletion server/src/api/models/dice/roll.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
class DiceRollResult(BaseModel):
player: str
roll: str
result: int
result: str
shareWithAll: bool

0 comments on commit 0422034

Please sign in to comment.