printTreeRecursive uses g.children

This commit is contained in:
Josh Deprez 2021-09-29 17:33:09 +10:00
parent 472af504e8
commit b52ff1164c
3 changed files with 8 additions and 9 deletions

View file

@ -18,8 +18,10 @@ func init() {
// DrawDFS is a DrawManager that does not add any structure. Components are // DrawDFS is a DrawManager that does not add any structure. Components are
// drawn in the order in which they are encountered by a depth-first search // drawn in the order in which they are encountered by a depth-first search
// through the game tree, without any extra sorting based on Z values or // through the game tree using Scan, without any extra sorting based on Z values
// consideration for DrawOrderer). // or consideration for DrawOrderer. Also, children registered in Game but not
// registered by subcomponents (such that they are visited with Scan) won't be
// drawn.
type DrawDFS struct { type DrawDFS struct {
Child interface{} Child interface{}
Hides Hides

View file

@ -201,7 +201,7 @@ func (g *Game) Scan(visit VisitFunc) error {
} }
// Load loads a component and all subcomponents recursively. // Load loads a component and all subcomponents recursively.
// Note that this method does not implement Loader. // Note that this method does not implement Loader itself.
func (g *Game) Load(component interface{}, assets fs.FS) error { func (g *Game) Load(component interface{}, assets fs.FS) error {
if l, ok := component.(Loader); ok { if l, ok := component.(Loader); ok {
if err := l.Load(assets); err != nil { if err := l.Load(assets); err != nil {
@ -217,7 +217,7 @@ func (g *Game) Load(component interface{}, assets fs.FS) error {
} }
// Prepare prepares a component and all subcomponents recursively. // Prepare prepares a component and all subcomponents recursively.
// Note that this method does not implement Prepper. // Note that this method does not implement Prepper itself.
func (g *Game) Prepare(component interface{}) error { func (g *Game) Prepare(component interface{}) error {
// Postorder traversal, in case ancestors depend on descendants being // Postorder traversal, in case ancestors depend on descendants being
// ready to answer queries. // ready to answer queries.

View file

@ -102,11 +102,8 @@ func (g *Game) printTreeRecursive(dst io.Writer, depth int, c interface{}) {
} else { } else {
fmt.Fprintf(dst, "%s%v\n", indent, c) fmt.Fprintf(dst, "%s%v\n", indent, c)
} }
if sc, ok := c.(Scanner); ok { for x := range g.children[c] {
sc.Scan(func(x interface{}) error {
g.printTreeRecursive(dst, depth+1, x) g.printTreeRecursive(dst, depth+1, x)
return nil
})
} }
} }