aboutsummaryrefslogtreecommitdiff
path: root/spawn.go
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2025-07-09 07:27:47 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2025-07-09 07:27:47 +0200
commit1a4f1f3bd5814af2deaac4b8ccd4be33264793a8 (patch)
tree9d1810f9234784fb2cd36387f4ecf76188cead2c /spawn.go
parent11fe00e83fe2d5e621fe9b7aeda273b0c0a0cea2 (diff)
Entity builders
Diffstat (limited to 'spawn.go')
-rw-r--r--spawn.go22
1 files changed, 7 insertions, 15 deletions
diff --git a/spawn.go b/spawn.go
index 0ee93d7..85ce24e 100644
--- a/spawn.go
+++ b/spawn.go
@@ -11,16 +11,16 @@ type spawnRequest struct {
}
type Spawn struct {
- UnitResourceCost int
+ UnitResourceCost int
UnitSpawnDuration time.Duration
- Requests []spawnRequest
+ Requests []spawnRequest
}
func NewSpawn(unitResourceCost int, unitSpawnDuration time.Duration) Spawn {
return Spawn{
- UnitResourceCost: unitResourceCost,
+ UnitResourceCost: unitResourceCost,
UnitSpawnDuration: unitSpawnDuration,
- Requests: make([]spawnRequest, 0),
+ Requests: make([]spawnRequest, 0),
}
}
@@ -32,7 +32,7 @@ func (spawn *Spawn) AddRequest(g *Game) {
spawn.Requests = append(spawn.Requests, spawnRequest{start: time.Now()})
}
-func UpdateSpawn(g *Game,spawn *ecs.Component[Spawn], position ecs.Component[physics.Point]) {
+func UpdateSpawn(g *Game, spawn *ecs.Component[Spawn], position ecs.Component[physics.Point]) {
if !spawn.IsEnabled || !position.IsEnabled {
return
}
@@ -40,17 +40,9 @@ func UpdateSpawn(g *Game,spawn *ecs.Component[Spawn], position ecs.Component[phy
if len(spawn.Value.Requests) == 0 || now.Sub(spawn.Value.Requests[0].start) < time.Duration(spawn.Value.UnitSpawnDuration) {
return
}
- // TODO: builder
- var order Order
spawnPosition, _ := g.Closest(position.Value, physics.AdjacentPoints(position.Value))
- unit := Entity{
- Position: ecs.C(spawnPosition),
- Image: ecs.C(g.personImage),
- Selection: ecs.C(Selection{IsSelected: false, Halo: g.personSelectionHalo}),
- Move: ecs.C(physics.Move{IsActive: false}),
- Order: ecs.C(order),
- ResourceGatherer: ecs.C(ResourceGatherer{MaxCapacity: 15}),
- }
+ unit := g.UnitBuilder.Build()
+ unit.Position = ecs.C(spawnPosition)
g.Entities = append(g.Entities, &unit)
spawn.Value.Requests = spawn.Value.Requests[1:]
if len(spawn.Value.Requests) > 0 {