Changed structure of levels/packs.

This commit is contained in:
Sander Schobers 2020-01-14 18:38:42 +01:00
parent 46e3ac060a
commit fd92207400
6 changed files with 22 additions and 13 deletions

View File

@ -98,27 +98,36 @@ func (g *game) loadTextures(pathToName map[string]string) error {
return nil
}
func (g *game) loadLevelPack(ids ...string) error {
func (g *game) loadLevelPacks() error {
g.ctx.Levels = map[string]levelPack{}
ids := []string{"1"}
for _, id := range ids {
fileName := fmt.Sprintf("levels/pack%s.txt", id)
f, err := g.ctx.Resources.Open(fileName)
err := g.loadLevelPack(id)
if err != nil {
return err
}
defer f.Close()
pack, err := parseLevelPackAsset(f, func(levelID string) (io.ReadCloser, error) {
fileName := fmt.Sprintf("levels/pack%s_level%s.txt", id, levelID)
return g.ctx.Resources.Open(fileName)
})
if err != nil {
return err
}
g.ctx.Levels[id] = pack
}
return nil
}
func (g *game) loadLevelPack(id string) error {
fileName := fmt.Sprintf("levels/pack%s/info.txt", id)
f, err := g.ctx.Resources.Open(fileName)
if err != nil {
return err
}
defer f.Close()
pack, err := parseLevelPackAsset(f, func(levelID string) (io.ReadCloser, error) {
fileName := fmt.Sprintf("levels/pack%s/level%s.txt", id, levelID)
return g.ctx.Resources.Open(fileName)
})
if err != nil {
return err
}
g.ctx.Levels[id] = pack
return nil
}
func (g *game) loadSprites(names ...string) error {
g.ctx.Sprites = map[string]sprite{}
for _, name := range names {
@ -165,7 +174,7 @@ func (g *game) loadAssets() error {
log.Printf("Loaded %d textures.\n", len(g.ctx.Textures))
log.Println("Loading levels...")
err = g.loadLevelPack("1")
err = g.loadLevelPacks()
if err != nil {
return err
}