fix bug
This commit is contained in:
parent
c352221606
commit
45e2b300e8
5 changed files with 19 additions and 23 deletions
|
@ -99,8 +99,7 @@ type SceneRef struct {
|
|||
scene *Scene // not exported for gob reasons
|
||||
}
|
||||
|
||||
// Load loads the scene from the file and then calls Load
|
||||
// on the freshly-loaded Scene.
|
||||
// Load loads the scene from the file.
|
||||
func (r *SceneRef) Load() error {
|
||||
f, err := AssetFS.Open(r.Path)
|
||||
if err != nil {
|
||||
|
@ -116,9 +115,6 @@ func (r *SceneRef) Load() error {
|
|||
if err := gob.NewDecoder(gz).Decode(sc); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := sc.Load(); err != nil {
|
||||
return err
|
||||
}
|
||||
r.scene = sc
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ func (g *Game) UnregisterComponent(c interface{}) {
|
|||
func (g *Game) Component(id string) interface{} { return g.componentsByID[id] }
|
||||
|
||||
// Scan implements Scanner.
|
||||
func (g *Game) Scan() []interface{} { return []interface{}{g.Scene} }
|
||||
func (g *Game) Scan() []interface{} { return []interface{}{g.Scener} }
|
||||
|
||||
// Walk calls v with every component reachable from c via Scan, recursively,
|
||||
// for as long as visit returns nil.
|
||||
|
@ -81,17 +81,29 @@ func Walk(c interface{}, v func(interface{}) error) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Load calls Load on all Loaders reachable via Scan (using Walk).
|
||||
// It stops on the first error.
|
||||
func (g *Game) Load() error {
|
||||
return Walk(g.Scener, func(c interface{}) error {
|
||||
l, ok := c.(Loader)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return l.Load()
|
||||
})
|
||||
}
|
||||
|
||||
// Prepare builds the component database (using Walk) and then calls
|
||||
// Prepare on every Preparer. You must call Prepare before any calls
|
||||
// to Component. You may call Prepare again (e.g. as an alternative to
|
||||
// fastidiously calling RegisterComponent/UnregisterComponent).
|
||||
func (g *Game) Prepare() {
|
||||
g.componentsByID = make(map[string]interface{})
|
||||
Walk(g, func(c interface{}) error {
|
||||
Walk(g.Scener, func(c interface{}) error {
|
||||
g.RegisterComponent(c)
|
||||
return nil
|
||||
})
|
||||
Walk(g, func(c interface{}) error {
|
||||
Walk(g.Scener, func(c interface{}) error {
|
||||
if p, ok := c.(Prepper); ok {
|
||||
p.Prepare(g)
|
||||
}
|
||||
|
|
|
@ -70,7 +70,6 @@ type Scener interface {
|
|||
Drawer
|
||||
DrawOrderer
|
||||
Identifier
|
||||
Loader
|
||||
Prepper
|
||||
Scanner
|
||||
Updater
|
||||
|
|
|
@ -39,20 +39,6 @@ func (s *Scene) Draw(screen *ebiten.Image, opts ebiten.DrawImageOptions) {
|
|||
}
|
||||
}
|
||||
|
||||
// Load loads any subcomponents that need loading.
|
||||
func (s *Scene) Load() error {
|
||||
for _, i := range s.Components {
|
||||
l, ok := i.(Loader)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if err := l.Load(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Prepare does an initial Z-order sort.
|
||||
func (s *Scene) Prepare(game *Game) { s.sortByDrawOrder() }
|
||||
|
||||
|
|
3
main.go
3
main.go
|
@ -43,6 +43,9 @@ func main() {
|
|||
tiles := make(map[image.Point]engine.Tile)
|
||||
for j, row := range denseTiles {
|
||||
for i, tile := range row {
|
||||
if tile == nil {
|
||||
continue
|
||||
}
|
||||
tiles[image.Pt(i, j)] = tile
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue