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
// 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
// consideration for DrawOrderer).
// through the game tree using Scan, without any extra sorting based on Z values
// 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 {
Child interface{}
Hides

View file

@ -201,7 +201,7 @@ func (g *Game) Scan(visit VisitFunc) error {
}
// 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 {
if l, ok := component.(Loader); ok {
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.
// Note that this method does not implement Prepper.
// Note that this method does not implement Prepper itself.
func (g *Game) Prepare(component interface{}) error {
// Postorder traversal, in case ancestors depend on descendants being
// ready to answer queries.

View file

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