Cleanup code

This commit is contained in:
2026-05-12 00:34:47 +02:00
parent 389517a774
commit 503ee9395a
92 changed files with 567 additions and 1012 deletions
+12 -30
View File
@@ -18,43 +18,25 @@ export class CDEMessage extends ChatMessage {
return html
}
getAssociatedActor() {
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)
}
#enrichChatCard(html) {
const actor = this.getAssociatedActor()
const tokenDoc = (this.speaker.scene && this.speaker.token)
? game.scenes.get(this.speaker.scene)?.tokens.get(this.speaker.token)
: null
const actor = tokenDoc?.actor ?? game.actors.get(this.speaker.actor) ?? null
let img
let nameText
if (this.isContentVisible) {
img = actor?.img ?? this.author.avatar
nameText = this.alias
} else {
img = this.author.avatar
nameText = this.author.name
}
const [img, nameText] = this.isContentVisible
? [actor?.img ?? this.author.avatar, this.alias]
: [this.author.avatar, this.author.name]
const avatar = document.createElement("a")
avatar.classList.add("avatar")
const avatarImg = Object.assign(document.createElement("img"), { src: img, alt: nameText })
const avatar = Object.assign(document.createElement("a"), { className: "avatar" })
if (actor) avatar.dataset.uuid = actor.uuid
const avatarImg = document.createElement("img")
Object.assign(avatarImg, { src: img, alt: nameText })
avatar.append(avatarImg)
const name = document.createElement("span")
name.classList.add("name-stacked")
const title = document.createElement("span")
title.classList.add("title")
title.append(nameText)
const title = Object.assign(document.createElement("span"), { className: "title", textContent: nameText })
const name = Object.assign(document.createElement("span"), { className: "name-stacked" })
name.append(title)
const sender = html.querySelector(".message-sender")
sender?.replaceChildren(avatar, name)
html.querySelector(".message-sender")?.replaceChildren(avatar, name)
}
}