aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2025-09-25 23:00:15 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2025-09-25 23:00:15 +0200
commit7e94ae0184b94f247c16a775b4d6b0172e8b3027 (patch)
tree583abab8cdcdf1eecec185bb6060297768c95f94 /main.go
parentbd750fa2605eecd14ab821f630a7c1b51c48c982 (diff)
Unify selection code and unselect
Diffstat (limited to 'main.go')
-rw-r--r--main.go23
1 files changed, 13 insertions, 10 deletions
diff --git a/main.go b/main.go
index eb6bcaa..ce69fee 100644
--- a/main.go
+++ b/main.go
@@ -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 {