From 2d2a9fe8520f469897f49dc261289d7cc1c5d26c Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Fri, 15 Sep 2023 08:10:04 +0200 Subject: refactor: Into ECS --- selection.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 selection.go (limited to 'selection.go') diff --git a/selection.go b/selection.go new file mode 100644 index 0000000..9b6dbb2 --- /dev/null +++ b/selection.go @@ -0,0 +1,34 @@ +package main + +import ( + "github.com/hajimehoshi/ebiten/v2" + "golang.org/x/exp/slog" +) + +type Selection struct { + IsSelected bool + SelectedImage *ebiten.Image +} + +func (e *Entity) SelectMultiple(cursor Point, selection GlobalSelection) { + if e.Selection.IsEnabled { + e.Selection.Value.IsSelected = false + selectionBounds := Rectangle{selection.Start, 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 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 + } + } + return false +} -- cgit v1.3