Add extra features to the Temple Enricher and fix the mousewheel issues with the Template Manager (#1147)

Co-authored-by: Chris Ryan <chrisr@blackhole>
This commit is contained in:
Chris Ryan 2025-09-07 09:27:46 +10:00 committed by GitHub
parent 2c6aabb97a
commit 58f039ce96
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 63 additions and 18 deletions

View file

@ -57,7 +57,10 @@ export default class DhTemplateManager {
* @param {wheel Event} event
*/
#onMouseWheel(event) {
if (!event.shiftKey) return;
if (!this.#activePreview) {
return;
}
if (!event.shiftKey && !event.ctrlKey) return;
event.stopPropagation();
event.preventDefault();
const { moveTime, object } = this.#activePreview;
@ -66,8 +69,10 @@ export default class DhTemplateManager {
if (now - (moveTime || 0) <= 16) return;
this.#activePreview.moveTime = now;
const multiplier = event.shiftKey ? 0.2 : 0.1;
object.document.updateSource({
direction: object.document.direction + event.deltaY * 0.2
direction: object.document.direction + event.deltaY * multiplier
});
object.renderFlags.set({ refresh: true });
}
@ -77,12 +82,13 @@ export default class DhTemplateManager {
* @param {contextmenu Event} event
*/
#cancelTemplate(event) {
const { mousemove, mousedown, contextmenu } = this.#activePreview.events;
const { mousemove, mousedown, contextmenu, wheel } = this.#activePreview.events;
canvas.templates._onDragLeftCancel(event);
canvas.stage.off('mousemove', mousemove);
canvas.stage.off('mousedown', mousedown);
canvas.app.view.removeEventListener('contextmenu', contextmenu);
canvas.app.view.removeEventListener('wheel', wheel);
}
/**
@ -91,9 +97,9 @@ export default class DhTemplateManager {
*/
#confirmTemplate(event) {
event.stopPropagation();
this.#cancelTemplate(event);
canvas.scene.createEmbeddedDocuments('MeasuredTemplate', [this.#activePreview.document.toObject()]);
this.#cancelTemplate(event);
this.#activePreview = undefined;
}
}