feat: Loksyu & TinJi standalone AppV2 apps with chat buttons and dice automation

- CDELoksyuApp: standalone HandlebarsApplicationMixin(ApplicationV2) app
  - 5-element Wu Xing grid with yin/yang inputs per element
  - Per-element reset buttons + global reset-all
  - Auto-refresh via updateActor hook

- CDETinjiApp: standalone AppV2 for the collective Tin Ji dice pool
  - Large neon counter with +/- buttons and direct input
  - Spend button sends a chat message with remaining count

- singletons.js: shared utilities
  - getSingletonActor: find or auto-create singleton actor
  - updateLoksyuFromRoll: compute lokAspect from Wu Xing cycle, update yin/yang
  - updateTinjiFromRoll: add tinji face count to value

- rolling.js: auto-update both singletons after every dice roll
  (weapon path + main roll path)

- system.js: renderChatLog hook injects Loksyu/TinJi footer buttons
  in the chat sidebar

- loksyu.js / tinji.js: actor sheets redirect to standalone apps
  when opened via the sidebar

- CSS: .cde-loksyu-standalone, .cde-tinji-standalone, .cde-chat-app-buttons,
  .cde-tinji-spend-msg styles added

- i18n: new keys in fr-cde.json and en-cde.json for all new UI strings
  (LoksyuNotFound, TinjiNotFound, Reset, ResetAll, SpendTinji, etc.)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-03-30 09:51:39 +02:00
parent 6fda4b9246
commit 0689fae792
41 changed files with 1558 additions and 13 deletions

121
src/ui/apps/loksyu-app.js Normal file
View File

@@ -0,0 +1,121 @@
import { getSingletonActor } from "./singletons.js"
import { ACTOR_TYPES } from "../../config/constants.js"
const SYSTEM_ID = "fvtt-chroniques-de-l-etrange"
export class CDELoksyuApp extends foundry.applications.api.HandlebarsApplicationMixin(
foundry.applications.api.ApplicationV2
) {
static DEFAULT_OPTIONS = {
id: "cde-loksyu-app",
tag: "div",
window: {
title: "CDE.Loksyu",
icon: "fas fa-yin-yang",
resizable: false,
},
classes: ["cde-app", "cde-loksyu-standalone"],
position: { width: 540, height: "auto" },
actions: {
resetElement: CDELoksyuApp.#onResetElement,
resetAll: CDELoksyuApp.#onResetAll,
},
}
static PARTS = {
main: {
template: `systems/${SYSTEM_ID}/templates/apps/cde-loksyu-app.html`,
},
}
/** @type {Actor|null} */
#actor = null
/** @type {Function|null} bound hook handler */
#updateHook = null
/** Singleton accessor — open or bring to front */
static open() {
const existing = Object.values(foundry.applications.instances ?? {}).find(
(app) => app instanceof CDELoksyuApp
)
if (existing) { existing.bringToFront(); return existing }
const app = new CDELoksyuApp()
app.render(true)
return app
}
async _prepareContext() {
this.#actor = await getSingletonActor(ACTOR_TYPES.loksyu)
if (!this.#actor) return { hasActor: false }
const sys = this.#actor.system
const ELEMENTS = [
{ key: "wood", nameKey: "CDE.Wood", qualKey: "CDE.WoodQualities", img: `systems/${SYSTEM_ID}/images/cde_bois.webp` },
{ key: "fire", nameKey: "CDE.Fire", qualKey: "CDE.FireQualities", img: `systems/${SYSTEM_ID}/images/cde_feu.webp` },
{ key: "earth", nameKey: "CDE.Earth", qualKey: "CDE.EarthQualities", img: `systems/${SYSTEM_ID}/images/cde_terre.webp` },
{ key: "metal", nameKey: "CDE.Metal", qualKey: "CDE.MetalQualities", img: `systems/${SYSTEM_ID}/images/cde_metal.webp` },
{ key: "water", nameKey: "CDE.Water", qualKey: "CDE.WaterQualities", img: `systems/${SYSTEM_ID}/images/cde_eau.webp` },
]
return {
hasActor: true,
canEdit: this.#actor.isOwner,
elements: ELEMENTS.map((el) => ({
...el,
yang: sys[el.key]?.yang?.value ?? 0,
yin: sys[el.key]?.yin?.value ?? 0,
})),
}
}
_onRender(context, options) {
super._onRender(context, options)
this.#bindInputs()
// Subscribe to actor updates to keep the app live
this.#updateHook = Hooks.on("updateActor", (actor) => {
if (actor.id === this.#actor?.id) this.render()
})
}
_onClose(options) {
if (this.#updateHook !== null) {
Hooks.off("updateActor", this.#updateHook)
this.#updateHook = null
}
super._onClose(options)
}
#bindInputs() {
const inputs = this.element?.querySelectorAll("input[data-field]")
if (!inputs?.length) return
inputs.forEach((input) => {
input.addEventListener("change", async (ev) => {
const field = ev.currentTarget.dataset.field
const val = parseInt(ev.currentTarget.value, 10)
if (!field || isNaN(val)) return
await this.#actor?.update({ [field]: Math.max(0, val) })
})
})
}
static async #onResetElement(event, target) {
const key = target.dataset.element
if (!key || !this.#actor) return
await this.#actor.update({
[`system.${key}.yin.value`]: 0,
[`system.${key}.yang.value`]: 0,
})
}
static async #onResetAll(_event, _target) {
if (!this.#actor) return
const KEYS = ["wood", "fire", "earth", "metal", "water"]
const update = {}
for (const k of KEYS) {
update[`system.${k}.yin.value`] = 0
update[`system.${k}.yang.value`] = 0
}
await this.#actor.update(update)
}
}