This commit is contained in:
Josh Deprez 2021-09-21 13:04:29 +10:00
parent 9a7e09195d
commit af70dcaf04
2 changed files with 20 additions and 50 deletions

View file

@ -45,28 +45,6 @@ func (b *Billboard) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
screen.DrawImage(b.Src.Image(), opts)
}
// DrawAfter reports if b.Pos.Z >= x.Max.Z.
func (b *Billboard) DrawAfter(x Drawer) bool {
switch x := x.(type) {
case BoundingBoxer:
return b.Pos.Z >= x.BoundingBox().Max.Z
case ZPositioner:
return b.Pos.Z > x.ZPos()
}
return false
}
// DrawBefore reports if b.Pos.Z < x.Min.Z.
func (b *Billboard) DrawBefore(x Drawer) bool {
switch x := x.(type) {
case BoundingBoxer:
return b.Pos.Z < x.BoundingBox().Min.Z
case ZPositioner:
return b.Pos.Z < x.ZPos()
}
return false
}
// Prepare saves the reference to Game.
func (b *Billboard) Prepare(g *Game) error {
b.game = g

View file

@ -51,16 +51,16 @@ var (
}
)
// BoundingRecter components have a bounding rectangle.
type BoundingRecter interface {
BoundingRect() image.Rectangle
}
// BoundingBoxer components have a bounding box.
type BoundingBoxer interface {
BoundingBox() geom.Box
}
// BoundingRecter components have a bounding rectangle.
type BoundingRecter interface {
BoundingRect() image.Rectangle
}
// Collider components have tangible form.
type Collider interface {
CollidesWith(geom.Box) bool
@ -73,11 +73,11 @@ type Disabler interface {
Enable()
}
// DrawManager is a component responsible for calling Draw on all Drawer
// components beneath it, except those beneath another DrawManager (it might
// call Draw on the DrawManager, but that's it).
type DrawManager interface {
ManagesDrawingSubcomponents()
// DrawBoxer components can both draw and have a bounding box (used for draw
// ordering).
type DrawBoxer interface {
BoundingBoxer
Drawer
}
// Drawer components can draw themselves. Draw is called often. Draw is not
@ -87,11 +87,11 @@ type Drawer interface {
Draw(*ebiten.Image, *ebiten.DrawImageOptions)
}
// DrawBoxer components can both draw and have a bounding box (used for draw
// ordering).
type DrawBoxer interface {
BoundingBoxer
Drawer
// DrawManager is a component responsible for calling Draw on all Drawer
// components beneath it, except those beneath another DrawManager (it might
// call Draw on the DrawManager, but that's it).
type DrawManager interface {
ManagesDrawingSubcomponents()
}
// DrawOrderer components have more specific ideas about draw ordering than
@ -128,6 +128,11 @@ type Prepper interface {
Prepare(game *Game) error
}
// Saver components can be saved to disk.
type Saver interface {
Save() error
}
// Scanner components can be scanned. It is called when the game tree is walked
// (such as when the game component database is constructed).
// Scan should return a slice containing all immediate subcomponents.
@ -135,11 +140,6 @@ type Scanner interface {
Scan() []interface{}
}
// Saver components can be saved to disk.
type Saver interface {
Save() error
}
// Transformer components can provide draw options to apply to themselves and
// any child components. The opts passed to Draw of a component c will be the
// cumulative opts of all parents of c plus the value returned from c.Transform.
@ -153,11 +153,3 @@ type Transformer interface {
type Updater interface {
Update() error
}
// ZPositioner components opt into a simpler method of determining draw order
// than DrawAfter/DrawBefore. Drawer implementations should handle the
// ZPositioner case as though the component were a flat infinite plane given by
// z = ZPos().
type ZPositioner interface {
ZPos() int
}