mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-07-21 18:09:54 +02:00
Preserve description expand state on re-render (#2089)
This commit is contained in:
parent
3a5529f1dc
commit
4974df16d0
4 changed files with 28 additions and 28 deletions
|
|
@ -185,8 +185,6 @@ export default class DhDeathMove extends HandlebarsApplicationMixin(ApplicationV
|
||||||
|
|
||||||
if (result === undefined) return;
|
if (result === undefined) return;
|
||||||
|
|
||||||
const autoExpandDescription = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance)
|
|
||||||
.expandRollMessage?.desc;
|
|
||||||
const cls = getDocumentClass('ChatMessage');
|
const cls = getDocumentClass('ChatMessage');
|
||||||
|
|
||||||
const msg = {
|
const msg = {
|
||||||
|
|
@ -202,7 +200,6 @@ export default class DhDeathMove extends HandlebarsApplicationMixin(ApplicationV
|
||||||
img: this.selectedMove.img,
|
img: this.selectedMove.img,
|
||||||
description: game.i18n.localize(this.selectedMove.description),
|
description: game.i18n.localize(this.selectedMove.description),
|
||||||
result: result,
|
result: result,
|
||||||
open: autoExpandDescription ? 'open' : '',
|
|
||||||
showRiskItAllButton: this.showRiskItAllButton,
|
showRiskItAllButton: this.showRiskItAllButton,
|
||||||
riskItAllButtonLabel: this.riskItAllButtonLabel,
|
riskItAllButtonLabel: this.riskItAllButtonLabel,
|
||||||
riskItAllHope: this.riskItAllHope
|
riskItAllHope: this.riskItAllHope
|
||||||
|
|
|
||||||
|
|
@ -196,9 +196,6 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV
|
||||||
.filter(x => x.testUserPermission(game.user, 'LIMITED'))
|
.filter(x => x.testUserPermission(game.user, 'LIMITED'))
|
||||||
.filter(x => x.uuid !== this.actor.uuid);
|
.filter(x => x.uuid !== this.actor.uuid);
|
||||||
|
|
||||||
const autoExpandDescription = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance)
|
|
||||||
.expandRollMessage?.desc;
|
|
||||||
|
|
||||||
const cls = getDocumentClass('ChatMessage');
|
const cls = getDocumentClass('ChatMessage');
|
||||||
const msg = {
|
const msg = {
|
||||||
user: game.user.id,
|
user: game.user.id,
|
||||||
|
|
@ -219,8 +216,7 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV
|
||||||
actor: { name: this.actor.name, img: this.actor.img },
|
actor: { name: this.actor.name, img: this.actor.img },
|
||||||
moves: moves,
|
moves: moves,
|
||||||
characters: characters,
|
characters: characters,
|
||||||
selfId: this.actor.uuid,
|
selfId: this.actor.uuid
|
||||||
open: autoExpandDescription ? 'open' : ''
|
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
flags: {
|
flags: {
|
||||||
|
|
|
||||||
|
|
@ -270,9 +270,6 @@ export function ActionMixin(Base) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async toChat(origin, config) {
|
async toChat(origin, config) {
|
||||||
const autoExpandDescription = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance)
|
|
||||||
.expandRollMessage?.desc;
|
|
||||||
|
|
||||||
const cls = getDocumentClass('ChatMessage');
|
const cls = getDocumentClass('ChatMessage');
|
||||||
const systemData = {
|
const systemData = {
|
||||||
title: game.i18n.localize('DAGGERHEART.CONFIG.FeatureForm.action'),
|
title: game.i18n.localize('DAGGERHEART.CONFIG.FeatureForm.action'),
|
||||||
|
|
@ -307,7 +304,7 @@ export function ActionMixin(Base) {
|
||||||
system: systemData,
|
system: systemData,
|
||||||
content: await foundry.applications.handlebars.renderTemplate(
|
content: await foundry.applications.handlebars.renderTemplate(
|
||||||
'systems/daggerheart/templates/ui/chat/action.hbs',
|
'systems/daggerheart/templates/ui/chat/action.hbs',
|
||||||
{ ...systemData, open: autoExpandDescription ? 'open' : '' }
|
systemData
|
||||||
),
|
),
|
||||||
flags: {
|
flags: {
|
||||||
daggerheart: {
|
daggerheart: {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,13 @@ import { emitGMUpdate, emitGMCreate, GMUpdateEvent } from '../systemRegistration
|
||||||
export default class DhpChatMessage extends foundry.documents.ChatMessage {
|
export default class DhpChatMessage extends foundry.documents.ChatMessage {
|
||||||
targetHook = null;
|
targetHook = null;
|
||||||
|
|
||||||
|
static #EXPAND_SECTIONS = [
|
||||||
|
{ selector: 'roll-section [data-action="expandRoll"]', key: 'roll' },
|
||||||
|
{ selector: 'damage-section', key: 'damage' },
|
||||||
|
{ selector: 'target-section', key: 'target' },
|
||||||
|
{ selector: 'description-section', key: 'desc' }
|
||||||
|
];
|
||||||
|
|
||||||
async renderHTML() {
|
async renderHTML() {
|
||||||
const actor = game.actors.get(this.speaker.actor);
|
const actor = game.actors.get(this.speaker.actor);
|
||||||
const actorData =
|
const actorData =
|
||||||
|
|
@ -89,23 +96,26 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check registered selectors and the main item section for expanding
|
||||||
|
// Preserving during re-render is handled by core foundry on anything with [data-action=expandRoll]
|
||||||
const autoExpandRoll = game.settings.get(
|
const autoExpandRoll = game.settings.get(
|
||||||
CONFIG.DH.id,
|
CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance
|
||||||
CONFIG.DH.SETTINGS.gameSettings.appearance
|
).expandRollMessage;
|
||||||
).expandRollMessage,
|
for (const { selector, key } of DhpChatMessage.#EXPAND_SECTIONS) {
|
||||||
rollSections = html.querySelectorAll('.roll-part'),
|
const elements = html.querySelectorAll(selector);
|
||||||
itemDesc = html.querySelector('.domain-card-move');
|
for (const element of elements) {
|
||||||
rollSections.forEach(s => {
|
element.classList.toggle('expanded', autoExpandRoll[key]);
|
||||||
if (s.classList.contains('roll-section')) {
|
}
|
||||||
const toExpand = s.querySelector('[data-action="expandRoll"]');
|
}
|
||||||
toExpand.classList.toggle('expanded', autoExpandRoll.roll);
|
|
||||||
} else if (s.classList.contains('damage-section'))
|
// Auto expand the item description. These are not preserved by foundry during re-renders
|
||||||
s.classList.toggle('expanded', autoExpandRoll.damage);
|
const itemDesc = html.querySelector('details');
|
||||||
else if (s.classList.contains('target-section')) s.classList.toggle('expanded', autoExpandRoll.target);
|
if (itemDesc) {
|
||||||
else if (s.classList.contains('description-section'))
|
const existing = document.querySelector(`.chat-message[data-message-id="${this.id}"] details`);
|
||||||
s.classList.toggle('expanded', autoExpandRoll.desc);
|
if (existing?.hasAttribute('open') ?? autoExpandRoll.desc) {
|
||||||
});
|
itemDesc.setAttribute('open', '');
|
||||||
if (itemDesc && autoExpandRoll.desc) itemDesc.setAttribute('open', '');
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.isAuthor && !this.speakerActor?.isOwner) {
|
if (!this.isAuthor && !this.speakerActor?.isOwner) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue