From f91c3d2419ad09289768bed3a9b198695032d39b Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 8 Mar 2026 13:11:14 -0600 Subject: [PATCH 01/19] Create the Item data model --- langs/en-ca.json | 3 +++ module/data/Item/generic.mjs | 25 +++++++++++++++++++++++++ module/documents/Item.mjs | 7 ------- module/hooks/init.mjs | 7 ++----- system.json | 9 ++++++++- 5 files changed, 38 insertions(+), 13 deletions(-) create mode 100644 module/data/Item/generic.mjs delete mode 100644 module/documents/Item.mjs diff --git a/langs/en-ca.json b/langs/en-ca.json index 6dee3ec..2790b0a 100644 --- a/langs/en-ca.json +++ b/langs/en-ca.json @@ -2,6 +2,9 @@ "TYPES": { "Actor": { "player": "Player" + }, + "Item": { + "generic": "Generic Item" } }, "taf": { diff --git a/module/data/Item/generic.mjs b/module/data/Item/generic.mjs new file mode 100644 index 0000000..b030f6f --- /dev/null +++ b/module/data/Item/generic.mjs @@ -0,0 +1,25 @@ +export class GenericItemData extends foundry.abstract.TypeDataModel { + static defineSchema() { + const fields = foundry.data.fields; + return { + weight: new fields.NumberField({ + min: 0, + initial: 0, + nullable: false, + }), + quantity: new fields.NumberField({ + integer: true, + min: 0, + initial: 1, + }), + equipped: new fields.BooleanField({ + initial: true, + }), + description: new fields.HTMLField({ + blank: true, + trim: true, + initial: ``, + }), + }; + }; +}; diff --git a/module/documents/Item.mjs b/module/documents/Item.mjs deleted file mode 100644 index 683187e..0000000 --- a/module/documents/Item.mjs +++ /dev/null @@ -1,7 +0,0 @@ -const { Item } = foundry.documents; - -export class TAFItem extends Item { - async _preCreate() { - return false; - }; -}; diff --git a/module/hooks/init.mjs b/module/hooks/init.mjs index 6ff92f0..283405a 100644 --- a/module/hooks/init.mjs +++ b/module/hooks/init.mjs @@ -5,11 +5,11 @@ import { SingleModePlayerSheet } from "../apps/SingleModePlayerSheet.mjs"; // Data Models import { PlayerData } from "../data/Player.mjs"; +import { GenericItemData } from "../data/Item/generic.mjs"; // Documents import { TAFActor } from "../documents/Actor.mjs"; import { TAFCombatant } from "../documents/Combatant.mjs"; -import { TAFItem } from "../documents/Item.mjs"; import { TAFTokenDocument } from "../documents/Token.mjs"; // Settings @@ -30,10 +30,7 @@ Hooks.on(`init`, () => { CONFIG.Combatant.documentClass = TAFCombatant; CONFIG.Actor.dataModels.player = PlayerData; - - // We disable items in the system for now - CONFIG.Item.documentClass = TAFItem; - delete CONFIG.ui.sidebar.TABS.items; + CONFIG.Item.dataModels.generic = GenericItemData; foundry.documents.collections.Actors.registerSheet( __ID__, diff --git a/system.json b/system.json index 94e2ccd..a756e80 100644 --- a/system.json +++ b/system.json @@ -39,7 +39,14 @@ "filePathFields": {} } }, - "Item": {} + "Item": { + "generic": { + "htmlFields": [ + "description" + ], + "filePathFields": {} + } + } }, "socket": true, "flags": { From 2518c7cf053d7d92d357b035c1e5e934c76e2943 Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 13 Mar 2026 01:05:52 -0600 Subject: [PATCH 02/19] Begin work on the most basic item sheet version --- module/apps/GenericItemSheet.mjs | 47 ++++++++++++++++++++++++++ module/hooks/init.mjs | 16 +++++++++ styles/Apps/GenericItemSheet.css | 18 ++++++++++ styles/main.css | 1 + templates/GenericItemSheet/content.hbs | 13 +++++++ templates/GenericItemSheet/header.hbs | 25 ++++++++++++++ 6 files changed, 120 insertions(+) create mode 100644 module/apps/GenericItemSheet.mjs create mode 100644 styles/Apps/GenericItemSheet.css create mode 100644 templates/GenericItemSheet/content.hbs create mode 100644 templates/GenericItemSheet/header.hbs diff --git a/module/apps/GenericItemSheet.mjs b/module/apps/GenericItemSheet.mjs new file mode 100644 index 0000000..a5f9ac8 --- /dev/null +++ b/module/apps/GenericItemSheet.mjs @@ -0,0 +1,47 @@ +import { __ID__, filePath } from "../consts.mjs"; + +const { HandlebarsApplicationMixin } = foundry.applications.api; +const { ItemSheetV2 } = foundry.applications.sheets; + +export class GenericItemSheet extends HandlebarsApplicationMixin(ItemSheetV2) { + // #region Options + static DEFAULT_OPTIONS = { + classes: [ + __ID__, + `GenericItemSheet`, + ], + position: { + width: 400, + height: 450, + }, + window: { + resizable: true, + }, + form: { + submitOnChange: true, + closeOnSubmit: false, + }, + actions: {}, + }; + + static PARTS = { + header: { template: filePath(`templates/GenericItemSheet/header.hbs`) }, + content: { template: filePath(`templates/GenericItemSheet/content.hbs`) }, + }; + // #endregion Options + + // #region Instance Data + // #endregion Instance Data + + // #region Lifecycle + async _prepareContext(partID) { + return { + item: this.item, + system: this.item.system, + }; + }; + // #endregion Lifecycle + + // #region Actions + // #endregion Actions +}; diff --git a/module/hooks/init.mjs b/module/hooks/init.mjs index 283405a..bcf540e 100644 --- a/module/hooks/init.mjs +++ b/module/hooks/init.mjs @@ -2,6 +2,7 @@ import { AttributeOnlyPlayerSheet } from "../apps/AttributeOnlyPlayerSheet.mjs"; import { PlayerSheet } from "../apps/PlayerSheet.mjs"; import { SingleModePlayerSheet } from "../apps/SingleModePlayerSheet.mjs"; +import { GenericItemSheet } from "../apps/GenericItemSheet.mjs"; // Data Models import { PlayerData } from "../data/Player.mjs"; @@ -25,13 +26,18 @@ import { registerSockets } from "../sockets/_index.mjs"; Hooks.on(`init`, () => { Logger.debug(`Initializing`); + // #region Documents CONFIG.Token.documentClass = TAFTokenDocument; CONFIG.Actor.documentClass = TAFActor; CONFIG.Combatant.documentClass = TAFCombatant; + // #endregion Documents + // #region Data Models CONFIG.Actor.dataModels.player = PlayerData; CONFIG.Item.dataModels.generic = GenericItemData; + // #endregion Data Models + // #region Sheets foundry.documents.collections.Actors.registerSheet( __ID__, PlayerSheet, @@ -51,6 +57,16 @@ Hooks.on(`init`, () => { { label: `taf.sheet-names.AttributeOnlyPlayerSheet` }, ); + foundry.documents.collections.Items.registerSheet( + __ID__, + GenericItemSheet, + { + makeDefault: true, + label: `taf.sheet-names.GenericItemSheet`, + }, + ); + // #endregion Sheets + registerWorldSettings(); registerSockets(); diff --git a/styles/Apps/GenericItemSheet.css b/styles/Apps/GenericItemSheet.css new file mode 100644 index 0000000..4d11f47 --- /dev/null +++ b/styles/Apps/GenericItemSheet.css @@ -0,0 +1,18 @@ +.taf.GenericItemSheet { + .bordered { + border-radius: 8px; + border: 1px solid rebeccapurple; + } + + .sheet-header { + display: grid; + grid-template-columns: auto 1fr min-content 75px; + gap: 4px; + align-items: center; + padding: 4px; + + img { + border-radius: 4px; + } + } +} diff --git a/styles/main.css b/styles/main.css index a4c4a2c..c75456b 100644 --- a/styles/main.css +++ b/styles/main.css @@ -24,6 +24,7 @@ @import url("./Apps/common.css") layer(apps); @import url("./Apps/Ask.css") layer(apps); @import url("./Apps/AttributeManager.css") layer(apps); +@import url("./Apps/GenericItemSheet.css") layer(apps); @import url("./Apps/PlayerSheet.css") layer(apps); @import url("./Apps/QueryStatus.css") layer(apps); @import url("./Apps/TAFDocumentSheetConfig.css") layer(apps); diff --git a/templates/GenericItemSheet/content.hbs b/templates/GenericItemSheet/content.hbs new file mode 100644 index 0000000..0018b47 --- /dev/null +++ b/templates/GenericItemSheet/content.hbs @@ -0,0 +1,13 @@ +
+ + + +
diff --git a/templates/GenericItemSheet/header.hbs b/templates/GenericItemSheet/header.hbs new file mode 100644 index 0000000..1e863fa --- /dev/null +++ b/templates/GenericItemSheet/header.hbs @@ -0,0 +1,25 @@ +
+ + + + +
From 94b3ec923be4e69d55e5582e88b64015829b6c00 Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 13 Mar 2026 21:31:03 -0600 Subject: [PATCH 03/19] Finish getting the main item sheet completed and fully functional --- module/apps/GenericItemSheet.mjs | 29 ++++++++++++++- styles/Apps/GenericItemSheet.css | 34 ++++++++++++++++++ templates/GenericItemSheet/content.hbs | 49 +++++++++++++++++++------- templates/GenericItemSheet/header.hbs | 5 ++- 4 files changed, 103 insertions(+), 14 deletions(-) diff --git a/module/apps/GenericItemSheet.mjs b/module/apps/GenericItemSheet.mjs index a5f9ac8..5b37eac 100644 --- a/module/apps/GenericItemSheet.mjs +++ b/module/apps/GenericItemSheet.mjs @@ -2,6 +2,7 @@ import { __ID__, filePath } from "../consts.mjs"; const { HandlebarsApplicationMixin } = foundry.applications.api; const { ItemSheetV2 } = foundry.applications.sheets; +const { setProperty } = foundry.utils; export class GenericItemSheet extends HandlebarsApplicationMixin(ItemSheetV2) { // #region Options @@ -34,12 +35,38 @@ export class GenericItemSheet extends HandlebarsApplicationMixin(ItemSheetV2) { // #endregion Instance Data // #region Lifecycle - async _prepareContext(partID) { + async _prepareContext() { return { + meta: { + idp: this.id, + editable: this.isEditable, + limited: this.isLimited + }, item: this.item, system: this.item.system, }; }; + + async _preparePartContext(partID, ctx) { + switch (partID) { + case `content`: { + await this._prepareContentContext(ctx); + break; + }; + }; + + return ctx; + }; + + async _prepareContentContext(ctx) { + const TextEditor = foundry.applications.ux.TextEditor.implementation; + + setProperty( + ctx, + `enriched.system.description`, + await TextEditor.enrichHTML(this.item.system.description), + ); + }; // #endregion Lifecycle // #region Actions diff --git a/styles/Apps/GenericItemSheet.css b/styles/Apps/GenericItemSheet.css index 4d11f47..b03cb30 100644 --- a/styles/Apps/GenericItemSheet.css +++ b/styles/Apps/GenericItemSheet.css @@ -15,4 +15,38 @@ border-radius: 4px; } } + + .content { + display: contents; + } + + .property { + display: grid; + grid-template-columns: 1fr 100px; + align-items: center; + gap: 8px; + + input[type="checkbox"] { + justify-self: end; + } + } + + .description { + flex-grow: 1; + overflow: hidden; + --table-row-color-odd: var(--table-header-bg-color); + + &:not(:has(> prose-mirror)) { + padding: 0.5rem; + } + } + + prose-mirror { + height: 100%; + + menu { + border-bottom-left-radius: 0; + border-bottom-right-radius: 0; + } + } } diff --git a/templates/GenericItemSheet/content.hbs b/templates/GenericItemSheet/content.hbs index 0018b47..818c483 100644 --- a/templates/GenericItemSheet/content.hbs +++ b/templates/GenericItemSheet/content.hbs @@ -1,13 +1,38 @@ -
- - - +
+
+ + +
+
+ + +
+
+ {{#if meta.editable}} + + {{{ enriched.system.description }}} + + {{else}} + {{{ enriched.system.description }}} + {{/if}} +
diff --git a/templates/GenericItemSheet/header.hbs b/templates/GenericItemSheet/header.hbs index 1e863fa..b942593 100644 --- a/templates/GenericItemSheet/header.hbs +++ b/templates/GenericItemSheet/header.hbs @@ -9,9 +9,11 @@ > @@ -19,6 +21,7 @@ type="number" name="system.quantity" value="{{system.quantity}}" + {{disabled (not meta.editable)}} data-tooltip aria-label="Quantity" > From d9d66abf276e8170a1e44543d7e8d7e58e197197 Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 13 Mar 2026 21:35:10 -0600 Subject: [PATCH 04/19] Add localization for the item sheet fields --- langs/en-ca.json | 7 ++++++- templates/GenericItemSheet/content.hbs | 10 ++++++---- templates/GenericItemSheet/header.hbs | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/langs/en-ca.json b/langs/en-ca.json index 2790b0a..0377938 100644 --- a/langs/en-ca.json +++ b/langs/en-ca.json @@ -55,7 +55,12 @@ "save-and-close": "Save and Close", "delete": "Delete", "resizable": "Resizable", - "not-resizable": "Not Resizable" + "not-resizable": "Not Resizable", + "item": { + "weight": "Weight", + "quantity": "Quantity", + "equipped": "Equipped" + } }, "Apps": { "Ask": { diff --git a/templates/GenericItemSheet/content.hbs b/templates/GenericItemSheet/content.hbs index 818c483..ec90aca 100644 --- a/templates/GenericItemSheet/content.hbs +++ b/templates/GenericItemSheet/content.hbs @@ -1,21 +1,23 @@
-
-
+
+ + +