Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(DiceTool): Resolve #1327, #1328 #1350

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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