1
0
forked from noxious/client

#159 : Camera control fixes

This commit is contained in:
2024-09-28 00:21:24 +02:00
parent 71042881dc
commit 0f231e10fa
4 changed files with 26 additions and 43 deletions

View File

@ -11,9 +11,7 @@ export function useGamePointerHandlers(scene: Phaser.Scene, layer: Phaser.Tilema
const pointerTile = getTile(px, py, layer)
waypoint.value.visible = !!pointerTile
if (!pointerTile) {
return
}
if (!pointerTile) return
const worldPoint = tileToWorldXY(layer, pointerTile.x, pointerTile.y)
waypoint.value.x = worldPoint.positionX
@ -21,9 +19,7 @@ export function useGamePointerHandlers(scene: Phaser.Scene, layer: Phaser.Tilema
}
function dragZone(pointer: Phaser.Input.Pointer) {
if (!gameStore.isPlayerDraggingCamera) {
return
}
if (!gameStore.isPlayerDraggingCamera) return
const { x, y, prevPosition } = pointer
const { scrollX, scrollY, zoom } = camera
@ -39,9 +35,7 @@ export function useGamePointerHandlers(scene: Phaser.Scene, layer: Phaser.Tilema
const { x: px, y: py } = camera.getWorldPoint(pointer.x, pointer.y)
const pointerTile = getTile(px, py, layer)
if (!pointerTile) {
return
}
if (!pointerTile) return
gameStore.connection?.emit('character:initMove', {
positionX: pointerTile.x,
@ -49,13 +43,11 @@ export function useGamePointerHandlers(scene: Phaser.Scene, layer: Phaser.Tilema
})
}
function handleZoom({ event, deltaY }: Phaser.Input.Pointer) {
if (event instanceof WheelEvent && event.shiftKey) {
return
}
function handleZoom(pointer: Phaser.Input.Pointer) {
if (!(pointer.event instanceof WheelEvent) || !pointer.event.shiftKey) return
scene.scale.setZoom(scene.scale.zoom - deltaY * 0.01)
camera = scene.cameras.main
const deltaY = pointer.event.deltaY
scene.scale.setZoom(scene.scale.zoom - deltaY * 0.005)
}
const setupPointerHandlers = () => {
@ -71,4 +63,4 @@ export function useGamePointerHandlers(scene: Phaser.Scene, layer: Phaser.Tilema
}
return { setupPointerHandlers, cleanupPointerHandlers }
}
}