From 2fa131d2c59147d8cba4efdff4f776b74c1f29a6 Mon Sep 17 00:00:00 2001 From: Byroks Date: Fri, 16 Oct 2026 14:51:36 +0200 Subject: [PATCH] add functoning rolls --- M6.css | 68 ++++++++- lang/de.json | 9 ++ src/data/character-data.mjs | 17 +++ src/helpers/handlebar-helpers.mjs | 5 + src/sheets/character-sheet.mjs | 136 +++++++++++++++++- src/system.mjs | 3 + src/templates/actor/stats.hbs | 106 +++++++------- src/templates/dialog/roll-dialog.hbs | 34 +++++ .../spezialisierung/spezialisierung.hbs | 0 9 files changed, 317 insertions(+), 61 deletions(-) create mode 100644 src/helpers/handlebar-helpers.mjs create mode 100644 src/templates/dialog/roll-dialog.hbs create mode 100644 src/templates/spezialisierung/spezialisierung.hbs diff --git a/M6.css b/M6.css index dac8eaa..ede0539 100644 --- a/M6.css +++ b/M6.css @@ -1,6 +1,13 @@ +:root { + --M6-background-grey: #d3d7d7; + --M6-background-brown: #eedecd; + --M6-background-white: #fdfeff; + --M6-text-grey: #595d5f; + --M6-text-brown: #be7742; +} .application.sheet.M6 { - background-color: #d3d7d7; - color: #595d5f; + background-color: var(--M6-background-grey); + color: var(--M6-text-grey); section { .sheet-header { @@ -9,7 +16,7 @@ position: absolute; top: 8px; left: 44%; - background-color: #d3d7d7; + background-color: var(--M6-background-grey); &:hover { cursor: pointer; } @@ -23,7 +30,7 @@ } } input { - background-color: #fdfeff; + background-color: var(--M6-background-white); color: black; border-radius: 0; &.skill { @@ -48,13 +55,16 @@ } } fieldset { - background-color: #eedecd; + background-color: var(--M6-background-brown); + legend { + color: var(--M6-text-brown); + } } .sheet-header { img { border-radius: 0 0 50% 50%; - border: solid 16px #d3d7d7; + border: solid 16px var(--M6-background-grey); border-top: none; flex: 0 0 100px; object-fit: fill; @@ -126,3 +136,49 @@ } } } + +.application.dialog { + background-color: var(--M6-background-grey); + color: var(--M6-text-grey); + + section { + input { + background-color: var(--M6-background-white); + color: black; + border-radius: 0; + &[type="range"] { + background-color: var(--M6-background-brown); + max-width: 30px; + } + &.skill { + max-width: 2rem; + text-align: center; + margin-left: 0.5rem; + } + &.attribut { + max-width: 2rem; + text-align: center; + margin: 0 0.5rem; + } + &.text { + &.right { + text-align: end; + } + } + } + p { + &.center { + text-align: center; + } + } + fieldset { + background-color: var(--M6-background-brown); + legend { + color: var(--M6-text-brown); + } + } + i { + color: var(--M6-text-brown); + } + } +} diff --git a/lang/de.json b/lang/de.json index b8dd41b..3ba7b9d 100644 --- a/lang/de.json +++ b/lang/de.json @@ -8,6 +8,10 @@ "glaube": "Glaube", "mondgestalt": "Mondgestalt" }, + "Dialog": { + "abbrechen": "Abbrechen", + "würfeln": "Würfeln" + }, "Skills": { "gruppen": { "kampf": "Kampf", @@ -40,6 +44,11 @@ "zaubern": "Zaubern", "zauberwissen": "Zauberwissen" }, + "Resistenzen": { + "reflexe": "Reflexe", + "willenskraft": "Willenskraft", + "zähigkeit": "Zähigkeit" + }, "Sheets": { "Tabs": { "properties": "Fertigkeiten", diff --git a/src/data/character-data.mjs b/src/data/character-data.mjs index ebea12a..a383134 100644 --- a/src/data/character-data.mjs +++ b/src/data/character-data.mjs @@ -32,6 +32,23 @@ function defineSchema() { }) }) }), + resistenzen: new fields.SchemaField({ + reflexe: new fields.NumberField({ + required: true, + min: 0, + initial: 4 + }), + willenskraft: new fields.NumberField({ + required: true, + min: 0, + initial: 4 + }), + zähigkeit: new fields.NumberField({ + required: true, + min: 0, + initial: 4 + }) + }), skills: new fields.SchemaField({ kampf: new fields.SchemaField( { diff --git a/src/helpers/handlebar-helpers.mjs b/src/helpers/handlebar-helpers.mjs new file mode 100644 index 0000000..73bbae0 --- /dev/null +++ b/src/helpers/handlebar-helpers.mjs @@ -0,0 +1,5 @@ +export const loadHelpers = async function () { + Handlebars.registerHelper("ifeq", function (arg1, arg2, options) { + return arg1 == arg2 ? options.fn(this) : options.inverse(this); + }); +}; diff --git a/src/sheets/character-sheet.mjs b/src/sheets/character-sheet.mjs index 2cce425..b3a83cc 100644 --- a/src/sheets/character-sheet.mjs +++ b/src/sheets/character-sheet.mjs @@ -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 */ /* -------------------------------------------------- */ diff --git a/src/system.mjs b/src/system.mjs index 1961e59..d18c10e 100644 --- a/src/system.mjs +++ b/src/system.mjs @@ -1,6 +1,7 @@ import { CharacterData } from "./data/character-data.mjs"; import { ItemData } from "./data/item-data.mjs"; import { M6ActorSheet } from "./sheets/character-sheet.mjs"; +import { loadHelpers } from "./helpers/handlebar-helpers.mjs"; Hooks.once("init", () => { CONFIG.Actor.dataModels.character = CharacterData; @@ -20,6 +21,8 @@ Hooks.once("init", () => { types: ["character"], makeDefault: true }); + + loadHelpers(); // foundry.applications.apps.DocumentSheetConfig.registerSheet(Item, "midgard6-lvd", ItemSheet, { // types: ["item"], // makeDefault: true diff --git a/src/templates/actor/stats.hbs b/src/templates/actor/stats.hbs index e2f5166..a43a0ce 100644 --- a/src/templates/actor/stats.hbs +++ b/src/templates/actor/stats.hbs @@ -1,65 +1,67 @@ -
-
- LP -
+
+
+
+ LP +
+ +

/

+ +
+
+
+ AP +
+ +

/

+ +
+
+
+ {{localize "Midgard6.Resistenzen.reflexe"}} -

/

+
+
+ {{localize "Midgard6.Resistenzen.willenskraft"}} -
-
-
- AP -
+
+
+ {{localize "Midgard6.Resistenzen.zähigkeit"}} -

/

- - -
-
- Reflexe - -
-
- Willenskraft - -
-
- Zähigkeit - -
+ +
\ No newline at end of file diff --git a/src/templates/dialog/roll-dialog.hbs b/src/templates/dialog/roll-dialog.hbs new file mode 100644 index 0000000..c6321c2 --- /dev/null +++ b/src/templates/dialog/roll-dialog.hbs @@ -0,0 +1,34 @@ +
+
+ Modifikation +
+ + {{#ifeq vorteil 1}} + + + {{/ifeq}} + +
+ + + +
+
+
+
\ No newline at end of file diff --git a/src/templates/spezialisierung/spezialisierung.hbs b/src/templates/spezialisierung/spezialisierung.hbs new file mode 100644 index 0000000..e69de29