From f6ec583988d57025930f038ea6127a8a368af890 Mon Sep 17 00:00:00 2001 From: Joaquin Pereyra Date: Wed, 9 Jul 2025 13:53:24 -0300 Subject: [PATCH] FIX: Add enritch to HTMLField FIX: Remove no-HTMLField from Manifest FIX: Convert Scar's HTMLField to StringField FIX: Remove unused HTMLField --- .../applications/sheets/actors/adversary.mjs | 39 ++++++++++++++++ .../applications/sheets/actors/character.mjs | 46 +++++++++++++++++++ .../sheets/actors/environment.mjs | 39 ++++++++++++++++ module/data/actor/base.mjs | 9 ---- module/data/actor/character.mjs | 2 +- system.json | 6 +-- templates/sheets/actors/adversary/notes.hbs | 3 +- .../sheets/actors/character/biography.hbs | 4 +- templates/sheets/actors/environment/notes.hbs | 2 +- 9 files changed, 133 insertions(+), 17 deletions(-) diff --git a/module/applications/sheets/actors/adversary.mjs b/module/applications/sheets/actors/adversary.mjs index 67f57781..bc3f1f54 100644 --- a/module/applications/sheets/actors/adversary.mjs +++ b/module/applications/sheets/actors/adversary.mjs @@ -41,6 +41,45 @@ export default class AdversarySheet extends DHBaseActorSheet { return context; } + /**@inheritdoc */ + async _preparePartContext(partId, context, options) { + context = await super._preparePartContext(partId, context, options); + switch (partId) { + case 'notes': + await this._prepareNotesContext(context, options); + break; + } + return context; + } + + /** + * Prepare render context for the Biography part. + * @param {ApplicationRenderContext} context + * @param {ApplicationRenderOptions} options + * @returns {Promise} + * @protected + */ + async _prepareNotesContext(context, _options) { + const { system } = this.document; + const { TextEditor } = foundry.applications.ux; + + const paths = { + notes: 'notes' + }; + + for (const [key, path] of Object.entries(paths)) { + const value = foundry.utils.getProperty(system, path); + context[key] = { + field: system.schema.getField(path), + value, + enriched: await TextEditor.implementation.enrichHTML(value, { + secrets: this.document.isOwner, + relativeTo: this.document + }) + }; + } + } + getItem(element) { const itemId = (element.target ?? element).closest('[data-item-id]').dataset.itemId, item = this.document.items.get(itemId); diff --git a/module/applications/sheets/actors/character.mjs b/module/applications/sheets/actors/character.mjs index e70774f5..804185d0 100644 --- a/module/applications/sheets/actors/character.mjs +++ b/module/applications/sheets/actors/character.mjs @@ -160,18 +160,64 @@ export default class CharacterSheet extends DHBaseActorSheet { case 'sidebar': await this._prepareSidebarContext(context, options); break; + case 'biography': + await this._prepareBiographyContext(context, options); + break; } return context; } + /** + * Prepare render context for the Loadout part. + * @param {ApplicationRenderContext} context + * @param {ApplicationRenderOptions} options + * @returns {Promise} + * @protected + */ async _prepareLoadoutContext(context, _options) { context.listView = game.user.getFlag(CONFIG.DH.id, CONFIG.DH.FLAGS.displayDomainCardsAsList); } + /** + * Prepare render context for the Sidebar part. + * @param {ApplicationRenderContext} context + * @param {ApplicationRenderOptions} options + * @returns {Promise} + * @protected + */ async _prepareSidebarContext(context, _options) { context.isDeath = this.document.system.deathMoveViable; } + /** + * Prepare render context for the Biography part. + * @param {ApplicationRenderContext} context + * @param {ApplicationRenderOptions} options + * @returns {Promise} + * @protected + */ + async _prepareBiographyContext(context, _options) { + const { system } = this.document; + const { TextEditor } = foundry.applications.ux; + + const paths = { + background: 'biography.background', + connections: 'biography.connections' + }; + + for (const [key, path] of Object.entries(paths)) { + const value = foundry.utils.getProperty(system, path); + context[key] = { + field: system.schema.getField(path), + value, + enriched: await TextEditor.implementation.enrichHTML(value, { + secrets: this.document.isOwner, + relativeTo: this.document + }) + }; + } + } + /* -------------------------------------------- */ /* Context Menu */ /* -------------------------------------------- */ diff --git a/module/applications/sheets/actors/environment.mjs b/module/applications/sheets/actors/environment.mjs index 188d24b4..84e5f180 100644 --- a/module/applications/sheets/actors/environment.mjs +++ b/module/applications/sheets/actors/environment.mjs @@ -35,6 +35,45 @@ export default class DhpEnvironment extends DHBaseActorSheet { } }; + /**@inheritdoc */ + async _preparePartContext(partId, context, options) { + context = await super._preparePartContext(partId, context, options); + switch (partId) { + case 'notes': + await this._prepareNotesContext(context, options); + break; + } + return context; + } + + /** + * Prepare render context for the Biography part. + * @param {ApplicationRenderContext} context + * @param {ApplicationRenderOptions} options + * @returns {Promise} + * @protected + */ + async _prepareNotesContext(context, _options) { + const { system } = this.document; + const { TextEditor } = foundry.applications.ux; + + const paths = { + notes: 'notes' + }; + + for (const [key, path] of Object.entries(paths)) { + const value = foundry.utils.getProperty(system, path); + context[key] = { + field: system.schema.getField(path), + value, + enriched: await TextEditor.implementation.enrichHTML(value, { + secrets: this.document.isOwner, + relativeTo: this.document + }) + }; + } + } + /* -------------------------------------------- */ getItem(element) { diff --git a/module/data/actor/base.mjs b/module/data/actor/base.mjs index 1b90968d..1958ea28 100644 --- a/module/data/actor/base.mjs +++ b/module/data/actor/base.mjs @@ -24,15 +24,6 @@ export default class BaseDataActor extends foundry.abstract.TypeDataModel { return this.constructor.metadata; } - /** @inheritDoc */ - static defineSchema() { - const fields = foundry.data.fields; - - return { - description: new fields.HTMLField({ required: true, nullable: true }) - }; - } - /** * Obtain a data object used to evaluate any dice rolls associated with this Item Type * @param {object} [options] - Options which modify the getRollData method. diff --git a/module/data/actor/character.mjs b/module/data/actor/character.mjs index 93926d9a..857cac81 100644 --- a/module/data/actor/character.mjs +++ b/module/data/actor/character.mjs @@ -77,7 +77,7 @@ export default class DhCharacter extends BaseDataActor { scars: new fields.TypedObjectField( new fields.SchemaField({ name: new fields.StringField({}), - description: new fields.HTMLField() + description: new fields.StringField() }) ), biography: new fields.SchemaField({ diff --git a/system.json b/system.json index 7bd337f0..c6625167 100644 --- a/system.json +++ b/system.json @@ -207,14 +207,14 @@ "documentTypes": { "Actor": { "character": { - "htmlFields": ["story", "description", "scars.*.description"] + "htmlFields": ["biography.background", "biography.connections"] }, "companion": {}, "adversary": { - "htmlFields": ["description", "motivesAndTactics"] + "htmlFields": ["description"] }, "environment": { - "htmlFields": ["description", "impulses"] + "htmlFields": ["description"] } }, "Item": { diff --git a/templates/sheets/actors/adversary/notes.hbs b/templates/sheets/actors/adversary/notes.hbs index effa7240..e7ae7342 100644 --- a/templates/sheets/actors/adversary/notes.hbs +++ b/templates/sheets/actors/adversary/notes.hbs @@ -5,6 +5,7 @@ >
{{localize tabs.notes.label}} - {{formInput systemFields.notes value=document.system.notes enriched=document.system.notes localize=true toggled=true}} + {{log notes}} + {{formInput notes.field value=notes.value enriched=notes.value toggled=true}}
\ No newline at end of file diff --git a/templates/sheets/actors/character/biography.hbs b/templates/sheets/actors/character/biography.hbs index 34313def..6913f279 100644 --- a/templates/sheets/actors/character/biography.hbs +++ b/templates/sheets/actors/character/biography.hbs @@ -26,11 +26,11 @@
{{localize 'DAGGERHEART.ACTORS.Character.story.backgroundTitle'}} - {{formInput systemFields.biography.fields.background value=source.system.biography.background enriched=source.system.biography.background localize=true toggled=true}} + {{formInput background.field value=background.value enriched=background.enriched toggled=true}}
{{localize 'DAGGERHEART.ACTORS.Character.story.connectionsTitle'}} - {{formInput systemFields.biography.fields.connections value=source.system.biography.connections enriched=source.system.biography.connections localize=true toggled=true}} + {{formInput connections.field value=connections.value enriched=connections.enriched toggled=true}}
\ No newline at end of file diff --git a/templates/sheets/actors/environment/notes.hbs b/templates/sheets/actors/environment/notes.hbs index effa7240..663a484a 100644 --- a/templates/sheets/actors/environment/notes.hbs +++ b/templates/sheets/actors/environment/notes.hbs @@ -5,6 +5,6 @@ >
{{localize tabs.notes.label}} - {{formInput systemFields.notes value=document.system.notes enriched=document.system.notes localize=true toggled=true}} + {{formInput notes.field value=notes.value enriched=notes.value toggled=true}}
\ No newline at end of file