Squashed commit of the following:

commit 2225a98e6b
Author: Byroks <byroks@gmail.com>
Date:   Sat Oct 17 16:14:40 2026 +0200

    A lot of stuff

commit f7627e3e46
Author: Byroks <byroks@gmail.com>
Date:   Fri Oct 16 22:04:36 2026 +0200

    not sure what happend

commit 0d21ad3031
Author: Byroks <byroks@gmail.com>
Date:   Fri Oct 16 18:10:38 2026 +0200

    mark active tab

commit 19da492843
Author: Byroks <byroks@gmail.com>
Date:   Fri Oct 16 18:05:58 2026 +0200

    shit is visible
This commit is contained in:
Byroks committed 2026-10-17 16:16:14 +02:00
1 parent 2fa131d2c5
commit ba31eea229
21 files changed
+3069 -377

No files matched your search

+57 -33
View File
@@ -36,13 +36,16 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
primary: {
tabs: [
{
id: "properties"
id: "properties",
icon: "fa-feather-pointed"
},
{
id: "items"
id: "items",
icon: "fa-suitcase"
},
{
id: "effects"
id: "effects",
icon: "fa-bolt"
}
],
initial: "properties",
@@ -54,15 +57,12 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
/** @inheritdoc */
static PARTS = {
tabs: {
template: systemPath("templates/actor/tabs.hbs")
},
header: {
template: systemPath("templates/actor/header.hbs")
},
stats: {
template: systemPath("templates/actor/stats.hbs")
},
tabs: {
template: "templates/generic/tab-navigation.hbs"
},
properties: {
template: systemPath("templates/shared/properties.hbs"),
scrollable: [""]
@@ -112,16 +112,17 @@ 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 "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];
break;
case "properties":
context.fields = await this._getSkills();
context.skills = await this._getSkills();
context.resistenzen = await this._getResistenzen();
context.tab = context.tabs[partId];
break;
case "items":
@@ -178,6 +179,27 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
return fieldSets;
}
async _getResistenzen() {
const doc = this.actor;
const source = doc._source;
const systemFields = CONFIG.Actor.dataModels[doc.type]?.schema.fields.resistenzen;
const fieldset = {
fieldset: true,
legend: `Midgard6.Attribute.${systemFields.label}`,
fields: []
};
for (const field of Object.values(systemFields.fields ?? {})) {
const path = `system.resistenzen.${field.name}`;
fieldset.fields.push({
field,
value: foundry.utils.getProperty(source, path),
localizationName: "Midgard6.Resistenzen." + field.name
});
}
console.warn(fieldset);
return fieldset;
}
async _getResources() {
const doc = this.actor;
const source = doc._source;
@@ -198,7 +220,6 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
fieldSets.push({ outer: { field, value: foundry.utils.getProperty(source, path) } });
}
}
console.warn(fieldSets);
return fieldSets;
}
@@ -343,10 +364,10 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
let die = "";
console.warn(dialogResult);
switch (dialogResult.vorteil) {
case "-1":
case -1:
die = "2d20kl";
break;
case "1":
case 1:
die = "2d20kh";
break;
default:
@@ -378,7 +399,7 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
// 1. Define the path to .hbs template
const templatePath = systemPath("templates/dialog/roll-dialog.hbs");
const templateData = {
classes: ["roll"],
classes: ["dialog"],
skill,
vorteil,
customRoll
@@ -400,22 +421,25 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
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;
}
// Variable bei jeder Änderung aktualisieren
document.querySelectorAll('input[name="vorteil-segment"]').forEach((radio) => {
radio.addEventListener("change", (e) => {
vorteil = parseInt(e.target.value);
console.log(vorteil);
switch (vorteil) {
case 1:
display.placeholder = `2d20kh + ${skill} (Vorteil)`;
break;
case -1:
display.placeholder = `2d20kl + ${skill} (Nachteil)`;
break;
default:
display.placeholder = `1d20 + ${skill}`;
break;
}
});
});
},
buttons: [
@@ -433,7 +457,7 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe
callback: (event, button, dialog) => {
const rollData = {
customRoll: button.form.elements.customRoll.value,
vorteil: button.form.elements.vorteil.value
vorteil
};
return rollData;
}
+522
View File
@@ -0,0 +1,522 @@
import { systemPath } from "../constants.mjs";
import { prepareActiveEffectCategories } from "../helpers/utils.mjs";
const { api, sheets } = foundry.applications;
/**
* Extend the basic ActorSheet with some very simple modifications.
*/
export class M6ItemSheet extends api.HandlebarsApplicationMixin(sheets.ItemSheetV2) {
/** @inheritdoc */
static DEFAULT_OPTIONS = {
classes: ["M6", "item"],
window: {
icon: "fa-solid fa-suitcase",
resizable: true
},
position: {
width: 800,
height: 400
},
form: {
submitOnChange: true
}
};
/* -------------------------------------------------- */
static TABS = {
primary: {
tabs: [
{
id: "properties",
icon: "fa-feather-pointed"
},
{
id: "items",
icon: "fa-suitcase"
},
{
id: "effects",
icon: "fa-bolt"
}
],
initial: "properties",
labelPrefix: "Midgard6.Sheets.Tabs"
}
};
/* -------------------------------------------------- */
/** @inheritdoc */
static PARTS = {
tabs: {
template: systemPath("templates/actor/tabs.hbs")
},
header: {
template: systemPath("templates/actor/header.hbs")
},
properties: {
template: systemPath("templates/shared/properties.hbs"),
scrollable: [""]
},
items: {
template: systemPath("templates/actor/items.hbs"),
scrollable: [""]
},
effects: {
template: systemPath("templates/shared/effects.hbs"),
scrollable: [""]
}
};
/* -------------------------------------------------- */
/** @inheritdoc */
_initializeApplicationOptions(options) {
const initialized = super._initializeApplicationOptions(options);
initialized.classes.push(initialized.document.type);
return initialized;
}
/* -------------------------------------------------- */
/** @inheritdoc */
async _prepareContext(options) {
const context = await super._prepareContext(options);
Object.assign(context, {
owner: this.document.isOwner,
limited: this.document.limited,
actor: this.actor,
system: this.actor.system,
skills: this.actor.system.skills,
flags: this.actor.flags,
config: CONFIG
});
return context;
}
/* -------------------------------------------------- */
/** @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];
break;
case "properties":
context.skills = await this._getSkills();
context.resistenzen = await this._getResistenzen();
context.tab = context.tabs[partId];
break;
case "items":
context.itemTypes = this._getItems();
context.tab = context.tabs[partId];
break;
}
return context;
}
/**
* Handles the system fields for the form-fields generic.
* @returns {object[]}
*/
async _getFields() {
const doc = this.actor;
const source = doc._source;
const systemFields = CONFIG.Actor.dataModels[doc.type]?.schema.fields;
const fieldSets = [];
// TODO: Find a clever way to handle enrichment
for (const field of Object.values(systemFields ?? {})) {
const path = `system.${field.name}`;
if (field instanceof foundry.data.fields.SchemaField) {
const fieldset = { fieldset: true, legend: 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) } });
}
}
return fieldSets;
}
async _getSkills() {
const doc = this.actor;
const source = doc._source;
const systemFields = CONFIG.Actor.dataModels[doc.type]?.schema.fields.skills.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.Skills.gruppen.${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) } });
}
}
return fieldSets;
}
async _getResistenzen() {
const doc = this.actor;
const source = doc._source;
const systemFields = CONFIG.Actor.dataModels[doc.type]?.schema.fields.resistenzen;
const fieldset = {
fieldset: true,
legend: `Midgard6.Attribute.${systemFields.label}`,
fields: []
};
for (const field of Object.values(systemFields.fields ?? {})) {
const path = `system.resistenzen.${field.name}`;
fieldset.fields.push({
field,
value: foundry.utils.getProperty(source, path),
localizationName: "Midgard6.Resistenzen." + field.name
});
}
console.warn(fieldset);
return fieldset;
}
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) } });
}
}
return fieldSets;
}
/* -------------------------------------------------- */
/**
* Recursively add system model fields to the fieldset.
*/
async #addSystemFields(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.#addSystemFields(fieldset, field.fields, source, path);
} else if (field.constructor.hasFormSupport) {
fieldset.fields.push({
field,
value: foundry.utils.getProperty(source, path),
localizationName: "Midgard6.Skills." + field.name
});
}
}
}
/* -------------------------------------------------- */
/**
* Adapted from Actor#itemTypes.
*/
_getItems() {
const types = Object.fromEntries(
game.documentTypes.Item.map((t) => {
return [t, { label: game.i18n.localize(CONFIG.Item.typeLabels[t]), items: [] }];
})
);
for (const item of this.actor.items) {
types[item.type].items.push(item);
}
// Only show Base if it's actually being used
if (types.base.items.length === 0) delete types.base;
return types;
}
/* -------------------------------------------------- */
/**
* Actions performed after any render of the Application.
* Post-render steps are not awaited by the render process.
* @param {ApplicationRenderContext} context Prepared context data.
* @param {RenderOptions} options Provided render options.
* @protected
* @inheritdoc
*/
async _onRender(context, options) {
await super._onRender(context, options);
this.#disableOverrides();
}
/* -------------------------------------------------- */
/* Event handlers */
/* -------------------------------------------------- */
/**
* Renders an embedded document's sheet.
*
* @this M6ActorSheet
* @param {PointerEvent} event The originating click event.
* @param {HTMLElement} target The capturing HTML element which defined a [data-action].
* @protected
*/
static async #viewDoc(event, target) {
const doc = this._getEmbeddedDocument(target);
doc.sheet.render(true);
}
/* -------------------------------------------------- */
/**
* Handles item deletion.
*
* @this M6ActorSheet
* @param {PointerEvent} event The originating click event.
* @param {HTMLElement} target The capturing HTML element which defined a [data-action].
* @protected
*/
static async #deleteDoc(event, target) {
const doc = this._getEmbeddedDocument(target);
doc.delete();
}
/* -------------------------------------------------- */
/**
* Handle creating a new Owned Item or ActiveEffect for the actor using initial data defined in the HTML dataset.
*
* @this M6ActorSheet
* @param {PointerEvent} event The originating click event.
* @param {HTMLElement} target The capturing HTML element which defined a [data-action].
* @private
*/
static async #createDoc(event, target) {
const docCls = getDocumentClass(target.dataset.documentClass);
const docData = {
name: docCls.defaultName({
type: target.dataset.type,
parent: this.actor
})
};
for (const [dataKey, value] of Object.entries(target.dataset)) {
if (["action", "documentClass"].includes(dataKey)) continue;
foundry.utils.setProperty(docData, dataKey, value);
}
docCls.create(docData, { parent: this.actor });
}
/* -------------------------------------------------- */
/**
* Determines effect parent to pass to helper.
*
* @this M6ActorSheet
* @param {PointerEvent} event The originating click event.
* @param {HTMLElement} target The capturing HTML element which defined a [data-action].
* @private
*/
static async #toggleEffect(event, target) {
const effect = this._getEmbeddedDocument(target);
effect.update({ disabled: !effect.disabled });
}
static async #rollSkill(event, target) {
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 = 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]
// Execute the roll
await roll.evaluate();
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 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 */
/* -------------------------------------------------- */
/**
* Fetches the embedded document representing the containing HTML element.
*
* @param {HTMLElement} target The element subject to search.
* @returns {Item|ActiveEffect} The embedded Item or ActiveEffect.
*/
_getEmbeddedDocument(target) {
const docRow = target.closest("li[data-document-class]");
if (docRow.dataset.documentClass === "Item") {
return this.actor.items.get(docRow.dataset.itemId);
} else if (docRow.dataset.documentClass === "ActiveEffect") {
const parent =
docRow.dataset.parentId === this.actor.id
? this.actor
: this.actor.items.get(docRow?.dataset.parentId);
return parent.effects.get(docRow.dataset.effectId);
} else {
console.warn("Could not find document class");
}
}
/* -------------------------------------------------- */
/* Actor override handling */
/* -------------------------------------------------- */
/**
* Submit a document update based on the processed form data.
* @param {SubmitEvent} event The originating form submission event.
* @param {HTMLFormElement} form The form element that was submitted.
* @param {object} submitData Processed and validated form data to be used for a document update.
* @returns {Promise<void>}
* @protected
* @inheritdoc
*/
async _processSubmitData(event, form, submitData) {
const overrides = foundry.utils.flattenObject(this.actor.overrides);
for (const k of Object.keys(overrides)) delete submitData[k];
this.document.update(submitData);
}
/* -------------------------------------------------- */
/**
* Disables inpM6 subject to active effects.
*/
#disableOverrides() {
const flatOverrides = foundry.utils.flattenObject(this.actor.overrides);
for (const override of Object.keys(flatOverrides)) {
const input = this.element.querySelector(`[name="${override}"]`);
if (input) input.disabled = true;
}
}
}