diff --git a/assets/sword.svg b/assets/sword.svg new file mode 100644 index 0000000..d19ad05 --- /dev/null +++ b/assets/sword.svg @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/lang/de.json b/lang/de.json index 75ef8f2..6bce8ce 100644 --- a/lang/de.json +++ b/lang/de.json @@ -1,6 +1,8 @@ { "Midgard6": { "name": "Name", + "Angriff": "Angriff", + "Schaden": "Schaden", "Biography": { "spezies": "Spezies", "kultur": "Kultur", @@ -75,7 +77,22 @@ }, "Item": { "Quantity": "Anzahl", - "Description": "Beschreibung" + "Description": "Beschreibung", + "Eigenschaften": "Eigenschaften", + "type": { + "item": { + "singular": "Gegenstand", + "plural": "Gegenstände" + }, + "weapon": { + "singular": "Waffe", + "plural": "Waffen" + }, + "armor": { + "singular": "Rüstung", + "plural": "Rüstungen" + } + } } }, "TYPES": { @@ -84,7 +101,8 @@ }, "Item": { "item": "Gegenstand", - "spezialisierung": "Spezialisierung" + "weapon": "Waffe", + "armor": "Rüstung" } } } diff --git a/src/constants.mjs b/src/constants.mjs index dfdf2d9..9afc4b6 100644 --- a/src/constants.mjs +++ b/src/constants.mjs @@ -6,3 +6,6 @@ export const systemID = "midgard6-lvd"; * @returns {string} The path relative to the Foundry data folder. */ export const systemPath = (path) => `systems/${systemID}/src/${path}`; +export const assetPath = (path) => `systems/${systemID}/assets/${path}`; + +export const swordSVG = "systems/midgard6-lvd/assets/sword.svg"; diff --git a/src/data/armor-data.mjs b/src/data/armor-data.mjs new file mode 100644 index 0000000..a6493d8 --- /dev/null +++ b/src/data/armor-data.mjs @@ -0,0 +1,22 @@ +import { ItemData } from "./item-data.mjs"; + +function defineSchema() { + const fields = foundry.data.fields; + const baseData = ItemData.defineSchema(); + const extendData = { + rüstung: new fields.NumberField({ + required: true, + nullable: false, + integer: true, + initial: 1, + min: 0 + }), + equipped: new fields.BooleanField({ inital: false }) + }; + + return Object.assign(baseData, extendData); +} + +export class ArmorData extends ItemData { + static defineSchema = defineSchema; +} diff --git a/src/data/weapon-data.mjs b/src/data/weapon-data.mjs new file mode 100644 index 0000000..4b198e4 --- /dev/null +++ b/src/data/weapon-data.mjs @@ -0,0 +1,19 @@ +import { ItemData } from "./item-data.mjs"; + +function defineSchema() { + const fields = foundry.data.fields; + const baseData = ItemData.defineSchema(); + const extendData = { + schaden: new fields.StringField({ initial: "1d6" }), + equipped: new fields.BooleanField({ inital: false }), + fertigkeit: new fields.StringField({ initial: "system.skills.kampf.nahkampf" }), + spezialisierung: new fields.StringField({ initial: "" }), + customRoll: new fields.StringField({ initial: "" }) + }; + + return Object.assign(baseData, extendData); +} + +export class WeaponData extends ItemData { + static defineSchema = defineSchema; +} diff --git a/src/helpers/handlebar-helpers.mjs b/src/helpers/handlebar-helpers.mjs index 73bbae0..8018d83 100644 --- a/src/helpers/handlebar-helpers.mjs +++ b/src/helpers/handlebar-helpers.mjs @@ -2,4 +2,17 @@ export const loadHelpers = async function () { Handlebars.registerHelper("ifeq", function (arg1, arg2, options) { return arg1 == arg2 ? options.fn(this) : options.inverse(this); }); + + Handlebars.registerHelper("fetchPath", function (actor, arg1, arg2 = "") { + let arg = arg1; + if (typeof arg2 === "string") { + arg = arg + "" + arg2; + } + console.warn(actor, arg); + return foundry.utils.getProperty(actor, arg); + }); + + Handlebars.registerHelper("isdefined", function (value) { + return value !== undefined; + }); }; diff --git a/src/sheets/armor-sheet.mjs b/src/sheets/armor-sheet.mjs new file mode 100644 index 0000000..ba93422 --- /dev/null +++ b/src/sheets/armor-sheet.mjs @@ -0,0 +1,27 @@ +import { prepareActiveEffectCategories } from "../helpers/utils.mjs"; +import { systemPath } from "../constants.mjs"; +import { M6ItemSheet } from "./item-sheet.mjs"; +const { api, sheets } = foundry.applications; + +/** + * Extend the basic ItemSheet with some very simple modifications. + */ +export class M6ArmorSheet extends M6ItemSheet { + static get DEFAULT_OPTIONS() { + return { + ...super.DEFAULT_OPTIONS, // Kopiert alle bestehenden Actions aus M6ItemSheet + actions: { + ...super.DEFAULT_OPTIONS.actions, + cycleEquip: this.#cycleEquip // Fügt NUR für dieses Sheet die neue Action hinzu + } + }; + } + + static #cycleEquip() { + this.item.update({ + system: { + equipped: !this.item.system.equipped + } + }); + } +} diff --git a/src/sheets/character-sheet.mjs b/src/sheets/character-sheet.mjs index 08429d5..be64d1d 100644 --- a/src/sheets/character-sheet.mjs +++ b/src/sheets/character-sheet.mjs @@ -24,12 +24,15 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe deleteDoc: this.#deleteDoc, toggleEffect: this.#toggleEffect, rollSkill: this.#rollSkill, + rollWeapon: this.#rollWeapon, + cycleEquip: this.#cycleEquip, addSpezialisierung: addSpezialisierung, editSepzialisierung: editSepzialisierung }, form: { submitOnChange: true - } + }, + dragDrop: [{ dragSelector: ".draggable", dropSelector: null }] }; /* -------------------------------------------------- */ @@ -39,12 +42,16 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe tabs: [ { id: "properties", - icon: "fa-feather-pointed" + icon: "fa-shield-halved" }, { id: "items", icon: "fa-suitcase" }, + { + id: "biographie", + icon: "fa-feather" + }, { id: "effects", icon: "fa-bolt" @@ -73,6 +80,10 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe template: systemPath("templates/actor/items.hbs"), scrollable: [""] }, + // biographie: { + // template: systemPath("templates/items/description.hbs"), + // scrollable: [""] + // }, effects: { template: systemPath("templates/shared/effects.hbs"), scrollable: [""] @@ -125,10 +136,11 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe case "properties": context.skills = await this._getSkills(); context.resistenzen = await this._getResistenzen(); + context.equippedWeapons = await this._prepWeapons(); context.tab = context.tabs[partId]; break; case "items": - context.itemTypes = this._getItems(); + context.itemTypes = await this._getItems(); context.gewicht = this._clacWeight(); context.tab = context.tabs[partId]; break; @@ -245,6 +257,35 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe return fieldSets; } + async _prepWeapons() { + const weaponItems = this.actor.items.filter((x) => x.type === "weapon" && x.system.equipped); + const weapons = []; + weaponItems.forEach((weapon) => { + const skill = foundry.utils.getProperty(this.actor, weapon.system.fertigkeit); + const w = { + name: weapon.name, + skillValue: skill.value, + bonusValue: + skill.bonuses.find((x) => x.name === weapon.system.spezialisierung)?.level + 1 || "", + img: weapon.img, + skillPath: weapon.system.fertigkeit, + path: weapon.system.fertigkeit, + id: weapon.id + }; + weapons.push(w); + }); + return weapons; + } + + static async #cycleEquip(event, target) { + const item = this.actor.items.get(target.dataset.itemId); + item.update({ + system: { + equipped: !item.system.equipped + } + }); + } + /* -------------------------------------------------- */ /** @@ -279,17 +320,18 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe 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; } _clacWeight() { - const items = this._getItems(); - let gewicht = items.item.items.reduce( - (accumulator, item) => accumulator + item.system.gewicht, - 0 - ); + const items = this.actor.items.filter((x) => x.system.gewicht); + let gewicht = items.reduce((accumulator, item) => accumulator + item.system.gewicht, 0); let traglast = Math.max(this.actor.system.skills.körper.athletik.value, 10); return { @@ -394,8 +436,8 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe skill, actor }); - console.warn(dialogResult); - if (dialogResult.noRoll) { + console.log("Dialog Result", dialogResult); + if (!dialogResult) { return; } // Construct the Roll instance @@ -441,11 +483,83 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe roll.toMessage(); } + static async #rollWeapon(event, target) { + const dataset = target.dataset; + const weapon = this.actor.items.get(dataset.itemId); + const skill = foundry.utils.getProperty(this.actor, weapon.system.fertigkeit); + const actor = this.actor; + const dialogResult = await this.rollDialog({ + name: weapon.name, + skill, + damageRoll: weapon.system.schaden, + preSelectedSpez: weapon.system.spezialisierung, + actor + }); + console.log("Dialog Result", dialogResult); + if (!dialogResult) { + return; + } + // Construct the Roll instance + const skillValue = skill.value; + 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.Angriff"); + let attackRoll; + let damageRoll; + + if (dialogResult.spezLevel) { + rollTerm += " + @spezBonus"; + rollFlavor += " (" + dialogResult.spezName + ")"; + } + rollFlavor += ": " + weapon.name; + + if (dialogResult.customRoll) { + attackRoll = await new Roll(dialogResult.customRoll).evaluate(); + } else { + attackRoll = await new Roll( + rollTerm, + { die: die, skill: skillValue, spezBonus: dialogResult.spezLevel + 1 }, + { flavor: rollFlavor } + ).evaluate(); + } + + damageRoll = await new Roll( + "@die", + { die: weapon.system.schaden }, + { flavor: game.i18n.localize("Midgard6.Schaden") } + ).evaluate(); + + // The parsed terms of the roll formula + + const chatData = { + user: game.user.id, + rolls: [attackRoll, damageRoll] // Übergibt beide Rolls an die Nachricht + }; + + console.log("Roll:", chatData.rolls); + + await ChatMessage.create(chatData); + } + async 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 damageRoll = rollDialogRequest.damageRoll || ""; + let preSelectedSpez = rollDialogRequest.preSelectedSpez || ""; let vorteil = 0; let customRoll = ""; let spezLevel; @@ -453,10 +567,11 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe // 1. Define the path to .hbs template const templatePath = systemPath("templates/dialog/roll-dialog.hbs"); const templateData = { - classes: ["M6", "dialog"], skillValue, bonuses, vorteil, + damageRoll, + preSelectedSpez, customRoll }; // 2. Render the Handlebars template into an HTML string @@ -471,6 +586,7 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe position: { width: 600 }, + classes: ["M6", "dialog"], content, actions: {}, render: (_event, dialog) => { @@ -499,9 +615,13 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe document.querySelectorAll('input[name="spezialisierung-segment"]').forEach((radio) => { radio.addEventListener("change", (e) => { + console.log(e.target.dataset.name); spezLevel = parseInt(e.target.value); spezName = e.target.dataset.name; }); + if (radio.dataset.name === preSelectedSpez) { + radio.click(); + } }); }, buttons: [ @@ -509,7 +629,7 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe action: "abort", label: "Midgard6.Dialog.abbrechen", callback: (event, button, dialog) => { - return { noRoll: true }; + return null; } }, { @@ -519,6 +639,7 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe callback: (event, button, dialog) => { const rollData = { customRoll: button.form.elements.customRoll.value, + customDamageRoll: button.form.elements.customDamageRoll?.value || "", vorteil, spezLevel, spezName @@ -577,7 +698,7 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe /* -------------------------------------------------- */ /** - * Disables inpM6 subject to active effects. + * Disables inputs subject to active effects. */ #disableOverrides() { const flatOverrides = foundry.utils.flattenObject(this.actor.overrides); @@ -586,4 +707,275 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe 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; + } + + /* -------------------------------------------------- */ + + /** + * 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; + + // Prüfen, ob das Item von diesem Actor stammt und Shift NICHT gedrückt ist + // Sortieren, nicht kopieren/verschieben + return this._onSortItem(event, data); + } + + /** + * 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)); + } + // item = items.get(item.itemId); + + // 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/item-sheet.mjs b/src/sheets/item-sheet.mjs index 2895f72..65905da 100644 --- a/src/sheets/item-sheet.mjs +++ b/src/sheets/item-sheet.mjs @@ -7,6 +7,7 @@ const { api, sheets } = foundry.applications; */ export class M6ItemSheet extends api.HandlebarsApplicationMixin(sheets.ItemSheet) { /** @inheritdoc */ + static DEFAULT_OPTIONS = { window: { resizable: true @@ -35,7 +36,7 @@ export class M6ItemSheet extends api.HandlebarsApplicationMixin(sheets.ItemSheet primary: { tabs: [ { - id: "description", + id: "beschreibung", icon: "fa-feather-pointed" }, { @@ -43,8 +44,8 @@ export class M6ItemSheet extends api.HandlebarsApplicationMixin(sheets.ItemSheet icon: "fa-bolt" } ], - initial: "description", - labelPrefix: "M6.Sheets.Tabs" + initial: "beschreibung", + labelPrefix: "Midgard6.Sheets.Tabs" } }; @@ -58,7 +59,7 @@ export class M6ItemSheet extends api.HandlebarsApplicationMixin(sheets.ItemSheet tabs: { template: systemPath("templates/actor/tabs.hbs") }, - description: { + beschreibung: { template: systemPath("templates/item/description.hbs"), scrollable: [""] }, @@ -109,7 +110,7 @@ export class M6ItemSheet extends api.HandlebarsApplicationMixin(sheets.ItemSheet context.effects = prepareActiveEffectCategories(this.item.effects); context.tab = context.tabs[partId]; break; - case "description": + case "beschreibung": context.fields = await this._getFields(); context.enrichedBeschreibung = await foundry.applications.ux.TextEditor.implementation.enrichHTML( @@ -125,6 +126,9 @@ export class M6ItemSheet extends api.HandlebarsApplicationMixin(sheets.ItemSheet ); context.tab = context.tabs[partId]; break; + default: + await this._addSpecifics(context); + context.tab = context.tabs[partId]; } return context; } @@ -338,8 +342,10 @@ export class M6ItemSheet extends api.HandlebarsApplicationMixin(sheets.ItemSheet async _onDrop(event) { const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event); const item = this.item; + console.warn(data.type); + const allowed = Hooks.call("dropItemSheetData", item, this, data); - if (allowed === false) return; + // if (allowed === false) return; // Handle different data types switch (data.type) { @@ -436,6 +442,55 @@ export class M6ItemSheet extends api.HandlebarsApplicationMixin(sheets.ItemSheet */ async _onDropItem(event, data) { if (!this.item.isOwner) return false; + + // Prüfen, ob das Item von diesem Actor stammt und Shift NICHT gedrückt ist + const isSameActor = this.actor.uuid === item.parent?.uuid; + const isShift = event.shiftKey; + console.warn(isSameActor); + + if (isSameActor) { + console.warn("here"); + // Sortieren, nicht kopieren/verschieben + return this._onSortItem(event, item); + } + } + + /** + * 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]"); + if (!dropTarget) return; + const target = items.get(dropTarget.dataset.itemId); + + // Don't sort on yourself + if (item.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 !== item.id) siblings.push(items.get(el.dataset.itemId)); + } + + // Perform the sort + const sortUpdates = foundry.utils.SortingHelpers.performIntegerSort(item, { + 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); } /* -------------------------------------------------- */ @@ -490,4 +545,8 @@ export class M6ItemSheet extends api.HandlebarsApplicationMixin(sheets.ItemSheet return new foundry.applications.ux.DragDrop(d); }); } + + async _addSpecifics(context) { + return null; + } } diff --git a/src/sheets/weapon-sheet.mjs b/src/sheets/weapon-sheet.mjs new file mode 100644 index 0000000..f1f265b --- /dev/null +++ b/src/sheets/weapon-sheet.mjs @@ -0,0 +1,74 @@ +import { prepareActiveEffectCategories } from "../helpers/utils.mjs"; +import { systemPath } from "../constants.mjs"; +import { M6ItemSheet } from "./item-sheet.mjs"; +const { api, sheets } = foundry.applications; + +/** + * Extend the basic ItemSheet with some very simple modifications. + */ +export class M6WeaponSheet extends M6ItemSheet { + static get DEFAULT_OPTIONS() { + return { + ...super.DEFAULT_OPTIONS, // Kopiert alle bestehenden Actions aus M6ItemSheet + actions: { + ...super.DEFAULT_OPTIONS.actions, + cycleEquip: this.#cycleEquip // Fügt NUR für dieses Sheet die neue Action hinzu + } + }; + } + + static TABS = { + primary: { + tabs: [ + { + id: "eigenschaften", + icon: "fa-shield-halved" + }, + { + id: "beschreibung", + icon: "fa-feather-pointed" + }, + { + id: "effects", + icon: "fa-bolt" + } + ], + initial: "eigenschaften", + labelPrefix: "Midgard6.Sheets.Tabs" + } + }; + + /** @inheritdoc */ + static PARTS = { + header: { + template: systemPath("templates/item/header.hbs") + }, + tabs: { + template: systemPath("templates/actor/tabs.hbs") + }, + eigenschaften: { + template: systemPath("templates/item/eigenschaften.hbs"), + scrollable: [""] + }, + beschreibung: { + template: systemPath("templates/item/description.hbs"), + scrollable: [""] + }, + effects: { + template: systemPath("templates/shared/effects.hbs"), + scrollable: [""] + } + }; + + _addSpecifics(context) { + context.bonuses = foundry.utils.getProperty(this.actor, this.item.system.fertigkeit).bonuses; + } + + static #cycleEquip() { + this.item.update({ + system: { + equipped: !this.item.system.equipped + } + }); + } +} diff --git a/src/styles/M6.scss b/src/styles/M6.scss index 458b18f..896c697 100644 --- a/src/styles/M6.scss +++ b/src/styles/M6.scss @@ -4,6 +4,7 @@ @import url("./resistenzen.scss"); @import url("./dialog.scss"); @import url("./items-page.scss"); +@import url("./icons.scss"); :root { --M6-background-grey: #d3d7d7; @@ -43,7 +44,7 @@ overflow: visible; } -.application.sheet.M6 { +.M6 { background-color: var(--M6-background-white); color: var(--M6-text-grey); @@ -51,6 +52,7 @@ background-color: var(--M6-background-white); color: black; border-radius: 0; + transition: none; &.skill { max-width: 2rem; text-align: center; @@ -63,6 +65,9 @@ margin: 0 0.5rem; } &.text { + &.center { + text-align: center; + } &.right { text-align: end; } @@ -71,6 +76,17 @@ input:focus { outline: none; } + + select { + background-color: var(--M6-background-white); + color: black; + border-radius: 0; + transition: none; + margin-bottom: 4px; + option:hover { + background-color: var(--M6-background-brown); + } + } p { &.center { text-align: center; diff --git a/src/styles/dialog.scss b/src/styles/dialog.scss index 98e96a7..c1ae867 100644 --- a/src/styles/dialog.scss +++ b/src/styles/dialog.scss @@ -1,4 +1,4 @@ -.application.dialog { +.application.dialog.M6 { background-color: var(--M6-background-white); color: var(--M6-text-grey); @@ -57,66 +57,67 @@ font-size: 20px; } } - /* Container für die gesamte Reihe */ - .segmented-button-row { - display: inline-flex; - overflow: hidden; - height: 32px; - } +} - /* Einzelnes Segment */ - .segmented-button { - position: relative; - cursor: pointer; - display: flex; - align-items: center; - } +/* Container für die gesamte Reihe */ +.segmented-button-row { + display: inline-flex; + overflow: hidden; + height: 32px; +} - /* Versteckt den echten Radio-Button, behält aber die Tastatur-Navigation */ - .segmented-button input[type="radio"] { - position: absolute; - opacity: 0; - width: 0; - height: 0; - } +/* Einzelnes Segment */ +.segmented-button { + position: relative; + cursor: pointer; + display: flex; + align-items: center; +} - /* Inhalt des Segments (Layout & Abstände) */ - .segmented-button__content { - display: flex; - align-items: center; - justify-content: center; - padding: 0 8px; - height: 100%; - transition: - background-color 0.2s, - color 0.2s; - background-color: transparent; - user-select: none; - } +/* Versteckt den echten Radio-Button, behält aber die Tastatur-Navigation */ +.segmented-button input[type="radio"] { + position: absolute; + opacity: 0; + width: 0; + height: 0; +} - /* --- ZUSTÄNDE --- */ +/* Inhalt des Segments (Layout & Abstände) */ +.segmented-button__content { + display: flex; + align-items: center; + justify-content: center; + padding: 0 8px; + height: 100%; + transition: + background-color 0.2s, + color 0.2s; + background-color: transparent; + user-select: none; +} - /* Selektiert (Selected State) */ - .segmented-button input[type="radio"]:checked + .segmented-button__content { - // background-color: #e8def8; /* M3 Secondary Container Color */ +/* --- ZUSTÄNDE --- */ + +/* Selektiert (Selected State) */ +.segmented-button input[type="radio"]:checked + .segmented-button__content { + // background-color: #e8def8; /* M3 Secondary Container Color */ + text-shadow: 0 0 10px var(--M6-text-brown) !important; + color: #1d192b; /* M3 On-Secondary Container Text */ + .icon { text-shadow: 0 0 10px var(--M6-text-brown) !important; - color: #1d192b; /* M3 On-Secondary Container Text */ - .icon { - text-shadow: 0 0 10px var(--M6-text-brown) !important; - } - } - - /* Hover-Effekt */ - .segmented-button:hover .segmented-button__content { - background-color: rgba(73, 69, 79, 0.08); - } - .segmented-button input[type="radio"]:checked:hover + .segmented-button__content { - background-color: rgba(232, 222, 248, 0.85); - } - - /* Tastatur-Fokus (Barrierefreiheit) */ - .segmented-button input[type="radio"]:focus-visible + .segmented-button__content { - outline: 2px solid #6750a4; - outline-offset: -2px; } } + +/* Hover-Effekt */ +.segmented-button:hover .segmented-button__content { + background-color: rgba(73, 69, 79, 0.08); +} +.segmented-button input[type="radio"]:checked:hover + .segmented-button__content { + background-color: rgba(232, 222, 248, 0.85); +} + +/* Tastatur-Fokus (Barrierefreiheit) */ +.segmented-button input[type="radio"]:focus-visible + .segmented-button__content { + outline: 2px solid #6750a4; + outline-offset: -2px; +} diff --git a/src/styles/flex/bootstrap-grid.css b/src/styles/flex/bootstrap-grid.css index af2089a..b1220af 100644 --- a/src/styles/flex/bootstrap-grid.css +++ b/src/styles/flex/bootstrap-grid.css @@ -19,7 +19,7 @@ html { box-sizing: inherit; } -.application.sheet.M6 { +.M6 { .container { width: 100%; /* padding-right: 15px; diff --git a/src/styles/header.scss b/src/styles/header.scss index fecd5d2..c46c42d 100644 --- a/src/styles/header.scss +++ b/src/styles/header.scss @@ -45,4 +45,8 @@ } } } + + .icon-checked { + background-color: var(--M6-text-brown); + } } diff --git a/src/styles/icons.scss b/src/styles/icons.scss new file mode 100644 index 0000000..8486c6b --- /dev/null +++ b/src/styles/icons.scss @@ -0,0 +1,10 @@ +.sword { + width: 24px; + height: 24px; + /* Das SVG wird als Maske geladen */ + mask: url("../assets/sword.svg") no-repeat center / contain; + -webkit-mask: url("../assets/sword.svg") no-repeat center / contain; + + /* Standardfarbe (wird durch die Maske in die Form des SVGs gepresst) */ + background-color: var(--M6-text-grey); +} diff --git a/src/system.mjs b/src/system.mjs index 948c524..f6cb305 100644 --- a/src/system.mjs +++ b/src/system.mjs @@ -1,7 +1,11 @@ import { CharacterData } from "./data/character-data.mjs"; +import { WeaponData } from "./data/weapon-data.mjs"; import { ItemData } from "./data/item-data.mjs"; +import { ArmorData } from "./data/armor-data.mjs"; import { M6ActorSheet } from "./sheets/character-sheet.mjs"; import { M6ItemSheet } from "./sheets/item-sheet.mjs"; +import { M6WeaponSheet } from "./sheets/weapon-sheet.mjs"; +import { M6ArmorSheet } from "./sheets/armor-sheet.mjs"; import { loadHelpers } from "./helpers/handlebar-helpers.mjs"; import "./styles/M6.scss"; @@ -18,6 +22,8 @@ Hooks.once("init", () => { } }; CONFIG.Item.dataModels.item = ItemData; + CONFIG.Item.dataModels.weapon = WeaponData; + CONFIG.Item.dataModels.armor = ArmorData; foundry.applications.apps.DocumentSheetConfig.registerSheet(Actor, "midgard6-lvd", M6ActorSheet, { types: ["character"], @@ -27,6 +33,12 @@ Hooks.once("init", () => { types: ["item"], makeDefault: true }); + foundry.applications.apps.DocumentSheetConfig.registerSheet(Item, "midgard6-lvd", M6WeaponSheet, { + types: ["weapon"] + }); + foundry.applications.apps.DocumentSheetConfig.registerSheet(Item, "midgard6-lvd", M6ArmorSheet, { + types: ["armor"] + }); loadHelpers(); }); diff --git a/src/templates/actor/items.hbs b/src/templates/actor/items.hbs index e2445a5..2c844f4 100644 --- a/src/templates/actor/items.hbs +++ b/src/templates/actor/items.hbs @@ -1,53 +1,164 @@ {{! Items Tab }} - - - {{#each itemTypes as |group type|}} - - - {{group.label}} - - - {{#if @root.editable}} - - - {{localize "DOCUMENT.New" type=group.label}} - - {{/if}} - - - - {{#each group.items as |item|}} - - - {{item.name}} - - - - - {{#if @root.editable}} - - - - {{/if}} - - - {{/each}} - - {{/each}} + + + + + + {{localize "Midgard6.Item.type.item.plural" }} + + {{#with itemTypes.item}} + + + {{#if @root.editable}} + + + {{localize "DOCUMENT.Create" type=this.label}} + + {{/if}} + + + + {{#each this.items as |item|}} + + + {{item.system.anzahl}}x {{item.name}} + + + + + {{#if @root.editable}} + + + + {{/if}} + + + {{/each}} + + {{/with}} + + + + {{!-- Waffen --}} + + + {{localize "Midgard6.Item.type.weapon.plural" }} + + {{#with itemTypes.weapon}} + + + {{#if @root.editable}} + + + {{localize "DOCUMENT.Create" type=this.label}} + + {{/if}} + + + + {{#each this.items as |item|}} + + + {{item.system.anzahl}}x {{item.name}} + + + + + + + {{#if @root.editable}} + + + + {{/if}} + + + {{/each}} + + {{/with}} + + + {{!-- Rüstung --}} + + + {{localize "Midgard6.Item.type.armor.plural" }} + + {{#with itemTypes.armor}} + + + {{#if @root.editable}} + + + {{localize "DOCUMENT.Create" type=this.label}} + + {{/if}} + + + + {{#each this.items as |item|}} + + + {{item.system.anzahl}}x {{item.name}} + + + + + {{#if @root.editable}} + + + + {{/if}} + + + {{/each}} + + {{/with}} + + + + diff --git a/src/templates/dialog/roll-dialog.hbs b/src/templates/dialog/roll-dialog.hbs index 925975d..05206ae 100644 --- a/src/templates/dialog/roll-dialog.hbs +++ b/src/templates/dialog/roll-dialog.hbs @@ -1,18 +1,20 @@ Modifikation - - - - - + + + {{! }} + + + + @@ -42,27 +44,41 @@ - - - - - - {{#each bonuses}} - - - - {{name}}: - {{level}} - - - {{/each}} + {{! }} + + + + + {{#each bonuses}} + + + + {{name}}: + {{level}} + + + {{/each}} + + {{#if damageRoll}} + + + + {{/if}} diff --git a/src/templates/item/description.hbs b/src/templates/item/description.hbs index aa50e85..a61840e 100644 --- a/src/templates/item/description.hbs +++ b/src/templates/item/description.hbs @@ -1,7 +1,13 @@ {{! Beschreibung Allgemein Tab }} - + {{! Editors must receive enriched text data from getData to properly handle rolls, UUID links, etc. }} + {{localize "Midgard6.Item.Description"}} {{#if editable}} + + {{localize "Midgard6.Item.Eigenschaften"}} + + + + + Schaden + + + + + + Fertigkeit + + {{localize + "Midgard6.Skills.fernkampf" + }} + {{localize + "Midgard6.Skills.nahkampf" + }} + + + + + + + + + + Spezialisierung + + {{#each bonuses as |bonus|}} + + {{bonus.name}} + + {{/each}} + + + + + + + + \ No newline at end of file diff --git a/src/templates/item/header.hbs b/src/templates/item/header.hbs index f6d393d..658c158 100644 --- a/src/templates/item/header.hbs +++ b/src/templates/item/header.hbs @@ -1,7 +1,17 @@ - + + {{#if (isdefined system.equipped)}} + + + + {{/if}} + + + + + @@ -16,15 +26,15 @@ - + \ No newline at end of file diff --git a/src/templates/shared/properties.hbs b/src/templates/shared/properties.hbs index 6d04f78..c2c46e7 100644 --- a/src/templates/shared/properties.hbs +++ b/src/templates/shared/properties.hbs @@ -142,6 +142,37 @@ + + + {{localize "Midgard6.Item.type.weapon.plural" }} + + {{#each equippedWeapons as |weapon|}} + + + + + {{weapon.name}}: + + + + {{weapon.skillValue}} {{#if weapon.bonusValue}}+ {{weapon.bonusValue}}{{/if}} + + + + + + + + + {{/each}} + + + diff --git a/src/types/data-config.d.mjs b/src/types/data-config.d.mjs index 182e412..127f1dc 100644 --- a/src/types/data-config.d.mjs +++ b/src/types/data-config.d.mjs @@ -1,9 +1,11 @@ import { CharacterData } from "../data/character-data"; import { ItemData } from "../data/item-data"; +import { WeaponData } from "../data/weapon-data"; +import { ArmorData } from "../data/armor-data"; declare module "fvtt-types/configuration" { interface DataModelConfig { Actor: { character: typeof CharacterData }; - Item: { item: typeof ItemData }; + Item: { item: typeof ItemData, weapon: typeof WeaponData, armor: typeof ArmorData }; } } diff --git a/system.json b/system.json index 14e92f7..8d1ac16 100644 --- a/system.json +++ b/system.json @@ -33,7 +33,9 @@ "character": {} }, "Item": { - "item": {} + "item": {}, + "weapon": {}, + "armor": {} } }, "compatibility": {
Schaden
Fertigkeit
Spezialisierung
{{weapon.name}}:
+ + + {{weapon.skillValue}} {{#if weapon.bonusValue}}+ {{weapon.bonusValue}}{{/if}}