Fix issue with CheckFactory parsing empty strings as NaN for check related values
This commit is contained in:
parent
ff6427f5a9
commit
1f6d13c49d
1 changed files with 16 additions and 7 deletions
|
@ -46,7 +46,8 @@ class CheckFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
createCheckTargetNumberModifier(): string {
|
createCheckTargetNumberModifier(): string {
|
||||||
return "v" + Math.max(this.checkTargetNumber + this.gmModifier, 0);
|
const totalCheckTargetNumber = Math.max(this.checkTargetNumber + this.gmModifier, 0);
|
||||||
|
return `v${totalCheckTargetNumber}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
createCoupFumbleModifier(): string | null {
|
createCoupFumbleModifier(): string | null {
|
||||||
|
@ -55,7 +56,7 @@ class CheckFactory {
|
||||||
const isMaximumCoupResultRequired = this.options.maximumCoupResult !== defaultCheckOptions.maximumCoupResult;
|
const isMaximumCoupResultRequired = this.options.maximumCoupResult !== defaultCheckOptions.maximumCoupResult;
|
||||||
|
|
||||||
if (isMinimumFumbleResultRequired || isMaximumCoupResultRequired) {
|
if (isMinimumFumbleResultRequired || isMaximumCoupResultRequired) {
|
||||||
return "c" + (this.options.maximumCoupResult ?? "") + ":" + (this.options.minimumFumbleResult ?? "");
|
return `c${this.options.maximumCoupResult ?? ""}:${this.options.minimumFumbleResult ?? ""}`;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -162,12 +163,20 @@ async function askGmModifier(
|
||||||
* @param formData - The filed dialog
|
* @param formData - The filed dialog
|
||||||
*/
|
*/
|
||||||
function parseDialogFormData(formData: HTMLFormElement): Partial<IntermediateGmModifierData> {
|
function parseDialogFormData(formData: HTMLFormElement): Partial<IntermediateGmModifierData> {
|
||||||
|
const chosenCheckTargetNumber = parseInt(formData["check-target-number"]?.value);
|
||||||
|
const chosenGMModifier = parseInt(formData["gm-modifier"]?.value);
|
||||||
|
const chosenMaximumCoupResult = parseInt(formData["maximum-coup-result"]?.value);
|
||||||
|
const chosenMinimumFumbleResult = parseInt(formData["minimum-fumble-result"]?.value);
|
||||||
|
const chosenRollMode = formData["roll-mode"]?.value;
|
||||||
|
|
||||||
|
const invalidNumbers = [NaN, Infinity, -Infinity];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
checkTargetNumber: parseInt(formData["check-target-number"]?.value),
|
checkTargetNumber: invalidNumbers.includes(chosenCheckTargetNumber) ? undefined : chosenCheckTargetNumber,
|
||||||
gmModifier: parseInt(formData["gm-modifier"]?.value),
|
gmModifier: invalidNumbers.includes(chosenGMModifier) ? undefined : chosenGMModifier,
|
||||||
maximumCoupResult: parseInt(formData["maximum-coup-result"]?.value),
|
maximumCoupResult: invalidNumbers.includes(chosenMaximumCoupResult) ? undefined : chosenMaximumCoupResult,
|
||||||
minimumFumbleResult: parseInt(formData["minimum-fumble-result"]?.value),
|
minimumFumbleResult: invalidNumbers.includes(chosenMinimumFumbleResult) ? undefined : chosenMinimumFumbleResult,
|
||||||
rollMode: formData["roll-mode"]?.value,
|
rollMode: Object.values(CONST.DICE_ROLL_MODES).includes(chosenRollMode) ? chosenRollMode : undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue