From 56b3d85afaf260be93e46e2b930f79ade461789b Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Fri, 4 Jul 2025 23:55:19 +0200 Subject: Simple refactor --- selection.go | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'selection.go') 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) { -- cgit v1.3