Merge branch 'small-check-factory-cleanup' into 'master'

Small check factory cleanup and use foundry form formating for roll dialog

See merge request dungeonslayers/ds4!95
This commit is contained in:
Johannes Loher 2021-03-17 19:04:33 +00:00
commit fc1f3bd73c
5 changed files with 81 additions and 59 deletions

View file

@ -224,11 +224,11 @@
"DS4.ErrorActorDoesNotHaveItem": "Der Aktor '{actor}' hat kein Item mit der ID '{id}'.", "DS4.ErrorActorDoesNotHaveItem": "Der Aktor '{actor}' hat kein Item mit der ID '{id}'.",
"DS4.ErrorUnexpectedError": "Es gab einen unerwarteten Fehler im Dungeonslayers 4 System. Für mehr Details schauen Sie bitte in die Konsole (F12).", "DS4.ErrorUnexpectedError": "Es gab einen unerwarteten Fehler im Dungeonslayers 4 System. Für mehr Details schauen Sie bitte in die Konsole (F12).",
"DS4.ErrorItemDoesNotHaveEffect": "Das Item '{item}' hat keinen Effekt mit der ID '{id}'.", "DS4.ErrorItemDoesNotHaveEffect": "Das Item '{item}' hat keinen Effekt mit der ID '{id}'.",
"DS4.RollDialogTargetLabel": "Probenwert", "DS4.RollDialogCheckTargetNumberLabel": "Probenwert",
"DS4.RollDialogModifierLabel": "SL-Modifikator", "DS4.RollDialogGMModifierLabel": "SL-Modifikator",
"DS4.RollDialogCoupLabel": "Immersieg bis", "DS4.RollDialogMaximumCoupResultLabel": "Immersieg bis",
"DS4.RollDialogFumbleLabel": "Patzer ab", "DS4.RollDialogMinimumFumbleResultLabel": "Patzer ab",
"DS4.RollDialogVisibilityLabel": "Sichtbarkeit", "DS4.RollDialogRollModeLabel": "Sichtbarkeit",
"DS4.TooltipBaseValue": "Basiswert", "DS4.TooltipBaseValue": "Basiswert",
"DS4.TooltipModifier": "Modifikator", "DS4.TooltipModifier": "Modifikator",
"DS4.TooltipEffects": "Effekte" "DS4.TooltipEffects": "Effekte"

View file

@ -224,11 +224,11 @@
"DS4.ErrorActorDoesNotHaveItem": "The actor '{actor}' does not have any item with the id '{id}'.", "DS4.ErrorActorDoesNotHaveItem": "The actor '{actor}' does not have any item with the id '{id}'.",
"DS4.ErrorUnexpectedError": "There was an unexpected error in the Dungeonslayers 4 system. For more details, please take a look at the console (F12).", "DS4.ErrorUnexpectedError": "There was an unexpected error in the Dungeonslayers 4 system. For more details, please take a look at the console (F12).",
"DS4.ErrorItemDoesNotHaveEffect": "The item '{item}' does not have any effect with the id '{id}'.", "DS4.ErrorItemDoesNotHaveEffect": "The item '{item}' does not have any effect with the id '{id}'.",
"DS4.RollDialogTargetLabel": "Check Target Number", "DS4.RollDialogCheckTargetNumberLabel": "Check Target Number",
"DS4.RollDialogModifierLabel": "Game Master Modifier", "DS4.RollDialogGMModifierLabel": "Game Master Modifier",
"DS4.RollDialogCoupLabel": "Coup to", "DS4.RollDialogMaximumCoupResultLabel": "Coup to",
"DS4.RollDialogFumbleLabel": "Fumble from", "DS4.RollDialogMinimumFumbleResultLabel": "Fumble from",
"DS4.RollDialogVisibilityLabel": "Visibility", "DS4.RollDialogRollModeLabel": "Visibility",
"DS4.TooltipBaseValue": "Base Value", "DS4.TooltipBaseValue": "Base Value",
"DS4.TooltipModifier": "Modifier", "DS4.TooltipModifier": "Modifier",
"DS4.TooltipEffects": "Effects" "DS4.TooltipEffects": "Effects"

View file

