Skip to content

Commit d76166b

Browse files
committed
Show reroll die prompt if move prompts are enabled
Currently, the "Reroll a die" action only shows a text input field when the "Prompt for rolls in Make a Move" setting is enabled. Changed to show the same die value selector as in all other moves intead, including the "Roll for me option".
1 parent bec3b9c commit d76166b

1 file changed

Lines changed: 29 additions & 18 deletions

File tree

packages/obsidian/src/moves/action/action-modal.ts

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import { appendNodesToMoveOrMechanicsBlockWithActor } from "mechanics/editor";
1616
import { DieKind } from "utils/dice-roller";
1717
import { node } from "utils/kdl";
1818
import { CustomSuggestModal } from "utils/suggest";
19-
import { PromptModal } from "utils/ui/prompt";
2019
import { CharacterContext } from "../../character-tracker";
2120
import { MomentumTracker, momentumTrackerReader } from "../../characters/lens";
2221
import { ActionMoveDescription } from "../desc";
2322
import { ActionMoveWrapper, formatRollResult } from "../wrapper";
23+
import { numberRange } from "@ironvault/utils/numbers";
2424

2525
export async function checkForMomentumBurn(
2626
app: App,
@@ -141,29 +141,40 @@ export async function rerollDie(
141141
undefined,
142142
"Select the die to reroll",
143143
);
144-
let newValue: string;
144+
let newValue: string | undefined = undefined;
145+
let dieSides: number = 10;
146+
147+
if (dieName === "action") {
148+
// Action die is always 6 sides.
149+
dieSides = 6;
150+
}
151+
// For challenge dice, we need to check the campaign settings to determine the number of sides.
152+
else if (dieName === "vs1" || dieName === "vs2") {
153+
// Get the number of sides for the challenge dice from the campaign settings.
154+
// This assumes that the campaign settings have been properly initialized and contain the sides for the dice.
155+
// If the campaign settings are not available, default to 10 sides for challenge dice.
156+
const [challenge1Sides, challenge2Sides] = actionContext.campaignContext
157+
.localSettings.actionRollChallengeDiceSides ?? [10, 10];
158+
dieSides = dieName === "vs1" ? challenge1Sides : challenge2Sides;
159+
}
160+
145161
if (plugin.settings.promptForRollsInMoves) {
146-
newValue = await PromptModal.prompt(
162+
const choice = await CustomSuggestModal.select(
147163
plugin.app,
148-
"Enter the new die roll value",
164+
["Roll for me", ...numberRange(1, dieSides)],
165+
(x) => x.toString(),
166+
undefined,
167+
`Roll ${dieName == "action" ? "your action" : "one challenge"} die (1d${dieSides}) and enter the value`,
149168
);
150-
} else {
151-
let dieSides: number = 10;
152169

153-
if (dieName === "action") {
154-
// Action die is always 6 sides.
155-
dieSides = 6;
156-
}
157-
// For challenge dice, we need to check the campaign settings to determine the number of sides.
158-
else if (dieName === "vs1" || dieName === "vs2") {
159-
// Get the number of sides for the challenge dice from the campaign settings.
160-
// This assumes that the campaign settings have been properly initialized and contain the sides for the dice.
161-
// If the campaign settings are not available, default to 10 sides for challenge dice.
162-
const [challenge1Sides, challenge2Sides] = actionContext.campaignContext
163-
.localSettings.actionRollChallengeDiceSides ?? [10, 10];
164-
dieSides = dieName === "vs1" ? challenge1Sides : challenge2Sides;
170+
if (typeof choice === "number") {
171+
newValue = "" + choice;
165172
}
173+
}
166174

175+
if (newValue === undefined) {
176+
// newValue isn't set yet, meaning either settings.promptForRollsInMoves isn't enabled,
177+
// or user chose "Roll for me" when prompted. Invoke dice roller in either case.
167178
newValue =
168179
"" +
169180
(

0 commit comments

Comments
 (0)