aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2025-07-25 11:49:42 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2025-07-25 11:49:42 +0200
commit87563d8bbf70cba9443435113a8bddfcd39f611d (patch)
treed0d98265f0552791e6459af99366f3658502788d
parent563b9ee704a14322ed4805896c4f8ca3fa5df03a (diff)
refactor: ECS patrol order
-rw-r--r--main.go4
-rw-r--r--patrol_order.go15
2 files changed, 10 insertions, 9 deletions
diff --git a/main.go b/main.go
index 3d014bf..86dc59b 100644
--- a/main.go
+++ b/main.go
@@ -103,7 +103,9 @@ func (g *Game) updatePatrolling(cursor physics.Point) {
if inpututil.IsMouseButtonJustReleased(ebiten.MouseButtonRight) {
destination := cursor.Div(100).Mul(100)
for _, e := range g.Entities {
- Patrol(e, destination)
+ if e.Selection.IsEnabled && e.Selection.Value.IsSelected {
+ Patrol(e.Position, e.Move, &e.Order, destination)
+ }
}
g.CurrentAction = Selecting
}
diff --git a/patrol_order.go b/patrol_order.go
index eb9dfb0..a5b8d83 100644
--- a/patrol_order.go
+++ b/patrol_order.go
@@ -1,6 +1,7 @@
package main
import (
+ "age_of_empires/ecs"
"age_of_empires/physics"
"golang.org/x/exp/slog"
@@ -24,13 +25,11 @@ func (o *PatrolOrder) Update(e *Entity, g *Game) {
}
}
-func Patrol(e *Entity, destination physics.Point) Order {
- if e.Selection.IsEnabled && e.Position.IsEnabled && e.Move.IsEnabled && e.Order.IsEnabled {
- if e.Selection.Value.IsSelected {
- origin := e.Position.Value
- slog.Info("patrolling between", slog.String("origin", origin.String()), slog.String("destination", destination.String()))
- e.Order.Value = &PatrolOrder{origin: origin, destination: destination}
- }
+func Patrol(position ecs.Component[physics.Point], move ecs.Component[physics.Move], order *ecs.Component[Order], destination physics.Point) {
+ if !position.IsEnabled || !move.IsEnabled || !order.IsEnabled {
+ return
}
- return &PatrolOrder{origin: e.Position.Value, destination: destination}
+ origin := position.Value
+ slog.Info("patrolling between", slog.String("origin", origin.String()), slog.String("destination", destination.String()))
+ order.Value = &PatrolOrder{origin: origin, destination: destination}
}