call it VisitFunc
This commit is contained in:
parent
3ad1cf8d4d
commit
67367b6cd1
16 changed files with 25 additions and 19 deletions
|
@ -52,7 +52,7 @@ func (b *Billboard) Prepare(g *Game) error {
|
|||
}
|
||||
|
||||
// Scan visits &b.Src.
|
||||
func (b *Billboard) Scan(visit func(interface{}) error) error {
|
||||
func (b *Billboard) Scan(visit VisitFunc) error {
|
||||
return visit(&b.Src)
|
||||
}
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ func (c *Camera) Prepare(game *Game) error {
|
|||
}
|
||||
|
||||
// Scan visits c.Child.
|
||||
func (c *Camera) Scan(visit func(interface{}) error) error {
|
||||
func (c *Camera) Scan(visit VisitFunc) error {
|
||||
return visit(c.Child)
|
||||
}
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ func (c *Container) Prepare(*Game) error {
|
|||
}
|
||||
|
||||
// Scan visits every non-nil component in the container.
|
||||
func (c *Container) Scan(visit func(interface{}) error) error {
|
||||
func (c *Container) Scan(visit VisitFunc) error {
|
||||
for _, x := range c.items {
|
||||
if x != nil {
|
||||
if err := visit(x); err != nil {
|
||||
|
|
|
@ -121,7 +121,7 @@ func (d *DrawDAG) Prepare(game *Game) error {
|
|||
}
|
||||
|
||||
// Scan visits d.Child.
|
||||
func (d *DrawDAG) Scan(visit func(interface{}) error) error {
|
||||
func (d *DrawDAG) Scan(visit VisitFunc) error {
|
||||
return visit(d.Child)
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ func (d *DrawDFS) drawRecursive(component interface{}, screen *ebiten.Image, opt
|
|||
}
|
||||
|
||||
// Scan visits d.Child.
|
||||
func (d *DrawDFS) Scan(visit func(interface{}) error) error {
|
||||
func (d *DrawDFS) Scan(visit VisitFunc) error {
|
||||
return visit(d.Child)
|
||||
}
|
||||
|
||||
|
|
|
@ -162,7 +162,7 @@ func (g *Game) ReversePath(component interface{}) []interface{} {
|
|||
//
|
||||
// visitPre is visited before descendants, while visitPost is visited after
|
||||
// descendants. nil visitors are ignored.
|
||||
func (g *Game) Query(ancestor interface{}, behaviour reflect.Type, visitPre, visitPost func(interface{}) error) error {
|
||||
func (g *Game) Query(ancestor interface{}, behaviour reflect.Type, visitPre, visitPost VisitFunc) error {
|
||||
pi := reflect.TypeOf(ancestor).Implements(behaviour)
|
||||
if pi && visitPre != nil {
|
||||
if err := visitPre(ancestor); err != nil {
|
||||
|
@ -192,7 +192,7 @@ func (g *Game) Query(ancestor interface{}, behaviour reflect.Type, visitPre, vis
|
|||
}
|
||||
|
||||
// Scan visits g.Root.
|
||||
func (g *Game) Scan(visit func(interface{}) error) error {
|
||||
func (g *Game) Scan(visit VisitFunc) error {
|
||||
return visit(g.Root)
|
||||
}
|
||||
|
||||
|
@ -425,6 +425,12 @@ func concatOpts(a, b ebiten.DrawImageOptions) ebiten.DrawImageOptions {
|
|||
return a
|
||||
}
|
||||
|
||||
// VisitFunc callbacks are either provided or called by various Game functions.
|
||||
// For example, Query takes two VisitFuncs that are called for each result, and
|
||||
// Scan is given a VisitFunc that should be called with each component. For
|
||||
// recursive operations, return Skip for components that should be skipped.
|
||||
type VisitFunc func(interface{}) error
|
||||
|
||||
// Skip is an "error" value that can be returned from visitor callbacks. It
|
||||
// tells recursive methods of Game to skip processing the current item and its
|
||||
// descendants, but will otherwise continue processing.
|
||||
|
|
|
@ -149,7 +149,7 @@ type Saver interface {
|
|||
// Scan should visit each immediate subcomponent, aborting early if an error is
|
||||
// returned from the visitor.
|
||||
type Scanner interface {
|
||||
Scan(visit func(interface{}) error) error
|
||||
Scan(visit VisitFunc) error
|
||||
}
|
||||
|
||||
// Transformer components can provide draw options to apply to themselves and
|
||||
|
|
|
@ -39,7 +39,7 @@ func (p *Parallax) Prepare(game *Game) error {
|
|||
}
|
||||
|
||||
// Scan visits p.Child.
|
||||
func (p *Parallax) Scan(visit func(interface{}) error) error {
|
||||
func (p *Parallax) Scan(visit VisitFunc) error {
|
||||
return visit(p.Child)
|
||||
}
|
||||
|
||||
|
|
|
@ -113,7 +113,7 @@ func (m *PrismMap) Prepare(g *Game) error {
|
|||
}
|
||||
|
||||
// Scan visits &m.Sheet and all Prisms.
|
||||
func (m *PrismMap) Scan(visit func(interface{}) error) error {
|
||||
func (m *PrismMap) Scan(visit VisitFunc) error {
|
||||
if err := visit(&m.Sheet); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ type Scene struct {
|
|||
}
|
||||
|
||||
// Scan visits s.Child.
|
||||
func (s *Scene) Scan(visit func(interface{}) error) error {
|
||||
func (s *Scene) Scan(visit VisitFunc) error {
|
||||
return visit(s.Child)
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ func (s *Sheet) Prepare(*Game) error {
|
|||
}
|
||||
|
||||
// Scan visits &s.Src.
|
||||
func (s *Sheet) Scan(visit func(interface{}) error) error {
|
||||
func (s *Sheet) Scan(visit VisitFunc) error {
|
||||
return visit(&s.Src)
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ func (s *Sprite) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
|
|||
}
|
||||
|
||||
// Scan visits &s.Actor and &s.Sheet.
|
||||
func (s *Sprite) Scan(visit func(interface{}) error) error {
|
||||
func (s *Sprite) Scan(visit VisitFunc) error {
|
||||
if err := visit(&s.Actor); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ func (t *Tilemap) Load(fs.FS) error {
|
|||
}
|
||||
|
||||
// Scan visits &t.Sheet and all tiles.
|
||||
func (t *Tilemap) Scan(visit func(interface{}) error) error {
|
||||
func (t *Tilemap) Scan(visit VisitFunc) error {
|
||||
if err := visit(&t.Sheet); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -155,6 +155,6 @@ type AnimatedTile struct {
|
|||
func (a *AnimatedTile) Cell() int { return a.anim.Cell() }
|
||||
|
||||
// Scan visits a.anim.
|
||||
func (a *AnimatedTile) Scan(visit func(interface{}) error) error {
|
||||
func (a *AnimatedTile) Scan(visit VisitFunc) error {
|
||||
return visit(a.anim)
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ func (w *Wall) CollidesWith(b geom.Box) bool {
|
|||
}
|
||||
|
||||
// Scan visits &w.Sheet and all WallUnits.
|
||||
func (w *Wall) Scan(visit func(interface{}) error) error {
|
||||
func (w *Wall) Scan(visit VisitFunc) error {
|
||||
if err := visit(&w.Sheet); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ func (u *WallUnit) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
|
|||
}
|
||||
|
||||
// Scan visits u.Tile.
|
||||
func (u *WallUnit) Scan(visit func(interface{}) error) error {
|
||||
func (u *WallUnit) Scan(visit VisitFunc) error {
|
||||
return visit(u.Tile)
|
||||
}
|
||||
|
||||
|
|
|
@ -259,7 +259,7 @@ func (aw *Awakeman) Prepare(game *engine.Game) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (aw *Awakeman) Scan(visit func(interface{}) error) error {
|
||||
func (aw *Awakeman) Scan(visit engine.VisitFunc) error {
|
||||
return visit(&aw.Sprite)
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ func NewBubble(pos geom.Int3) *Bubble {
|
|||
}
|
||||
}
|
||||
|
||||
func (b *Bubble) Scan(visit func(interface{}) error) error {
|
||||
func (b *Bubble) Scan(visit engine.VisitFunc) error {
|
||||
return visit(&b.Sprite)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue