Cleanup code
This commit is contained in:
+1
-18
@@ -11,25 +11,8 @@
|
||||
* @license CC BY-NC-SA 4.0 – https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
*/
|
||||
|
||||
import { ACTOR_TYPES } from "../config/constants.js"
|
||||
|
||||
export class CDEActor extends Actor {
|
||||
getRollData() {
|
||||
const data = this.toObject(false).system
|
||||
return data
|
||||
}
|
||||
|
||||
prepareBaseData() {
|
||||
super.prepareBaseData()
|
||||
|
||||
if (this.type === ACTOR_TYPES.character) {
|
||||
this.system.anti_initiative = 25 - (this.system.initiative ?? 0)
|
||||
}
|
||||
|
||||
if (this.type === ACTOR_TYPES.npc) {
|
||||
this.system.vitality.calcul = (this.system.aptitudes.physical.value ?? 0) * 4
|
||||
this.system.hei.calcul = (this.system.aptitudes.spiritual.value ?? 0) * 4
|
||||
this.system.anti_initiative = 25 - (this.system.initiative ?? 0)
|
||||
}
|
||||
return this.toObject(false).system
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user