@ -93,8 +93,8 @@ export class DS4Item extends Item<DS4ItemData> {
const checkTargetValue = (ownerDataData.combatValues[combatValue].total as number) + weaponBonus; const checkTargetValue = (ownerDataData.combatValues[combatValue].total as number) + weaponBonus;
await createCheckRoll(checkTargetValue, { await createCheckRoll(checkTargetValue, {
rollMode: game.settings.get("core", "rollMode"), rollMode: game.settings.get("core", "rollMode"),
maxCritSuccess: ownerDataData.rolling.maximumCoupResult, maximumCoupResult: ownerDataData.rolling.maximumCoupResult,
minCritFailure: ownerDataData.rolling.minimumFumbleResult, minimumFumbleResult: ownerDataData.rolling.minimumFumbleResult,
}); });
} }
@ -135,8 +135,8 @@ export class DS4Item extends Item<DS4ItemData> {
await createCheckRoll(checkTargetValue, { await createCheckRoll(checkTargetValue, {
rollMode: game.settings.get("core", "rollMode"), rollMode: game.settings.get("core", "rollMode"),
maxCritSuccess: ownerDataData.rolling.maximumCoupResult, maximumCoupResult: ownerDataData.rolling.maximumCoupResult,
minCritFailure: ownerDataData.rolling.minimumFumbleResult, minimumFumbleResult: ownerDataData.rolling.minimumFumbleResult,
}); });
} }

View file

