From 5224fdc80913597287a5f67efec5d0be3254ce59 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Fri, 4 Jul 2025 23:05:42 +0200 Subject: Fmt --- README.md | 23 ++--------------------- gather_order.go | 10 +++++----- main.go | 6 +++--- order.go | 7 +++---- selection.go | 2 +- 5 files changed, 14 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 84d4fc9..643ac8c 100644 --- a/README.md +++ b/README.md @@ -5,27 +5,8 @@ ## TODO - atm, stops moving if someone settles at destination - -```go -func (g \*Game) updatePlacingWall(cursor Point) { - if inpututil.IsMouseButtonJustReleased(ebiten.MouseButtonLeft) { - if cursor.In(soil.Bounds()) { - position := cursor.Sub(soil.Position).Div(100).Mul(100).Add(Point{50, 50}) - g.Blocks = append(g.Blocks, Block{NewTile(Point{100, 100}, position, color.RGBA{0x00, 0x00, 0x00, 0xff}), WallBlock}) - } - } -} -``` - -```go - if inpututil.IsMouseButtonJustReleased(ebiten.MouseButtonLeft) && cursor.In(wallButton.CollisionBounds()) { - if g.CurrentAction == PlacingWall { - g.CurrentAction = Selecting - } else { - g.CurrentAction = PlacingWall - } - } -``` +- save globally resources +- an entity may spawn other enities with a cost ## Dependencies diff --git a/gather_order.go b/gather_order.go index 2f5a060..e359146 100644 --- a/gather_order.go +++ b/gather_order.go @@ -24,8 +24,8 @@ func (o *GatherOrder) Update(e *Entity, g *Game) { return } if physics.Distance(e.Position.Value, gatherer.CurrentTarget.Position.Value) <= 100 { - o.updateGathering(gatherer, source) - return + o.updateGathering(gatherer, source) + return } if !e.Move.Value.IsActive { o.startMoveToSource(e, gatherer, g) @@ -57,7 +57,7 @@ func (o *GatherOrder) updateGathererFull(e *Entity, g *Game, gatherer *ResourceG slog.Info("storage target", slog.String("storage", destination.String()), slog.Int("distance", distance)) if distance > 1 { slog.Info("moving to storage", slog.String("storage", destination.String())) - physics.StartMove(&e.Move,e.Position, destination, g.getMoveMap()) + physics.StartMove(&e.Move, e.Position, destination, g.getMoveMap()) return } gatherer.CurrentVolume = 0 @@ -73,7 +73,7 @@ func (o *GatherOrder) startMoveToSource(e *Entity, gatherer *ResourceGatherer, g e.Order.Value = nil return } - physics.StartMove(&e.Move,e.Position, destination, g.getMoveMap()) + physics.StartMove(&e.Move, e.Position, destination, g.getMoveMap()) } func getAllStorageDockings(g *Game) []physics.Point { @@ -99,7 +99,7 @@ func Gather(e *Entity, source *Entity, g *Game) Order { e.Order.Value = nil return nil } - physics.StartMove(&e.Move,e.Position, destination, g.getMoveMap()) + physics.StartMove(&e.Move, e.Position, destination, g.getMoveMap()) } } return &GatherOrder{source: source} diff --git a/main.go b/main.go index 5eb330e..b521616 100644 --- a/main.go +++ b/main.go @@ -35,7 +35,7 @@ type Game struct { Selection GlobalSelection } -func DrawMove(screen *ebiten.Image, e *Entity) { +func DrawMove(screen *ebiten.Image, e *Entity) { if e.Move.IsEnabled && e.Position.IsEnabled && e.Selection.IsEnabled { if e.Selection.Value.IsSelected && e.Move.Value.IsActive { last := e.Position.Value @@ -96,7 +96,7 @@ func (g *Game) updateSelecting(cursor physics.Point, moveMap physics.MoveMap) { if entityAtDestination != nil && entityAtDestination.ResourceSource.IsEnabled { Gather(e, entityAtDestination, g) } else { - physics.StartMove(&e.Move,e.Position, destination, moveMap) + physics.StartMove(&e.Move, e.Position, destination, moveMap) } } } @@ -147,7 +147,7 @@ func (g *Game) Update() error { g.updatePatrolling(cursor) } for _, e := range g.Entities { - physics.UpdateMove(&e.Move,&e.Position, moveMap) + physics.UpdateMove(&e.Move, &e.Position, moveMap) e.UpdateOrder(g) } return nil diff --git a/order.go b/order.go index 5716731..f1e89bc 100644 --- a/order.go +++ b/order.go @@ -5,9 +5,8 @@ type Order interface { } func (e *Entity) UpdateOrder(g *Game) { - if e.Order.IsEnabled { - if e.Order.Value != nil { - e.Order.Value.Update(e, g) - } + if !e.Order.IsEnabled || e.Order.Value == nil { + return } + e.Order.Value.Update(e, g) } diff --git a/selection.go b/selection.go index 91f35fe..d9120d2 100644 --- a/selection.go +++ b/selection.go @@ -17,7 +17,7 @@ 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() + 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())) -- cgit v1.3