diff --git a/cmd/krampus19/game.go b/cmd/krampus19/game.go index 9a1877c..95a5f0e 100644 --- a/cmd/krampus19/game.go +++ b/cmd/krampus19/game.go @@ -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 } diff --git a/cmd/krampus19/res/levels/pack1.txt b/cmd/krampus19/res/levels/pack1/info.txt similarity index 100% rename from cmd/krampus19/res/levels/pack1.txt rename to cmd/krampus19/res/levels/pack1/info.txt diff --git a/cmd/krampus19/res/levels/pack1_level1.txt b/cmd/krampus19/res/levels/pack1/level1.txt similarity index 100% rename from cmd/krampus19/res/levels/pack1_level1.txt rename to cmd/krampus19/res/levels/pack1/level1.txt diff --git a/cmd/krampus19/res/levels/pack1_level2.txt b/cmd/krampus19/res/levels/pack1/level2.txt similarity index 100% rename from cmd/krampus19/res/levels/pack1_level2.txt rename to cmd/krampus19/res/levels/pack1/level2.txt diff --git a/cmd/krampus19/res/levels/pack1_level3.txt b/cmd/krampus19/res/levels/pack1/level3.txt similarity index 100% rename from cmd/krampus19/res/levels/pack1_level3.txt rename to cmd/krampus19/res/levels/pack1/level3.txt diff --git a/cmd/krampus19/res/levels/pack1_level4.txt b/cmd/krampus19/res/levels/pack1/level4.txt similarity index 100% rename from cmd/krampus19/res/levels/pack1_level4.txt rename to cmd/krampus19/res/levels/pack1/level4.txt