Rework des fiches creature/PJ et Tinji/Loksyu

This commit is contained in:
2026-03-30 16:36:38 +02:00
parent 0689fae792
commit cab77645b7
70 changed files with 1712 additions and 1075 deletions
+16 -34
View File
@@ -1,5 +1,4 @@
import { getSingletonActor } from "./singletons.js"
import { ACTOR_TYPES } from "../../config/constants.js"
import { getTinjiValue, setTinjiValue } from "./singletons.js"
const SYSTEM_ID = "fvtt-chroniques-de-l-etrange"
@@ -30,13 +29,11 @@ export class CDETinjiApp extends foundry.applications.api.HandlebarsApplicationM
},
}
/** @type {Actor|null} */
#actor = null
/** @type {Function|null} */
#updateHook = null
_updateHook = null
static open() {
const existing = Object.values(foundry.applications.instances ?? {}).find(
const existing = Array.from(foundry.applications.instances.values()).find(
(app) => app instanceof CDETinjiApp
)
if (existing) { existing.bringToFront(); return existing }
@@ -46,29 +43,22 @@ export class CDETinjiApp extends foundry.applications.api.HandlebarsApplicationM
}
async _prepareContext() {
this.#actor = await getSingletonActor(ACTOR_TYPES.tinji)
if (!this.#actor) return { hasActor: false, value: 0 }
return {
hasActor: true,
canEdit: this.#actor.isOwner,
value: this.#actor.system.value ?? 0,
canEdit: game.user.isGM,
value: getTinjiValue(),
}
}
_onRender(context, options) {
super._onRender(context, options)
this.#bindDirectInput()
this.#updateHook = Hooks.on("updateActor", (actor) => {
if (actor.id === this.#actor?.id) this.render()
})
this._updateHook = Hooks.on("cde:tinjiUpdated", () => this.render())
}
_onClose(options) {
if (this.#updateHook !== null) {
Hooks.off("updateActor", this.#updateHook)
this.#updateHook = null
if (this._updateHook !== null) {
Hooks.off("cde:tinjiUpdated", this._updateHook)
this._updateHook = null
}
super._onClose(options)
}
@@ -78,39 +68,31 @@ export class CDETinjiApp extends foundry.applications.api.HandlebarsApplicationM
if (!input) return
input.addEventListener("change", async (ev) => {
const val = parseInt(ev.currentTarget.value, 10)
if (!isNaN(val) && this.#actor) {
await this.#actor.update({ "system.value": Math.max(0, val) })
}
if (!isNaN(val)) await setTinjiValue(val)
})
}
static async #onIncrement() {
if (!this.#actor) return
const current = this.#actor.system.value ?? 0
await this.#actor.update({ "system.value": current + 1 })
await setTinjiValue(getTinjiValue() + 1)
}
static async #onDecrement() {
if (!this.#actor) return
const current = this.#actor.system.value ?? 0
const current = getTinjiValue()
if (current <= 0) return
await this.#actor.update({ "system.value": current - 1 })
await setTinjiValue(current - 1)
}
static async #onReset() {
if (!this.#actor) return
await this.#actor.update({ "system.value": 0 })
await setTinjiValue(0)
}
/** Spend 1 Tin Ji die and announce it in chat */
static async #onSpend() {
if (!this.#actor) return
const current = this.#actor.system.value ?? 0
const current = getTinjiValue()
if (current <= 0) {
ui.notifications.warn(game.i18n.localize("CDE.TinjiEmpty"))
return
}
await this.#actor.update({ "system.value": current - 1 })
await setTinjiValue(current - 1)
ChatMessage.create({
user: game.user.id,
content: `<div class="cde-tinji-spend-msg">