Don't destroy ordering information in conv.ConvertObjects
This commit is contained in:
@@ -87,7 +87,7 @@ func main() {
|
||||
env := &env{
|
||||
gameMap: gameMap,
|
||||
set: mapSet,
|
||||
objects: objects,
|
||||
objects: conv.MapByName(objects),
|
||||
batch: batch,
|
||||
}
|
||||
|
||||
|
@@ -69,7 +69,7 @@ func main() {
|
||||
objects, spritesheet := conv.ConvertObjects(rawObjs)
|
||||
batch := pixel.NewBatch(&pixel.TrianglesData{}, spritesheet)
|
||||
|
||||
env := &env{objects: objects, set: mapSet, batch: batch}
|
||||
env := &env{objects: conv.MapByName(objects), set: mapSet, batch: batch}
|
||||
|
||||
// The main thread now belongs to pixelgl
|
||||
pixelgl.Run(env.run)
|
||||
|
@@ -35,7 +35,17 @@ type Object struct {
|
||||
Sprites []*Sprite
|
||||
}
|
||||
|
||||
func ConvertObjects(objects []*data.Object) (map[string]*Object, *pixel.PictureData) {
|
||||
func MapByName(objects []*Object) map[string]*Object {
|
||||
out := make(map[string]*Object, len(objects))
|
||||
|
||||
for _, obj := range objects {
|
||||
out[obj.Name] = obj
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
func ConvertObjects(objects []*data.Object) ([]*Object, *pixel.PictureData) {
|
||||
// FIXME: this is rather inefficient. It would be better to determine the
|
||||
// maximum size we need for the objects at hand.
|
||||
spritesheet := pixel.MakePictureData(
|
||||
@@ -47,7 +57,7 @@ func ConvertObjects(objects []*data.Object) (map[string]*Object, *pixel.PictureD
|
||||
yOffset := 0
|
||||
rowMaxY := 0
|
||||
|
||||
out := make(map[string]*Object)
|
||||
out := make([]*Object, 0, len(objects))
|
||||
|
||||
for _, rawObj := range objects {
|
||||
sprites := make([]*Sprite, 0, len(rawObj.Sprites))
|
||||
@@ -75,7 +85,7 @@ func ConvertObjects(objects []*data.Object) (map[string]*Object, *pixel.PictureD
|
||||
}
|
||||
}
|
||||
|
||||
out[rawObj.Name] = &Object{Name: rawObj.Name, Sprites: sprites}
|
||||
out = append(out, &Object{Name: rawObj.Name, Sprites: sprites})
|
||||
}
|
||||
|
||||
return out, spritesheet
|
||||
|
Reference in New Issue
Block a user