make it possible to pass rollMode to createCheckRoll

This commit is contained in:
Johannes Loher 2021-01-24 03:19:31 +01:00
parent 2c8878bd94
commit 159f5b8529
2 changed files with 22 additions and 21 deletions

View file

@ -28,7 +28,7 @@ class CheckFactory {
private gmModifier: number,
passedOptions: Partial<DS4CheckFactoryOptions> = {},
) {
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<DS4CheckFactoryOptions>} 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<DS4CheckFactoryOptions> = {
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<IntermediateGmModifierData>} The data given by the user.
* @returns The data given by the user.
*/
async function askGmModifier(
targetValue: number,
options: Partial<DS4CheckFactoryOptions> = {},
{ template, title }: { template?: string; title?: string } = {},
): Promise<IntermediateGmModifierData> {
): Promise<Partial<IntermediateGmModifierData>> {
// 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<IntermediateGmModifierData> {
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,
};
}

View file

@ -9,8 +9,10 @@
<input id="minfumble" data-type="Number" type="number" name="minfumble" value="{{minCritFailure}}" />
<label for="visibility">{{localize "DS4.RollDialogVisibilityLabel"}}</label>
<select id="visibility" data-type="String">
{{#each rollModes as |rollMode|}}
<option value="{{rollMode}}">{{lookup ../config.chatVisibilities rollMode}}</option>
{{#select rollMode}}
{{#each config.chatVisibilities as |rollModeValue rollModeKey|}}
<option value="{{rollModeKey}}">{{rollModeValue}}</option>
{{/each}}
{{/select}}
</select>
</form>