fix(physarum): paint only while the pointer is pressed

Ignore pointer moves after release.
This commit is contained in:
lobo committed 2026-10-23 10:01:03 +02:00
1 parent 0013dc175a
commit 26601bef46
1 file changed
+6 -6
@@ -70,7 +70,8 @@ export class PhysarumComponent implements OnDestroy {
private canvas: HTMLCanvasElement | null = null;
private pointerAttached = false;
private agentCountInitialized = false;
private readonly pointerLeaveHandler = () => { this.food.active = false; };
private pressed = false;
private readonly pointerLeaveHandler = () => { this.pressed = false; this.food.active = false; };
private readonly fpsCounter = new FpsCounter();
readonly minAgents = MIN_AGENTS;
@@ -231,17 +232,16 @@ export class PhysarumComponent implements OnDestroy {
scene.onPointerObservable.add((info) => {
if (info.type === PointerEventTypes.POINTERUP) {
this.pressed = false;
this.food.active = false;
return;
}
if (info.type !== PointerEventTypes.POINTERDOWN && info.type !== PointerEventTypes.POINTERMOVE) {
if (info.type === PointerEventTypes.POINTERDOWN) {
this.pressed = true;
} else if (info.type !== PointerEventTypes.POINTERMOVE || !this.pressed) {
return;
}
const event = info.event as PointerEvent;
if (!(event.buttons & 1) && event.pointerType !== 'touch') {
this.food.active = false;
return;
}
const target = event.target as HTMLElement;
const cell = pointerToCell(event.offsetX, event.offsetY, target.clientWidth, target.clientHeight, this.mapSize(), this.mapSize());
this.food.x = cell.x;