| 6 | import { useTilemapEditorStore } from '../stores/TilemapEditorStore'; |
| 7 | |
| 8 | export class SelectTool implements ITilemapTool { |
| 9 | readonly id = 'select'; |
| 10 | readonly name = 'Select'; |
| 11 | readonly icon = 'BoxSelect'; |
| 12 | readonly cursor = 'crosshair'; |
| 13 | |
| 14 | private _isSelecting = false; |
| 15 | private _startX = -1; |
| 16 | private _startY = -1; |
| 17 | private _currentX = -1; |
| 18 | private _currentY = -1; |
| 19 | |
| 20 | onMouseDown(tileX: number, tileY: number, _ctx: ToolContext): void { |
| 21 | this._isSelecting = true; |
| 22 | this._startX = tileX; |
| 23 | this._startY = tileY; |
| 24 | this._currentX = tileX; |
| 25 | this._currentY = tileY; |
| 26 | } |
| 27 | |
| 28 | onMouseMove(tileX: number, tileY: number, _ctx: ToolContext): void { |
| 29 | if (!this._isSelecting) return; |
| 30 | this._currentX = tileX; |
| 31 | this._currentY = tileY; |
| 32 | } |
| 33 | |
| 34 | onMouseUp(tileX: number, tileY: number, ctx: ToolContext): void { |
| 35 | if (!this._isSelecting) return; |
| 36 | |
| 37 | this._currentX = tileX; |
| 38 | this._currentY = tileY; |
| 39 | |
| 40 | const minX = Math.max(0, Math.min(this._startX, this._currentX)); |
| 41 | const maxX = Math.min(ctx.tilemap.width - 1, Math.max(this._startX, this._currentX)); |
| 42 | const minY = Math.max(0, Math.min(this._startY, this._currentY)); |
| 43 | const maxY = Math.min(ctx.tilemap.height - 1, Math.max(this._startY, this._currentY)); |
| 44 | |
| 45 | const width = maxX - minX + 1; |
| 46 | const height = maxY - minY + 1; |
| 47 | |
| 48 | const tiles: number[] = []; |
| 49 | for (let y = minY; y <= maxY; y++) { |
| 50 | for (let x = minX; x <= maxX; x++) { |
| 51 | const tileIndex = ctx.tilemap.getTile(ctx.currentLayer, x, y); |
| 52 | tiles.push(tileIndex); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | useTilemapEditorStore.getState().setSelectedTiles({ |
| 57 | x: minX, |
| 58 | y: minY, |
| 59 | width, |
| 60 | height, |
| 61 | tiles |
| 62 | }); |
| 63 | |
| 64 | this.reset(); |
| 65 | } |
nothing calls this directly
no outgoing calls
no test coverage detected