make it possible to pass rollMode to createCheckRoll
This commit is contained in:
parent
2c8878bd94
commit
159f5b8529
2 changed files with 22 additions and 21 deletions
|
@ -28,7 +28,7 @@ class CheckFactory {
|
||||||
private gmModifier: number,
|
private gmModifier: number,
|
||||||
passedOptions: Partial<DS4CheckFactoryOptions> = {},
|
passedOptions: Partial<DS4CheckFactoryOptions> = {},
|
||||||
) {
|
) {
|
||||||
this.checkOptions = new DefaultCheckOptions().mergeWith(passedOptions);
|
this.checkOptions = defaultCheckOptions.mergeWith(passedOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
private checkOptions: DS4CheckFactoryOptions;
|
private checkOptions: DS4CheckFactoryOptions;
|
||||||
|
@ -45,7 +45,6 @@ class CheckFactory {
|
||||||
const roll = new rollCls(formula);
|
const roll = new rollCls(formula);
|
||||||
|
|
||||||
const rollModeTemplate = this.checkOptions.rollMode;
|
const rollModeTemplate = this.checkOptions.rollMode;
|
||||||
console.log(rollModeTemplate);
|
|
||||||
return roll.toMessage({}, { rollMode: rollModeTemplate, create: true });
|
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.
|
* 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 targetValue The Check Target Number ("CTN")
|
||||||
* @param options {Partial<DS4CheckFactoryOptions>} Options changing the behaviour of the roll and message.
|
* @param options Options changing the behaviour of the roll and message.
|
||||||
*/
|
*/
|
||||||
export async function createCheckRoll(
|
export async function createCheckRoll(
|
||||||
targetValue: number,
|
targetValue: number,
|
||||||
|
@ -86,6 +85,8 @@ 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 gmModifier = gmModifierData.gmModifier ?? 0;
|
||||||
const newOptions: Partial<DS4CheckFactoryOptions> = {
|
const newOptions: Partial<DS4CheckFactoryOptions> = {
|
||||||
maxCritSuccess: gmModifierData.maxCritSuccess ?? options.maxCritSuccess ?? undefined,
|
maxCritSuccess: gmModifierData.maxCritSuccess ?? options.maxCritSuccess ?? undefined,
|
||||||
minCritFailure: gmModifierData.minCritFailure ?? options.minCritFailure ?? undefined,
|
minCritFailure: gmModifierData.minCritFailure ?? options.minCritFailure ?? undefined,
|
||||||
|
@ -94,7 +95,7 @@ export async function createCheckRoll(
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create Factory
|
// Create Factory
|
||||||
const cf = new CheckFactory(gmModifierData.checkTargetValue, gmModifierData.gmModifier, newOptions);
|
const cf = new CheckFactory(newTargetValue, gmModifier, newOptions);
|
||||||
|
|
||||||
// Possibly additional processing
|
// Possibly additional processing
|
||||||
|
|
||||||
|
@ -108,13 +109,13 @@ export async function createCheckRoll(
|
||||||
* @notes
|
* @notes
|
||||||
* At the moment, this asks for more data than it will do after some iterations.
|
* 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(
|
async function askGmModifier(
|
||||||
targetValue: number,
|
targetValue: number,
|
||||||
options: Partial<DS4CheckFactoryOptions> = {},
|
options: Partial<DS4CheckFactoryOptions> = {},
|
||||||
{ template, title }: { template?: string; title?: string } = {},
|
{ template, title }: { template?: string; title?: string } = {},
|
||||||
): Promise<IntermediateGmModifierData> {
|
): Promise<Partial<IntermediateGmModifierData>> {
|
||||||
// Render model interface and return value
|
// Render model interface and return value
|
||||||
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");
|
||||||
|
@ -124,7 +125,7 @@ async function askGmModifier(
|
||||||
checkTargetValue: targetValue,
|
checkTargetValue: targetValue,
|
||||||
maxCritSuccess: options.maxCritSuccess ?? defaultCheckOptions.maxCritSuccess,
|
maxCritSuccess: options.maxCritSuccess ?? defaultCheckOptions.maxCritSuccess,
|
||||||
minCritFailure: options.minCritFailure ?? defaultCheckOptions.minCritFailure,
|
minCritFailure: options.minCritFailure ?? defaultCheckOptions.minCritFailure,
|
||||||
rollModes: rollModes,
|
rollMode: options.rollMode,
|
||||||
config: DS4,
|
config: DS4,
|
||||||
};
|
};
|
||||||
const renderedHtml = await renderTemplate(usedTemplate, templateData);
|
const renderedHtml = await renderTemplate(usedTemplate, templateData);
|
||||||
|
@ -167,22 +168,20 @@ async function askGmModifier(
|
||||||
).render(true);
|
).render(true);
|
||||||
});
|
});
|
||||||
const dialogForm = await dialogPromise;
|
const dialogForm = await dialogPromise;
|
||||||
return parseDialogFormData(dialogForm, targetValue);
|
return parseDialogFormData(dialogForm);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts Dialog data from the returned DOM element.
|
* Extracts Dialog data from the returned DOM element.
|
||||||
* @param formData {HTMLFormElement} The filed dialog
|
* @param formData The filed dialog
|
||||||
* @param targetValue {number} The previously known target value (slated for removal once data automation is available)
|
|
||||||
*/
|
*/
|
||||||
function parseDialogFormData(formData: HTMLFormElement, targetValue: number): IntermediateGmModifierData {
|
function parseDialogFormData(formData: HTMLFormElement): Partial<IntermediateGmModifierData> {
|
||||||
return {
|
return {
|
||||||
checkTargetValue: parseInt(formData["ctv"]?.value) ?? targetValue,
|
checkTargetValue: parseInt(formData["ctv"]?.value),
|
||||||
gmModifier: parseInt(formData["gmmod"]?.value) ?? 0,
|
gmModifier: parseInt(formData["gmmod"]?.value),
|
||||||
maxCritSuccess: parseInt(formData["maxcoup"]?.value) ?? defaultCheckOptions.maxCritSuccess,
|
maxCritSuccess: parseInt(formData["maxcoup"]?.value),
|
||||||
minCritFailure: parseInt(formData["minfumble"]?.value) ?? defaultCheckOptions.minCritFailure,
|
minCritFailure: parseInt(formData["minfumble"]?.value),
|
||||||
useSlayingDice: false,
|
rollMode: formData["visibility"]?.value,
|
||||||
rollMode: formData["visibility"]?.value ?? defaultCheckOptions.rollMode,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,10 @@
|
||||||
<input id="minfumble" data-type="Number" type="number" name="minfumble" value="{{minCritFailure}}" />
|
<input id="minfumble" data-type="Number" type="number" name="minfumble" value="{{minCritFailure}}" />
|
||||||
<label for="visibility">{{localize "DS4.RollDialogVisibilityLabel"}}</label>
|
<label for="visibility">{{localize "DS4.RollDialogVisibilityLabel"}}</label>
|
||||||
<select id="visibility" data-type="String">
|
<select id="visibility" data-type="String">
|
||||||
{{#each rollModes as |rollMode|}}
|
{{#select rollMode}}
|
||||||
<option value="{{rollMode}}">{{lookup ../config.chatVisibilities rollMode}}</option>
|
{{#each config.chatVisibilities as |rollModeValue rollModeKey|}}
|
||||||
|
<option value="{{rollModeKey}}">{{rollModeValue}}</option>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
|
{{/select}}
|
||||||
</select>
|
</select>
|
||||||
</form>
|
</form>
|
Loading…
Reference in a new issue