diff --git a/lang/de.json b/lang/de.json index 2c6410e..7ba4803 100644 --- a/lang/de.json +++ b/lang/de.json @@ -1,5 +1,6 @@ { "TICKWERK.AdvanceTicks": "Auf der Tickleiste Vorrücken", + "TICKWERK.NumberOfTicks": "Anzahl an Ticks", "TICKWERK.StopWaiting": "Abwarten Beenden", "TICKWERK.Tick": "Tick", "TICKWERK.Wait": "Abwarten", @@ -7,5 +8,6 @@ "TICKWERK.WarningCannotAdvanceWhileWaiting": "Während des Abwartens ist es nicht möglich, auf der Tickleiste vorzurücken.", "TICKWERK.WarningCannotAdvanceWithoutStartedCombat": "Solange der Kampf nicht gestartet ist es nicht möglich, auf der Tickleiste vorzurücken.", "TICKWERK.WarningCannotAdvanceWithoutTickValue": "Ohne Tickwert ist es nicht möglich, auf der Tickleiste vorzurücken.", - "TICKWERK.WarningCannotStartCombat": "Der Kampf kann nur begonnen werden, wenn mindestens ein Kampfteilnehmer einen Tickwert hat." + "TICKWERK.WarningCannotStartCombat": "Der Kampf kann nur begonnen werden, wenn mindestens ein Kampfteilnehmer einen Tickwert hat.", + "TICKWERK.WarningInvalidNumberOfTicks": "Bitte gib eine valide Anzahl an Ticks ein." } diff --git a/lang/en.json b/lang/en.json index 698bec6..667ddd4 100644 --- a/lang/en.json +++ b/lang/en.json @@ -1,5 +1,6 @@ { "TICKWERK.AdvanceTicks": "Advance on the Tickbar", + "TICKWERK.NumberOfTicks": "Number of Ticks", "TICKWERK.StopWaiting": "Stop Waiting", "TICKWERK.Tick": "Tick", "TICKWERK.Wait": "Wait", @@ -7,5 +8,6 @@ "TICKWERK.WarningCannotAdvanceWhileWaiting": "Cannot advance while waiting.", "TICKWERK.WarningCannotAdvanceWithoutStartedCombat": "Cannot advance without the combat being started.", "TICKWERK.WarningCannotAdvanceWithoutTickValue": "Cannot advance without having a tick value.", - "TICKWERK.WarningCannotStartCombat": "In order to start the combat, there needs to be at least one combatant with a tick value." + "TICKWERK.WarningCannotStartCombat": "In order to start the combat, there needs to be at least one combatant with a tick value.", + "TICKWERK.WarningInvalidNumberOfTicks": "Please enter a valid number of ticks." } diff --git a/src/data/documents/combatant.ts b/src/data/documents/combatant.ts index 8e0a9a4..f0c75cd 100644 --- a/src/data/documents/combatant.ts +++ b/src/data/documents/combatant.ts @@ -65,19 +65,30 @@ const CombatantMixin = (BaseCombatant: typeof Combatant) => { async advanceTicksDialog(): Promise<void> { const game = getGame(); + const id = foundry.utils.randomID(); - const ticks = await Dialog.prompt({ + const form = `<form><div class="form-group"> + <label for="ticks-${id}">${game.i18n.localize('TICKWERK.NumberOfTicks')}</label> + <input id="ticks-${id}" name="ticks" type="number" value="5" min="0" required /> + </div></form>`; + + const ticks = await Dialog.confirm({ title: game.i18n.localize('TICKWERK.AdvanceTicks'), - content: '<input name="ticks" type="number" value="5" min="0" />', - label: game.i18n.localize('TICKWERK.AdvanceTicks'), - callback: (html) => { + content: form, + yes: (html) => { const ticks = html[0]?.querySelector<HTMLInputElement>('input[name="ticks"]')?.value; - return ticks !== undefined ? parseInt(ticks) : undefined; + const parsedTicks = ticks !== undefined ? parseInt(ticks) : undefined; + return Number.isSafeInteger(parsedTicks) ? parsedTicks : undefined; }, rejectClose: false, }); - if (ticks !== undefined && ticks !== null) { + if (ticks === undefined) { + ui.notifications?.warn('TICKWERK.WarningInvalidNumberOfTicks', { localize: true }); + return; + } + + if (ticks !== null && ticks !== false) { await this.advanceTicks(ticks); } }