From ef00bd029efe1e10ffd4827c5e62022ea6b0c777 Mon Sep 17 00:00:00 2001 From: Sven Balzer <4653051+Kyuusokuna@users.noreply.github.com> Date: Sun, 26 Jan 2025 17:15:43 +0100 Subject: [PATCH] add more context to chat messages --- src/Chat/Header.hbs | 7 +++++++ src/main.css | 15 ++++++++++++++- src/main.mjs | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 src/Chat/Header.hbs diff --git a/src/Chat/Header.hbs b/src/Chat/Header.hbs new file mode 100644 index 0000000..a48a6e8 --- /dev/null +++ b/src/Chat/Header.hbs @@ -0,0 +1,7 @@ +
+ {{name}} +
+ {{name}} + {{author}} +
+
\ No newline at end of file diff --git a/src/main.css b/src/main.css index bf4258c..522a8e9 100644 --- a/src/main.css +++ b/src/main.css @@ -49,7 +49,7 @@ html { height: fit-content; } - & .row { + & .row, &.row { display: flex; flex-direction: row; flex: 1; @@ -145,6 +145,19 @@ html { margin-right: 0.5rem; } + &.chat-header { + & img { + margin-right: .75em; + width: 38px; + height: 38px; + } + + & .subtitle { + color: #666; + font-size: .6875rem; + } + } + & .die { display: inline-grid; diff --git a/src/main.mjs b/src/main.mjs index ae2567d..916d619 100644 --- a/src/main.mjs +++ b/src/main.mjs @@ -14,6 +14,7 @@ Hooks.once("init", async function() { CONFIG.Actor.dataModels.Player = DSA41_CharacterData; CONFIG.Actor.documentClass = DSA41_CharacterDocument; + CONFIG.ChatMessage.documentClass = DSA41_ChatMessage; CONFIG.Item.dataModels.Gegenstand = DSA41_GegenstandData; CONFIG.Item.dataModels.Ruestung = DSA41_RuestungData; CONFIG.Item.dataModels.Bewaffnung = DSA41_BewaffnungData; @@ -22,6 +23,8 @@ Hooks.once("init", async function() { CONFIG.Item.dataModels.Sonderfertigkeit = DSA41_SonderfertigkeitData; CONFIG.Item.dataModels.VorNachteil = DSA41_VorNachteilData; + CONFIG.statusEffects = []; + DocumentSheetConfig.unregisterSheet(Actor, "core", ActorSheet); DocumentSheetConfig.registerSheet(Actor, "dsa41", DSA41_ActorSheet, { makeDefault: true, @@ -70,10 +73,40 @@ Hooks.once("init", async function() { "fernkampf_attacke_tooltip": "systems/dsa-4th-edition/src/Tooltips/FernkampfAttacke.hbs", "fernkampf_trefferpunkte_tooltip": "systems/dsa-4th-edition/src/Tooltips/FernkampfTrefferpunkte.hbs", + "CHAT_HEADER": "systems/dsa-4th-edition/src/Chat/Header.hbs", "talent_chat": "systems/dsa-4th-edition/src/Chat/Talent.hbs", }); }); +class DSA41_ChatMessage extends ChatMessage { + get actor() { + if (this.speaker.scene && this.speaker.token) { + const scene = game.scenes.get(this.speaker.scene); + const token = scene?.tokens.get(this.speaker.token); + if (token) return token.actor; + } + + return game.actors.get(this.speaker.actor); + } + + async getHTML() { + const html = (await super.getHTML())[0]; + + const img = this.actor?.img ?? this.author.avatar; + const name = this.alias; + + const header_html = await renderTemplate("CHAT_HEADER", { img: img, name: name, author: this.author?.name ?? "" }); + const header_template = document.createElement("template"); + header_template.innerHTML = header_html; + const header = header_template.content.children; + + const sender = html?.querySelector(".message-sender"); + sender?.replaceChildren(...header); + + return html; + } +} + function get_minified_formula(formula, data) { const terms = Roll.simplifyTerms(Roll.parse(formula, data)); let output = [];