add functoning rolls
This commit is contained in:
1 parent
24c81dbcf8
commit
2fa131d2c5
9 files changed
+317
-61
No files matched your search
@@ -112,6 +112,10 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
|
||||
/** @inheritdoc */
|
||||
async _preparePartContext(partId, context) {
|
||||
switch (partId) {
|
||||
case "stats":
|
||||
context.fields = await this._getResources();
|
||||
context.tab = context.tabs[partId];
|
||||
break;
|
||||
case "effects":
|
||||
context.effects = prepareActiveEffectCategories(this.actor.allApplicableEffects());
|
||||
context.tab = context.tabs[partId];
|
||||
@@ -174,6 +178,30 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
|
||||
return fieldSets;
|
||||
}
|
||||
|
||||
async _getResources() {
|
||||
const doc = this.actor;
|
||||
const source = doc._source;
|
||||
const systemFields = CONFIG.Actor.dataModels[doc.type]?.schema.fields.resources.fields;
|
||||
const fieldSets = [];
|
||||
// TODO: Find a clever way to handle enrichment
|
||||
for (const field of Object.values(systemFields ?? {})) {
|
||||
const path = `system.skills.${field.name}`;
|
||||
if (field instanceof foundry.data.fields.SchemaField) {
|
||||
const fieldset = {
|
||||
fieldset: true,
|
||||
legend: `Midgard6.resources.${field.label}`,
|
||||
fields: []
|
||||
};
|
||||
await this.#addSystemFields(fieldset, field.fields, source, path);
|
||||
fieldSets.push(fieldset);
|
||||
} else {
|
||||
fieldSets.push({ outer: { field, value: foundry.utils.getProperty(source, path) } });
|
||||
}
|
||||
}
|
||||
console.warn(fieldSets);
|
||||
return fieldSets;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
/**
|
||||
@@ -301,10 +329,32 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
|
||||
}
|
||||
|
||||
static async #rollSkill(event, target) {
|
||||
console.warn(event, target.dataset);
|
||||
const dataset = target.dataset;
|
||||
const actor = this.actor;
|
||||
const dialogResult = await this.rollDialog({
|
||||
dataset,
|
||||
actor
|
||||
});
|
||||
if (dialogResult.noRoll) {
|
||||
return;
|
||||
}
|
||||
// Construct the Roll instance
|
||||
const skillValue = target.dataset.value;
|
||||
let roll = new Roll("2d20kh + @skill", { skill: skillValue }, { flavor: target.dataset.name });
|
||||
const skillValue = dataset.value;
|
||||
let die = "";
|
||||
console.warn(dialogResult);
|
||||
switch (dialogResult.vorteil) {
|
||||
case "-1":
|
||||
die = "2d20kl";
|
||||
break;
|
||||
case "1":
|
||||
die = "2d20kh";
|
||||
break;
|
||||
default:
|
||||
die = "1d20";
|
||||
break;
|
||||
}
|
||||
|
||||
let roll = new Roll("@die + @skill", { die: die, skill: skillValue }, { flavor: dataset.name });
|
||||
|
||||
// The parsed terms of the roll formula
|
||||
console.log("Roll:", roll); // [Die, OperatorTerm, NumericTerm, OperatorTerm, NumericTerm]
|
||||
@@ -319,6 +369,86 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
|
||||
// console.warn(message);
|
||||
}
|
||||
|
||||
async rollDialog(rollDialogRequest) {
|
||||
// Assamble dialog depending on roll type
|
||||
let label = rollDialogRequest.dataset.name;
|
||||
let skill = rollDialogRequest.dataset.value;
|
||||
let vorteil = 0;
|
||||
let customRoll = "";
|
||||
// 1. Define the path to .hbs template
|
||||
const templatePath = systemPath("templates/dialog/roll-dialog.hbs");
|
||||
const templateData = {
|
||||
classes: ["roll"],
|
||||
skill,
|
||||
vorteil,
|
||||
customRoll
|
||||
};
|
||||
// 2. Render the Handlebars template into an HTML string
|
||||
const content = await foundry.applications.handlebars.renderTemplate(
|
||||
templatePath,
|
||||
templateData
|
||||
);
|
||||
// return new Promise((resolve, reject) => {
|
||||
// const dialog = new foundry.applications.api.DialogV2({
|
||||
return foundry.applications.api.DialogV2.wait({
|
||||
window: { title: "Würfel Modifikatoren: " + label },
|
||||
position: {
|
||||
width: 600
|
||||
},
|
||||
content,
|
||||
actions: {},
|
||||
render: (_event, dialog) => {
|
||||
const dialogHTML = dialog.element;
|
||||
|
||||
const slider = dialogHTML.querySelector("#vorteilSlider");
|
||||
const display = dialogHTML.querySelector("#rollDisplay");
|
||||
|
||||
slider.addEventListener("input", (e) => {
|
||||
const vorteilWert = parseInt(e.target.value);
|
||||
switch (vorteilWert) {
|
||||
case 1:
|
||||
display.placeholder = `2d20kh + ${skill} (Vorteil)`;
|
||||
break;
|
||||
case -1:
|
||||
display.placeholder = `2d20kl + ${skill} (Nachteil)`;
|
||||
break;
|
||||
default:
|
||||
display.placeholder = `1d20 + ${skill}`;
|
||||
break;
|
||||
}
|
||||
});
|
||||
},
|
||||
buttons: [
|
||||
{
|
||||
action: "abort",
|
||||
label: "Midgard6.Dialog.abbrechen",
|
||||
callback: (event, button, dialog) => {
|
||||
return { noRoll: true };
|
||||
}
|
||||
},
|
||||
{
|
||||
action: "roll",
|
||||
label: "Midgard6.Dialog.würfeln",
|
||||
default: true,
|
||||
callback: (event, button, dialog) => {
|
||||
const rollData = {
|
||||
customRoll: button.form.elements.customRoll.value,
|
||||
vorteil: button.form.elements.vorteil.value
|
||||
};
|
||||
return rollData;
|
||||
}
|
||||
}
|
||||
]
|
||||
// submit: (rollData) => {
|
||||
// if (noRoll) {
|
||||
// resolve({ noRoll: true });
|
||||
// } else {
|
||||
// resolve(rollData);
|
||||
// }
|
||||
// }
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------------- */
|
||||
/* Helper functions */
|
||||
/* -------------------------------------------------- */
|
||||
|
||||
Reference in new issue
Block a user