import { systemPath } from "../../constants.mjs"; /* -------------------------------------------------- */ export async function addSpezialisierung(event, target) { const dataset = target.dataset; const path = dataset.path.replace(".value", ""); const name = dataset.name; let level = 1; const templatePath = systemPath("templates/dialog/spezialisierung-dialog.hbs"); const templateData = { classes: ["M6", "dialog"], level }; const skill = foundry.utils.getProperty(this.actor, path); console.warn(skill); // 2. Render the Handlebars template into an HTML string const content = await foundry.applications.handlebars.renderTemplate(templatePath, templateData); return foundry.applications.api.DialogV2.wait({ window: { title: "Würfel Modifikatoren: " + game.i18n.localize(`Midgard6.Skills.${name}`) }, position: { width: 600 }, content, actions: {}, render: (_event, dialog) => { const dialogHTML = dialog.element; const display = dialogHTML.querySelector("#rollDisplay"); // Variable bei jeder Änderung aktualisieren document.querySelectorAll('input[name="level-segment"]').forEach((radio) => { radio.addEventListener("change", (e) => { level = parseInt(e.target.value); }); }); }, buttons: [ { action: "abort", label: "Midgard6.Dialog.abbrechen" }, { action: "safe", label: "Midgard6.Dialog.speichern", default: true, callback: async (event, button, dialog) => { const spez = { name: button.form.elements.spezName.value, level, path }; skill.bonuses.push(spez); await this.actor.update({ [`${path}.bonuses`]: skill.bonuses }); } } ] }); } export async function editSepzialisierung(event, target) { const dataset = target.dataset; const path = dataset.path; const name = dataset.name; let level = 1; let spezName = dataset.name; const templatePath = systemPath("templates/dialog/spezialisierung-dialog.hbs"); const templateData = { classes: ["M6", "dialog"], spezName, level }; console.warn(path.replace(/^.*\.(?=[^.]+$)/g, "")); const skill = foundry.utils.getProperty(this.actor, path); // 2. Render the Handlebars template into an HTML string const content = await foundry.applications.handlebars.renderTemplate(templatePath, templateData); return foundry.applications.api.DialogV2.wait({ window: { title: game.i18n.localize("Midgard6.Sheets.spezialisierung") + " " + game.i18n.localize(path.replace(/^.*\.(?=[^.]+$)/g, "Midgard6.Skills.")) }, position: { width: 600 }, content, actions: {}, render: (_event, dialog) => { const dialogHTML = dialog.element; const display = dialogHTML.querySelector("#rollDisplay"); // Variable bei jeder Änderung aktualisieren document.querySelectorAll('input[name="level-segment"]').forEach((radio) => { radio.addEventListener("change", (e) => { level = parseInt(e.target.value); }); }); }, buttons: [ { action: "abort", label: "Midgard6.Dialog.abbrechen" }, { action: "delete", label: "Midgard6.Dialog.löschen", callback: async (event, button, dialog) => { // const bonuses = this.actor[path].bonuses || []; const bonuses = skill.bonuses.filter((x) => x.name !== name); await this.actor.update({ [`${path}.bonuses`]: bonuses }); } }, { action: "safe", label: "Midgard6.Dialog.speichern", default: true, callback: async (event, button, dialog) => { const spez = { name: button.form.elements.spezName.value, level, path }; const index = skill.bonuses.findIndex((x) => x.name === name); skill.bonuses.splice(index, 1, spez); await this.actor.update({ [`${path}.bonuses`]: skill.bonuses }); } } ] }); }