add Spezialisierungen

This commit is contained in:
Byroks committed 2026-10-18 13:52:08 +02:00
1 parent 9b36127621
commit 4351e5bd1f
13 files changed
+546 -668

No files matched your search

+69 -23
View File
@@ -1,5 +1,6 @@
import { systemPath } from "../constants.mjs";
import { prepareActiveEffectCategories } from "../helpers/utils.mjs";
import { addSpezialisierung, editSepzialisierung } from "./components/spezialisierung-actions.mjs";
const { api, sheets } = foundry.applications;
@@ -23,7 +24,9 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
createDoc: this.#createDoc,
deleteDoc: this.#deleteDoc,
toggleEffect: this.#toggleEffect,
rollSkill: this.#rollSkill
rollSkill: this.#rollSkill,
addSpezialisierung: addSpezialisierung,
editSepzialisierung: editSepzialisierung
},
form: {
submitOnChange: true
@@ -156,6 +159,8 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
return fieldSets;
}
/* -------------------------------------------------- */
async _getSkills() {
const doc = this.actor;
const source = doc._source;
@@ -170,7 +175,7 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
legend: `Midgard6.Skills.gruppen.${field.label}`,
fields: []
};
await this.#addSystemFields(fieldset, field.fields, source, path);
await this.#addSkillFields(fieldset, field.fields, source, path);
fieldSets.push(fieldset);
} else {
fieldSets.push({ outer: { field, value: foundry.utils.getProperty(source, path) } });
@@ -179,6 +184,24 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
return fieldSets;
}
async #addSkillFields(fieldset, schema, source, _path = "system") {
for (const field of Object.values(schema)) {
const path = `${_path}.${field.name}`;
if (field instanceof foundry.data.fields.SchemaField) {
this.#addSkillFields(fieldset, field.fields, source, path);
} else if (field.constructor.hasFormSupport) {
fieldset.fields.push({
field,
value: foundry.utils.getProperty(source, path),
localizationName: "Midgard6.Skills." + field.label,
bonuses: foundry.utils.getProperty(source, _path).bonuses
});
}
}
}
/* -------------------------------------------------- */
async _getResistenzen() {
const doc = this.actor;
const source = doc._source;
@@ -196,7 +219,6 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
localizationName: "Midgard6.Resistenzen." + field.name
});
}
console.warn(fieldset);
return fieldset;
}
@@ -237,7 +259,7 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
fieldset.fields.push({
field,
value: foundry.utils.getProperty(source, path),
localizationName: "Midgard6.Skills." + field.name
localizationName: "Midgard6.Skills." + field.label
});
}
}
@@ -351,16 +373,19 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
static async #rollSkill(event, target) {
const dataset = target.dataset;
const skill = foundry.utils.getProperty(this.actor, target.dataset.path.replace(".value", ""));
const actor = this.actor;
const dialogResult = await this.rollDialog({
dataset,
name: dataset.name,
skill,
actor
});
console.warn(dialogResult);
if (dialogResult.noRoll) {
return;
}
// Construct the Roll instance
const skillValue = dataset.value;
const skillValue = skill.value;
let die = "";
switch (dialogResult.vorteil) {
case -1:
@@ -374,7 +399,24 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
break;
}
let roll = new Roll("@die + @skill", { die: die, skill: skillValue }, { flavor: dataset.name });
let rollTerm = "@die + @skill";
let rollFlavor = dataset.name;
let roll;
if (dialogResult.spezLevel) {
rollTerm += " + @spezBonus";
rollFlavor += ": " + dialogResult.spezName;
}
if (dialogResult.customRoll) {
roll = new Roll(dialogResult.customRoll);
} else {
roll = new Roll(
rollTerm,
{ die: die, skill: skillValue, spezBonus: dialogResult.spezLevel + 1 },
{ flavor: rollFlavor }
);
}
// The parsed terms of the roll formula
console.log("Roll:", roll); // [Die, OperatorTerm, NumericTerm, OperatorTerm, NumericTerm]
@@ -385,21 +427,23 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
roll.toMessage();
roll.toAnchor();
// let message = new Message(roll);
// console.warn(message);
}
async rollDialog(rollDialogRequest) {
// Assamble dialog depending on roll type
let label = rollDialogRequest.dataset.name;
let skill = rollDialogRequest.dataset.value;
let label = rollDialogRequest.name;
let skillValue = rollDialogRequest.skill.value || rollDialogRequest.skill;
let bonuses = rollDialogRequest.skill.bonuses || [];
let vorteil = 0;
let customRoll = "";
let spezLevel;
let spezName = "";
// 1. Define the path to .hbs template
const templatePath = systemPath("templates/dialog/roll-dialog.hbs");
const templateData = {
classes: ["M6", "dialog"],
skill,
skillValue,
bonuses,
vorteil,
customRoll
};
@@ -429,17 +473,24 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
console.log(vorteil);
switch (vorteil) {
case 1:
display.placeholder = `2d20kh + ${skill} (Vorteil)`;
display.placeholder = `2d20kh + ${skillValue} (Vorteil)`;
break;
case -1:
display.placeholder = `2d20kl + ${skill} (Nachteil)`;
display.placeholder = `2d20kl + ${skillValue} (Nachteil)`;
break;
default:
display.placeholder = `1d20 + ${skill}`;
display.placeholder = `1d20 + ${skillValue}`;
break;
}
});
});
document.querySelectorAll('input[name="spezialisierung-segment"]').forEach((radio) => {
radio.addEventListener("change", (e) => {
spezLevel = parseInt(e.target.value);
spezName = e.target.dataset.name;
});
});
},
buttons: [
{
@@ -456,19 +507,14 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
callback: (event, button, dialog) => {
const rollData = {
customRoll: button.form.elements.customRoll.value,
vorteil
vorteil,
spezLevel,
spezName
};
return rollData;
}
}
]
// submit: (rollData) => {
// if (noRoll) {
// resolve({ noRoll: true });
// } else {
// resolve(rollData);
// }
// }
});
}