Scrolling Texts are now queued with a 600ms delay (#989)

This commit is contained in:
WBHarry 2025-08-18 03:52:20 +02:00 committed by GitHub
parent 8c84edddad
commit 5cd5de31aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 43 additions and 25 deletions

View file

@ -1,5 +1,5 @@
import DHBaseActorSettings from '../../applications/sheets/api/actor-setting.mjs'; import DHBaseActorSettings from '../../applications/sheets/api/actor-setting.mjs';
import { createScrollText, getScrollTextData } from '../../helpers/utils.mjs'; import { getScrollTextData } from '../../helpers/utils.mjs';
const resistanceField = (resistanceLabel, immunityLabel, reductionLabel) => const resistanceField = (resistanceLabel, immunityLabel, reductionLabel) =>
new foundry.data.fields.SchemaField({ new foundry.data.fields.SchemaField({
@ -148,6 +148,6 @@ export default class BaseDataActor extends foundry.abstract.TypeDataModel {
_onUpdate(changes, options, userId) { _onUpdate(changes, options, userId) {
super._onUpdate(changes, options, userId); super._onUpdate(changes, options, userId);
createScrollText(this.parent, options.scrollingTextData); if (options.scrollingTextData) this.parent.queueScrollText(options.scrollingTextData);
} }
} }

View file

@ -221,6 +221,8 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
super._onUpdate(changed, options, userId); super._onUpdate(changed, options, userId);
updateLinkedItemApps(options, this.parent.sheet); updateLinkedItemApps(options, this.parent.sheet);
createScrollText(this.parent?.parent, options.scrollingTextData);
if (this.parent?.parent && options.scrollingTextData)
this.parent.parent.queueScrollText(options.scrollingTextData);
} }
} }

View file

@ -1,10 +1,13 @@
import { emitAsGM, GMUpdateEvent } from '../systemRegistration/socket.mjs'; import { emitAsGM, GMUpdateEvent } from '../systemRegistration/socket.mjs';
import { LevelOptionType } from '../data/levelTier.mjs'; import { LevelOptionType } from '../data/levelTier.mjs';
import DHFeature from '../data/item/feature.mjs'; import DHFeature from '../data/item/feature.mjs';
import { damageKeyToNumber } from '../helpers/utils.mjs'; import { createScrollText, damageKeyToNumber } from '../helpers/utils.mjs';
import DhCompanionLevelUp from '../applications/levelup/companionLevelup.mjs'; import DhCompanionLevelUp from '../applications/levelup/companionLevelup.mjs';
export default class DhpActor extends Actor { export default class DhpActor extends Actor {
#scrollTextQueue = [];
#scrollTextInterval;
/** /**
* Return the first Actor active owner. * Return the first Actor active owner.
*/ */
@ -27,7 +30,7 @@ export default class DhpActor extends Actor {
/** @inheritDoc */ /** @inheritDoc */
static migrateData(source) { static migrateData(source) {
if(source.system?.attack && !source.system.attack.type) source.system.attack.type = "attack"; if (source.system?.attack && !source.system.attack.type) source.system.attack.type = 'attack';
return super.migrateData(source); return super.migrateData(source);
} }
@ -572,19 +575,15 @@ export default class DhpActor extends Actor {
if (armorSlotResult) { if (armorSlotResult) {
const { modifiedDamage, armorSpent, stressSpent } = armorSlotResult; const { modifiedDamage, armorSpent, stressSpent } = armorSlotResult;
updates.find(u => u.key === 'hitPoints').value = modifiedDamage; updates.find(u => u.key === 'hitPoints').value = modifiedDamage;
if(armorSpent) { if (armorSpent) {
const armorUpdate = updates.find(u => u.key === 'armor'); const armorUpdate = updates.find(u => u.key === 'armor');
if(armorUpdate) if (armorUpdate) armorUpdate.value += armorSpent;
armorUpdate.value += armorSpent; else updates.push({ value: armorSpent, key: 'armor' });
else
updates.push({ value: armorSpent, key: 'armor' });
} }
if(stressSpent) { if (stressSpent) {
const stressUpdate = updates.find(u => u.key === 'stress'); const stressUpdate = updates.find(u => u.key === 'stress');
if(stressUpdate) if (stressUpdate) stressUpdate.value += stressSpent;
stressUpdate.value += stressSpent; else updates.push({ value: stressSpent, key: 'stress' });
else
updates.push({ value: stressSpent, key: 'stress' });
} }
} }
} }
@ -754,4 +753,23 @@ export default class DhpActor extends Actor {
} }
} }
} }
queueScrollText(scrollingTextData) {
this.#scrollTextQueue.push(...scrollingTextData.map(data => () => createScrollText(this, data)));
if (!this.#scrollTextInterval) {
const scrollFunc = this.#scrollTextQueue.pop();
scrollFunc?.();
const intervalFunc = () => {
const scrollFunc = this.#scrollTextQueue.pop();
scrollFunc?.();
if (this.#scrollTextQueue.length === 0) {
clearInterval(this.#scrollTextInterval);
this.#scrollTextInterval = null;
}
};
this.#scrollTextInterval = setInterval(intervalFunc.bind(this), 600);
}
}
} }

View file

@ -371,17 +371,15 @@ export function getScrollTextData(resources, resource, key) {
return { text, stroke, fill, direction }; return { text, stroke, fill, direction };
} }
export function createScrollText(actor, optionsData) { export function createScrollText(actor, data) {
if (actor && optionsData?.length) { if (actor) {
actor.getActiveTokens().forEach(token => { actor.getActiveTokens().forEach(token => {
optionsData.forEach(data => { const { text, ...options } = data;
const { text, ...options } = data; canvas.interface.createScrollingText(token.getCenterPoint(), data.text, {
canvas.interface.createScrollingText(token.getCenterPoint(), data.text, { duration: 2000,
duration: 2000, distance: token.h,
distance: token.h, jitter: 0,
jitter: 0, ...options
...options
});
}); });
}); });
} }