@ -1,11 +1,9 @@
import { DS4 } from "../config";
/** /**
* Provides default values for all arguments the `CheckFactory` expects. * Provides default values for all arguments the `CheckFactory` expects.
*/ */
class DefaultCheckOptions implements DS4CheckFactoryOptions { class DefaultCheckOptions implements DS4CheckFactoryOptions {
readonly maxCritSuccess = 1; readonly maximumCoupResult = 1;
readonly minCritFailure = 20; readonly minimumFumbleResult = 20;
readonly useSlayingDice = false; readonly useSlayingDice = false;
readonly rollMode: Const.DiceRollMode = "roll"; readonly rollMode: Const.DiceRollMode = "roll";
@ -52,11 +50,13 @@ class CheckFactory {
} }
createCritTerm(): string | null { createCritTerm(): string | null {
const minCritRequired = this.checkOptions.minCritFailure !== defaultCheckOptions.minCritFailure; const minCritRequired = this.checkOptions.minimumFumbleResult !== defaultCheckOptions.minimumFumbleResult;
const maxCritRequired = this.checkOptions.maxCritSuccess !== defaultCheckOptions.maxCritSuccess; const maxCritRequired = this.checkOptions.maximumCoupResult !== defaultCheckOptions.maximumCoupResult;
if (minCritRequired || maxCritRequired) { if (minCritRequired || maxCritRequired) {
return "c" + (this.checkOptions.maxCritSuccess ?? "") + ":" + (this.checkOptions.minCritFailure ?? ""); return (
"c" + (this.checkOptions.maximumCoupResult ?? "") + ":" + (this.checkOptions.minimumFumbleResult ?? "")
);
} else { } else {
return null; return null;
} }
@ -75,11 +75,11 @@ export async function createCheckRoll(
// Ask for additional required data; // Ask for additional required data;
const gmModifierData = await askGmModifier(targetValue, options); const gmModifierData = await askGmModifier(targetValue, options);
const newTargetValue = gmModifierData.checkTargetValue ?? targetValue; const newTargetValue = gmModifierData.checkTargetNumber ?? targetValue;
const gmModifier = gmModifierData.gmModifier ?? 0; const gmModifier = gmModifierData.gmModifier ?? 0;
const newOptions: Partial<DS4CheckFactoryOptions> = { const newOptions: Partial<DS4CheckFactoryOptions> = {
maxCritSuccess: gmModifierData.maxCritSuccess ?? options.maxCritSuccess ?? undefined, maximumCoupResult: gmModifierData.maximumCoupResult ?? options.maximumCoupResult ?? undefined,
minCritFailure: gmModifierData.minCritFailure ?? options.minCritFailure ?? undefined, minimumFumbleResult: gmModifierData.minimumFumbleResult ?? options.minimumFumbleResult ?? undefined,
useSlayingDice: gmModifierData.useSlayingDice ?? options.useSlayingDice ?? undefined, useSlayingDice: gmModifierData.useSlayingDice ?? options.useSlayingDice ?? undefined,
rollMode: gmModifierData.rollMode ?? options.rollMode ?? undefined, rollMode: gmModifierData.rollMode ?? options.rollMode ?? undefined,
}; };
@ -102,7 +102,7 @@ export async function createCheckRoll(
* @returns The data given by the user. * @returns The data given by the user.
*/ */
async function askGmModifier( async function askGmModifier(
targetValue: number, checkTargetNumber: number,
options: Partial<DS4CheckFactoryOptions> = {}, options: Partial<DS4CheckFactoryOptions> = {},
{ template, title }: { template?: string; title?: string } = {}, { template, title }: { template?: string; title?: string } = {},
): Promise<Partial<IntermediateGmModifierData>> { ): Promise<Partial<IntermediateGmModifierData>> {
@ -110,11 +110,10 @@ async function askGmModifier(
const usedTemplate = template ?? "systems/ds4/templates/roll/roll-options.hbs"; const usedTemplate = template ?? "systems/ds4/templates/roll/roll-options.hbs";
const usedTitle = title ?? game.i18n.localize("DS4.RollDialogDefaultTitle"); const usedTitle = title ?? game.i18n.localize("DS4.RollDialogDefaultTitle");
const templateData = { const templateData = {
cssClass: "roll-option",
title: usedTitle, title: usedTitle,
checkTargetValue: targetValue, checkTargetNumber: checkTargetNumber,
maxCritSuccess: options.maxCritSuccess ?? defaultCheckOptions.maxCritSuccess, maximumCoupResult: options.maximumCoupResult ?? defaultCheckOptions.maximumCoupResult,
minCritFailure: options.minCritFailure ?? defaultCheckOptions.minCritFailure, minimumFumbleResult: options.minimumFumbleResult ?? defaultCheckOptions.minimumFumbleResult,
rollMode: options.rollMode, rollMode: options.rollMode,
rollModes: CONFIG.Dice.rollModes, rollModes: CONFIG.Dice.rollModes,
}; };
@ -168,11 +167,11 @@ async function askGmModifier(
*/ */
function parseDialogFormData(formData: HTMLFormElement): Partial<IntermediateGmModifierData> { function parseDialogFormData(formData: HTMLFormElement): Partial<IntermediateGmModifierData> {
return { return {
checkTargetValue: parseInt(formData["ctv"]?.value), checkTargetNumber: parseInt(formData["check-target-number"]?.value),
gmModifier: parseInt(formData["gmmod"]?.value), gmModifier: parseInt(formData["gm-modifier"]?.value),
maxCritSuccess: parseInt(formData["maxcoup"]?.value), maximumCoupResult: parseInt(formData["maximum-coup-result"]?.value),
minCritFailure: parseInt(formData["minfumble"]?.value), minimumFumbleResult: parseInt(formData["minimum-fumble-result"]?.value),
rollMode: formData["visibility"]?.value, rollMode: formData["roll-mode"]?.value,
}; };
} }
@ -189,10 +188,10 @@ interface GmModifierData {
* *
* @deprecated * @deprecated
* Quite a lot of this information is requested due to a lack of automation: * Quite a lot of this information is requested due to a lack of automation:
* - maxCritSuccess * - maximumCoupResult
* - minCritFailure * - minimumFumbleResult
* - useSlayingDice * - useSlayingDice
* - checkTargetValue * - checkTargetNumber
* *
* They will and should be removed once effects and data retrieval is in place. * They will and should be removed once effects and data retrieval is in place.
* If a "raw" roll dialog is necessary, create another pre-processing Dialog * If a "raw" roll dialog is necessary, create another pre-processing Dialog
@ -200,10 +199,10 @@ interface GmModifierData {
* This interface should then be replaced with the `GmModifierData`. * This interface should then be replaced with the `GmModifierData`.
*/ */
interface IntermediateGmModifierData extends GmModifierData { interface IntermediateGmModifierData extends GmModifierData {
checkTargetValue: number; checkTargetNumber: number;
gmModifier: number; gmModifier: number;
maxCritSuccess: number; maximumCoupResult: number;
minCritFailure: number; minimumFumbleResult: number;
// TODO: In final version from system settings // TODO: In final version from system settings
useSlayingDice: boolean; useSlayingDice: boolean;
rollMode: Const.DiceRollMode; rollMode: Const.DiceRollMode;
@ -213,8 +212,8 @@ interface IntermediateGmModifierData extends GmModifierData {
* The minimum behavioral options that need to be passed to the factory. * The minimum behavioral options that need to be passed to the factory.
*/ */
export interface DS4CheckFactoryOptions { export interface DS4CheckFactoryOptions {
maxCritSuccess: number; maximumCoupResult: number;
minCritFailure: number; minimumFumbleResult: number;
useSlayingDice: boolean; useSlayingDice: boolean;
rollMode: Const.DiceRollMode; rollMode: Const.DiceRollMode;
} }

View file

@ -1,18 +1,41 @@
<form class="{{cssClass}} grid"> {{!--
<label for="ctv">{{localize "DS4.RollDialogTargetLabel"}}</label> !-- Render a roll options dialog. It uses the default form classes of Foundry VTT.
<input id="ctv" data-type="Number" type="number" name="ctv" value="{{checkTargetValue}}" /> !-- @param checkTargetNumber: The preselected check target number.
<label for="gmmod">{{localize "DS4.RollDialogModifierLabel"}}</label> !-- @param maximumCoupResult: The preselected maximum coup result.
<input id="gmmod" data-type="Number" type="number" name="gmmod" value="0" autofocus /> !-- @param minimumFumbleResult: The preselected minimum fumble result.
<label for="maxcoup">{{localize "DS4.RollDialogCoupLabel"}}</label> !-- @param rollMode: The preselected roll mode (= chat roll-mode).
<input id="maxcoup" data-type="Number" type="number" name="maxcoup" value="{{maxCritSuccess}}" /> !-- @param rollModes: A map of all roll modes and their i18n keys.
<label for="minfumble">{{localize "DS4.RollDialogFumbleLabel"}}</label> --}}
<input id="minfumble" data-type="Number" type="number" name="minfumble" value="{{minCritFailure}}" /> <form class="ds4-roll-options">
<label for="visibility">{{localize "DS4.RollDialogVisibilityLabel"}}</label> <div class="form-group">
<select id="visibility" data-type="String"> <label for="check-target-number">{{localize "DS4.RollDialogCheckTargetNumberLabel"}}</label>
{{#select rollMode}} <input id="check-target-number" data-type="Number" type="number" name="check-target-number"
{{#each rollModes as |rollModeValue rollModeKey|}} value="{{checkTargetNumber}}" />
<option value="{{rollModeKey}}">{{localize rollModeValue}}</option> </div>
{{/each}} <div class="form-group">
{{/select}} <label for="gm-modifier">{{localize "DS4.RollDialogGMModifierLabel"}}</label>
</select> <input id="gm-modifier" data-type="Number" type="number" name="gm-modifier" value="0" />
</div>
<div class="form-group">
<label for="maximum-coup-result">{{localize "DS4.RollDialogMaximumCoupResultLabel"}}</label>
<input id="maximum-coup-result" data-type="Number" type="number" name="maximum-coup-result"
value="{{maximumCoupResult}}" />
</div>
<div class="form-group">
<label for="minimum-fumble-result">{{localize "DS4.RollDialogMinimumFumbleResultLabel"}}</label>
<input id="minimum-fumble-result" data-type="Number" type="number" name="minimum-fumble-result"
value="{{minimumFumbleResult}}" />
</div>
<div class="form-group">
<label for="roll-mode">{{localize "DS4.RollDialogRollModeLabel"}}</label>
<div class="form-fields">
<select id="roll-mode" name="roll-mode" data-type="String">
{{#select rollMode}}
{{#each rollModes as |rollModeValue rollModeKey|}}
<option value="{{rollModeKey}}">{{localize rollModeValue}}</option>
{{/each}}
{{/select}}
</select>
</div>
</div>
</form> </form>