diff --git a/src/components/gameMaster/zoneEditor/EventTiles.vue b/src/components/gameMaster/zoneEditor/EventTiles.vue index 4075de7..1091437 100644 --- a/src/components/gameMaster/zoneEditor/EventTiles.vue +++ b/src/components/gameMaster/zoneEditor/EventTiles.vue @@ -25,7 +25,8 @@ function getEventTileImageProps(tile: ZoneEventTile) { } } -function addZoneEventTile(pointer: Phaser.Input.Pointer) { +function pencil(pointer: Phaser.Input.Pointer) { + // Check if zone is set if (!zoneEditorStore.zone) return // Check if tool is pencil @@ -69,13 +70,42 @@ function addZoneEventTile(pointer: Phaser.Input.Pointer) { zoneEditorStore.zone.zoneEventTiles = zoneEditorStore.zone.zoneEventTiles.concat(newEventTile as ZoneEventTile) } +function eraser(pointer: Phaser.Input.Pointer) { + // Check if zone is set + if (!zoneEditorStore.zone) return + + // Check if tool is pencil + if (zoneEditorStore.tool !== 'eraser') return + + // Check if draw mode is blocking tile or teleport + if (zoneEditorStore.eraserMode !== 'blocking tile' && zoneEditorStore.eraserMode !== 'teleport') return + + // Check if left mouse button is pressed + if (!pointer.isDown) return + + // Check if there is a tile + const tile = getTile(props.tilemap, pointer.worldX, pointer.worldY) + if (!tile) return + + // Check if event tile already exists on position + const existingEventTile = zoneEditorStore.zone.zoneEventTiles.find((eventTile) => eventTile.positionX === tile.x && eventTile.positionY === tile.y) + if (!existingEventTile) return + + // Remove existing event tile + zoneEditorStore.zone.zoneEventTiles = zoneEditorStore.zone.zoneEventTiles.filter((eventTile) => eventTile.id !== existingEventTile.id) +} + onBeforeMount(() => { - scene.input.on(Phaser.Input.Events.POINTER_DOWN, addZoneEventTile) - scene.input.on(Phaser.Input.Events.POINTER_MOVE, addZoneEventTile) + scene.input.on(Phaser.Input.Events.POINTER_DOWN, pencil) + scene.input.on(Phaser.Input.Events.POINTER_MOVE, pencil) + scene.input.on(Phaser.Input.Events.POINTER_DOWN, eraser) + scene.input.on(Phaser.Input.Events.POINTER_MOVE, eraser) }) onBeforeUnmount(() => { - scene.input.off(Phaser.Input.Events.POINTER_DOWN, addZoneEventTile) - scene.input.off(Phaser.Input.Events.POINTER_MOVE, addZoneEventTile) + scene.input.off(Phaser.Input.Events.POINTER_DOWN, pencil) + scene.input.off(Phaser.Input.Events.POINTER_MOVE, pencil) + scene.input.off(Phaser.Input.Events.POINTER_DOWN, eraser) + scene.input.off(Phaser.Input.Events.POINTER_MOVE, eraser) }) diff --git a/src/components/gameMaster/zoneEditor/Objects.vue b/src/components/gameMaster/zoneEditor/Objects.vue index a2fc234..33c7d94 100644 --- a/src/components/gameMaster/zoneEditor/Objects.vue +++ b/src/components/gameMaster/zoneEditor/Objects.vue @@ -5,7 +5,7 @@