diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-09-25 23:00:15 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-09-25 23:00:15 +0200 |
| commit | 7e94ae0184b94f247c16a775b4d6b0172e8b3027 (patch) | |
| tree | 583abab8cdcdf1eecec185bb6060297768c95f94 /main.go | |
| parent | bd750fa2605eecd14ab821f630a7c1b51c48c982 (diff) | |
Unify selection code and unselect
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 23 |
1 files changed, 13 insertions, 10 deletions
@@ -67,7 +67,7 @@ const ( func (g *Game) updateSelecting(cursor physics.Point, moveMap physics.MoveMap) { if inpututil.IsKeyJustReleased(ebiten.KeyEscape) { - g.Selection.Clear() + g.Selection.Unselect() } if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) { g.Selection.Start(cursor) @@ -84,18 +84,21 @@ func (g *Game) updateSelecting(cursor physics.Point, moveMap physics.MoveMap) { } if inpututil.IsMouseButtonJustReleased(ebiten.MouseButtonLeft) { if g.Selection.IsActive(cursor) { - selector := g.Selection.Select(cursor) - for _, e := range g.Entities { - selector.Preselect(e.Position, e.RelBounds, &e.Selection) + // TODO: simplify with component columns + targets := make([]selection.SelectTarget, len(g.Entities)) + for i, e := range g.Entities { + targets[i] = selection.SelectTarget{ + Selection: &e.Selection, + Position: e.Position, + Bounds: e.RelBounds, + } } - selector.Select() - } else { - selector := selection.NewSingle(cursor) - for _, e := range g.Entities { - selector.Select(e.Position, e.RelBounds, &e.Selection) + if g.Selection.IsArea(cursor) { + g.Selection.SelectMultiple(cursor, targets) + } else { + g.Selection.SelectSingle(cursor, targets) } } - g.Selection.Clear() } if inpututil.IsKeyJustReleased(KeySpawnRequest) { for _, e := range g.Entities { |
