diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2023-09-15 08:10:04 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2023-09-15 08:10:04 +0200 |
| commit | 2d2a9fe8520f469897f49dc261289d7cc1c5d26c (patch) | |
| tree | 79cf40889d6bf3cdaa26c158ec271d40f9692f6a /selection.go | |
| parent | f7c05f1b9417eff446753b8fafc7829859521aa3 (diff) | |
refactor: Into ECS
Diffstat (limited to 'selection.go')
| -rw-r--r-- | selection.go | 34 |
1 files changed, 34 insertions, 0 deletions
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 +} |
