From 3fba97cc521394c3cafd4e5855601c9423cb7846 Mon Sep 17 00:00:00 2001 From: jalensailin Date: Sat, 19 Jul 2025 21:10:58 -0400 Subject: [PATCH] create/register sheets for all actor types; vehicle sheets don't work quite yet and npc/unnatural are the same thing --- module/deltagreen.js | 32 ++++++++++++---- module/sheets/agent-sheet.js | 51 ++++++++----------------- module/sheets/npc-sheet.js | 65 ++++++++++++++++++++++++++++++++ module/sheets/unnatural-sheet.js | 65 ++++++++++++++++++++++++++++++++ module/sheets/vehicle-sheet.js | 65 ++++++++++++++++++++++++++++++++ 5 files changed, 234 insertions(+), 44 deletions(-) create mode 100644 module/sheets/npc-sheet.js create mode 100644 module/sheets/unnatural-sheet.js create mode 100644 module/sheets/vehicle-sheet.js diff --git a/module/deltagreen.js b/module/deltagreen.js index 7499a56..85bb252 100644 --- a/module/deltagreen.js +++ b/module/deltagreen.js @@ -1,7 +1,7 @@ // Import Modules import DG from "./config.js"; import DeltaGreenActor from "./actor/actor.js"; -import DeltaGreenActorSheet from "./actor/actor-sheet.js"; +import DGAgentSheet from "./sheets/agent-sheet.js"; import DeltaGreenItem from "./item/item.js"; import DeltaGreenItemSheet from "./item/item-sheet.js"; import * as DGRolls from "./roll/roll.js"; @@ -17,6 +17,9 @@ import { rollSkillTestAndDamageForOwnedItem, } from "./other/macro-functions.js"; import { handleInlineActions } from "./other/inline.js"; +import DGNPCSheet from "./sheets/npc-sheet.js"; +import DGUnnaturalSheet from "./sheets/unnatural-sheet.js"; +import DGVehicleSheet from "./sheets/vehicle-sheet.js"; const { Actors, Items } = foundry.documents.collections; @@ -50,13 +53,26 @@ Hooks.once("init", async () => { CONFIG.Actor.documentClass = DeltaGreenActor; CONFIG.Item.documentClass = DeltaGreenItem; - // Register sheet application classes + // Unregister core sheets. Actors.unregisterSheet("core", foundry.appv1.sheets.ActorSheet); Items.unregisterSheet("core", foundry.appv1.sheets.ItemSheet); - Actors.registerSheet(DG.ID, DeltaGreenActorSheet, { - makeDefault: true, - themes: null, + + // Register all actor sheets. + const sheetClassMap = { + agent: DGAgentSheet, + npc: DGNPCSheet, + unnatural: DGUnnaturalSheet, + vehicle: DGVehicleSheet, + }; + Object.entries(sheetClassMap).forEach(([actorType, SheetClass]) => { + Actors.registerSheet(DG.ID, SheetClass, { + makeDefault: true, + themes: null, + types: [actorType], + }); }); + + // Register item sheet. Items.registerSheet(DG.ID, DeltaGreenItemSheet, { makeDefault: true, themes: null, @@ -199,11 +215,11 @@ Hooks.on("renderGamePause", function (_, html, options) { Hooks.on("renderChatLog", async (app, element, context, options) => { element.addEventListener("click", (event) => { const btnWithAction = event.target.closest("button[data-action]"); - const message = event.target.closest("li[data-message-id]") + const message = event.target.closest("li[data-message-id]"); - const { messageId } = message?.dataset || {} + const { messageId } = message?.dataset || {}; if (btnWithAction && messageId) { handleInlineActions(btnWithAction, messageId); } }); -}); \ No newline at end of file +}); diff --git a/module/sheets/agent-sheet.js b/module/sheets/agent-sheet.js index 06ac906..2eccc00 100644 --- a/module/sheets/agent-sheet.js +++ b/module/sheets/agent-sheet.js @@ -79,42 +79,21 @@ export default class DGAgentSheet extends DGActorSheet { async _prepareContext(options) { const context = await super._prepareContext(options); - switch (this.actor.type) { - case "agent": { - const enrichedDescription = - await foundry.applications.ux.TextEditor.implementation.enrichHTML( - this.actor.system.physicalDescription, - { - rollData: this.document.getRollData(), - relativeTo: this.document, - }, - ); - const { HTMLProseMirrorElement } = foundry.applications.elements; - context.descriptionField = HTMLProseMirrorElement.create({ - name: "system.physicalDescription", - value: this.actor.system.physicalDescription, - enriched: enrichedDescription, - toggled: true, - }).outerHTML; - break; - } - case "vehicle": - context.enrichedDescription = - await foundry.applications.ux.TextEditor.implementation.enrichHTML( - this.actor.system.description, - { async: true }, - ); - break; - case "npc": - case "unnatural": - context.enrichedDescription = - await foundry.applications.ux.TextEditor.implementation.enrichHTML( - this.actor.system.notes, - { async: true }, - ); - break; - default: - } + const enrichedDescription = + await foundry.applications.ux.TextEditor.implementation.enrichHTML( + this.actor.system.physicalDescription, + { + rollData: this.document.getRollData(), + relativeTo: this.document, + }, + ); + const { HTMLProseMirrorElement } = foundry.applications.elements; + context.descriptionField = HTMLProseMirrorElement.create({ + name: "system.physicalDescription", + value: this.actor.system.physicalDescription, + enriched: enrichedDescription, + toggled: true, + }).outerHTML; return context; } diff --git a/module/sheets/npc-sheet.js b/module/sheets/npc-sheet.js new file mode 100644 index 0000000..afa2b2a --- /dev/null +++ b/module/sheets/npc-sheet.js @@ -0,0 +1,65 @@ +import DGActorSheet from "./base-actor-sheet.js"; + +/** @extends {DGSheetMixin(ActorSheetV2)} */ +export default class DGNPCSheet extends DGActorSheet { + /** @override */ + static TABS = /** @type {const} */ ({ + primary: { + initial: "skills", + labelPrefix: "DG.Navigation", + tabs: [ + { id: "skills", label: "Skills" }, + { id: "physical", label: "Physical" }, + { id: "gear", label: "Gear" }, + { id: "about", icon: "fas fa-question-circle", label: "" }, + ], + }, + }); + + /** @override */ + static PARTS = /** @type {const} */ ({ + header: { + template: `${this.TEMPLATE_PATH}/actor/parts/header.html`, + }, + tabs: { + template: `templates/generic/tab-navigation.hbs`, // From FoundryVTT + }, + skills: { + template: `${this.TEMPLATE_PATH}/actor/parts/skills-tab.html`, + templates: [ + `${this.TEMPLATE_PATH}/actor/partials/custom-skills-partial.html`, + ], + scrollable: [""], + }, + physical: { + template: `${this.TEMPLATE_PATH}/actor/parts/physical-tab.html`, + templates: [ + `${this.TEMPLATE_PATH}/actor/partials/attributes-grid-partial.html`, + ], + scrollable: [""], + }, + gear: { + template: `${this.TEMPLATE_PATH}/actor/parts/gear-tab.html`, + scrollable: [""], + }, + about: { + template: `${this.TEMPLATE_PATH}/actor/parts/about-tab.html`, + scrollable: [""], + }, + }); + + /* -------------------------------------------- */ + + /** @override */ + async _prepareContext(options) { + const context = await super._prepareContext(options); + + context.enrichedDescription = + await foundry.applications.ux.TextEditor.implementation.enrichHTML( + this.actor.system.notes, + { async: true }, + ); + + return context; + } +} diff --git a/module/sheets/unnatural-sheet.js b/module/sheets/unnatural-sheet.js new file mode 100644 index 0000000..7e33dcc --- /dev/null +++ b/module/sheets/unnatural-sheet.js @@ -0,0 +1,65 @@ +import DGActorSheet from "./base-actor-sheet.js"; + +/** @extends {DGSheetMixin(ActorSheetV2)} */ +export default class DGUnnaturalSheet extends DGActorSheet { + /** @override */ + static TABS = /** @type {const} */ ({ + primary: { + initial: "skills", + labelPrefix: "DG.Navigation", + tabs: [ + { id: "skills", label: "Skills" }, + { id: "physical", label: "Physical" }, + { id: "gear", label: "Gear" }, + { id: "about", icon: "fas fa-question-circle", label: "" }, + ], + }, + }); + + /** @override */ + static PARTS = /** @type {const} */ ({ + header: { + template: `${this.TEMPLATE_PATH}/actor/parts/header.html`, + }, + tabs: { + template: `templates/generic/tab-navigation.hbs`, // From FoundryVTT + }, + skills: { + template: `${this.TEMPLATE_PATH}/actor/parts/skills-tab.html`, + templates: [ + `${this.TEMPLATE_PATH}/actor/partials/custom-skills-partial.html`, + ], + scrollable: [""], + }, + physical: { + template: `${this.TEMPLATE_PATH}/actor/parts/physical-tab.html`, + templates: [ + `${this.TEMPLATE_PATH}/actor/partials/attributes-grid-partial.html`, + ], + scrollable: [""], + }, + gear: { + template: `${this.TEMPLATE_PATH}/actor/parts/gear-tab.html`, + scrollable: [""], + }, + about: { + template: `${this.TEMPLATE_PATH}/actor/parts/about-tab.html`, + scrollable: [""], + }, + }); + + /* -------------------------------------------- */ + + /** @override */ + async _prepareContext(options) { + const context = await super._prepareContext(options); + + context.enrichedDescription = + await foundry.applications.ux.TextEditor.implementation.enrichHTML( + this.actor.system.notes, + { async: true }, + ); + + return context; + } +} diff --git a/module/sheets/vehicle-sheet.js b/module/sheets/vehicle-sheet.js new file mode 100644 index 0000000..59ea47c --- /dev/null +++ b/module/sheets/vehicle-sheet.js @@ -0,0 +1,65 @@ +import DGActorSheet from "./base-actor-sheet.js"; + +/** @extends {DGSheetMixin(ActorSheetV2)} */ +export default class DGVehicleSheet extends DGActorSheet { + /** @override */ + static TABS = /** @type {const} */ ({ + primary: { + initial: "skills", + labelPrefix: "DG.Navigation", + tabs: [ + { id: "skills", label: "Skills" }, + { id: "physical", label: "Physical" }, + { id: "gear", label: "Gear" }, + { id: "about", icon: "fas fa-question-circle", label: "" }, + ], + }, + }); + + /** @override */ + static PARTS = /** @type {const} */ ({ + header: { + template: `${this.TEMPLATE_PATH}/actor/parts/header.html`, + }, + tabs: { + template: `templates/generic/tab-navigation.hbs`, // From FoundryVTT + }, + skills: { + template: `${this.TEMPLATE_PATH}/actor/parts/skills-tab.html`, + templates: [ + `${this.TEMPLATE_PATH}/actor/partials/custom-skills-partial.html`, + ], + scrollable: [""], + }, + physical: { + template: `${this.TEMPLATE_PATH}/actor/parts/physical-tab.html`, + templates: [ + `${this.TEMPLATE_PATH}/actor/partials/attributes-grid-partial.html`, + ], + scrollable: [""], + }, + gear: { + template: `${this.TEMPLATE_PATH}/actor/parts/gear-tab.html`, + scrollable: [""], + }, + about: { + template: `${this.TEMPLATE_PATH}/actor/parts/about-tab.html`, + scrollable: [""], + }, + }); + + /* -------------------------------------------- */ + + /** @override */ + async _prepareContext(options) { + const context = await super._prepareContext(options); + + context.enrichedDescription = + await foundry.applications.ux.TextEditor.implementation.enrichHTML( + this.actor.system.description, + { async: true }, + ); + + return context; + } +}