DrawDFS uses Children

This commit is contained in:
Josh Deprez 2021-09-30 10:39:23 +10:00
parent 8ec3ef2a58
commit fb2c9a1474

View file

@ -25,6 +25,8 @@ func init() {
type DrawDFS struct { type DrawDFS struct {
Child interface{} Child interface{}
Hides Hides
game *Game
} }
func (d *DrawDFS) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) { func (d *DrawDFS) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
@ -56,13 +58,16 @@ func (d *DrawDFS) drawRecursive(component interface{}, screen *ebiten.Image, opt
return return
} }
// Has subcomponents? recurse // Has subcomponents? recurse
// TODO: use g.Children or g.Query - but need to go in Scan order... // TODO: use g.Query?
if sc, ok := component.(Scanner); ok { d.game.Children(component).Scan(func(x interface{}) error {
sc.Scan(func(x interface{}) error { d.drawRecursive(x, screen, opts)
d.drawRecursive(x, screen, opts) return nil
return nil })
}) }
}
func (d *DrawDFS) Prepare(g *Game) error {
d.game = g
return nil
} }
// Scan visits d.Child. // Scan visits d.Child.