diff options
| -rw-r--r-- | entity.go | 9 | ||||
| -rw-r--r-- | main.go | 10 | ||||
| -rw-r--r-- | selection.go | 32 |
3 files changed, 27 insertions, 24 deletions
@@ -26,9 +26,10 @@ func (e Entity) Bounds() physics.Rectangle { } func Draw(screen *ebiten.Image, e *Entity) { - if e.Image.IsEnabled && e.Position.IsEnabled { - op := &ebiten.DrawImageOptions{} - op.GeoM.Translate(float64(e.Position.Value.X), float64(e.Position.Value.Y)) - screen.DrawImage(e.Image.Value, op) + if !e.Image.IsEnabled || !e.Position.IsEnabled { + return } + op := &ebiten.DrawImageOptions{} + op.GeoM.Translate(float64(e.Position.Value.X), float64(e.Position.Value.Y)) + screen.DrawImage(e.Image.Value, op) } @@ -35,11 +35,11 @@ type GlobalSelection struct { } type Game struct { - Entities []*Entity - CurrentAction Action - Selection GlobalSelection + Entities []*Entity + CurrentAction Action + Selection GlobalSelection ResourceAmount int - FaceSource *text.GoTextFaceSource + FaceSource *text.GoTextFaceSource } func DrawMove(screen *ebiten.Image, e *Entity) { @@ -186,7 +186,7 @@ func (g *Game) Draw(screen *ebiten.Image) { text.Draw(screen, resourceText, &text.GoTextFace{ Source: g.FaceSource, Size: 100, - } , op) + }, op) } func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) { 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) { |
