diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-07-04 23:55:19 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-07-04 23:57:36 +0200 |
| commit | 56b3d85afaf260be93e46e2b930f79ade461789b (patch) | |
| tree | d15e08f5c29d94b363b04e00c35044d63f762a06 /selection.go | |
| parent | 548b18531aed2eeb284ce121832070bd10822d4f (diff) | |
Simple refactor
Diffstat (limited to 'selection.go')
| -rw-r--r-- | selection.go | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/selection.go b/selection.go index d9120d2..329f6d7 100644 --- a/selection.go +++ b/selection.go @@ -15,26 +15,28 @@ type Selection struct { } func (e *Entity) SelectMultiple(cursor physics.Point, selection GlobalSelection) { - if e.Selection.IsEnabled { - e.Selection.Value.IsSelected = false - selectionBounds := physics.Rectangle{Min: selection.Start, Max: cursor}.Canon() - if selectionBounds.Overlaps(e.Bounds()) { - e.Selection.Value.IsSelected = true - slog.Info("entity selected", slog.String("position", e.Position.Value.String())) - } + if !e.Selection.IsEnabled { + return + } + e.Selection.Value.IsSelected = false + selectionBounds := physics.Rectangle{Min: selection.Start, Max: cursor}.Canon() + if selectionBounds.Overlaps(e.Bounds()) { + e.Selection.Value.IsSelected = true + slog.Info("entity selected", slog.String("position", e.Position.Value.String())) } } func (e *Entity) SelectSingle(cursor physics.Point, canBeSelected bool) bool { - if e.Selection.IsEnabled { - e.Selection.Value.IsSelected = false - if canBeSelected && cursor.In(e.Bounds()) { - e.Selection.Value.IsSelected = true - slog.Info("entity selected", slog.String("position", e.Position.Value.String())) - return true - } + if !e.Selection.IsEnabled { + return false + } + e.Selection.Value.IsSelected = false + if !canBeSelected || cursor.In(e.Bounds()) { + return false } - return false + e.Selection.Value.IsSelected = true + slog.Info("entity selected", slog.String("position", e.Position.Value.String())) + return true } func DrawSelection(screen *ebiten.Image, e *Entity) { |
