diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-07-09 07:27:47 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2025-07-09 07:27:47 +0200 |
| commit | 1a4f1f3bd5814af2deaac4b8ccd4be33264793a8 (patch) | |
| tree | 9d1810f9234784fb2cd36387f4ecf76188cead2c /entity.go | |
| parent | 11fe00e83fe2d5e621fe9b7aeda273b0c0a0cea2 (diff) | |
Entity builders
Diffstat (limited to 'entity.go')
| -rw-r--r-- | entity.go | 63 |
1 files changed, 63 insertions, 0 deletions
@@ -3,6 +3,7 @@ package main import ( "age_of_empires/ecs" "age_of_empires/physics" + "image/color" "github.com/hajimehoshi/ebiten/v2" ) @@ -25,3 +26,65 @@ func (e Entity) Bounds() physics.Rectangle { Max: e.Position.Value.Add(e.Image.Value.Bounds().Size()), } } + +type EntityBuilder Entity + +func (b EntityBuilder) WithPosition(position physics.Point) EntityBuilder { + b.Position = ecs.C(position) + return b +} + +func (b EntityBuilder) WithImage(image *ebiten.Image) EntityBuilder { + b.Image = ecs.C(image) + return b +} + +var red = color.RGBA{0xff, 0x00, 0x00, 0xff} + +func (b EntityBuilder) WithSelection(haloKind string) EntityBuilder { + b.Selection = ecs.C(Selection{ + IsSelected: false, + Halo: nil, + }) + switch haloKind { + case "round": + b.Selection.Value.Halo = NewStrokeCircleImage(110, SELECTION_HALO_WIDTH, red) + case "square": + b.Selection.Value.Halo = NewStrokeRectangleImage(physics.Point{X: 110, Y: 110}, SELECTION_HALO_WIDTH, red) + } + return b +} + +func (b EntityBuilder) WithResourceStorage() EntityBuilder { + b.ResourceStorage = ecs.C(ResourceStorage{}) + return b +} + +func (b EntityBuilder) WithResourceSource(amount int) EntityBuilder { + b.ResourceSource = ecs.C(ResourceSource{Remaining: amount}) + return b +} + +func (b EntityBuilder) WithSpawn(spawn Spawn) EntityBuilder { + b.Spawn = ecs.C(spawn) + return b +} + +func (b EntityBuilder) WithMove() EntityBuilder { + b.Move = ecs.C(physics.Move{IsActive: false}) + return b +} + +func (b EntityBuilder) WithOrder() EntityBuilder { + b.Order.IsEnabled = true + return b +} + +func (b EntityBuilder) WithResourceGatherer(maxCapacity int) EntityBuilder { + b.ResourceGatherer = ecs.C(ResourceGatherer{MaxCapacity: maxCapacity}) + return b +} + +func (b EntityBuilder) Build() Entity { + return Entity(b) +} |
