create/register sheets for all actor types;

vehicle sheets don't work quite yet and npc/unnatural are the same thing
This commit is contained in:
jalensailin
2025-07-22 12:36:13 -04:00
parent 47e800cd57
commit 3fba97cc52
5 changed files with 234 additions and 44 deletions
+24 -8
View File
@@ -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);
}
});
});
});
+15 -36
View File
@@ -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;
}
+65
View File
@@ -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;
}
}
+65
View File
@@ -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;
}
}
+65
View File
@@ -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;
}
}