From c8516aa35643233b5431d8eb1db81c9f0c29bef8 Mon Sep 17 00:00:00 2001 From: Byroks Date: Fri, 30 Oct 2026 15:46:15 +0100 Subject: [PATCH 1/3] =?UTF-8?q?NSC=20Bogen=20&=20w=C3=BCrfe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lang/de.json | 20 +- src/data/nsc-data.mjs | 97 ++++ src/sheets/actor-sheet.mjs | 609 +++++++++++++++++++++ src/sheets/character-sheet.mjs | 635 ++-------------------- src/sheets/components/roll-actions.mjs | 68 +-- src/sheets/nsc-sheet.mjs | 454 ++++++++++++++++ src/styles/M6.scss | 18 +- src/system.mjs | 57 +- src/types/data-config.d.mjs | 3 +- system.json | 3 +- templates/dialog/nsc-resistenz-dialog.hbs | 39 ++ templates/nsc/biographie.hbs | 24 + templates/nsc/eigenschaften.hbs | 275 ++++++++++ templates/nsc/header.hbs | 51 ++ templates/nsc/hintergrund.hbs | 320 +++++++++++ templates/nsc/items.hbs | 241 ++++++++ templates/nsc/zauber.hbs | 60 ++ vite.config.ts | 19 +- 18 files changed, 2328 insertions(+), 665 deletions(-) create mode 100644 src/data/nsc-data.mjs create mode 100644 src/sheets/actor-sheet.mjs create mode 100644 src/sheets/nsc-sheet.mjs create mode 100644 templates/dialog/nsc-resistenz-dialog.hbs create mode 100644 templates/nsc/biographie.hbs create mode 100644 templates/nsc/eigenschaften.hbs create mode 100644 templates/nsc/header.hbs create mode 100644 templates/nsc/hintergrund.hbs create mode 100644 templates/nsc/items.hbs create mode 100644 templates/nsc/zauber.hbs diff --git a/lang/de.json b/lang/de.json index 129b070..8d4517b 100644 --- a/lang/de.json +++ b/lang/de.json @@ -161,6 +161,23 @@ } } }, + "NSC": { + "Größe": { + "winzig": "Winzig", + "klein": "Klein", + "normal": "Normal", + "groß": "Groß", + "riesig": "Riesig" + }, + "kompetenz": { + "miserabel": "Miserabel", + "mittelmäßig": "Mittelmäßig", + "kompetent": "Sehr Gut", + "würfe": "Kompetenz Würfe", + "hinzufügen": "Kompetenz hinzufügen", + "kompetenz": "Kompetenz" + } + }, "RollList": { "RollMode": "Wurf-Modus" }, @@ -184,7 +201,8 @@ }, "TYPES": { "Actor": { - "character": "Charakter" + "character": "Charakter", + "nsc": "Nebenfigur" }, "Item": { "item": "Gegenstand", diff --git a/src/data/nsc-data.mjs b/src/data/nsc-data.mjs new file mode 100644 index 0000000..1c5ae2d --- /dev/null +++ b/src/data/nsc-data.mjs @@ -0,0 +1,97 @@ +function defineSchema() { + const fields = foundry.data.fields; + return { + locked: new fields.BooleanField({ initial: false }), + biographie: new fields.SchemaField({ + spezies: new fields.StringField({ initial: "" }), + kultur: new fields.StringField({ initial: "" }), + beschreibung: new fields.HTMLField({ initial: "" }), + }), + größe: new fields.StringField({ initial: "normal" }), + kompetenz: new fields.NumberField({ + required: true, + nullable: false, + integer: true, + initial: 1, + max: 10, + min: 0, + }), + resources: new fields.SchemaField({ + leben: new fields.SchemaField({ + value: new fields.NumberField({ + required: true, + min: 0, + initial: 4, + }), + max: new fields.NumberField({ + required: true, + initial: 8, + }), + }), + ausdauer: new fields.SchemaField({ + value: new fields.NumberField({ + required: true, + min: 0, + initial: 4, + }), + max: new fields.NumberField({ + required: true, + initial: 44, + }), + }), + }), + resistenzen: new fields.SchemaField( + { + reflexe: new fields.SchemaField({ + value: new fields.StringField({}), + kompetent: new fields.NumberField({ + required: true, + initial: false, + max: 1, + min: -1, + initial: -1, + }), + }), + willenskraft: new fields.SchemaField({ + value: new fields.StringField({}), + kompetent: new fields.NumberField({ + required: true, + initial: false, + max: 1, + min: -1, + initial: 0, + }), + }), + zähigkeit: new fields.SchemaField({ + value: new fields.StringField({}), + kompetent: new fields.NumberField({ + required: true, + initial: false, + max: 1, + min: -1, + initial: 1, + }), + }), + }, + { label: "resistenzen" }, + ), + rüstwert: new fields.SchemaField({ + base: new fields.NumberField({ + required: true, + min: 0, + initial: 0, + }), + mod: new fields.NumberField({ + required: true, + initial: 0, + }), + }), + merkmale: new fields.ArrayField(new fields.StringField({}), { initial: [] }), + angriffe: new fields.ArrayField(new fields.ObjectField({}), { initial: [] }), + fertigkeiten: new fields.ArrayField(new fields.StringField({}), { initial: [] }), + }; +} + +export class NSCData extends foundry.abstract.TypeDataModel { + static defineSchema = defineSchema; +} diff --git a/src/sheets/actor-sheet.mjs b/src/sheets/actor-sheet.mjs new file mode 100644 index 0000000..d3443fc --- /dev/null +++ b/src/sheets/actor-sheet.mjs @@ -0,0 +1,609 @@ +const { api, sheets } = foundry.applications; + +/** + * Extend the basic ActorSheet with some very simple modifications. + */ +export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorSheetV2) { + /** @inheritdoc */ + static DEFAULT_OPTIONS = { + classes: ["M6", "actor"], + window: { + resizable: true, + }, + position: { + width: 800, + height: 800, + }, + actions: { + viewDoc: this.#viewDoc, + createDoc: this.#createDoc, + deleteDoc: this.#deleteDoc, + toggleEffect: this.#toggleEffect, + increaseDoc: this.#increaseDoc, + decreaseDoc: this.#decreaseDoc, + cycleLock: this.#cycleLock, + }, + form: { + submitOnChange: true, + }, + dragDrop: [{ dragSelector: ".draggable", dropSelector: null }], + }; + + /* -------------------------------------------------- */ + + static TABS = { + primary: { + tabs: [], + labelPrefix: "Midgard6.Sheets.Tabs", + }, + }; + + /* -------------------------------------------------- */ + + /** @inheritdoc */ + static PARTS = {}; + + _attachPartListeners(partId, html, bubble) { + super._attachPartListeners(partId, html, bubble); + + const collapsible = html.querySelectorAll("div[data-action=collapsible]"); + if (collapsible) { + collapsible.forEach((node) => { + node.addEventListener( + "click", + function (e) { + e = window.event || e; + if (this === e.target) { + node.classList.toggle("active"); + var content = node.nextElementSibling; + content.classList.toggle("active"); + node.getElementsByTagName("i")[0].classList.toggle("fa-compress"); + } + }, + { capture: true }, + ); + }); + } + } + + /* -------------------------------------------------- */ + + /** @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, + flags: this.actor.flags, + config: CONFIG, + }); + 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; + } + + /** + * 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.label, + }); + } + } + } + + /* -------------------------------------------------- */ + + /** + * 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); + } + + for (const item of this.actor.items) { + types[item.type].items.sort((a, b) => a.sort - b.sort); + } + // Only show Base if it's actually being used + if (types.base.items.length === 0) delete types.base; + return types; + } + + /* -------------------------------------------------- */ + + static async #cycleLock(event) { + const actor = this.actor; + + // Update the locked state + actor.update({ "system.locked": !actor.system.locked }); + } + + /* -------------------------------------------------- */ + + /** + * 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 */ + /* -------------------------------------------------- */ + + static async #increaseDoc(event, target) { + const item = this.actor.items.get(target.dataset.itemId); + if (event.shiftKey || event.ctrlKey) { + return item.update({ ["system.anzahl"]: (item.system.anzahl += 10) }); + } + return item.update({ ["system.anzahl"]: (item.system.anzahl += 1) }); + } + + static async #decreaseDoc(event, target) { + const item = this.actor.items.get(target.dataset.itemId); + if (event.shiftKey || event.ctrlKey) { + return item.update({ ["system.anzahl"]: (item.system.anzahl -= 10) }); + } + return item.update({ ["system.anzahl"]: (item.system.anzahl -= 1) }); + } + + /** + * 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); + } + const doc = await docCls.create(docData, { parent: this.actor }); + doc.sheet.render(true); + } + + /* -------------------------------------------------- */ + + /** + * 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 }); + } + + /* -------------------------------------------------- */ + /* 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("[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} + * @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 inputs 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; + } + } + + /* -------------------------------------------------- */ + /* Drag and drop */ + /* -------------------------------------------------- */ + + /** + * Define whether a user is able to begin a dragstart workflow for a given drag selector. + * @param {string} selector The candidate HTML selector for dragging. + * @returns {boolean} Can the current user drag this selector? + * @protected + */ + _canDragStart(selector) { + return this.isEditable; + } + + /* -------------------------------------------------- */ + + /** + * Define whether a user is able to conclude a drag-and-drop workflow for a given drop selector. + * @param {string} selector The candidate HTML selector for the drop target. + * @returns {boolean} Can the current user drop on this selector? + * @protected + */ + _canDragDrop(selector) { + return this.isEditable; + } + + /* -------------------------------------------------- */ + + /** + * Callback actions which occur at the beginning of a drag start workflow. + * @param {DragEvent} event The originating DragEvent. + * @protected + */ + _onDragStart(event) { + const li = event.currentTarget; + const dataset = event.target.dataset; + + if ("link" in event.target.dataset) return; + + let dragData = null; + + if (li.dataset.effectId) { + const effect = this.item.effects.get(li.dataset.effectId); + dragData = effect.toDragData(); + } + + dragData = { + type: dataset.type, + itemId: dataset.itemId, + }; + + if (!dragData) return; + + event.dataTransfer.setData("text/plain", JSON.stringify(dragData)); + } + + /* -------------------------------------------------- */ + + /** + * Callback actions which occur when a dragged element is over a drop target. + * @param {DragEvent} event The originating DragEvent. + * @protected + */ + _onDragOver(event) {} + + /* -------------------------------------------------- */ + + /** + * Callback actions which occur when a dragged element is dropped on a target. + * @param {DragEvent} event The originating DragEvent. + * @protected + */ + async _onDrop(event) { + const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event); + const item = this.item; + + const allowed = Hooks.call("dropItemSheetData", item, this, data); + if (allowed === false) return; + // Handle different data types + switch (data.type) { + case "ActiveEffect": + return this._onDropActiveEffect(event, data); + case "Actor": + return this._onDropActor(event, data); + case "Item": + return this._onDropItem(event, data); + case "Folder": + return this._onDropFolder(event, data); + } + } + + /* -------------------------------------------------- */ + + /** + * Handle the dropping of ActiveEffect data onto an Actor Sheet. + * @param {DragEvent} event The concluding DragEvent which contains drop data. + * @param {object} data The data transfer extracted from the event. + * @returns {Promise} The created ActiveEffect object or false if it couldn't be created. + * @protected + */ + async _onDropActiveEffect(event, data) { + const aeCls = getDocumentClass("ActiveEffect"); + const effect = await aeCls.fromDropData(data); + if (!this.item.isOwner || !effect) return false; + + if (this.item.uuid === effect.parent?.uuid) return this._onEffectSort(event, effect); + aeCls.create(effect, { parent: this.item }); + } + + /* -------------------------------------------------- */ + + /** + * Sorts an Active Effect based on its surrounding attributes. + * + * @param {DragEvent} event + * @param {ActiveEffect} effect + */ + _onEffectSort(event, effect) { + const effects = this.item.effects; + const dropTarget = event.target.closest("[data-effect-id]"); + if (!dropTarget) return; + const target = effects.get(dropTarget.dataset.effectId); + + // Don't sort on yourself + if (effect.id === target.id) return; + + // Identify sibling items based on adjacent HTML elements + const siblings = []; + for (let el of dropTarget.parentElement.children) { + const siblingId = el.dataset.effectId; + if (siblingId && siblingId !== effect.id) siblings.push(effects.get(el.dataset.effectId)); + } + + // Perform the sort + const sortUpdates = foundry.utils.performIntegerSort(effect, { + target, + siblings, + }); + const updateData = sortUpdates.map((u) => { + const update = u.update; + update._id = u.target._id; + return update; + }); + + // Perform the update + this.item.updateEmbeddedDocuments("ActiveEffect", updateData); + } + + /* -------------------------------------------------- */ + + /** + * Handle dropping of an Actor data onto another Actor sheet. + * @param {DragEvent} event The concluding DragEvent which contains drop data. + * @param {object} data The data transfer extracted from the event. + * @returns {Promise} A data object which describes the result of the drop, or false if the drop was + * not permitted. + * @protected + */ + async _onDropActor(event, data) { + if (!this.item.isOwner) return false; + } + + /* -------------------------------------------------- */ + + async _onDropItemCreate(actor, itemData) { + itemData = itemData instanceof Array ? itemData : [itemData]; + return actor.createEmbeddedDocuments("Item", itemData); + } + + /** + * Handle dropping of an item reference or item data onto an Actor Sheet. + * @param {DragEvent} event The concluding DragEvent which contains drop data. + * @param {object} data The data transfer extracted from the event. + * @returns {Promise} The created or updated Item instances, or false if the drop was not permitted. + * @protected + */ + async _onDropItem(event, data) { + if (!this.actor.isOwner) return false; + + if (this.actor.items.get(data.itemId)) return this._onSortItem(event, data); + + const item = await Item.implementation.fromDropData(data); + const itemData = item.toObject(); + + return this._onDropItemCreate(this.actor, itemData); + } + + /** + * Handle a drop event for an existing embedded Item to sort that Item relative to its siblings + * @param {Event} event + * @param {Item} item + * @private + */ + _onSortItem(event, item) { + // Get the drag source and drop target + const items = this.actor.items; + const dropTarget = event.target.closest("[data-item-id]"); + const source = items.get(item.itemId); + if (!dropTarget) return; + const target = items.get(dropTarget.dataset.itemId); + // Don't sort on yourself + if (source.id === target.id) return; + // Identify sibling items based on adjacent HTML elements + const siblings = []; + for (let el of dropTarget.parentElement.children) { + const siblingId = el.dataset.itemId; + if (siblingId && siblingId !== source.id) siblings.push(items.get(siblingId)); + } + + // Perform the sort + const sortUpdates = foundry.utils.performIntegerSort(source, { + target, + siblings, + }); + const updateData = sortUpdates.map((u) => { + const update = u.update; + update._id = u.target.id; + return update; + }); + + // Perform the update + return this.actor.updateEmbeddedDocuments("Item", updateData); + } + + /* -------------------------------------------------- */ + + /** + * Handle dropping of a Folder on an Actor Sheet. + * The core sheet currently supports dropping a Folder of Items to create all items as owned items. + * @param {DragEvent} event The concluding DragEvent which contains drop data. + * @param {object} data The data transfer extracted from the event. + * @returns {Promise} + * @protected + */ + async _onDropFolder(event, data) { + if (!this.item.isOwner) return []; + } + + /* -------------------------------------------------- */ + /* The following pieces set up drag */ + /* handling and are unlikely to need modification */ + /* -------------------------------------------------- */ + + // This is marked as private because there's no real need + // for subclasses or external hooks to mess with it directly + #dragDrop = this.#createDragDropHandlers(); + + /** + * Returns an array of DragDrop instances. + * @type {DragDrop[]} + */ + get dragDrop() { + return this.#dragDrop; + } + + /* -------------------------------------------------- */ + + /** + * Create drag-and-drop workflow handlers for this Application. + * @returns {DragDrop[]} An array of DragDrop handlers. + * @private + */ + #createDragDropHandlers() { + return this.options.dragDrop.map((d) => { + d.permissions = { + dragstart: this._canDragStart.bind(this), + drop: this._canDragDrop.bind(this), + }; + d.callbacks = { + dragstart: this._onDragStart.bind(this), + dragover: this._onDragOver.bind(this), + drop: this._onDrop.bind(this), + }; + return new foundry.applications.ux.DragDrop(d); + }); + } +} diff --git a/src/sheets/character-sheet.mjs b/src/sheets/character-sheet.mjs index d08d9af..6f590a9 100644 --- a/src/sheets/character-sheet.mjs +++ b/src/sheets/character-sheet.mjs @@ -3,43 +3,30 @@ import { prepareActiveEffectCategories } from "../helpers/utils.mjs"; import { addSpezialisierung, editSepzialisierung } from "./components/spezialisierung-actions.mjs"; import { prepArmor, prepWeapons, prepWeight, prepSpells } from "./components/character-prep.mjs"; import { rollSpell, rollWeapon, rollSkill } from "./components/roll-actions.mjs"; +import { M6ActorSheet } from "./actor-sheet.mjs"; const { api, sheets } = foundry.applications; /** - * Extend the basic ActorSheet with some very simple modifications. + * Extend the M6ActorSheet. */ -export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorSheetV2) { +export class M6CharacterSheet extends M6ActorSheet { /** @inheritdoc */ - static DEFAULT_OPTIONS = { - classes: ["M6", "actor"], - window: { - resizable: true - }, - position: { - width: 800, - height: 800 - }, - actions: { - viewDoc: this.#viewDoc, - createDoc: this.#createDoc, - deleteDoc: this.#deleteDoc, - toggleEffect: this.#toggleEffect, - rollSkill: rollSkill, - rollWeapon: rollWeapon, - rollSpell: rollSpell, - cycleEquip: this.#cycleEquip, - cycleLock: this.#cycleLock, - addSpezialisierung: addSpezialisierung, - editSepzialisierung: editSepzialisierung, - increaseDoc: this.#increaseDoc, - decreaseDoc: this.#decreaseDoc - }, - form: { - submitOnChange: true - }, - dragDrop: [{ dragSelector: ".draggable", dropSelector: null }] - }; + static get DEFAULT_OPTIONS() { + return { + ...super.DEFAULT_OPTIONS, // Kopiert alle bestehenden Options aus M6ActorSheet + actions: { + ...super.DEFAULT_OPTIONS.actions, // Kopiert alle bestehenden Actions aus M6ActorSheet + cycleEquip: this.#cycleEquip, + rollSkill: rollSkill, + rollWeapon: rollWeapon, + rollSpell: rollSpell, + cycleEquip: this.#cycleEquip, + addSpezialisierung: addSpezialisierung, + editSepzialisierung: editSepzialisierung, + }, + }; + } /* -------------------------------------------------- */ @@ -48,33 +35,32 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe tabs: [ { id: "eigenschaften", - icon: "fa-shield-halved" + icon: "fa-shield-halved", }, - { id: "items", - icon: "fa-suitcase" + icon: "fa-suitcase", }, { id: "zauber", - icon: "fa-hand-sparkles" + icon: "fa-hand-sparkles", }, { id: "hintergrund", - icon: "fa-list" + icon: "fa-list", }, { id: "biographie", - icon: "fa-feather-pointed" - } + icon: "fa-feather-pointed", + }, // { // id: "effects", // icon: "fa-bolt" // } ], initial: "eigenschaften", - labelPrefix: "Midgard6.Sheets.Tabs" - } + labelPrefix: "Midgard6.Sheets.Tabs", + }, }; /* -------------------------------------------------- */ @@ -82,75 +68,37 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe /** @inheritdoc */ static PARTS = { tabs: { - template: systemPath("templates/shared/tabs.hbs") + template: systemPath("templates/shared/tabs.hbs"), }, header: { - template: systemPath("templates/actor/header.hbs") + template: systemPath("templates/actor/header.hbs"), }, eigenschaften: { template: systemPath("templates/actor/eigenschaften.hbs"), - scrollable: [""] + scrollable: [""], }, zauber: { template: systemPath("templates/actor/zauber.hbs"), - scrollable: [""] + scrollable: [""], }, items: { template: systemPath("templates/actor/items.hbs"), - scrollable: [""] + scrollable: [""], }, hintergrund: { template: systemPath("templates/actor/hintergrund.hbs"), - scrollable: [""] + scrollable: [""], }, biographie: { template: systemPath("templates/actor/biographie.hbs"), - scrollable: [""] - } + scrollable: [""], + }, // effects: { // template: systemPath("templates/shared/effects.hbs"), // scrollable: [""] // } }; - _attachPartListeners(partId, html, bubble) { - super._attachPartListeners(partId, html, bubble); - - switch (partId) { - case "hintergrund": - const collapsible = html.querySelectorAll("div[data-action=collapsible]"); - if (collapsible) { - collapsible.forEach((node) => { - node.addEventListener( - "click", - function (e) { - e = window.event || e; - if (this === e.target) { - node.classList.toggle("active"); - var content = node.nextElementSibling; - content.classList.toggle("active"); - node.getElementsByTagName("i")[0].classList.toggle("fa-compress"); - } - }, - { capture: true } - ); - }); - } - break; - } - } - - /* -------------------------------------------------- */ - - /** @inheritdoc */ - _initializeApplicationOptions(options) { - const initialized = super._initializeApplicationOptions(options); - - initialized.classes.push(initialized.document.type); - - return initialized; - } - /* -------------------------------------------------- */ /** @inheritdoc */ @@ -164,7 +112,7 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe system: this.actor.system, skills: this.actor.system.skills, flags: this.actor.flags, - config: CONFIG + config: CONFIG, }); return context; } @@ -187,7 +135,7 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe context.tab = context.tabs[partId]; break; case "items": - context.itemTypes = await this._getItems(); + context.itemTypes = await super._getItems(); context.gewicht = await prepWeight(this.actor); context.tab = context.tabs[partId]; break; @@ -196,7 +144,7 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe context.tab = context.tabs[partId]; break; case "hintergrund": - context.fields = await this._getFields(); + context.fields = await super._getFields(); context.tab = context.tabs[partId]; break; case "biographie": @@ -209,8 +157,8 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe // Data to fill in for inline rolls rollData: this.actor.getRollData(), // Relative UUID resolution - relativeTo: this.actor - } + relativeTo: this.actor, + }, ); context.tab = context.tabs[partId]; break; @@ -220,29 +168,6 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe 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() { @@ -257,7 +182,7 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe const fieldset = { fieldset: true, legend: `Midgard6.Skills.gruppen.${field.label}`, - fields: [] + fields: [], }; await this.#addSkillFields(fieldset, field.fields, source, path); fieldSets.push(fieldset); @@ -278,7 +203,7 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe field, value: foundry.utils.getProperty(source, path), localizationName: "Midgard6.Skills." + field.label, - bonuses: foundry.utils.getProperty(source, _path).bonuses + bonuses: foundry.utils.getProperty(source, _path).bonuses, }); } } @@ -293,14 +218,14 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe const fieldset = { fieldset: true, legend: `Midgard6.Attribute.${systemFields.label}`, - fields: [] + 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 + localizationName: "Midgard6.Resistenzen." + field.name, }); } return fieldset; @@ -318,7 +243,7 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe const fieldset = { fieldset: true, legend: `Midgard6.resources.${field.label}`, - fields: [] + fields: [], }; await this.#addSystemFields(fieldset, field.fields, source, path); fieldSets.push(fieldset); @@ -333,18 +258,11 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe const item = this.actor.items.get(target.dataset.itemId); item.update({ system: { - equipped: !item.system.equipped - } + equipped: !item.system.equipped, + }, }); } - static async #cycleLock(event) { - const actor = this.actor; - - // Update the locked state - actor.update({ "system.locked": !actor.system.locked }); - } - /* -------------------------------------------------- */ /** @@ -359,7 +277,7 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe fieldset.fields.push({ field, value: foundry.utils.getProperty(source, path), - localizationName: "Midgard6.Skills." + field.label + localizationName: "Midgard6.Skills." + field.label, }); } } @@ -367,466 +285,7 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe /* -------------------------------------------------- */ - /** - * 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); - } - - for (const item of this.actor.items) { - types[item.type].items.sort((a, b) => a.sort - b.sort); - } - // Only show Base if it's actually being used - if (types.base.items.length === 0) delete types.base; - return types; - } - _getZauber() { return this.actor.items.filter((item) => item.type === "zauber"); } - - /* -------------------------------------------------- */ - - /** - * 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 */ - /* -------------------------------------------------- */ - - static async #increaseDoc(event, target) { - const item = this.actor.items.get(target.dataset.itemId); - if (event.shiftKey || event.ctrlKey) { - return item.update({ ["system.anzahl"]: (item.system.anzahl += 10) }); - } - return item.update({ ["system.anzahl"]: (item.system.anzahl += 1) }); - } - - static async #decreaseDoc(event, target) { - const item = this.actor.items.get(target.dataset.itemId); - if (event.shiftKey || event.ctrlKey) { - return item.update({ ["system.anzahl"]: (item.system.anzahl -= 10) }); - } - return item.update({ ["system.anzahl"]: (item.system.anzahl -= 1) }); - } - - /** - * 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); - } - const doc = await docCls.create(docData, { parent: this.actor }); - doc.sheet.render(true); - } - - /* -------------------------------------------------- */ - - /** - * 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 }); - } - - /* -------------------------------------------------- */ - /* 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("[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} - * @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 inputs 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; - } - } - - /* -------------------------------------------------- */ - /* Drag and drop */ - /* -------------------------------------------------- */ - - /** - * Define whether a user is able to begin a dragstart workflow for a given drag selector. - * @param {string} selector The candidate HTML selector for dragging. - * @returns {boolean} Can the current user drag this selector? - * @protected - */ - _canDragStart(selector) { - return this.isEditable; - } - - /* -------------------------------------------------- */ - - /** - * Define whether a user is able to conclude a drag-and-drop workflow for a given drop selector. - * @param {string} selector The candidate HTML selector for the drop target. - * @returns {boolean} Can the current user drop on this selector? - * @protected - */ - _canDragDrop(selector) { - return this.isEditable; - } - - /* -------------------------------------------------- */ - - /** - * Callback actions which occur at the beginning of a drag start workflow. - * @param {DragEvent} event The originating DragEvent. - * @protected - */ - _onDragStart(event) { - const li = event.currentTarget; - const dataset = event.target.dataset; - - if ("link" in event.target.dataset) return; - - let dragData = null; - - if (li.dataset.effectId) { - const effect = this.item.effects.get(li.dataset.effectId); - dragData = effect.toDragData(); - } - - dragData = { - type: dataset.type, - itemId: dataset.itemId - }; - - if (!dragData) return; - - event.dataTransfer.setData("text/plain", JSON.stringify(dragData)); - } - - /* -------------------------------------------------- */ - - /** - * Callback actions which occur when a dragged element is over a drop target. - * @param {DragEvent} event The originating DragEvent. - * @protected - */ - _onDragOver(event) {} - - /* -------------------------------------------------- */ - - /** - * Callback actions which occur when a dragged element is dropped on a target. - * @param {DragEvent} event The originating DragEvent. - * @protected - */ - async _onDrop(event) { - const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event); - const item = this.item; - - const allowed = Hooks.call("dropItemSheetData", item, this, data); - if (allowed === false) return; - // Handle different data types - switch (data.type) { - case "ActiveEffect": - return this._onDropActiveEffect(event, data); - case "Actor": - return this._onDropActor(event, data); - case "Item": - return this._onDropItem(event, data); - case "Folder": - return this._onDropFolder(event, data); - } - } - - /* -------------------------------------------------- */ - - /** - * Handle the dropping of ActiveEffect data onto an Actor Sheet. - * @param {DragEvent} event The concluding DragEvent which contains drop data. - * @param {object} data The data transfer extracted from the event. - * @returns {Promise} The created ActiveEffect object or false if it couldn't be created. - * @protected - */ - async _onDropActiveEffect(event, data) { - const aeCls = getDocumentClass("ActiveEffect"); - const effect = await aeCls.fromDropData(data); - if (!this.item.isOwner || !effect) return false; - - if (this.item.uuid === effect.parent?.uuid) return this._onEffectSort(event, effect); - aeCls.create(effect, { parent: this.item }); - } - - /* -------------------------------------------------- */ - - /** - * Sorts an Active Effect based on its surrounding attributes. - * - * @param {DragEvent} event - * @param {ActiveEffect} effect - */ - _onEffectSort(event, effect) { - const effects = this.item.effects; - const dropTarget = event.target.closest("[data-effect-id]"); - if (!dropTarget) return; - const target = effects.get(dropTarget.dataset.effectId); - - // Don't sort on yourself - if (effect.id === target.id) return; - - // Identify sibling items based on adjacent HTML elements - const siblings = []; - for (let el of dropTarget.parentElement.children) { - const siblingId = el.dataset.effectId; - if (siblingId && siblingId !== effect.id) siblings.push(effects.get(el.dataset.effectId)); - } - - // Perform the sort - const sortUpdates = foundry.utils.performIntegerSort(effect, { - target, - siblings - }); - const updateData = sortUpdates.map((u) => { - const update = u.update; - update._id = u.target._id; - return update; - }); - - // Perform the update - this.item.updateEmbeddedDocuments("ActiveEffect", updateData); - } - - /* -------------------------------------------------- */ - - /** - * Handle dropping of an Actor data onto another Actor sheet. - * @param {DragEvent} event The concluding DragEvent which contains drop data. - * @param {object} data The data transfer extracted from the event. - * @returns {Promise} A data object which describes the result of the drop, or false if the drop was - * not permitted. - * @protected - */ - async _onDropActor(event, data) { - if (!this.item.isOwner) return false; - } - - /* -------------------------------------------------- */ - - async _onDropItemCreate(actor, itemData) { - itemData = itemData instanceof Array ? itemData : [itemData]; - return actor.createEmbeddedDocuments("Item", itemData); - } - - /** - * Handle dropping of an item reference or item data onto an Actor Sheet. - * @param {DragEvent} event The concluding DragEvent which contains drop data. - * @param {object} data The data transfer extracted from the event. - * @returns {Promise} The created or updated Item instances, or false if the drop was not permitted. - * @protected - */ - async _onDropItem(event, data) { - if (!this.actor.isOwner) return false; - - if (this.actor.items.get(data.itemId)) return this._onSortItem(event, data); - - const item = await Item.implementation.fromDropData(data); - const itemData = item.toObject(); - - return this._onDropItemCreate(this.actor, itemData); - } - - /** - * Handle a drop event for an existing embedded Item to sort that Item relative to its siblings - * @param {Event} event - * @param {Item} item - * @private - */ - _onSortItem(event, item) { - // Get the drag source and drop target - const items = this.actor.items; - const dropTarget = event.target.closest("[data-item-id]"); - const source = items.get(item.itemId); - if (!dropTarget) return; - const target = items.get(dropTarget.dataset.itemId); - // Don't sort on yourself - if (source.id === target.id) return; - // Identify sibling items based on adjacent HTML elements - const siblings = []; - for (let el of dropTarget.parentElement.children) { - const siblingId = el.dataset.itemId; - if (siblingId && siblingId !== source.id) siblings.push(items.get(siblingId)); - } - - // Perform the sort - const sortUpdates = foundry.utils.performIntegerSort(source, { - target, - siblings - }); - const updateData = sortUpdates.map((u) => { - const update = u.update; - update._id = u.target.id; - return update; - }); - - // Perform the update - return this.actor.updateEmbeddedDocuments("Item", updateData); - } - - /* -------------------------------------------------- */ - - /** - * Handle dropping of a Folder on an Actor Sheet. - * The core sheet currently supports dropping a Folder of Items to create all items as owned items. - * @param {DragEvent} event The concluding DragEvent which contains drop data. - * @param {object} data The data transfer extracted from the event. - * @returns {Promise} - * @protected - */ - async _onDropFolder(event, data) { - if (!this.item.isOwner) return []; - } - - /* -------------------------------------------------- */ - /* The following pieces set up drag */ - /* handling and are unlikely to need modification */ - /* -------------------------------------------------- */ - - // This is marked as private because there's no real need - // for subclasses or external hooks to mess with it directly - #dragDrop = this.#createDragDropHandlers(); - - /** - * Returns an array of DragDrop instances. - * @type {DragDrop[]} - */ - get dragDrop() { - return this.#dragDrop; - } - - /* -------------------------------------------------- */ - - /** - * Create drag-and-drop workflow handlers for this Application. - * @returns {DragDrop[]} An array of DragDrop handlers. - * @private - */ - #createDragDropHandlers() { - return this.options.dragDrop.map((d) => { - d.permissions = { - dragstart: this._canDragStart.bind(this), - drop: this._canDragDrop.bind(this) - }; - d.callbacks = { - dragstart: this._onDragStart.bind(this), - dragover: this._onDragOver.bind(this), - drop: this._onDrop.bind(this) - }; - return new foundry.applications.ux.DragDrop(d); - }); - } } diff --git a/src/sheets/components/roll-actions.mjs b/src/sheets/components/roll-actions.mjs index 0913106..99163f4 100644 --- a/src/sheets/components/roll-actions.mjs +++ b/src/sheets/components/roll-actions.mjs @@ -10,7 +10,7 @@ export async function rollSpell(event, target) { skill, damageRoll: item.system.eigenschaften.schaden, preSelectedSpez: item.system.eigenschaften.ursprung, - actor + actor, }); console.log("Dialog Result", dialogResult); if (dialogResult === "abort") { @@ -48,9 +48,9 @@ export async function rollSpell(event, target) { { die: die, skill: skillValue, - spezBonus: dialogResult.spezLevel + 1 + spezBonus: dialogResult.spezLevel + 1, }, - { title: rollFlavor } + { title: rollFlavor }, ); } @@ -61,8 +61,8 @@ export async function rollSpell(event, target) { await new Roll( "@die", { die: item.system.eigenschaften.schaden }, - { title: game.i18n.localize("Midgard6.Schaden") } - ).evaluate() + { title: game.i18n.localize("Midgard6.Schaden") }, + ).evaluate(), ]; } else { // Execute the roll @@ -88,11 +88,11 @@ export async function rollSpell(event, target) { // Data to fill in for inline rolls rollData: this.actor.getRollData(), // Relative UUID resolution - relativeTo: this.actor - } - ) - } - } + relativeTo: this.actor, + }, + ), + }, + }, }; ChatMessage.applyMode(chatData, dialogResult.rollMode); @@ -107,7 +107,7 @@ export async function rollSkill(event, target) { const dialogResult = await rollDialog({ name: dataset.name, skill, - actor + actor, }); console.log("Dialog Result", dialogResult); if (dialogResult === "abort") { @@ -145,9 +145,9 @@ export async function rollSkill(event, target) { { die: die, skill: skillValue, - spezBonus: dialogResult.spezLevel + 1 + spezBonus: dialogResult.spezLevel + 1, }, - { title: rollFlavor } + { title: rollFlavor }, ); } @@ -162,9 +162,9 @@ export async function rollSkill(event, target) { speaker: ChatMessage.getSpeaker(), flags: { "midgard6-lvd": { - title: rollFlavor - } - } + title: rollFlavor, + }, + }, }; // Nutze applyRollMode, um Sichtbarkeiten (Whisper, Blind) korrekt zu setzen @@ -184,7 +184,7 @@ export async function rollWeapon(event, target) { skill, damageRoll: weapon.system.schaden, preSelectedSpez: weapon.system.spezialisierung, - actor + actor, }); console.log("Dialog Result", dialogResult); if (dialogResult === "abort") { @@ -224,18 +224,18 @@ export async function rollWeapon(event, target) { { die: die, skill: skillValue, - spezBonus: dialogResult.spezLevel + 1 + spezBonus: dialogResult.spezLevel + 1, }, { - title: rollFlavor - } + title: rollFlavor, + }, ).evaluate(); } damageRoll = await new Roll( "@die", { die: weapon.system.schaden }, - { title: game.i18n.localize("Midgard6.Schaden") } + { title: game.i18n.localize("Midgard6.Schaden") }, ).evaluate(); // The parsed terms of the roll formula @@ -252,11 +252,11 @@ export async function rollWeapon(event, target) { { secrets: false, rollData: this.actor.getRollData(), - relativeTo: this.actor - } - ) - } - } + relativeTo: this.actor, + }, + ), + }, + }, }; ChatMessage.applyMode(chatData, dialogResult.rollMode); @@ -264,7 +264,7 @@ export async function rollWeapon(event, target) { await ChatMessage.create(chatData); } -async function rollDialog(rollDialogRequest) { +export async function rollDialog(rollDialogRequest) { // Assamble dialog depending on roll type let label = rollDialogRequest.name; let skillValue = rollDialogRequest.skill.value || rollDialogRequest.skill; @@ -284,7 +284,7 @@ async function rollDialog(rollDialogRequest) { damageRoll, preSelectedSpez, customRoll, - rollModes: CONFIG.ChatMessage.modes + rollModes: CONFIG.ChatMessage.modes, }; // 2. Render the Handlebars template into an HTML string const content = await foundry.applications.handlebars.renderTemplate(templatePath, templateData); @@ -293,7 +293,7 @@ async function rollDialog(rollDialogRequest) { return foundry.applications.api.DialogV2.wait({ window: { title: "Würfel Modifikatoren: " + label }, position: { - width: 600 + width: 600, }, classes: ["M6", "dialog"], content, @@ -349,7 +349,7 @@ async function rollDialog(rollDialogRequest) { label: "Midgard6.Dialog.abbrechen", callback: (event, button, dialog) => { return null; - } + }, }, { action: "roll", @@ -363,11 +363,11 @@ async function rollDialog(rollDialogRequest) { spezLevel, spezName, rollMode: - button.form.elements.rollMode?.value || game.settings.get("core", "messageMode") + button.form.elements.rollMode?.value || game.settings.get("core", "messageMode"), }; return rollData; - } - } - ] + }, + }, + ], }); } diff --git a/src/sheets/nsc-sheet.mjs b/src/sheets/nsc-sheet.mjs new file mode 100644 index 0000000..2fad778 --- /dev/null +++ b/src/sheets/nsc-sheet.mjs @@ -0,0 +1,454 @@ +import { systemPath } from "../constants.mjs"; +import { prepareActiveEffectCategories } from "../helpers/utils.mjs"; +import { addSpezialisierung, editSepzialisierung } from "./components/spezialisierung-actions.mjs"; +import { prepArmor, prepWeapons, prepWeight, prepSpells } from "./components/character-prep.mjs"; +import { rollSpell, rollWeapon, rollSkill, rollDialog } from "./components/roll-actions.mjs"; +import { M6ActorSheet } from "./actor-sheet.mjs"; + +const { api, sheets } = foundry.applications; + +/** + * Extend the M6ActorSheet. + */ +export class M6NSCSheet extends M6ActorSheet { + /** @inheritdoc */ + static get DEFAULT_OPTIONS() { + return { + ...super.DEFAULT_OPTIONS, // Kopiert alle bestehenden Options aus M6ActorSheet + actions: { + ...super.DEFAULT_OPTIONS.actions, // Kopiert alle bestehenden Actions aus M6ActorSheet + cycleEquip: this.#cycleEquip, + rollKompetenz: this.#rollKompetenz, + rollResistenz: this.#rollResistenz, + rollSpell: rollSpell, + cycleEquip: this.#cycleEquip, + addKompetenz: this.#addKompetenz, + editResistenz: this.#editResistenz, + }, + }; + } + + /* -------------------------------------------------- */ + + static TABS = { + primary: { + tabs: [ + { + id: "eigenschaften", + icon: "fa-shield-halved", + }, + { + id: "items", + icon: "fa-suitcase", + }, + { + id: "zauber", + icon: "fa-hand-sparkles", + }, + { + id: "biographie", + icon: "fa-feather-pointed", + }, + // { + // id: "effects", + // icon: "fa-bolt" + // } + ], + initial: "eigenschaften", + labelPrefix: "Midgard6.Sheets.Tabs", + }, + }; + + /* -------------------------------------------------- */ + + /** @inheritdoc */ + static PARTS = { + tabs: { + template: systemPath("templates/shared/tabs.hbs"), + }, + header: { + template: systemPath("templates/nsc/header.hbs"), + }, + eigenschaften: { + template: systemPath("templates/nsc/eigenschaften.hbs"), + scrollable: [""], + }, + zauber: { + template: systemPath("templates/nsc/zauber.hbs"), + scrollable: [""], + }, + items: { + template: systemPath("templates/nsc/items.hbs"), + scrollable: [""], + }, + biographie: { + template: systemPath("templates/nsc/biographie.hbs"), + scrollable: [""], + }, + // effects: { + // template: systemPath("templates/shared/effects.hbs"), + // scrollable: [""] + // } + }; + + /* -------------------------------------------------- */ + + /** @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, + flags: this.actor.flags, + config: CONFIG, + }); + return context; + } + + /* -------------------------------------------------- */ + + /** @inheritdoc */ + async _preparePartContext(partId, context) { + switch (partId) { + case "eigenschaften": + // context.armor = await prepArmor(this.actor); + // context.skills = await this._getSkills(); + // context.resistenzen = await this._getResistenzen(); + // context.equippedWeapons = await prepWeapons(this.actor); + // context.equippedSpells = await prepSpells(this.actor); + context.kompetenzWürfe = await this.calcKompetenzWürfe(); + context.tab = context.tabs[partId]; + break; + case "effects": + context.effects = prepareActiveEffectCategories(this.actor.allApplicableEffects()); + context.tab = context.tabs[partId]; + break; + case "items": + context.itemTypes = await super._getItems(); + context.tab = context.tabs[partId]; + break; + case "zauber": + context.zauber = await this._getZauber(); + context.tab = context.tabs[partId]; + break; + case "biographie": + context.enrichedBeschreibung = + await foundry.applications.ux.TextEditor.implementation.enrichHTML( + this.actor.system.biographie.beschreibung, + { + // Whether to show secret blocks in the finished html + secrets: this.document.isOwner, + // Data to fill in for inline rolls + rollData: this.actor.getRollData(), + // Relative UUID resolution + relativeTo: this.actor, + }, + ); + context.tab = context.tabs[partId]; + break; + default: + context.tab = context.tabs[partId]; + } + return context; + } + + /* -------------------------------------------------- */ + + async calcKompetenzWürfe() { + const kompetenz = this.actor.system.kompetenz; + const resistenzen = this.actor.system.resistenzen; + for (var key in resistenzen) { + let calc; + switch (resistenzen[key].kompetent) { + case -1: + calc = "d3"; + break; + case 1: + calc = kompetenz + 8; + break; + default: + calc = Math.floor((kompetenz + 8) / 2); + } + resistenzen[key].value = calc; + } + + return { kompetent: kompetenz + 8, mittelmäßig: Math.floor((kompetenz + 8) / 2) }; + } + + 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, + }); + } + 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; + } + + static async #cycleEquip(event, target) { + const item = this.actor.items.get(target.dataset.itemId); + item.update({ + system: { + equipped: !item.system.equipped, + }, + }); + } + + /* -------------------------------------------------- */ + + /** + * 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.label, + }); + } + } + } + + /* -------------------------------------------------- */ + + _getZauber() { + return this.actor.items.filter((item) => item.type === "zauber"); + } + + static async #addKompetenz(event, target) {} + + static async #editResistenz(event, target) { + const resistenzen = this.actor.system.resistenzen; + const templatePath = systemPath("templates/dialog/nsc-resistenz-dialog.hbs"); + const templateData = { + resistenzen, + }; + const content = await foundry.applications.handlebars.renderTemplate( + templatePath, + templateData, + ); + return foundry.applications.api.DialogV2.wait({ + window: { + title: game.i18n.localize("Midgard6.Attribute.resistenzen"), + }, + classes: ["M6", "dialog"], + position: { + width: 600, + }, + content, + actions: {}, + render: (_event, dialog) => { + const dialogHTML = dialog.element; + // Variable bei jeder Änderung aktualisieren + for (const key in resistenzen) { + dialogHTML.querySelectorAll(`input[name="${key}-segment"]`).forEach((radio) => { + if (radio.value == resistenzen[key].kompetent) { + radio.click(); + } + radio.addEventListener("change", (e) => { + resistenzen[key].kompetent = parseInt(e.target.value); + }); + }); + } + }, + buttons: [ + { + action: "abort", + label: "Midgard6.Dialog.abbrechen", + }, + { + action: "safe", + label: "Midgard6.Dialog.speichern", + default: true, + callback: async (event, button, dialog) => { + console.warn(resistenzen); + await this.actor.update({ [`system.resistenzen`]: resistenzen }); + }, + }, + ], + }); + } + + static async #rollKompetenz(event, target) { + const dataset = target.dataset; + const kompetenz = dataset.kompetenz; + const kompetenzValue = dataset.kompetenzValue; + + const dialogResult = await rollDialog({ + skill: kompetenzValue, + }); + + console.log("Dialog Result", dialogResult); + if (dialogResult === "abort") { + return; + } + // Construct the Roll instance + const skillValue = kompetenzValue; + let die = ""; + switch (dialogResult.vorteil) { + case -1: + die = "2d20kl"; + break; + case 1: + die = "2d20kh"; + break; + default: + die = "1d20"; + break; + } + + let rollTerm = "@die + @skill"; + let rollFlavor = kompetenz; + let roll; + + if (dialogResult.spezLevel) { + rollTerm += " + @spezBonus"; + rollFlavor += ": " + dialogResult.spezName; + } + + if (dialogResult.customRoll) { + roll = new Roll(dialogResult.customRoll, {}, { title: rollFlavor }); + } else { + roll = new Roll( + rollTerm, + { + die: die, + skill: skillValue, + spezBonus: dialogResult.spezLevel + 1, + }, + { title: rollFlavor }, + ); + } + + // The parsed terms of the roll formula + console.log("Roll:", roll); // [Die, OperatorTerm, NumericTerm, OperatorTerm, NumericTerm] + + // Execute the roll + await roll.evaluate(); + + const chatData = { + rolls: roll, + speaker: ChatMessage.getSpeaker(), + flags: { + "midgard6-lvd": { + title: rollFlavor, + }, + }, + }; + ChatMessage.applyMode(chatData, dialogResult.rollMode); + + await ChatMessage.create(chatData); + } + + static async #rollResistenz(event, target) { + const dataset = target.dataset; + const name = target.dataset.name; + const skill = foundry.utils.getProperty(this.actor, "system.resistenzen." + name); + const dialogResult = await rollDialog({ + name: game.i18n.localize("Midgard6.Resistenzen." + name), + skill, + }); + + console.log("Dialog Result", dialogResult); + if (dialogResult === "abort") { + return; + } + // Construct the Roll instance + const skillValue = skill.value || skill; + let die = ""; + switch (dialogResult.vorteil) { + case -1: + die = "2d20kl"; + break; + case 1: + die = "2d20kh"; + break; + default: + die = "1d20"; + break; + } + + let rollTerm = "@die + @skill"; + let rollFlavor = game.i18n.localize("Midgard6.Resistenzen." + name); + let roll; + + if (dialogResult.spezLevel) { + rollTerm += " + @spezBonus"; + rollFlavor += ": " + dialogResult.spezName; + } + + if (dialogResult.customRoll) { + roll = new Roll(dialogResult.customRoll, {}, { title: rollFlavor }); + } else { + roll = new Roll( + rollTerm, + { + die: die, + skill: skillValue, + spezBonus: dialogResult.spezLevel + 1, + }, + { title: rollFlavor }, + ); + } + + // The parsed terms of the roll formula + console.log("Roll:", roll); // [Die, OperatorTerm, NumericTerm, OperatorTerm, NumericTerm] + + // Execute the roll + await roll.evaluate(); + + const chatData = { + rolls: roll, + speaker: ChatMessage.getSpeaker(), + flags: { + "midgard6-lvd": { + title: rollFlavor, + }, + }, + }; + ChatMessage.applyMode(chatData, dialogResult.rollMode); + + await ChatMessage.create(chatData); + } +} diff --git a/src/styles/M6.scss b/src/styles/M6.scss index ade715f..f75301f 100644 --- a/src/styles/M6.scss +++ b/src/styles/M6.scss @@ -73,13 +73,17 @@ text-align: center; margin: 0 0.5rem; } - &.text { - &.center { - text-align: center; - } - &.right { - text-align: end; - } + } + .text { + &.center { + text-align: center; + } + &.right { + text-align: end; + } + &.highlight { + color: var(--M6-text-brown); + font-weight: bold; } } input:disabled { diff --git a/src/system.mjs b/src/system.mjs index 25a1b58..25daab7 100644 --- a/src/system.mjs +++ b/src/system.mjs @@ -4,12 +4,14 @@ import { loadPartials } from "./helpers/partials.mjs"; import { loadSettings } from "./helpers/settings.mjs"; import { CharacterData } from "./data/character-data.mjs"; +import { NSCData } from "./data/nsc-data.mjs"; import { WeaponData } from "./data/weapon-data.mjs"; import { ItemData } from "./data/item-data.mjs"; import { ArmorData } from "./data/armor-data.mjs"; import { ZauberData } from "./data/zauber-data.mjs"; import { HintergrundData } from "./data/hintergrund-data.mjs"; -import { M6ActorSheet } from "./sheets/character-sheet.mjs"; +import { M6CharacterSheet } from "./sheets/character-sheet.mjs"; +import { M6NSCSheet } from "./sheets/nsc-sheet.mjs"; import { M6ItemSheet } from "./sheets/item-sheet.mjs"; import { M6WeaponSheet } from "./sheets/weapon-sheet.mjs"; import { M6ArmorSheet } from "./sheets/armor-sheet.mjs"; @@ -24,7 +26,8 @@ Hooks.once("init", () => { CONFIG.ChatMessage.template = systemPath("templates/chat/message-default.hbs"); CONFIG.Actor.dataModels = { - character: CharacterData + character: CharacterData, + nsc: NSCData, }; CONFIG.Item.dataModels = { item: ItemData, @@ -32,70 +35,78 @@ Hooks.once("init", () => { weapon: WeaponData, armor: ArmorData, zauber: ZauberData, - hintergrund: HintergrundData + hintergrund: HintergrundData, }; CONFIG.Actor.trackableAttributes = { pc: { bar: ["resources.leben", "resources.ausdauer"], - value: ["schicksalsmünzen"] + value: ["schicksalsmünzen"], }, npc: { bar: ["resources.leben", "resources.ausdauer"], - value: [] - } + value: [], + }, }; - foundry.applications.apps.DocumentSheetConfig.registerSheet(Actor, "midgard6-lvd", M6ActorSheet, { - types: ["character"], - makeDefault: true + foundry.applications.apps.DocumentSheetConfig.registerSheet( + Actor, + "midgard6-lvd", + M6CharacterSheet, + { + types: ["character"], + makeDefault: true, + }, + ); + foundry.applications.apps.DocumentSheetConfig.registerSheet(Actor, "midgard6-lvd", M6NSCSheet, { + types: ["nsc"], }); foundry.applications.apps.DocumentSheetConfig.registerSheet(Item, "midgard6-lvd", M6ItemSheet, { types: ["item"], - makeDefault: true + makeDefault: true, }); foundry.applications.apps.DocumentSheetConfig.registerSheet(Item, "midgard6-lvd", M6ItemSheet, { - types: ["geld"] + types: ["geld"], }); foundry.applications.apps.DocumentSheetConfig.registerSheet(Item, "midgard6-lvd", M6WeaponSheet, { - types: ["weapon"] + types: ["weapon"], }); foundry.applications.apps.DocumentSheetConfig.registerSheet(Item, "midgard6-lvd", M6ArmorSheet, { - types: ["armor"] + types: ["armor"], }); foundry.applications.apps.DocumentSheetConfig.registerSheet(Item, "midgard6-lvd", M6ZauberSheet, { - types: ["zauber"] + types: ["zauber"], }); foundry.applications.apps.DocumentSheetConfig.registerSheet( Item, "midgard6-lvd", M6HintergrundSheet, { - types: ["gunst"] - } + types: ["gunst"], + }, ); foundry.applications.apps.DocumentSheetConfig.registerSheet( Item, "midgard6-lvd", M6HintergrundSheet, { - types: ["makel"] - } + types: ["makel"], + }, ); foundry.applications.apps.DocumentSheetConfig.registerSheet( Item, "midgard6-lvd", M6HintergrundSheet, { - types: ["schicksalsgabe"] - } + types: ["schicksalsgabe"], + }, ); foundry.applications.apps.DocumentSheetConfig.registerSheet( Item, "midgard6-lvd", M6HintergrundSheet, { - types: ["legende"] - } + types: ["legende"], + }, ); loadSettings(); @@ -117,7 +128,7 @@ Hooks.on("renderChatMessageHTML", (message, html, data) => { content.classList.toggle("active"); node.getElementsByTagName("i")[0].classList.toggle("fa-compress"); }, - { capture: true } + { capture: true }, ); }); } diff --git a/src/types/data-config.d.mjs b/src/types/data-config.d.mjs index 490951d..3872476 100644 --- a/src/types/data-config.d.mjs +++ b/src/types/data-config.d.mjs @@ -1,4 +1,5 @@ import { CharacterData } from "../data/character-data"; +import { NSCData } from "../data/ncs-data"; import { ItemData } from "../data/item-data"; import { WeaponData } from "../data/weapon-data"; import { ArmorData } from "../data/armor-data"; @@ -7,7 +8,7 @@ import { HintergrundData } from "../data/hintergrund-data"; declare module "fvtt-types/configuration" { interface DataModelConfig { - Actor: { character: typeof CharacterData }; + Actor: { character: typeof CharacterData, nsc: typeOf NSCData }; Item: { item: typeof ItemData, weapon: typeof WeaponData, diff --git a/system.json b/system.json index 7883ab7..568aec4 100644 --- a/system.json +++ b/system.json @@ -30,7 +30,8 @@ ], "documentTypes": { "Actor": { - "character": {} + "character": {}, + "nsc": {} }, "Item": { "item": {}, diff --git a/templates/dialog/nsc-resistenz-dialog.hbs b/templates/dialog/nsc-resistenz-dialog.hbs new file mode 100644 index 0000000..4c52acc --- /dev/null +++ b/templates/dialog/nsc-resistenz-dialog.hbs @@ -0,0 +1,39 @@ +
+
+ {{localize "Midgard6.Attribute.resistenzen"}} + {{localize "Midgard6.NSC.kompetenz.kompetenz"}} + {{#each resistenzen}} +
+
+
+ +

{{localizeConcat "Midgard6.Resistenzen." @key}}

+ + + + + + + + +
+
+
+ {{/each}} +
+
\ No newline at end of file diff --git a/templates/nsc/biographie.hbs b/templates/nsc/biographie.hbs new file mode 100644 index 0000000..8d8eecc --- /dev/null +++ b/templates/nsc/biographie.hbs @@ -0,0 +1,24 @@ +{{! Beschreibung Allgemein Tab }} +
+
+ {{localize "Midgard6.Sheets.Tabs.biographie"}} + {{#if editable}} + + {{{enrichedBeschreibung}}} + + {{else}} + {{{enrichedBeschreibung}}} + {{/if}} +
+
\ No newline at end of file diff --git a/templates/nsc/eigenschaften.hbs b/templates/nsc/eigenschaften.hbs new file mode 100644 index 0000000..273abd2 --- /dev/null +++ b/templates/nsc/eigenschaften.hbs @@ -0,0 +1,275 @@ +
+
+
+
+
+ {{localize "Midgard6.NSC.kompetenz.würfe"}} +
+
+
+ + + +

+ {{kompetenzWürfe.kompetent}}

+
+
+
+ + + +

+ {{kompetenzWürfe.mittelmäßig}}

+
+
+
+ + + +

+ d3

+
+
+
+
+
+
+
+
+ {{localize "Midgard6.Sheets.Tabs.eigenschaften"}} + {{#if @root.editable}} + {{#unless system.locked}} + + + + {{/unless}} + {{/if}} + + {{#each fertigkeiten as |fertigkeit|}} + + {{/each}} +
+
+
+
+ {{localize "Midgard6.Attribute.resistenzen"}} + {{#if @root.editable}} + {{#unless system.locked}} + + + + {{/unless}} + {{/if}} + +
+ {{#each system.resistenzen as |resistenz|}} + +
+

{{localizeConcat "Midgard6.Resistenzen." @key}}

+
+ + + + +
+
+ {{/each}} +
+
+
+
+ {{localize "Midgard6.Attribute.lp"}} +
+
+

{{localize "Midgard6.aktuell"}}

+
+
+ + {{system.rüstwert.mod}} +
+ +
+
+

/

+
+

{{localize "Midgard6.maximal.short"}}

+ +
+
+
+
+ {{localize "Midgard6.Attribute.ap"}} +
+
+

{{localize "Midgard6.aktuell"}}

+ + +
+

/

+
+

{{localize "Midgard6.maximal.short"}}

+ +
+
+
+
+ {{!--
+
+ {{localize "Midgard6.Item.type.weapon.plural" }} +
+ {{#each equippedWeapons as |weapon|}} +
+
+
+ {{weapon.name}} +

{{weapon.name}}:

+

+ + + {{weapon.skillValue}} {{#if weapon.bonusValue}}+ {{weapon.bonusValue}}{{/if}}

+
+
+
+ + + +
+
+ {{/each}} +
+
+
+
+
+ {{localize "Midgard6.Item.type.armor.plural" }} +
+ {{#each armor.armors as |armor|}} +
+
+
+ {{armor.name}} +

{{armor.name}}

+
+
+
+
+ + {{armor.rüstwert}} +
+
+
+ {{/each}} + {{#if armor.einschränkungen}} +

{{localize "Midgard6.Item.einschränkung"}}

+

{{splitArray armor.einschränkungen}}

+ {{/if}} +
+
+
+
+
+ {{localize "Midgard6.Item.type.zauber.plural" }} +
+ {{#each equippedSpells as |weapon|}} +
+
+
+ {{weapon.name}} +

{{weapon.name}}:

+

+ + + {{weapon.skillValue}} {{#if weapon.bonusValue}}+ {{weapon.bonusValue}}{{/if}}

+
+
+
+ + + +
+
+ {{/each}} +
+
+
--}} +
+
+
+
\ No newline at end of file diff --git a/templates/nsc/header.hbs b/templates/nsc/header.hbs new file mode 100644 index 0000000..c5466fb --- /dev/null +++ b/templates/nsc/header.hbs @@ -0,0 +1,51 @@ +
+
+
+
+ + + +
+ {{actor.name}} +
+ + +
+ {{!-- --}} +
+
+
+
diff --git a/templates/nsc/hintergrund.hbs b/templates/nsc/hintergrund.hbs new file mode 100644 index 0000000..695100b --- /dev/null +++ b/templates/nsc/hintergrund.hbs @@ -0,0 +1,320 @@ +{{! Beschreibung Allgemein Tab }} +
+
+
+
+
+ {{localize "Midgard6.Grad.grad"}} +
+ +

{{localize + "Midgard6.Grad.erfahrung" + }}

+
+ + +
+

+

+
+ + +
+ +

=

+
+ + +
+ +
+
+
+ +
+
+ {{localize "Midgard6.Hintergrund.type.gunst.singular"}} + & + {{localize "Midgard6.Hintergrund.type.makel.singular"}} +
+
+ {{#with itemTypes.gunst}} +
+
+ {{#if @root.editable}} + + + {{localize "DOCUMENT.Create" type=this.label}} + + {{/if}} +
+
+ {{#each this.items as |gunst|}} +
{{gunst.name}} +
+ + {{#if @root.editable}} + + + + + + + {{/if}} +
+
+ +
+ {{{gunst.system.beschreibung}}} +
+ {{/each}} + {{/with}} +
+
+ {{#with itemTypes.makel}} +
+
+ {{#if @root.editable}} + + + {{localize "DOCUMENT.Create" type=this.label}} + + {{/if}} +
+
+ {{#each this.items as |makel|}} +
{{makel.name}} +
+ + {{#if @root.editable}} + + + + + + + {{/if}} +
+
+
+ {{{makel.system.beschreibung}}} +
+ {{/each}} + {{/with}} +
+
+
+
+ +
+
+ {{localize "Midgard6.Hintergrund.type.legende.plural"}} +
+
+ {{#with itemTypes.legende}} +
+
+ {{#if @root.editable}} + + + {{localize "DOCUMENT.Create" type=this.label}} + + {{/if}} +
+
+ {{#each this.items as |legende|}} +
{{legende.name}} +
+ + + {{#if @root.editable}} + + + + + + + {{/if}} +
+
+ +
+ {{{legende.system.beschreibung}}} +
+ {{/each}} + {{/with}} +
+
+
+
+ +
+
+ {{localize "Midgard6.Hintergrund.type.schicksalsgabe.plural"}} +
+
+ {{#with itemTypes.schicksalsgabe}} +
+
+ {{#if @root.editable}} + + + {{localize "DOCUMENT.Create" type=this.label}} + + {{/if}} +
+
+ {{#each this.items as |schicksalsgabe|}} +
{{schicksalsgabe.name}} +
+ + {{#if @root.editable}} + + + + + + + {{/if}} +
+
+ +
+ {{{gunst.system.beschreibung}}} +
+ {{/each}} + {{/with}} +
+
+
+
+
+
+
\ No newline at end of file diff --git a/templates/nsc/items.hbs b/templates/nsc/items.hbs new file mode 100644 index 0000000..3f8fb69 --- /dev/null +++ b/templates/nsc/items.hbs @@ -0,0 +1,241 @@ +{{! Items Tab }} +
+
+
+
+
+ {{localize "Midgard6.Item.type.münze.plural" }} +
+
+ {{localize "Midgard6.Item.type.item.plural" }} +
+
+
+ {{!-- Waffen --}} + +
+ {{localize "Midgard6.Item.type.weapon.plural" }} +
+ + {{!-- Rüstung --}} + +
+ {{localize "Midgard6.Item.type.armor.plural" }} +
+
+
+
+ +
+
+ {{localize "Midgard6.Traglast"}}: {{gewicht.gewicht}} / {{gewicht.traglast}} + +
+ +
+
+
+
\ No newline at end of file diff --git a/templates/nsc/zauber.hbs b/templates/nsc/zauber.hbs new file mode 100644 index 0000000..d04cdee --- /dev/null +++ b/templates/nsc/zauber.hbs @@ -0,0 +1,60 @@ +{{! Items Tab }} +
+
+
+
+
+ {{localize "Midgard6.Item.type.zauber.plural" }} + +
    +
  • +
    + {{#if @root.editable}} + + + {{localize "DOCUMENT.Create" type="Zauber"}} + + {{/if}} +
    +
  • +
      + {{#each zauber as |zauber|}} +
    • +

      {{zauber.name}}

      +

      {{zauber.system.eigenschaften.ursprung}}

      +

      {{localize "Midgard6.Zauber.stufe"}} {{zauber.system.eigenschaften.stufe}}

      + + +
      + {{#if @root.editable}} + + + + + + + {{/if}} +
      +
    • + {{/each}} +
    +
+
+
+
+ +
\ No newline at end of file diff --git a/vite.config.ts b/vite.config.ts index 40e0149..7c83656 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,15 +1,14 @@ import { defineConfig } from "vite"; -import react from "@vitejs/plugin-react"; export default defineConfig({ - plugins: [react()], + plugins: [], define: { - "process.env.NODE_ENV": JSON.stringify("production") + "process.env.NODE_ENV": JSON.stringify("production"), }, css: { preprocessorOptions: { - scss: { api: "modern-compiler" } - } + scss: { api: "modern-compiler" }, + }, }, build: { outDir: "dist", @@ -17,13 +16,13 @@ export default defineConfig({ lib: { entry: "src/system.mjs", formats: ["es"], - fileName: () => "system.mjs" + fileName: () => "system.mjs", }, rollupOptions: { output: { // single-file bundle, no code-splitting: Foundry loads this one ESM file directly - inlineDynamicImports: true - } - } - } + inlineDynamicImports: true, + }, + }, + }, }); -- 2.54.0 From 2045acc269503a452635ddadb3ce5761baf17d62 Mon Sep 17 00:00:00 2001 From: Byroks Date: Fri, 30 Oct 2026 19:10:57 +0100 Subject: [PATCH 2/3] besondere fertigkeiten tracken --- src/data/nsc-data.mjs | 2 +- src/sheets/nsc-sheet.mjs | 214 +++++++++++------- .../nsc-fertigkeit-hinzufügen-dialog.hbs | 46 ++++ templates/nsc/eigenschaften.hbs | 39 +++- 4 files changed, 215 insertions(+), 86 deletions(-) create mode 100644 templates/dialog/nsc-fertigkeit-hinzufügen-dialog.hbs diff --git a/src/data/nsc-data.mjs b/src/data/nsc-data.mjs index 1c5ae2d..2f25632 100644 --- a/src/data/nsc-data.mjs +++ b/src/data/nsc-data.mjs @@ -88,7 +88,7 @@ function defineSchema() { }), merkmale: new fields.ArrayField(new fields.StringField({}), { initial: [] }), angriffe: new fields.ArrayField(new fields.ObjectField({}), { initial: [] }), - fertigkeiten: new fields.ArrayField(new fields.StringField({}), { initial: [] }), + fertigkeiten: new fields.ArrayField(new fields.ObjectField({}), { initial: [] }), }; } diff --git a/src/sheets/nsc-sheet.mjs b/src/sheets/nsc-sheet.mjs index 2fad778..691e66b 100644 --- a/src/sheets/nsc-sheet.mjs +++ b/src/sheets/nsc-sheet.mjs @@ -19,10 +19,11 @@ export class M6NSCSheet extends M6ActorSheet { ...super.DEFAULT_OPTIONS.actions, // Kopiert alle bestehenden Actions aus M6ActorSheet cycleEquip: this.#cycleEquip, rollKompetenz: this.#rollKompetenz, - rollResistenz: this.#rollResistenz, rollSpell: rollSpell, cycleEquip: this.#cycleEquip, addKompetenz: this.#addKompetenz, + deleteKompetenz: this.#deleteKompetenz, + editKompetenz: this.#editKompetenz, editResistenz: this.#editResistenz, }, }; @@ -114,11 +115,6 @@ export class M6NSCSheet extends M6ActorSheet { async _preparePartContext(partId, context) { switch (partId) { case "eigenschaften": - // context.armor = await prepArmor(this.actor); - // context.skills = await this._getSkills(); - // context.resistenzen = await this._getResistenzen(); - // context.equippedWeapons = await prepWeapons(this.actor); - // context.equippedSpells = await prepSpells(this.actor); context.kompetenzWürfe = await this.calcKompetenzWürfe(); context.tab = context.tabs[partId]; break; @@ -175,6 +171,21 @@ export class M6NSCSheet extends M6ActorSheet { resistenzen[key].value = calc; } + this.actor.system.fertigkeiten.forEach((fertigkeit) => { + let calc; + switch (fertigkeit.kompetenz) { + case -1: + calc = "d3"; + break; + case 1: + calc = kompetenz + 8; + break; + default: + calc = Math.floor((kompetenz + 8) / 2); + } + fertigkeit.wurf = calc; + }); + return { kompetent: kompetenz + 8, mittelmäßig: Math.floor((kompetenz + 8) / 2) }; } @@ -256,7 +267,125 @@ export class M6NSCSheet extends M6ActorSheet { return this.actor.items.filter((item) => item.type === "zauber"); } - static async #addKompetenz(event, target) {} + static async #addKompetenz(event, target) { + const templatePath = systemPath("templates/dialog/nsc-fertigkeit-hinzufügen-dialog.hbs"); + let fertigkeit = { + name: "", + kompetenz: "", + wurf: "", + }; + const templateData = { + fertigkeit, + }; + const content = await foundry.applications.handlebars.renderTemplate( + templatePath, + templateData, + ); + return foundry.applications.api.DialogV2.wait({ + window: { + title: game.i18n.localize("Midgard6.Attribute.resistenzen"), + }, + classes: ["M6", "dialog"], + position: { + width: 600, + }, + content, + actions: {}, + render: (_event, dialog) => { + const dialogHTML = dialog.element; + dialogHTML.querySelectorAll(`input[name="kompetenz-segment"]`).forEach((radio) => { + radio.addEventListener("change", (e) => { + fertigkeit.kompetenz = parseInt(e.target.value); + }); + if (radio.value == 1) { + radio.click(); + } + }); + }, + buttons: [ + { + action: "abort", + label: "Midgard6.Dialog.abbrechen", + }, + { + action: "safe", + label: "Midgard6.Dialog.speichern", + default: true, + callback: async (event, button, dialog) => { + const fertigkeiten = this.actor.system.fertigkeiten; + fertigkeit.name = button.form.elements.fertigkeitsName.value; + await this.actor.update({ ["system.fertigkeiten"]: [...fertigkeiten, fertigkeit] }); + }, + }, + ], + }); + } + + static async #editKompetenz(event, target) { + const templatePath = systemPath("templates/dialog/nsc-fertigkeit-hinzufügen-dialog.hbs"); + const OGName = target.dataset.name; + const kompetenz = target.dataset.kompetenz; + + let fertigkeit = { + name: target.dataset.name, + kompetenz, + wurf: "", + }; + const templateData = { + fertigkeit, + }; + const content = await foundry.applications.handlebars.renderTemplate( + templatePath, + templateData, + ); + return foundry.applications.api.DialogV2.wait({ + window: { + title: game.i18n.localize("Midgard6.Attribute.resistenzen"), + }, + classes: ["M6", "dialog"], + position: { + width: 600, + }, + content, + actions: {}, + render: (_event, dialog) => { + const dialogHTML = dialog.element; + dialogHTML.querySelectorAll(`input[name="kompetenz-segment"]`).forEach((radio) => { + radio.addEventListener("change", (e) => { + fertigkeit.kompetenz = parseInt(e.target.value); + }); + if (radio.value == kompetenz) { + radio.click(); + } + }); + }, + buttons: [ + { + action: "abort", + label: "Midgard6.Dialog.abbrechen", + }, + { + action: "safe", + label: "Midgard6.Dialog.speichern", + default: true, + callback: async (event, button, dialog) => { + fertigkeit.name = button.form.elements.fertigkeitsName.value; + const fertigkeiten = this.actor.system.fertigkeiten.map((x) => + x.name === OGName ? fertigkeit : x, + ); + await this.actor.update({ ["system.fertigkeiten"]: fertigkeiten }); + }, + }, + ], + }); + } + + static async #deleteKompetenz(event, target) { + const fertigkeiten = this.actor.system.fertigkeiten.filter( + (x) => x.name !== target.dataset.name, + ); + await this.actor.update({ ["system.fertigkeiten"]: fertigkeiten }); + } static async #editResistenz(event, target) { const resistenzen = this.actor.system.resistenzen; @@ -380,75 +509,4 @@ export class M6NSCSheet extends M6ActorSheet { await ChatMessage.create(chatData); } - - static async #rollResistenz(event, target) { - const dataset = target.dataset; - const name = target.dataset.name; - const skill = foundry.utils.getProperty(this.actor, "system.resistenzen." + name); - const dialogResult = await rollDialog({ - name: game.i18n.localize("Midgard6.Resistenzen." + name), - skill, - }); - - console.log("Dialog Result", dialogResult); - if (dialogResult === "abort") { - return; - } - // Construct the Roll instance - const skillValue = skill.value || skill; - let die = ""; - switch (dialogResult.vorteil) { - case -1: - die = "2d20kl"; - break; - case 1: - die = "2d20kh"; - break; - default: - die = "1d20"; - break; - } - - let rollTerm = "@die + @skill"; - let rollFlavor = game.i18n.localize("Midgard6.Resistenzen." + name); - let roll; - - if (dialogResult.spezLevel) { - rollTerm += " + @spezBonus"; - rollFlavor += ": " + dialogResult.spezName; - } - - if (dialogResult.customRoll) { - roll = new Roll(dialogResult.customRoll, {}, { title: rollFlavor }); - } else { - roll = new Roll( - rollTerm, - { - die: die, - skill: skillValue, - spezBonus: dialogResult.spezLevel + 1, - }, - { title: rollFlavor }, - ); - } - - // The parsed terms of the roll formula - console.log("Roll:", roll); // [Die, OperatorTerm, NumericTerm, OperatorTerm, NumericTerm] - - // Execute the roll - await roll.evaluate(); - - const chatData = { - rolls: roll, - speaker: ChatMessage.getSpeaker(), - flags: { - "midgard6-lvd": { - title: rollFlavor, - }, - }, - }; - ChatMessage.applyMode(chatData, dialogResult.rollMode); - - await ChatMessage.create(chatData); - } } diff --git a/templates/dialog/nsc-fertigkeit-hinzufügen-dialog.hbs b/templates/dialog/nsc-fertigkeit-hinzufügen-dialog.hbs new file mode 100644 index 0000000..2c74431 --- /dev/null +++ b/templates/dialog/nsc-fertigkeit-hinzufügen-dialog.hbs @@ -0,0 +1,46 @@ +
+
+ {{localize "Midgard6.NSC.kompetenz.kompetenz"}} +
+
+ +
+
+ +

{{localize "Midgard6.NSC.kompetenz.kompetenz"}}:

+ + + + + + + + +
+
+
+
+
+
\ No newline at end of file diff --git a/templates/nsc/eigenschaften.hbs b/templates/nsc/eigenschaften.hbs index 273abd2..f877a15 100644 --- a/templates/nsc/eigenschaften.hbs +++ b/templates/nsc/eigenschaften.hbs @@ -65,15 +65,39 @@ {{/unless}} {{/if}} - {{#each fertigkeiten as |fertigkeit|}} + {{#each system.fertigkeiten as |fertigkeit|}}
+ {{#if @root.editable}} + {{#unless @root.system.locked}} + + + + + + + {{/unless}} + {{/if}} -

{{fertigkeit}}

+
+ {{fertigkeit.name}} +{{fertigkeit.wurf}} +
@@ -103,8 +127,9 @@
-- 2.54.0 From f6d41483c828e09f5ea8d507213e6789b7e4420b Mon Sep 17 00:00:00 2001 From: Byroks Date: Mon, 2 Nov 2026 15:35:17 +0100 Subject: [PATCH 3/3] Angriffe, Zauber & Merkmale Bug fix: Zauber konnten nicht Sortiert werden --- lang/de.json | 12 +- src/sheets/actor-sheet.mjs | 12 +- src/sheets/character-sheet.mjs | 5 +- src/sheets/components/character-prep.mjs | 17 +- src/sheets/components/nsc-prep.mjs | 70 +++++ src/sheets/components/roll-actions.mjs | 4 +- src/sheets/nsc-sheet.mjs | 92 ++++--- src/styles/M6.scss | 9 +- src/system.mjs | 8 + system.json | 3 +- templates/actor/items.hbs | 138 ++++------ templates/actor/zauber.hbs | 81 +++--- templates/dialog/roll-dialog.hbs | 2 +- templates/nsc/eigenschaften.hbs | 97 +++++-- templates/nsc/hintergrund.hbs | 320 ----------------------- templates/nsc/items.hbs | 138 ++++------ templates/nsc/zauber.hbs | 81 +++--- 17 files changed, 451 insertions(+), 638 deletions(-) create mode 100644 src/sheets/components/nsc-prep.mjs delete mode 100644 templates/nsc/hintergrund.hbs diff --git a/lang/de.json b/lang/de.json index 8d4517b..5ccc5f9 100644 --- a/lang/de.json +++ b/lang/de.json @@ -176,6 +176,15 @@ "würfe": "Kompetenz Würfe", "hinzufügen": "Kompetenz hinzufügen", "kompetenz": "Kompetenz" + }, + "angriff": { + "singular": "Angriff", + "plural": "Angriffe" + }, + "merkmal": { + "singular": "Merkmal", + "plural": "Merkmale", + "hinzufügen": "Merkmal hinzufügen" } }, "RollList": { @@ -213,7 +222,8 @@ "makel": "Makel", "schicksalsgabe": "Schicksalsgabe", "legende": "Legende", - "geld": "Geld" + "geld": "Geld", + "merkmal": "Merkmal" } } } diff --git a/src/sheets/actor-sheet.mjs b/src/sheets/actor-sheet.mjs index d3443fc..85ef54e 100644 --- a/src/sheets/actor-sheet.mjs +++ b/src/sheets/actor-sheet.mjs @@ -46,18 +46,21 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe _attachPartListeners(partId, html, bubble) { super._attachPartListeners(partId, html, bubble); - const collapsible = html.querySelectorAll("div[data-action=collapsible]"); + const collapsible = html.querySelectorAll("[data-action=collapsible]"); if (collapsible) { collapsible.forEach((node) => { node.addEventListener( "click", function (e) { e = window.event || e; + if (this === e.target) { - node.classList.toggle("active"); - var content = node.nextElementSibling; + const header = node.closest("div[data-action=collapsible]"); + header.classList.toggle("active"); + const content = header.nextElementSibling; content.classList.toggle("active"); - node.getElementsByTagName("i")[0].classList.toggle("fa-compress"); + const icon = node.closest(".fa-expand") || node.getElementsByTagName("i")[0]; + icon.classList.toggle("fa-compress"); } }, { capture: true }, @@ -508,7 +511,6 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe */ async _onDropItem(event, data) { if (!this.actor.isOwner) return false; - if (this.actor.items.get(data.itemId)) return this._onSortItem(event, data); const item = await Item.implementation.fromDropData(data); diff --git a/src/sheets/character-sheet.mjs b/src/sheets/character-sheet.mjs index 6f590a9..8cfc67d 100644 --- a/src/sheets/character-sheet.mjs +++ b/src/sheets/character-sheet.mjs @@ -114,6 +114,9 @@ export class M6CharacterSheet extends M6ActorSheet { flags: this.actor.flags, config: CONFIG, }); + + context.itemTypes = await super._getItems(); + return context; } @@ -135,12 +138,10 @@ export class M6CharacterSheet extends M6ActorSheet { context.tab = context.tabs[partId]; break; case "items": - context.itemTypes = await super._getItems(); context.gewicht = await prepWeight(this.actor); context.tab = context.tabs[partId]; break; case "zauber": - context.zauber = await this._getZauber(); context.tab = context.tabs[partId]; break; case "hintergrund": diff --git a/src/sheets/components/character-prep.mjs b/src/sheets/components/character-prep.mjs index 49a8560..d794da4 100644 --- a/src/sheets/components/character-prep.mjs +++ b/src/sheets/components/character-prep.mjs @@ -1,19 +1,16 @@ export async function prepArmor(actor) { const actorData = actor.system; - // 1. Basis-Wert festlegen let baseRüstwert = actorData.rüstwert.base || 0; - // 2. Ausgerüstete Rüstung finden und addieren const equippedMainArmor = actor.items.filter( - (i) => i.type === "armor" && i.system.equipped && !i.system.zusätzlich + (i) => i.type === "armor" && i.system.equipped && !i.system.zusätzlich, ); const equippedAddArmor = actor.items.filter( - (i) => i.type === "armor" && i.system.equipped && i.system.zusätzlich + (i) => i.type === "armor" && i.system.equipped && i.system.zusätzlich, ); let armorBonus = Math.max(...equippedMainArmor.map((x) => x.system.rüstwert), 0); for (let armor of equippedAddArmor) { armorBonus += armor.system.rüstwert; } - // 3. Finalen Standard-Wert berechnen actorData.rüstwert.mod = baseRüstwert + armorBonus; const armors = []; @@ -25,7 +22,7 @@ export async function prepArmor(actor) { name: armor.name, rüstwert: armor.system.rüstwert, img: armor.img, - id: armor.id + id: armor.id, }; armors.push(w); }); @@ -46,7 +43,7 @@ export async function prepWeapons(actor) { img: weapon.img, skillPath: weapon.system.fertigkeit, path: weapon.system.fertigkeit, - id: weapon.id + id: weapon.id, }; weapons.push(w); }); @@ -66,7 +63,7 @@ export async function prepSpells(actor) { img: spell.img, skillPath: "system.skills.magie.zaubern", path: "Zaubern", - id: spell.id + id: spell.id, }; spells.push(w); }); @@ -77,12 +74,12 @@ export async function prepWeight(actor) { const items = actor.items.filter((x) => x.system.gewicht && !x.system.equipped); let gewicht = items.reduce( (accumulator, item) => accumulator + item.system.gewicht * item.system.anzahl, - 0 + 0, ); let traglast = Math.max(actor.system.skills.körper.athletik.value, 10); return { traglast, - gewicht + gewicht, }; } diff --git a/src/sheets/components/nsc-prep.mjs b/src/sheets/components/nsc-prep.mjs new file mode 100644 index 0000000..9877597 --- /dev/null +++ b/src/sheets/components/nsc-prep.mjs @@ -0,0 +1,70 @@ +export async function prepArmor(actor) { + const actorData = actor.system; + let baseRüstwert = actorData.rüstwert.base || 0; + const equippedMainArmor = actor.items.filter( + (i) => i.type === "armor" && i.system.equipped && !i.system.zusätzlich, + ); + const equippedAddArmor = actor.items.filter( + (i) => i.type === "armor" && i.system.equipped && i.system.zusätzlich, + ); + let armorBonus = Math.max(...equippedMainArmor.map((x) => x.system.rüstwert), 0); + for (let armor of equippedAddArmor) { + armorBonus += armor.system.rüstwert; + } + actorData.rüstwert.mod = baseRüstwert + armorBonus; + + const armors = []; + const einschränkungen = []; + [...equippedMainArmor, ...equippedAddArmor]?.forEach((armor) => { + einschränkungen.push(...armor.system.merkmale); + + const w = { + name: armor.name, + rüstwert: armor.system.rüstwert, + img: armor.img, + id: armor.id, + }; + armors.push(w); + }); + + return { armors: armors, einschränkungen: [...new Set(einschränkungen)] }; +} + +export async function prepWeapons(actor) { + const weaponItems = actor.items.filter((x) => x.type === "weapon" && x.system.equipped); + const weapons = []; + weaponItems.forEach((weapon) => { + const skillValue = + actor.system.fertigkeiten.find((x) => x.name === weapon.fertigkeit)?.wurf || + Math.floor((actor.system.kompetenz + 8) / 2); + const w = { + name: weapon.name, + skillValue, + schaden: weapon.system.schaden, + img: weapon.img, + id: weapon.id, + }; + weapons.push(w); + }); + return weapons; +} + +export async function prepSpells(actor) { + const spellItems = actor.items.filter((x) => x.type === "zauber" && x.system.equipped); + const spells = []; + const skillValue = + actor.system.fertigkeiten.find((x) => x.name === "Zaubern")?.wurf || + Math.floor((actor.system.kompetenz + 8) / 2); + spellItems.forEach((spell) => { + const w = { + name: spell.name, + skillValue, + schaden: spell.system.eigenschaften.schaden, + img: spell.img, + path: "Zaubern", + id: spell.id, + }; + spells.push(w); + }); + return spells; +} diff --git a/src/sheets/components/roll-actions.mjs b/src/sheets/components/roll-actions.mjs index 99163f4..b5404f5 100644 --- a/src/sheets/components/roll-actions.mjs +++ b/src/sheets/components/roll-actions.mjs @@ -267,8 +267,8 @@ export async function rollWeapon(event, target) { export async function rollDialog(rollDialogRequest) { // Assamble dialog depending on roll type let label = rollDialogRequest.name; - let skillValue = rollDialogRequest.skill.value || rollDialogRequest.skill; - let bonuses = rollDialogRequest.skill.bonuses || []; + let skillValue = rollDialogRequest.skill?.value || rollDialogRequest.skill; + let bonuses = rollDialogRequest.skill?.bonuses || []; let damageRoll = rollDialogRequest.damageRoll || ""; let preSelectedSpez = rollDialogRequest.preSelectedSpez || ""; let vorteil = 0; diff --git a/src/sheets/nsc-sheet.mjs b/src/sheets/nsc-sheet.mjs index 691e66b..c288e67 100644 --- a/src/sheets/nsc-sheet.mjs +++ b/src/sheets/nsc-sheet.mjs @@ -1,7 +1,7 @@ import { systemPath } from "../constants.mjs"; import { prepareActiveEffectCategories } from "../helpers/utils.mjs"; import { addSpezialisierung, editSepzialisierung } from "./components/spezialisierung-actions.mjs"; -import { prepArmor, prepWeapons, prepWeight, prepSpells } from "./components/character-prep.mjs"; +import { prepArmor, prepWeapons, prepWeight, prepSpells } from "./components/nsc-prep.mjs"; import { rollSpell, rollWeapon, rollSkill, rollDialog } from "./components/roll-actions.mjs"; import { M6ActorSheet } from "./actor-sheet.mjs"; @@ -19,6 +19,7 @@ export class M6NSCSheet extends M6ActorSheet { ...super.DEFAULT_OPTIONS.actions, // Kopiert alle bestehenden Actions aus M6ActorSheet cycleEquip: this.#cycleEquip, rollKompetenz: this.#rollKompetenz, + // rollWeapon: this.#rollWeapon, rollSpell: rollSpell, cycleEquip: this.#cycleEquip, addKompetenz: this.#addKompetenz, @@ -75,15 +76,15 @@ export class M6NSCSheet extends M6ActorSheet { scrollable: [""], }, zauber: { - template: systemPath("templates/nsc/zauber.hbs"), + template: systemPath("templates/actor/zauber.hbs"), scrollable: [""], }, items: { - template: systemPath("templates/nsc/items.hbs"), + template: systemPath("templates/actor/items.hbs"), scrollable: [""], }, biographie: { - template: systemPath("templates/nsc/biographie.hbs"), + template: systemPath("templates/actor/biographie.hbs"), scrollable: [""], }, // effects: { @@ -116,6 +117,10 @@ export class M6NSCSheet extends M6ActorSheet { switch (partId) { case "eigenschaften": context.kompetenzWürfe = await this.calcKompetenzWürfe(); + context.itemTypes = await super._getItems(); + context.armor = await prepArmor(this.actor); + context.equippedWeapons = await prepWeapons(this.actor); + context.equippedSpells = await prepSpells(this.actor); context.tab = context.tabs[partId]; break; case "effects": @@ -123,11 +128,9 @@ export class M6NSCSheet extends M6ActorSheet { context.tab = context.tabs[partId]; break; case "items": - context.itemTypes = await super._getItems(); context.tab = context.tabs[partId]; break; case "zauber": - context.zauber = await this._getZauber(); context.tab = context.tabs[partId]; break; case "biographie": @@ -255,7 +258,6 @@ export class M6NSCSheet extends M6ActorSheet { fieldset.fields.push({ field, value: foundry.utils.getProperty(source, path), - localizationName: "Midgard6.Skills." + field.label, }); } } @@ -431,7 +433,6 @@ export class M6NSCSheet extends M6ActorSheet { label: "Midgard6.Dialog.speichern", default: true, callback: async (event, button, dialog) => { - console.warn(resistenzen); await this.actor.update({ [`system.resistenzen`]: resistenzen }); }, }, @@ -441,11 +442,14 @@ export class M6NSCSheet extends M6ActorSheet { static async #rollKompetenz(event, target) { const dataset = target.dataset; - const kompetenz = dataset.kompetenz; + const kompetenz = dataset.kompetenz || ""; const kompetenzValue = dataset.kompetenzValue; + const schaden = dataset.schaden; + const item = this.actor.items.get(dataset.itemId); const dialogResult = await rollDialog({ skill: kompetenzValue, + damageRoll: schaden, }); console.log("Dialog Result", dialogResult); @@ -466,45 +470,65 @@ export class M6NSCSheet extends M6ActorSheet { die = "1d20"; break; } - - let rollTerm = "@die + @skill"; - let rollFlavor = kompetenz; - let roll; - - if (dialogResult.spezLevel) { - rollTerm += " + @spezBonus"; - rollFlavor += ": " + dialogResult.spezName; + let rollFlavor = dataset.name ?? kompetenz; + let rolls; + if (dialogResult.customRoll) { + rolls = [await new Roll(dialogResult.customRoll, {}, { title: rollFlavor }).evaluate()]; + } else { + rolls = [ + await new Roll( + "@die + @skill", + { + die: die, + skill: skillValue, + spezBonus: dialogResult.spezLevel + 1, + }, + { title: rollFlavor }, + ).evaluate(), + ]; } - if (dialogResult.customRoll) { - roll = new Roll(dialogResult.customRoll, {}, { title: rollFlavor }); - } else { - roll = new Roll( - rollTerm, - { - die: die, - skill: skillValue, - spezBonus: dialogResult.spezLevel + 1, - }, - { title: rollFlavor }, + if (dialogResult.customDamageRoll) { + rolls.push( + await new Roll( + "@die", + { die: dialogResult.customDamageRoll }, + { title: game.i18n.localize("Midgard6.Schaden") }, + ).evaluate(), + ); + } else if (schaden) { + rolls.push( + await new Roll( + "@die", + { die: schaden }, + { title: game.i18n.localize("Midgard6.Schaden") }, + ).evaluate(), ); } - // The parsed terms of the roll formula - console.log("Roll:", roll); // [Die, OperatorTerm, NumericTerm, OperatorTerm, NumericTerm] - - // Execute the roll - await roll.evaluate(); + console.log("Roll:", rolls); const chatData = { - rolls: roll, + rolls: rolls, speaker: ChatMessage.getSpeaker(), flags: { "midgard6-lvd": { title: rollFlavor, + eigenschaften: item?.system?.eigenschaften, + merkmale: item?.system?.merkmale, + isSpell: item?.type === "zauber", + beschreibung: await foundry.applications.ux.TextEditor.implementation.enrichHTML( + item?.system?.beschreibung, + { + secrets: false, + rollData: this.actor.getRollData(), + relativeTo: this.actor, + }, + ), }, }, }; + ChatMessage.applyMode(chatData, dialogResult.rollMode); await ChatMessage.create(chatData); diff --git a/src/styles/M6.scss b/src/styles/M6.scss index f75301f..410d234 100644 --- a/src/styles/M6.scss +++ b/src/styles/M6.scss @@ -99,10 +99,17 @@ border-radius: 0; transition: none; margin-bottom: 4px; - option:hover { + border: none; + > :nth-child(odd) { + background-color: var(--M6-background-grey); + } + > :hover { background-color: var(--M6-background-brown); } } + select:focus { + outline: none; + } p { &.center { text-align: center; diff --git a/src/system.mjs b/src/system.mjs index 25daab7..7fef784 100644 --- a/src/system.mjs +++ b/src/system.mjs @@ -108,6 +108,14 @@ Hooks.once("init", () => { types: ["legende"], }, ); + foundry.applications.apps.DocumentSheetConfig.registerSheet( + Item, + "midgard6-lvd", + M6HintergrundSheet, + { + types: ["merkmal"], + }, + ); loadSettings(); diff --git a/system.json b/system.json index 568aec4..82241b9 100644 --- a/system.json +++ b/system.json @@ -42,7 +42,8 @@ "makel": {}, "schicksalsgabe": {}, "legende": {}, - "geld": {} + "geld": {}, + "merkmal": {} } }, "compatibility": { diff --git a/templates/actor/items.hbs b/templates/actor/items.hbs index 3f8fb69..e33513e 100644 --- a/templates/actor/items.hbs +++ b/templates/actor/items.hbs @@ -4,25 +4,22 @@
- {{localize "Midgard6.Item.type.münze.plural" }} + {{localize "Midgard6.Item.type.münze.plural" }} + {{#if @root.editable}} + {{#unless system.locked}} + + + + {{/unless}} + {{/if}} +
- {{localize "Midgard6.Item.type.item.plural" }} + {{localize "Midgard6.Item.type.item.plural" }} + {{#if @root.editable}} + {{#unless system.locked}} + + + + {{/unless}} + {{/if}} +
    {{#with itemTypes.item}} -
  • -
    - {{#if @root.editable}} - - - {{localize "DOCUMENT.Create" type=this.label}} - - {{/if}} -
    -
    • {{#each this.items as |item|}}
    • @@ -120,25 +114,22 @@ {{!-- Waffen --}}
      - {{localize "Midgard6.Item.type.weapon.plural" }} + {{localize "Midgard6.Item.type.weapon.plural" }} + {{#if @root.editable}} + {{#unless system.locked}} + + + + {{/unless}} + {{/if}} +
      {{!-- Rüstung --}} -
      - {{localize "Midgard6.Item.type.armor.plural" }} + {{localize "Midgard6.Item.type.armor.plural" }} + {{#if @root.editable}} + {{#unless system.locked}} + + + + {{/unless}} + {{/if}} +
-
-
- {{localize "Midgard6.Traglast"}}: {{gewicht.gewicht}} / {{gewicht.traglast}} - -
- -
-
-
\ No newline at end of file diff --git a/templates/actor/zauber.hbs b/templates/actor/zauber.hbs index d04cdee..ffe5952 100644 --- a/templates/actor/zauber.hbs +++ b/templates/actor/zauber.hbs @@ -4,53 +4,52 @@
- {{localize "Midgard6.Item.type.zauber.plural" }} + {{localize "Midgard6.Item.type.zauber.plural" }} + {{#if @root.editable}} + {{#unless system.locked}} + + + + {{/unless}} + {{/if}} +
    -
  • -
    - {{#if @root.editable}} - - - {{localize "DOCUMENT.Create" type="Zauber"}} - - {{/if}} -
    -
    • - {{#each zauber as |zauber|}} -
    • -

      {{zauber.name}}

      -

      {{zauber.system.eigenschaften.ursprung}}

      -

      {{localize "Midgard6.Zauber.stufe"}} {{zauber.system.eigenschaften.stufe}}

      - - -
      - {{#if @root.editable}} - - - + {{#with itemTypes.zauber}} + {{#each this.items as |zauber|}} +
    • +

      {{zauber.name}}

      +

      {{zauber.system.eigenschaften.ursprung}}

      +

      {{localize "Midgard6.Zauber.stufe"}} {{zauber.system.eigenschaften.stufe}}

      + + +
      + {{#if @root.editable}} - + - {{/if}} -
      -
    • - {{/each}} + + + + {{/if}} +
+ + {{/each}} + {{/with}}
diff --git a/templates/dialog/roll-dialog.hbs b/templates/dialog/roll-dialog.hbs index a8a3994..3f89023 100644 --- a/templates/dialog/roll-dialog.hbs +++ b/templates/dialog/roll-dialog.hbs @@ -46,7 +46,7 @@ {{#if damageRoll}} {{#each system.fertigkeiten as |fertigkeit|}}
-
+
{{#if @root.editable}} {{#unless @root.system.locked}} {{/each}} +
+ + {{localize "Midgard6.NSC.merkmal.plural"}} + {{#if @root.editable}} + {{#unless system.locked}} + + + + {{/unless}} + {{/if}} + +
+
+ {{#with itemTypes.merkmal}} + {{#each this.items as |merkmal|}} +
{{merkmal.name}} +
+ + + + {{#if @root.editable}} + {{#unless @root.system.locked}} + + + + + + + {{/unless}} + {{/if}} +
+
+ +
+ {{{merkmal.system.beschreibung}}} +
+ {{/each}} + {{/with}} +
+
+
@@ -203,9 +265,11 @@
- {{!--
+
- {{localize "Midgard6.Item.type.weapon.plural" }} + + {{localize "Midgard6.NSC.angriff.plural" }} +
{{#each equippedWeapons as |weapon|}}
@@ -215,16 +279,18 @@

{{weapon.name}}:

- + {{weapon.skillValue}} {{#if weapon.bonusValue}}+ {{weapon.bonusValue}}{{/if}}

+ + {{weapon.skillValue}}

--}} +
diff --git a/templates/nsc/hintergrund.hbs b/templates/nsc/hintergrund.hbs deleted file mode 100644 index 695100b..0000000 --- a/templates/nsc/hintergrund.hbs +++ /dev/null @@ -1,320 +0,0 @@ -{{! Beschreibung Allgemein Tab }} -
-
-
-
-
- {{localize "Midgard6.Grad.grad"}} -
- -

{{localize - "Midgard6.Grad.erfahrung" - }}

-
- - -
-

+

-
- - -
- -

=

-
- - -
- -
-
-
- -
- -
-
- {{localize "Midgard6.Hintergrund.type.legende.plural"}} -
-
- {{#with itemTypes.legende}} -
-
- {{#if @root.editable}} - - - {{localize "DOCUMENT.Create" type=this.label}} - - {{/if}} -
-
- {{#each this.items as |legende|}} -
{{legende.name}} -
- - - {{#if @root.editable}} - - - - - - - {{/if}} -
-
- -
- {{{legende.system.beschreibung}}} -
- {{/each}} - {{/with}} -
-
-
-
- -
-
- {{localize "Midgard6.Hintergrund.type.schicksalsgabe.plural"}} -
-
- {{#with itemTypes.schicksalsgabe}} -
-
- {{#if @root.editable}} - - - {{localize "DOCUMENT.Create" type=this.label}} - - {{/if}} -
-
- {{#each this.items as |schicksalsgabe|}} -
{{schicksalsgabe.name}} -
- - {{#if @root.editable}} - - - - - - - {{/if}} -
-
- -
- {{{gunst.system.beschreibung}}} -
- {{/each}} - {{/with}} -
-
-
-
-
-
-
\ No newline at end of file diff --git a/templates/nsc/items.hbs b/templates/nsc/items.hbs index 3f8fb69..e33513e 100644 --- a/templates/nsc/items.hbs +++ b/templates/nsc/items.hbs @@ -4,25 +4,22 @@
- {{localize "Midgard6.Item.type.münze.plural" }} + {{localize "Midgard6.Item.type.münze.plural" }} + {{#if @root.editable}} + {{#unless system.locked}} + + + + {{/unless}} + {{/if}} +
- {{localize "Midgard6.Item.type.item.plural" }} + {{localize "Midgard6.Item.type.item.plural" }} + {{#if @root.editable}} + {{#unless system.locked}} + + + + {{/unless}} + {{/if}} +
    {{#with itemTypes.item}} -
  • -
    - {{#if @root.editable}} - - - {{localize "DOCUMENT.Create" type=this.label}} - - {{/if}} -
    -
    • {{#each this.items as |item|}}
    • @@ -120,25 +114,22 @@ {{!-- Waffen --}}
      - {{localize "Midgard6.Item.type.weapon.plural" }} + {{localize "Midgard6.Item.type.weapon.plural" }} + {{#if @root.editable}} + {{#unless system.locked}} + + + + {{/unless}} + {{/if}} +
      {{!-- Rüstung --}} -
      - {{localize "Midgard6.Item.type.armor.plural" }} + {{localize "Midgard6.Item.type.armor.plural" }} + {{#if @root.editable}} + {{#unless system.locked}} + + + + {{/unless}} + {{/if}} +
-
-
- {{localize "Midgard6.Traglast"}}: {{gewicht.gewicht}} / {{gewicht.traglast}} - -
- -
-
-
\ No newline at end of file diff --git a/templates/nsc/zauber.hbs b/templates/nsc/zauber.hbs index d04cdee..3e33e6c 100644 --- a/templates/nsc/zauber.hbs +++ b/templates/nsc/zauber.hbs @@ -4,53 +4,52 @@
- {{localize "Midgard6.Item.type.zauber.plural" }} + {{localize "Midgard6.Item.type.zauber.plural" }} + {{#if @root.editable}} + {{#unless system.locked}} + + + + {{/unless}} + {{/if}} +
    -
  • -
    - {{#if @root.editable}} - - - {{localize "DOCUMENT.Create" type="Zauber"}} - - {{/if}} -
    -
    • - {{#each zauber as |zauber|}} -
    • -

      {{zauber.name}}

      -

      {{zauber.system.eigenschaften.ursprung}}

      -

      {{localize "Midgard6.Zauber.stufe"}} {{zauber.system.eigenschaften.stufe}}

      - - -
      - {{#if @root.editable}} - - - + {{#with itemTypes.zauber}} + {{#each this.item as |zauber|}} +
    • +

      {{zauber.name}}

      +

      {{zauber.system.eigenschaften.ursprung}}

      +

      {{localize "Midgard6.Zauber.stufe"}} {{zauber.system.eigenschaften.stufe}}

      + + +
      + {{#if @root.editable}} - + - {{/if}} -
      -
    • - {{/each}} + + + + {{/if}} +
+ + {{/each}} + {{/with}}
-- 2.54.0