cleanups
This commit is contained in:
parent
9a7e09195d
commit
af70dcaf04
2 changed files with 20 additions and 50 deletions
|
@ -45,28 +45,6 @@ func (b *Billboard) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
|
||||||
screen.DrawImage(b.Src.Image(), opts)
|
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.
|
// Prepare saves the reference to Game.
|
||||||
func (b *Billboard) Prepare(g *Game) error {
|
func (b *Billboard) Prepare(g *Game) error {
|
||||||
b.game = g
|
b.game = g
|
||||||
|
|
|
@ -51,16 +51,16 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// BoundingRecter components have a bounding rectangle.
|
|
||||||
type BoundingRecter interface {
|
|
||||||
BoundingRect() image.Rectangle
|
|
||||||
}
|
|
||||||
|
|
||||||
// BoundingBoxer components have a bounding box.
|
// BoundingBoxer components have a bounding box.
|
||||||
type BoundingBoxer interface {
|
type BoundingBoxer interface {
|
||||||
BoundingBox() geom.Box
|
BoundingBox() geom.Box
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BoundingRecter components have a bounding rectangle.
|
||||||
|
type BoundingRecter interface {
|
||||||
|
BoundingRect() image.Rectangle
|
||||||
|
}
|
||||||
|
|
||||||
// Collider components have tangible form.
|
// Collider components have tangible form.
|
||||||
type Collider interface {
|
type Collider interface {
|
||||||
CollidesWith(geom.Box) bool
|
CollidesWith(geom.Box) bool
|
||||||
|
@ -73,11 +73,11 @@ type Disabler interface {
|
||||||
Enable()
|
Enable()
|
||||||
}
|
}
|
||||||
|
|
||||||
// DrawManager is a component responsible for calling Draw on all Drawer
|
// DrawBoxer components can both draw and have a bounding box (used for draw
|
||||||
// components beneath it, except those beneath another DrawManager (it might
|
// ordering).
|
||||||
// call Draw on the DrawManager, but that's it).
|
type DrawBoxer interface {
|
||||||
type DrawManager interface {
|
BoundingBoxer
|
||||||
ManagesDrawingSubcomponents()
|
Drawer
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drawer components can draw themselves. Draw is called often. Draw is not
|
// Drawer components can draw themselves. Draw is called often. Draw is not
|
||||||
|
@ -87,11 +87,11 @@ type Drawer interface {
|
||||||
Draw(*ebiten.Image, *ebiten.DrawImageOptions)
|
Draw(*ebiten.Image, *ebiten.DrawImageOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DrawBoxer components can both draw and have a bounding box (used for draw
|
// DrawManager is a component responsible for calling Draw on all Drawer
|
||||||
// ordering).
|
// components beneath it, except those beneath another DrawManager (it might
|
||||||
type DrawBoxer interface {
|
// call Draw on the DrawManager, but that's it).
|
||||||
BoundingBoxer
|
type DrawManager interface {
|
||||||
Drawer
|
ManagesDrawingSubcomponents()
|
||||||
}
|
}
|
||||||
|
|
||||||
// DrawOrderer components have more specific ideas about draw ordering than
|
// DrawOrderer components have more specific ideas about draw ordering than
|
||||||
|
@ -128,6 +128,11 @@ type Prepper interface {
|
||||||
Prepare(game *Game) error
|
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
|
// Scanner components can be scanned. It is called when the game tree is walked
|
||||||
// (such as when the game component database is constructed).
|
// (such as when the game component database is constructed).
|
||||||
// Scan should return a slice containing all immediate subcomponents.
|
// Scan should return a slice containing all immediate subcomponents.
|
||||||
|
@ -135,11 +140,6 @@ type Scanner interface {
|
||||||
Scan() []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
|
// 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
|
// 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.
|
// cumulative opts of all parents of c plus the value returned from c.Transform.
|
||||||
|
@ -153,11 +153,3 @@ type Transformer interface {
|
||||||
type Updater interface {
|
type Updater interface {
|
||||||
Update() error
|
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
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue