change order
This commit is contained in:
parent
e00782ea6c
commit
c551ebd55a
1 changed files with 3 additions and 42 deletions
|
@ -30,53 +30,14 @@ type DrawDFS struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DrawDFS) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
|
func (d *DrawDFS) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
|
||||||
if true {
|
d.drawRecursive(screen, *opts, d)
|
||||||
d.drawRecursive(d, screen, *opts)
|
|
||||||
} else {
|
|
||||||
d.drawWithQuery(screen, opts)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ManagesDrawingSubcomponents is present so DrawDFS is recognised as a
|
// ManagesDrawingSubcomponents is present so DrawDFS is recognised as a
|
||||||
// DrawManager.
|
// DrawManager.
|
||||||
func (DrawDFS) ManagesDrawingSubcomponents() {}
|
func (DrawDFS) ManagesDrawingSubcomponents() {}
|
||||||
|
|
||||||
// This doesn't work! This misses Hiders, Transformers that are not Drawers.
|
func (d *DrawDFS) drawRecursive(screen *ebiten.Image, opts ebiten.DrawImageOptions, component interface{}) {
|
||||||
func (d *DrawDFS) drawWithQuery(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
|
|
||||||
stack := []ebiten.DrawImageOptions{*opts}
|
|
||||||
d.game.Query(d, DrawerType,
|
|
||||||
// visitPre
|
|
||||||
func(x interface{}) error {
|
|
||||||
if h, ok := x.(Hider); ok && h.Hidden() {
|
|
||||||
return Skip
|
|
||||||
}
|
|
||||||
opts := stack[len(stack)-1]
|
|
||||||
if tf, ok := x.(Transformer); ok {
|
|
||||||
opts = concatOpts(tf.Transform(), opts)
|
|
||||||
stack = append(stack, opts)
|
|
||||||
}
|
|
||||||
if x == d {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if dr, ok := x.(Drawer); ok {
|
|
||||||
dr.Draw(screen, &opts)
|
|
||||||
}
|
|
||||||
if _, isDM := x.(DrawManager); isDM {
|
|
||||||
return Skip
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
// visitPost
|
|
||||||
func(x interface{}) error {
|
|
||||||
if _, ok := x.(Transformer); ok {
|
|
||||||
stack = stack[:len(stack)-1]
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *DrawDFS) drawRecursive(component interface{}, screen *ebiten.Image, opts ebiten.DrawImageOptions) {
|
|
||||||
// Hidden? stop drawing
|
// Hidden? stop drawing
|
||||||
if h, ok := component.(Hider); ok && h.Hidden() {
|
if h, ok := component.(Hider); ok && h.Hidden() {
|
||||||
return
|
return
|
||||||
|
@ -97,7 +58,7 @@ func (d *DrawDFS) drawRecursive(component interface{}, screen *ebiten.Image, opt
|
||||||
}
|
}
|
||||||
// Has subcomponents? recurse
|
// Has subcomponents? recurse
|
||||||
d.game.Children(component).Scan(func(x interface{}) error {
|
d.game.Children(component).Scan(func(x interface{}) error {
|
||||||
d.drawRecursive(x, screen, opts)
|
d.drawRecursive(screen, opts, x)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue