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:
328
dist/system.js
vendored
328
dist/system.js
vendored
@@ -100,7 +100,9 @@ var TEMPLATE_PARTIALS = [
|
||||
"systems/fvtt-chroniques-de-l-etrange/templates/actor/parts/cde-npc-supernaturals.html",
|
||||
"systems/fvtt-chroniques-de-l-etrange/templates/actor/parts/cde-npc-spells.html",
|
||||
"systems/fvtt-chroniques-de-l-etrange/templates/actor/parts/cde-npc-kungfus.html",
|
||||
"systems/fvtt-chroniques-de-l-etrange/templates/actor/parts/cde-npc-items.html"
|
||||
"systems/fvtt-chroniques-de-l-etrange/templates/actor/parts/cde-npc-items.html",
|
||||
"systems/fvtt-chroniques-de-l-etrange/templates/apps/cde-loksyu-app.html",
|
||||
"systems/fvtt-chroniques-de-l-etrange/templates/apps/cde-tinji-app.html"
|
||||
];
|
||||
|
||||
// src/config/localize.js
|
||||
@@ -927,6 +929,61 @@ async function rollInitiativeNPC(actor) {
|
||||
});
|
||||
}
|
||||
|
||||
// src/ui/apps/singletons.js
|
||||
var WU_XING_CYCLE = {
|
||||
wood: ["wood", "fire", "water", "earth", "metal"],
|
||||
fire: ["fire", "earth", "wood", "metal", "water"],
|
||||
earth: ["earth", "metal", "fire", "water", "wood"],
|
||||
metal: ["metal", "water", "earth", "wood", "fire"],
|
||||
water: ["water", "wood", "metal", "fire", "earth"]
|
||||
};
|
||||
var ASPECT_FACES = {
|
||||
metal: [3, 8],
|
||||
water: [1, 6],
|
||||
earth: [0, 5],
|
||||
fire: [2, 7],
|
||||
wood: [4, 9]
|
||||
};
|
||||
async function getSingletonActor(type) {
|
||||
const existing = game.actors.find((a) => a.type === type);
|
||||
if (existing) return existing;
|
||||
if (!game.user.isGM) {
|
||||
ui.notifications.warn(game.i18n.localize(type === ACTOR_TYPES.loksyu ? "CDE.LoksyuNotFound" : "CDE.TinjiNotFound"));
|
||||
return null;
|
||||
}
|
||||
const nameKey = type === ACTOR_TYPES.loksyu ? "CDE.UpperCaseLoksyu" : "CDE.UpperCaseTinJi";
|
||||
const actor = await Actor.create({
|
||||
name: game.i18n.localize(nameKey),
|
||||
type,
|
||||
img: type === ACTOR_TYPES.loksyu ? "systems/fvtt-chroniques-de-l-etrange/images/loksyu_long.webp" : "systems/fvtt-chroniques-de-l-etrange/images/tinji.webp"
|
||||
});
|
||||
return actor ?? null;
|
||||
}
|
||||
async function updateLoksyuFromRoll(activeAspect, faces) {
|
||||
const cycle = WU_XING_CYCLE[activeAspect];
|
||||
if (!cycle) return;
|
||||
const lokAspect = cycle[3];
|
||||
const [yinFace, yangFace] = ASPECT_FACES[lokAspect] ?? [];
|
||||
if (yinFace === void 0) return;
|
||||
const yinCount = faces[yinFace] ?? 0;
|
||||
const yangCount = faces[yangFace] ?? 0;
|
||||
if (yinCount === 0 && yangCount === 0) return;
|
||||
const actor = await getSingletonActor(ACTOR_TYPES.loksyu);
|
||||
if (!actor) return;
|
||||
const current = actor.system[lokAspect] ?? { yin: { value: 0 }, yang: { value: 0 } };
|
||||
await actor.update({
|
||||
[`system.${lokAspect}.yin.value`]: (current.yin.value ?? 0) + yinCount,
|
||||
[`system.${lokAspect}.yang.value`]: (current.yang.value ?? 0) + yangCount
|
||||
});
|
||||
}
|
||||
async function updateTinjiFromRoll(count) {
|
||||
if (!count || count <= 0) return;
|
||||
const actor = await getSingletonActor(ACTOR_TYPES.tinji);
|
||||
if (!actor) return;
|
||||
const current = actor.system.value ?? 0;
|
||||
await actor.update({ "system.value": current + count });
|
||||
}
|
||||
|
||||
// src/ui/rolling.js
|
||||
var RESULT_TEMPLATE2 = "systems/fvtt-chroniques-de-l-etrange/templates/form/cde-dice-result.html";
|
||||
var SKILL_PROMPT_TEMPLATE = "systems/fvtt-chroniques-de-l-etrange/templates/form/cde-skill-dice-prompt.html";
|
||||
@@ -955,7 +1012,7 @@ var ASPECT_ICONS = {
|
||||
fire: "systems/fvtt-chroniques-de-l-etrange/images/cde_feu.webp",
|
||||
wood: "systems/fvtt-chroniques-de-l-etrange/images/cde_bois.webp"
|
||||
};
|
||||
var ASPECT_FACES = {
|
||||
var ASPECT_FACES2 = {
|
||||
metal: [3, 8],
|
||||
water: [1, 6],
|
||||
earth: [0, 5],
|
||||
@@ -963,7 +1020,7 @@ var ASPECT_FACES = {
|
||||
fire: [2, 7],
|
||||
wood: [4, 9]
|
||||
};
|
||||
var WU_XING_CYCLE = {
|
||||
var WU_XING_CYCLE2 = {
|
||||
wood: ["wood", "fire", "water", "earth", "metal"],
|
||||
fire: ["fire", "earth", "wood", "metal", "water"],
|
||||
earth: ["earth", "metal", "fire", "water", "wood"],
|
||||
@@ -993,14 +1050,14 @@ function countFaces(rollResults) {
|
||||
return counts;
|
||||
}
|
||||
function computeWuXingResults(faces, aspectName, bonusAuspicious = 0) {
|
||||
const cycle = WU_XING_CYCLE[aspectName];
|
||||
const cycle = WU_XING_CYCLE2[aspectName];
|
||||
if (!cycle) return null;
|
||||
const [succAspect, ausAspect, noxAspect, lokAspect, tinAspect] = cycle;
|
||||
const [succYin, succYang] = ASPECT_FACES[succAspect];
|
||||
const [ausYin, ausYang] = ASPECT_FACES[ausAspect];
|
||||
const [noxYin, noxYang] = ASPECT_FACES[noxAspect];
|
||||
const [lokYin, lokYang] = ASPECT_FACES[lokAspect];
|
||||
const [tinYin, tinYang] = ASPECT_FACES[tinAspect];
|
||||
const [succYin, succYang] = ASPECT_FACES2[succAspect];
|
||||
const [ausYin, ausYang] = ASPECT_FACES2[ausAspect];
|
||||
const [noxYin, noxYang] = ASPECT_FACES2[noxAspect];
|
||||
const [lokYin, lokYang] = ASPECT_FACES2[lokAspect];
|
||||
const [tinYin, tinYang] = ASPECT_FACES2[tinAspect];
|
||||
const yin = game.i18n.localize("CDE.Yin");
|
||||
const yang = game.i18n.localize("CDE.Yang");
|
||||
return {
|
||||
@@ -1296,6 +1353,8 @@ async function rollForActor(actor, rollKey) {
|
||||
if (game.modules.get("dice-so-nice")?.active && wpMsg?.id) {
|
||||
await game.dice3d.waitFor3DAnimationByMessageID(wpMsg.id);
|
||||
}
|
||||
if ((wpResults.loksyudice ?? 0) > 0) await updateLoksyuFromRoll(wpAspectName, wpFaces);
|
||||
if ((wpResults.tinjidice ?? 0) > 0) await updateTinjiFromRoll(wpResults.tinjidice);
|
||||
return;
|
||||
}
|
||||
default:
|
||||
@@ -1449,6 +1508,8 @@ async function rollForActor(actor, rollKey) {
|
||||
if (game.modules.get("dice-so-nice")?.active && msg?.id) {
|
||||
await game.dice3d.waitFor3DAnimationByMessageID(msg.id);
|
||||
}
|
||||
if ((results.loksyudice ?? 0) > 0) await updateLoksyuFromRoll(wuXingAspectName, faces);
|
||||
if ((results.tinjidice ?? 0) > 0) await updateTinjiFromRoll(results.tinjidice);
|
||||
}
|
||||
|
||||
// src/ui/sheets/actors/base.js
|
||||
@@ -1769,6 +1830,118 @@ var CDENpcSheet = class extends CDEBaseActorSheet {
|
||||
}
|
||||
};
|
||||
|
||||
// src/ui/apps/tinji-app.js
|
||||
var SYSTEM_ID2 = "fvtt-chroniques-de-l-etrange";
|
||||
var CDETinjiApp = class _CDETinjiApp extends foundry.applications.api.HandlebarsApplicationMixin(
|
||||
foundry.applications.api.ApplicationV2
|
||||
) {
|
||||
static DEFAULT_OPTIONS = {
|
||||
id: "cde-tinji-app",
|
||||
tag: "div",
|
||||
window: {
|
||||
title: "CDE.TinJi2",
|
||||
icon: "fas fa-star",
|
||||
resizable: false
|
||||
},
|
||||
classes: ["cde-app", "cde-tinji-standalone"],
|
||||
position: { width: 320, height: "auto" },
|
||||
actions: {
|
||||
increment: _CDETinjiApp.#onIncrement,
|
||||
decrement: _CDETinjiApp.#onDecrement,
|
||||
reset: _CDETinjiApp.#onReset,
|
||||
spend: _CDETinjiApp.#onSpend
|
||||
}
|
||||
};
|
||||
static PARTS = {
|
||||
main: {
|
||||
template: `systems/${SYSTEM_ID2}/templates/apps/cde-tinji-app.html`
|
||||
}
|
||||
};
|
||||
/** @type {Actor|null} */
|
||||
#actor = null;
|
||||
/** @type {Function|null} */
|
||||
#updateHook = null;
|
||||
static open() {
|
||||
const existing = Object.values(foundry.applications.instances ?? {}).find(
|
||||
(app2) => app2 instanceof _CDETinjiApp
|
||||
);
|
||||
if (existing) {
|
||||
existing.bringToFront();
|
||||
return existing;
|
||||
}
|
||||
const app = new _CDETinjiApp();
|
||||
app.render(true);
|
||||
return app;
|
||||
}
|
||||
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
|
||||
};
|
||||
}
|
||||
_onRender(context, options) {
|
||||
super._onRender(context, options);
|
||||
this.#bindDirectInput();
|
||||
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);
|
||||
}
|
||||
#bindDirectInput() {
|
||||
const input = this.element?.querySelector("input.cde-tinji-direct");
|
||||
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) });
|
||||
}
|
||||
});
|
||||
}
|
||||
static async #onIncrement() {
|
||||
if (!this.#actor) return;
|
||||
const current = this.#actor.system.value ?? 0;
|
||||
await this.#actor.update({ "system.value": current + 1 });
|
||||
}
|
||||
static async #onDecrement() {
|
||||
if (!this.#actor) return;
|
||||
const current = this.#actor.system.value ?? 0;
|
||||
if (current <= 0) return;
|
||||
await this.#actor.update({ "system.value": current - 1 });
|
||||
}
|
||||
static async #onReset() {
|
||||
if (!this.#actor) return;
|
||||
await this.#actor.update({ "system.value": 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;
|
||||
if (current <= 0) {
|
||||
ui.notifications.warn(game.i18n.localize("CDE.TinjiEmpty"));
|
||||
return;
|
||||
}
|
||||
await this.#actor.update({ "system.value": current - 1 });
|
||||
ChatMessage.create({
|
||||
user: game.user.id,
|
||||
content: `<div class="cde-tinji-spend-msg">
|
||||
<i class="fas fa-star"></i>
|
||||
<strong>${game.i18n.localize("CDE.TinJi2")}</strong>
|
||||
${game.i18n.format("CDE.TinjiSpent", { name: game.user.name })}
|
||||
<span class="cde-tinji-remain">(${current - 1} ${game.i18n.localize("CDE.TinjiRemaining")})</span>
|
||||
</div>`
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// src/ui/sheets/actors/tinji.js
|
||||
var CDETinjiSheet = class extends CDEBaseActorSheet {
|
||||
static DEFAULT_OPTIONS = {
|
||||
@@ -1778,6 +1951,120 @@ var CDETinjiSheet = class extends CDEBaseActorSheet {
|
||||
main: { template: "systems/fvtt-chroniques-de-l-etrange/templates/actor/cde-tinji-sheet.html" }
|
||||
};
|
||||
tabGroups = { primary: "tinji" };
|
||||
/** Redirect any direct actor-sheet open to the standalone app instead */
|
||||
async _onFirstRender(context, options) {
|
||||
await this.close({ animate: false });
|
||||
CDETinjiApp.open();
|
||||
}
|
||||
};
|
||||
|
||||
// src/ui/apps/loksyu-app.js
|
||||
var SYSTEM_ID3 = "fvtt-chroniques-de-l-etrange";
|
||||
var CDELoksyuApp = 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_ID3}/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(
|
||||
(app2) => app2 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_ID3}/images/cde_bois.webp` },
|
||||
{ key: "fire", nameKey: "CDE.Fire", qualKey: "CDE.FireQualities", img: `systems/${SYSTEM_ID3}/images/cde_feu.webp` },
|
||||
{ key: "earth", nameKey: "CDE.Earth", qualKey: "CDE.EarthQualities", img: `systems/${SYSTEM_ID3}/images/cde_terre.webp` },
|
||||
{ key: "metal", nameKey: "CDE.Metal", qualKey: "CDE.MetalQualities", img: `systems/${SYSTEM_ID3}/images/cde_metal.webp` },
|
||||
{ key: "water", nameKey: "CDE.Water", qualKey: "CDE.WaterQualities", img: `systems/${SYSTEM_ID3}/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();
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
// src/ui/sheets/actors/loksyu.js
|
||||
@@ -1789,6 +2076,11 @@ var CDELoksyuSheet = class extends CDEBaseActorSheet {
|
||||
main: { template: "systems/fvtt-chroniques-de-l-etrange/templates/actor/cde-loksyu-sheet.html" }
|
||||
};
|
||||
tabGroups = { primary: "loksyu" };
|
||||
/** Redirect any direct actor-sheet open to the standalone app instead */
|
||||
async _onFirstRender(context, options) {
|
||||
await this.close({ animate: false });
|
||||
CDELoksyuApp.open();
|
||||
}
|
||||
};
|
||||
|
||||
// src/ui/sheets/items/base.js
|
||||
@@ -2177,6 +2469,24 @@ Hooks.once("init", async () => {
|
||||
Hooks.once("ready", async () => {
|
||||
await migrateIfNeeded();
|
||||
});
|
||||
Hooks.on("renderChatLog", (_app, html) => {
|
||||
const el = html instanceof HTMLElement ? html : html[0];
|
||||
const controls = el?.querySelector?.(".chat-controls");
|
||||
if (!controls) return;
|
||||
const wrapper = document.createElement("div");
|
||||
wrapper.classList.add("cde-chat-app-buttons");
|
||||
wrapper.innerHTML = `
|
||||
<button class="cde-chat-btn cde-chat-btn--loksyu" title="${game.i18n.localize("CDE.Loksyu")}">
|
||||
<i class="fas fa-yin-yang"></i> ${game.i18n.localize("CDE.Loksyu")}
|
||||
</button>
|
||||
<button class="cde-chat-btn cde-chat-btn--tinji" title="${game.i18n.localize("CDE.TinJi2")}">
|
||||
<i class="fas fa-star"></i> ${game.i18n.localize("CDE.TinJi2")}
|
||||
</button>
|
||||
`;
|
||||
controls.appendChild(wrapper);
|
||||
wrapper.querySelector(".cde-chat-btn--loksyu")?.addEventListener("click", () => CDELoksyuApp.open());
|
||||
wrapper.querySelector(".cde-chat-btn--tinji")?.addEventListener("click", () => CDETinjiApp.open());
|
||||
});
|
||||
function injectCompendiumLink(html) {
|
||||
const header = html[0]?.querySelector?.("h4.divider");
|
||||
if (!header) return;
|
||||
|
||||
Reference in New Issue
Block a user