refactor(framework): use callback instead of events in

dragDropEventEffect

Replace Phaser event emissions with a `DragDropCallback` in
`dragDropEventEffect` to provide a more explicit and type-safe API
for handling drag-and-drop interactions.
This commit is contained in:
hypercross 2026-04-19 12:50:50 +08:00
parent c25759d147
commit 4d34f9fa78
3 changed files with 8 additions and 7 deletions

View File

@ -4,7 +4,7 @@ export type { IDisposable, DisposableItem } from "./utils";
// Drag & drop utilities
export { dragDropEventEffect, DragDropEventType } from "./utils";
export type { DragDropEvent } from "./utils";
export type { DragDropEvent, DragDropCallback } from "./utils";
// Data-driven object spawning
export { spawnEffect } from "./spawner";

View File

@ -18,8 +18,11 @@ export type DragDropEvent = {
deltaY: number;
};
export type DragDropCallback = (event: DragDropEvent) => void;
export function dragDropEventEffect(
gameObject: Phaser.GameObjects.GameObject,
callback: DragDropCallback,
disposables?: DisposableBag,
): () => void {
let isDragging = false;
@ -35,8 +38,7 @@ export function dragDropEventEffect(
deltaX: 0,
deltaY: 0,
};
gameObject.emit("drag", event);
gameObject.emit("dragstart", event);
callback(event);
}
function onPointerUp(pointer: Phaser.Input.Pointer) {
@ -46,8 +48,7 @@ export function dragDropEventEffect(
const deltaX = pointer.x - down.x;
const deltaY = pointer.y - down.y;
const event: DragDropEvent = { type: DragDropEventType.UP, deltaX, deltaY };
gameObject.emit("drag", event);
gameObject.emit("dragend", event);
callback(event);
down = null;
}
@ -61,8 +62,7 @@ export function dragDropEventEffect(
deltaX,
deltaY,
};
gameObject.emit("drag", event);
gameObject.emit("dragmove", event);
callback(event);
}
gameObject.on("pointerdown", onPointerDown);

View File

@ -4,4 +4,5 @@ export {
dragDropEventEffect,
DragDropEventType,
type DragDropEvent,
type DragDropCallback,
} from "./dnd";