diff --git a/src/module/rolls/check-factory.ts b/src/module/rolls/check-factory.ts index c972120c..44339b47 100644 --- a/src/module/rolls/check-factory.ts +++ b/src/module/rolls/check-factory.ts @@ -4,10 +4,10 @@ import { DS4 } from "../config"; * Provides default values for all arguments the `CheckFactory` expects. */ class DefaultCheckOptions implements DS4CheckFactoryOptions { - maxCritSuccess = 1; - minCritFailure = 20; - useSlayingDice = false; - rollMode: DS4RollMode = "roll"; + readonly maxCritSuccess = 1; + readonly minCritFailure = 20; + readonly useSlayingDice = false; + readonly rollMode: DS4RollMode = "roll"; mergeWith(other: Partial): DS4CheckFactoryOptions { return { ...this, ...other } as DS4CheckFactoryOptions; @@ -28,7 +28,7 @@ class CheckFactory { private gmModifier: number, passedOptions: Partial = {}, ) { - this.checkOptions = new DefaultCheckOptions().mergeWith(passedOptions); + this.checkOptions = defaultCheckOptions.mergeWith(passedOptions); } private checkOptions: DS4CheckFactoryOptions; @@ -45,7 +45,6 @@ class CheckFactory { const roll = new rollCls(formula); const rollModeTemplate = this.checkOptions.rollMode; - console.log(rollModeTemplate); return roll.toMessage({}, { rollMode: rollModeTemplate, create: true }); } @@ -76,8 +75,8 @@ class CheckFactory { /** * Asks the user for all unknown/necessary information and passes them on to perform a roll. - * @param targetValue {number} The Check Target Number ("CTN") - * @param options {Partial} Options changing the behaviour of the roll and message. + * @param targetValue The Check Target Number ("CTN") + * @param options Options changing the behaviour of the roll and message. */ export async function createCheckRoll( targetValue: number, @@ -86,6 +85,8 @@ export async function createCheckRoll( // Ask for additional required data; const gmModifierData = await askGmModifier(targetValue, options); + const newTargetValue = gmModifierData.checkTargetValue ?? targetValue; + const gmModifier = gmModifierData.gmModifier ?? 0; const newOptions: Partial = { maxCritSuccess: gmModifierData.maxCritSuccess ?? options.maxCritSuccess ?? undefined, minCritFailure: gmModifierData.minCritFailure ?? options.minCritFailure ?? undefined, @@ -94,7 +95,7 @@ export async function createCheckRoll( }; // Create Factory - const cf = new CheckFactory(gmModifierData.checkTargetValue, gmModifierData.gmModifier, newOptions); + const cf = new CheckFactory(newTargetValue, gmModifier, newOptions); // Possibly additional processing @@ -108,13 +109,13 @@ export async function createCheckRoll( * @notes * At the moment, this asks for more data than it will do after some iterations. * - * @returns {Promise} The data given by the user. + * @returns The data given by the user. */ async function askGmModifier( targetValue: number, options: Partial = {}, { template, title }: { template?: string; title?: string } = {}, -): Promise { +): Promise> { // Render model interface and return value const usedTemplate = template ?? "systems/ds4/templates/roll/roll-options.hbs"; const usedTitle = title ?? game.i18n.localize("DS4.RollDialogDefaultTitle"); @@ -124,7 +125,7 @@ async function askGmModifier( checkTargetValue: targetValue, maxCritSuccess: options.maxCritSuccess ?? defaultCheckOptions.maxCritSuccess, minCritFailure: options.minCritFailure ?? defaultCheckOptions.minCritFailure, - rollModes: rollModes, + rollMode: options.rollMode, config: DS4, }; const renderedHtml = await renderTemplate(usedTemplate, templateData); @@ -167,22 +168,20 @@ async function askGmModifier( ).render(true); }); const dialogForm = await dialogPromise; - return parseDialogFormData(dialogForm, targetValue); + return parseDialogFormData(dialogForm); } /** * Extracts Dialog data from the returned DOM element. - * @param formData {HTMLFormElement} The filed dialog - * @param targetValue {number} The previously known target value (slated for removal once data automation is available) + * @param formData The filed dialog */ -function parseDialogFormData(formData: HTMLFormElement, targetValue: number): IntermediateGmModifierData { +function parseDialogFormData(formData: HTMLFormElement): Partial { return { - checkTargetValue: parseInt(formData["ctv"]?.value) ?? targetValue, - gmModifier: parseInt(formData["gmmod"]?.value) ?? 0, - maxCritSuccess: parseInt(formData["maxcoup"]?.value) ?? defaultCheckOptions.maxCritSuccess, - minCritFailure: parseInt(formData["minfumble"]?.value) ?? defaultCheckOptions.minCritFailure, - useSlayingDice: false, - rollMode: formData["visibility"]?.value ?? defaultCheckOptions.rollMode, + checkTargetValue: parseInt(formData["ctv"]?.value), + gmModifier: parseInt(formData["gmmod"]?.value), + maxCritSuccess: parseInt(formData["maxcoup"]?.value), + minCritFailure: parseInt(formData["minfumble"]?.value), + rollMode: formData["visibility"]?.value, }; } diff --git a/src/templates/roll/roll-options.hbs b/src/templates/roll/roll-options.hbs index 0ef4912a..6db4e245 100644 --- a/src/templates/roll/roll-options.hbs +++ b/src/templates/roll/roll-options.hbs @@ -9,8 +9,10 @@ - + \ No newline at end of file