diff --git a/lang/de.json b/lang/de.json index 0871021..aeaab22 100644 --- a/lang/de.json +++ b/lang/de.json @@ -157,6 +157,9 @@ "plural": "Schicksalsgaben" } } + }, + "RollList": { + "RollMode": "Wurf-Modus" } }, "TYPES": { diff --git a/src/helpers/partials.mjs b/src/helpers/partials.mjs new file mode 100644 index 0000000..de601a7 --- /dev/null +++ b/src/helpers/partials.mjs @@ -0,0 +1,5 @@ +export const loadPartials = async function () { + await foundry.applications.handlebars.loadTemplates([ + "systems/midgard6-lvd/src/templates/chat/chat-message-header.hbs" + ]); +}; diff --git a/src/sheets/character-sheet.mjs b/src/sheets/character-sheet.mjs index 4d82aef..77c456c 100644 --- a/src/sheets/character-sheet.mjs +++ b/src/sheets/character-sheet.mjs @@ -2,6 +2,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 { rollSpell, rollWeapon, rollSkill } from "./components/roll-actions.mjs"; const { api, sheets } = foundry.applications; @@ -24,9 +25,9 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe createDoc: this.#createDoc, deleteDoc: this.#deleteDoc, toggleEffect: this.#toggleEffect, - rollSkill: this.#rollSkill, - rollWeapon: this.#rollWeapon, - rollSpell: this.#rollSpell, + rollSkill: rollSkill, + rollWeapon: rollWeapon, + rollSpell: rollSpell, cycleEquip: this.#cycleEquip, cycleLock: this.#cycleLock, addSpezialisierung: addSpezialisierung, @@ -492,287 +493,6 @@ export class M6ActorSheet extends api.HandlebarsApplicationMixin(sheets.ActorShe effect.update({ disabled: !effect.disabled }); } - static async #rollSpell(event, target) { - const dataset = target.dataset; - const skill = foundry.utils.getProperty(this.actor, "system.skills.magie.zaubern"); - const item = this.actor.items.get(dataset.itemId); - const actor = this.actor; - const dialogResult = await this.rollDialog({ - name: dataset.name, - skill, - damageRoll: item.system.eigenschaften.schaden, - preSelectedSpez: item.system.eigenschaften.ursprung, - actor - }); - console.log("Dialog Result", dialogResult); - if (dialogResult === "abort") { - 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 = dataset.name; - let roll; - - if (dialogResult.spezLevel) { - rollTerm += " + @spezBonus"; - rollFlavor += ": " + dialogResult.spezName; - } - - if (dialogResult.customRoll) { - roll = new Roll(dialogResult.customRoll); - } else { - roll = new Roll( - rollTerm, - { die: die, skill: skillValue, spezBonus: dialogResult.spezLevel + 1 }, - { flavor: rollFlavor } - ); - } - - // The parsed terms of the roll formula - console.log("Roll:", roll); // [Die, OperatorTerm, NumericTerm, OperatorTerm, NumericTerm] - - // Execute the roll - await roll.evaluate(); - - roll.toMessage(); - } - - static async #rollSkill(event, target) { - const dataset = target.dataset; - const skill = foundry.utils.getProperty(this.actor, target.dataset.path.replace(".value", "")); - const actor = this.actor; - const dialogResult = await this.rollDialog({ - name: dataset.name, - skill, - actor - }); - console.log("Dialog Result", dialogResult); - if (dialogResult === "abort") { - 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 = dataset.name; - let roll; - - if (dialogResult.spezLevel) { - rollTerm += " + @spezBonus"; - rollFlavor += ": " + dialogResult.spezName; - } - - if (dialogResult.customRoll) { - roll = new Roll(dialogResult.customRoll); - } else { - roll = new Roll( - rollTerm, - { die: die, skill: skillValue, spezBonus: dialogResult.spezLevel + 1 }, - { flavor: rollFlavor } - ); - } - - // The parsed terms of the roll formula - console.log("Roll:", roll); // [Die, OperatorTerm, NumericTerm, OperatorTerm, NumericTerm] - - // Execute the roll - await roll.evaluate(); - - 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 === "abort") { - 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; - let spezName = ""; - // 1. Define the path to .hbs template - const templatePath = systemPath("templates/dialog/roll-dialog.hbs"); - const templateData = { - skillValue, - bonuses, - vorteil, - damageRoll, - preSelectedSpez, - customRoll - }; - // 2. Render the Handlebars template into an HTML string - const content = await foundry.applications.handlebars.renderTemplate( - templatePath, - templateData - ); - // return new Promise((resolve, reject) => { - // const dialog = new foundry.applications.api.DialogV2({ - return foundry.applications.api.DialogV2.wait({ - window: { title: "Würfel Modifikatoren: " + label }, - position: { - width: 600 - }, - classes: ["M6", "dialog"], - content, - actions: {}, - render: (_event, dialog) => { - const dialogHTML = dialog.element; - - const display = dialogHTML.querySelector("#rollDisplay"); - - // Variable bei jeder Änderung aktualisieren - document.querySelectorAll('input[name="vorteil-segment"]').forEach((radio) => { - radio.addEventListener("change", (e) => { - vorteil = parseInt(e.target.value); - switch (vorteil) { - case 1: - display.placeholder = `2d20kh + ${skillValue} (Vorteil)`; - break; - case -1: - display.placeholder = `2d20kl + ${skillValue} (Nachteil)`; - break; - default: - display.placeholder = `1d20 + ${skillValue}`; - break; - } - }); - }); - - document.querySelectorAll('input[name="spezialisierung-segment"]').forEach((radio) => { - radio.addEventListener("change", (e) => { - spezLevel = parseInt(e.target.value); - spezName = e.target.dataset.name; - }); - if (radio.dataset.name === preSelectedSpez) { - radio.click(); - } - }); - }, - buttons: [ - { - action: "abort", - label: "Midgard6.Dialog.abbrechen", - callback: (event, button, dialog) => { - return null; - } - }, - { - action: "roll", - label: "Midgard6.Dialog.würfeln", - default: true, - callback: (event, button, dialog) => { - const rollData = { - customRoll: button.form.elements.customRoll.value, - customDamageRoll: button.form.elements.customDamageRoll?.value || "", - vorteil, - spezLevel, - spezName - }; - return rollData; - } - } - ] - }); - } - /* -------------------------------------------------- */ /* Helper functions */ /* -------------------------------------------------- */ diff --git a/src/sheets/components/roll-actions.mjs b/src/sheets/components/roll-actions.mjs new file mode 100644 index 0000000..da17bb2 --- /dev/null +++ b/src/sheets/components/roll-actions.mjs @@ -0,0 +1,348 @@ +import { systemPath } from "../../constants.mjs"; + +export async function rollSpell(event, target) { + const dataset = target.dataset; + const skill = foundry.utils.getProperty(this.actor, "system.skills.magie.zaubern"); + const item = this.actor.items.get(dataset.itemId); + const actor = this.actor; + const dialogResult = await rollDialog({ + name: dataset.name, + skill, + damageRoll: item.system.eigenschaften.schaden, + preSelectedSpez: item.system.eigenschaften.ursprung, + actor + }); + console.log("Dialog Result", dialogResult); + if (dialogResult === "abort") { + 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 = dataset.name; + let roll; + + if (dialogResult.spezLevel) { + rollTerm += " + @spezBonus"; + rollFlavor += ": " + dialogResult.spezName; + } + + if (dialogResult.customRoll) { + roll = new Roll(dialogResult.customRoll); + } else { + roll = new Roll( + rollTerm, + { + die: die, + skill: skillValue, + spezBonus: dialogResult.spezLevel + 1 + }, + { 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, + eigenschaften: item.eigenschaften, + isSpell: true, + beschreibung: await foundry.applications.ux.TextEditor.implementation.enrichHTML( + item.system.beschreibung, + { + // Whether to show secret blocks in the finished html + secrets: false, + // Data to fill in for inline rolls + rollData: this.actor.getRollData(), + // Relative UUID resolution + relativeTo: this.actor + } + ) + } + } + }; + + ChatMessage.applyMode(chatData, dialogResult.rollMode); + + await ChatMessage.create(chatData); +} + +export async function rollSkill(event, target) { + const dataset = target.dataset; + const skill = foundry.utils.getProperty(this.actor, target.dataset.path.replace(".value", "")); + const actor = this.actor; + const dialogResult = await rollDialog({ + name: dataset.name, + skill, + actor + }); + console.log("Dialog Result", dialogResult); + if (dialogResult === "abort") { + 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 = dataset.name; + let roll; + + if (dialogResult.spezLevel) { + rollTerm += " + @spezBonus"; + rollFlavor += ": " + dialogResult.spezName; + } + + if (dialogResult.customRoll) { + roll = new Roll(dialogResult.customRoll); + } else { + roll = new Roll( + rollTerm, + { + die: die, + skill: skillValue, + spezBonus: dialogResult.spezLevel + 1 + }, + { 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 + } + } + }; + console.warn(dialogResult); + + // Nutze applyRollMode, um Sichtbarkeiten (Whisper, Blind) korrekt zu setzen + ChatMessage.applyMode(chatData, dialogResult.rollMode); + + // Erstelle die Nachricht mit den manipulierten Daten + await ChatMessage.create(chatData); +} + +export async function 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 rollDialog({ + name: weapon.name, + skill, + damageRoll: weapon.system.schaden, + preSelectedSpez: weapon.system.spezialisierung, + actor + }); + console.log("Dialog Result", dialogResult); + if (dialogResult === "abort") { + 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 + }, + { title: rollFlavor } + ).evaluate(); + } + + damageRoll = await new Roll( + "@die", + { die: weapon.system.schaden }, + { title: game.i18n.localize("Midgard6.Schaden") } + ).evaluate(); + + // The parsed terms of the roll formula + console.warn(dialogResult); + const chatData = { + rolls: [attackRoll, damageRoll], + speaker: ChatMessage.getSpeaker(), + flags: { + "midgard6-lvd": { + title: rollFlavor, + eigenschaften: weapon.eigenschaften, + beschreibung: await foundry.applications.ux.TextEditor.implementation.enrichHTML( + weapon.system.beschreibung, + { + secrets: false, + rollData: this.actor.getRollData(), + relativeTo: this.actor + } + ) + } + } + }; + + ChatMessage.applyMode(chatData, dialogResult.rollMode); + + await ChatMessage.create(chatData); +} + +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 damageRoll = rollDialogRequest.damageRoll || ""; + let preSelectedSpez = rollDialogRequest.preSelectedSpez || ""; + let vorteil = 0; + let customRoll = ""; + let spezLevel; + let spezName = ""; + // 1. Define the path to .hbs template + const templatePath = systemPath("templates/dialog/roll-dialog.hbs"); + const templateData = { + skillValue, + bonuses, + vorteil, + damageRoll, + preSelectedSpez, + customRoll, + rollModes: CONFIG.ChatMessage.modes + }; + // 2. Render the Handlebars template into an HTML string + const content = await foundry.applications.handlebars.renderTemplate(templatePath, templateData); + // return new Promise((resolve, reject) => { + // const dialog = new foundry.applications.api.DialogV2({ + return foundry.applications.api.DialogV2.wait({ + window: { title: "Würfel Modifikatoren: " + label }, + position: { + width: 600 + }, + classes: ["M6", "dialog"], + content, + actions: {}, + render: (_event, dialog) => { + const dialogHTML = dialog.element; + + const display = dialogHTML.querySelector("#rollDisplay"); + + // Variable bei jeder Änderung aktualisieren + document.querySelectorAll('input[name="vorteil-segment"]').forEach((radio) => { + radio.addEventListener("change", (e) => { + vorteil = parseInt(e.target.value); + switch (vorteil) { + case 1: + display.placeholder = `2d20kh + ${skillValue} (Vorteil)`; + break; + case -1: + display.placeholder = `2d20kl + ${skillValue} (Nachteil)`; + break; + default: + display.placeholder = `1d20 + ${skillValue}`; + break; + } + }); + }); + + document.querySelectorAll('input[name="spezialisierung-segment"]').forEach((radio) => { + radio.addEventListener("change", (e) => { + spezLevel = parseInt(e.target.value); + spezName = e.target.dataset.name; + }); + if (radio.dataset.name === preSelectedSpez) { + radio.click(); + } + }); + }, + buttons: [ + { + action: "abort", + label: "Midgard6.Dialog.abbrechen", + callback: (event, button, dialog) => { + return null; + } + }, + { + action: "roll", + label: "Midgard6.Dialog.würfeln", + default: true, + callback: (event, button, dialog) => { + const rollData = { + customRoll: button.form.elements.customRoll.value, + customDamageRoll: button.form.elements.customDamageRoll?.value || "", + vorteil, + spezLevel, + spezName, + rollMode: + button.form.elements.rollMode?.value || game.settings.get("core", "messageMode") + }; + return rollData; + } + } + ] + }); +} diff --git a/src/styles/M6.scss b/src/styles/M6.scss index a1b84c2..ade715f 100644 --- a/src/styles/M6.scss +++ b/src/styles/M6.scss @@ -6,6 +6,7 @@ @import url("./items-page.scss"); @import url("./hintergrund.scss"); @import url("./icons.scss"); +@import url("./chat-messages.scss"); :root { --M6-background-grey: #d3d7d7; @@ -15,6 +16,9 @@ --M6-text-brown: #be7742; } +.inline-roll { + background-color: var(--M6-background-brown); +} .M6 { fieldset { border-radius: 0; diff --git a/src/styles/chat-messages.scss b/src/styles/chat-messages.scss new file mode 100644 index 0000000..d24977f --- /dev/null +++ b/src/styles/chat-messages.scss @@ -0,0 +1,61 @@ +.chat-message { + background: none; + border-radius: 0; +} +.message-header { + .message-names { + color: var(--M6-text-brown); + font-weight: bold; + font-size: 18px; + } +} +.chat-message.message { + background-color: var(--M6-background-grey); + + fieldset { + background-color: var(--M6-background-white); + + &.highlight { + background-color: var(--M6-background-brown); + } + legend { + color: var(--M6-text-brown); + font-size: 18px; + font-weight: bold; + } + } + + .collapsible { + background-color: var(--M6-background-white); + cursor: pointer; + padding: 12px; + font-size: 15px; + margin-bottom: 4px; + display: flex; + justify-content: space-between; + margin: 8px 4px; + + &.active { + background-color: var(--M6-background-brown); + box-shadow: none; + margin-bottom: 0px; + } + } + + /* Add a background color to the button if it is clicked on (add the .active class with JS), and when you move the mouse over it (hover) */ + + /* Style the collapsible content. Note: hidden by default */ + .content { + padding: 0 18px; + display: none; + width: auto; + overflow: hidden; + background-color: var(--M6-background-white); + &.active { + display: block; + width: auto; + margin: 8px 4px; + margin-top: 0; + } + } +} diff --git a/src/system.mjs b/src/system.mjs index 1b47591..f5e5588 100644 --- a/src/system.mjs +++ b/src/system.mjs @@ -1,3 +1,7 @@ +import { systemPath } from "./constants.mjs"; +import { loadHelpers } from "./helpers/handlebar-helpers.mjs"; +import { loadPartials } from "./helpers/partials.mjs"; + import { CharacterData } from "./data/character-data.mjs"; import { WeaponData } from "./data/weapon-data.mjs"; import { ItemData } from "./data/item-data.mjs"; @@ -10,10 +14,13 @@ import { M6WeaponSheet } from "./sheets/weapon-sheet.mjs"; import { M6ArmorSheet } from "./sheets/armor-sheet.mjs"; import { M6ZauberSheet } from "./sheets/zauber-sheet.mjs"; import { M6HintergrundSheet } from "./sheets/hintergrund-sheet.mjs"; -import { loadHelpers } from "./helpers/handlebar-helpers.mjs"; +import { M6ChatMessage } from "./ui/chat-message.mjs"; import "./styles/M6.scss"; Hooks.once("init", () => { + CONFIG.ChatMessage.documentClass = M6ChatMessage; + CONFIG.ChatMessage.template = systemPath("templates/chat/message-default.hbs"); + CONFIG.Actor.dataModels.character = CharacterData; CONFIG.Actor.trackableAttributes = { pc: { @@ -57,7 +64,7 @@ Hooks.once("init", () => { "midgard6-lvd", M6HintergrundSheet, { - types: ["hintergrund", "gunst"] + types: ["gunst"] } ); foundry.applications.apps.DocumentSheetConfig.registerSheet( @@ -65,7 +72,7 @@ Hooks.once("init", () => { "midgard6-lvd", M6HintergrundSheet, { - types: ["hintergrund", "makel"] + types: ["makel"] } ); foundry.applications.apps.DocumentSheetConfig.registerSheet( @@ -73,7 +80,7 @@ Hooks.once("init", () => { "midgard6-lvd", M6HintergrundSheet, { - types: ["hintergrund", "schicksalsgabe"] + types: ["schicksalsgabe"] } ); foundry.applications.apps.DocumentSheetConfig.registerSheet( @@ -81,9 +88,29 @@ Hooks.once("init", () => { "midgard6-lvd", M6HintergrundSheet, { - types: ["hintergrund", "legende"] + types: ["legende"] } ); loadHelpers(); + + loadPartials(); +}); + +Hooks.on("renderChatMessageHTML", (message, html, data) => { + const collapsible = html.querySelectorAll("div[data-action=collapsible]"); + if (collapsible) { + collapsible.forEach((node) => { + node.addEventListener( + "click", + function () { + node.classList.toggle("active"); + var content = node.nextElementSibling; + content.classList.toggle("active"); + node.getElementsByTagName("i")[0].classList.toggle("fa-compress"); + }, + { capture: true } + ); + }); + } }); diff --git a/src/templates/actor/zauber.hbs b/src/templates/actor/zauber.hbs index f8e09e3..a9ba01d 100644 --- a/src/templates/actor/zauber.hbs +++ b/src/templates/actor/zauber.hbs @@ -7,7 +7,6 @@ {{localize "Midgard6.Item.type.zauber.plural" }} - {{!-- {{/with}} --}} diff --git a/src/templates/chat/chat-message-header.hbs b/src/templates/chat/chat-message-header.hbs new file mode 100644 index 0000000..fae0f84 --- /dev/null +++ b/src/templates/chat/chat-message-header.hbs @@ -0,0 +1,34 @@ +
+
+ {{alias}} +
+
+ + {{alias}} + + {{#if isWhisper}} + {{localize "CHAT.To"}}: {{whisperTo}} + {{/if}} +
+
+ {{!-- --}} + {{#if canDelete}} + + + + {{/if}} + {{#if canClose}} + + + + {{/if}} +
+ + {{#if message.flavor}} + {{{message.flavor}}} + {{/if}} +
\ No newline at end of file diff --git a/src/templates/chat/message-default.hbs b/src/templates/chat/message-default.hbs new file mode 100644 index 0000000..c0e478c --- /dev/null +++ b/src/templates/chat/message-default.hbs @@ -0,0 +1,48 @@ +
  • + {{> "systems/midgard6-lvd/src/templates/chat/chat-message-header.hbs"}} + + {{!--
    --}} + {{#if isContentVisible}} + {{#if isRoll}} + {{#each message.content as |roll|}} +
    + {{#if roll.options.title}}{{roll.options.title}}{{/if}} + {{{roll.html}}} +
    + {{/each}} + {{else}} +
    + {{#if title}}{{title}}{{/if}} + {{{message.content}}} +
    + {{/if}} + + {{#if beschreibung}} +
    {{localize "Midgard6.Item.Description"}} +
    + +
    +
    +
    + {{{beschreibung}}} +
    + {{/if}} + {{else}} +
    + {{#if isRoll}} + ??? +
    +
    +
    ???
    +

    ?

    +
    +
    + {{else}} +

    ???

    + {{/if}} +
    + {{/if}} +
  • \ No newline at end of file diff --git a/src/templates/dialog/roll-dialog.hbs b/src/templates/dialog/roll-dialog.hbs index 05206ae..cbd3490 100644 --- a/src/templates/dialog/roll-dialog.hbs +++ b/src/templates/dialog/roll-dialog.hbs @@ -80,6 +80,12 @@ {{/if}} +
    + +
    + \ No newline at end of file diff --git a/src/ui/chat-message.mjs b/src/ui/chat-message.mjs new file mode 100644 index 0000000..7b18818 --- /dev/null +++ b/src/ui/chat-message.mjs @@ -0,0 +1,188 @@ +// import { processMessage } from "./message-logic/process-message.js"; + +export class M6ChatMessage extends ChatMessage { + // Default avatar for the chat message + static DEFAULT_AVATAR = "icons/svg/mystery-man.svg"; + + _attachPartListeners(partId, html, bubble) { + super._attachPartListeners(partId, html, bubble); + console.warn("Here"); + + switch (partId) { + case "hintergrund": + const collapsible = html.querySelectorAll("div[data-action=collapsible]"); + if (collapsible) { + collapsible.forEach((node) => { + node.addEventListener( + "click", + function () { + node.classList.toggle("active"); + var content = node.nextElementSibling; + content.classList.toggle("active"); + node.getElementsByTagName("i")[0].classList.toggle("fa-compress"); + }, + { capture: true } + ); + }); + } + break; + } + } + + /** + * Render the HTML for the ChatMessage which should be added to the log + * @param {object} [options] Additional options passed to the Handlebars template. + * @param {boolean} [options.canDelete] Render a delete button. By default, this is true for GM users. + * @param {boolean} [options.canClose] Render a close button for dismissing chat card notifications. + * @returns {Promise} + */ + async renderHTML({ canDelete, canClose = false, ...rest } = {}) { + // Default message template + this.template = CONFIG.ChatMessage.template; + + // By default, GM users have the trash-bin icon in the chat log itself + canDelete ??= game.user.isGM; + + if (typeof this.system.renderHTML === "function") { + const html = await this.system.renderHTML({ canDelete, canClose, ...rest }); + Hooks.callAll("renderChatMessageHTML", this, html); + return html; + } + // Determine some metadata + const speakerActor = this.speakerActor; + const data = this.toObject(false); + if (!this.isRoll || this.isContentVisible) { + data.content = await foundry.applications.ux.TextEditor.implementation.enrichHTML( + data?.flags?.m6?.description || this.content, + { + rollData: this.getRollData(), + secrets: speakerActor?.isOwner ?? game.user.isGM + } + ); + } + const isWhisper = this.whisper.length; + + // Construct message data + this.messageData = { + // Base messageData and permissions + ...rest, + message: data, + canDelete, + canClose, + isGM: game.user.isGM, + isWhisper: this.whisper.length, + whisperTo: this.whisper.map((u) => game.users.get(u)?.name).filterJoin(", "), + isContentVisible: this.isContentVisible, + + // User and author data + user: game.user, + author: this.author, + + // Display info + title: this.flags["midgard6-lvd"]?.title, + name: this.flags["midgard6-lvd"]?.name, + description: this.flags["midgard6-lvd"]?.description, + alias: this.alias, + speakerActor, + + // If the user can't see the currently visible content, then prefer the author's avatar; + // Otherwise, use the character's avatar (if present), and fall back to the default avatar + // as a last resort + portrait: + ((this.isContentVisible ? speakerActor?.img : undefined) ?? this.author?.avatar) || + this.constructor.DEFAULT_AVATAR, + + // CSS classes + cssClass: [ + this.style === CONST.CHAT_MESSAGE_STYLES.IC ? "ic" : null, + this.style === CONST.CHAT_MESSAGE_STYLES.EMOTE ? "emote" : null, + isWhisper ? "whisper" : null, + this.blind ? "blind" : null + ].filterJoin(" "), + + // System-specific flags + beschreibung: this.isContentVisible ? this.getFlag("midgard6-lvd", "beschreibung") : "", + isSpell: this.getFlag("midgard6-lvd", "isSpell"), + isRoll: this?.isRoll || false + }; + // Render additional message data + if (this.isRoll) { + await this.#renderRollContent(this.messageData); + } + + // Add a check in for in case modules are adding content to use that as the description + // if (this.messageData?.message?.content) { + // this.messageData.description = this.messageData?.message?.content; + // } + console.warn(this.messageData); + // Render the chat message + let html = await foundry.applications.handlebars.renderTemplate( + this.template, + this.messageData + ); + html = foundry.utils.parseHTML(html); + // Flag expanded state of dice rolls + Hooks.callAll("renderChatMessageHTML", this, html, this.messageData); + + // Get whether descriptions should auto-collapse for this user or not and apply the styling + // const autoCollapse = game.settings.get("midgard6-lvd", "autoCollapseDescriptions"); + // if (!autoCollapse) { + // const collapsibleContent = html.querySelector(".collapsible-content"); + // if (collapsibleContent) collapsibleContent.style.maxHeight = "unset"; + // } + + return html; + } + + // Code pulled from core since this is a private method as of V13 + async #renderRollContent(messageData) { + const data = messageData.message; + const renderRolls = async (isPrivate) => { + let html = ""; + let content = []; + + for (const roll of this.rolls) { + html = await roll.render({ + isPrivate + }); + content.push({ options: roll.options, html }); + } + return content; + }; + + // Suppress the "to:" whisper flavor for private rolls + if (this.blind || this.whisper.length) messageData.isWhisper = false; + + // Display standard Roll HTML content + if (this.isContentVisible) { + const el = document.createElement("div"); + el.innerHTML = data.content; // Ensure the content does not already contain custom HTML + if (!el.childElementCount && this.rolls.length) { + data.content = await this.#renderRollHTML(false); + } + } else { + // Otherwise, show "rolled privately" messages for Roll content + const name = this.author?.name ?? game.i18n.localize("CHAT.UnknownUser"); + data.flavor = game.i18n.format("CHAT.PrivateRollContent", { + user: foundry.utils.escapeHTML(name) + }); + data.content = await renderRolls(true); + messageData.alias = name; + } + } + + async #renderRollHTML(isPrivate) { + let html = ""; + let content = []; + + for (const roll of this.rolls) { + html = await roll.render({ + isPrivate, + message: this + }); + content.push({ options: roll.options, html }); + } + + return content; + } +}