// DecodeAll returns the sequential frames of a CEL or CL2 image based on a // given conf. func DecodeAll(imgName string, conf *cel.Config) (imgs []image.Image, err error) { // Decode CEL version 1 images using the cel package. if path.Ext(imgName) == ".cel" { return cel.DecodeAll(imgName, conf) } // Get frame contents. frames, err := cel.GetFrames(imgName) if err != nil { return nil, err } // Decode frames. for frameNum, frame := range frames { width, ok := conf.FrameWidth[frameNum] if !ok { // Use default frame width. width = conf.Width } height, ok := conf.FrameHeight[frameNum] if !ok { // Use default frame height. height = conf.Height } // Decode frame. img := DecodeFrameType6(frame, width, height, conf.Pal) imgs = append(imgs, img) } return imgs, nil }
// tilDump creates a dump directory and dumps the TIL file's squares using the // pillars constructed based on the MIN format, once for each image config // (pal). func tilDump(tilName string) (err error) { squares, err := til.Parse(tilName) if err != nil { return err } nameWithoutExt := tilName[:len(tilName)-len(path.Ext(tilName))] minName := nameWithoutExt + ".min" pillars, err := min.Parse(minName) if err != nil { return err } imgName := nameWithoutExt + ".cel" relPalPaths := imgconf.GetRelPalPaths(imgName) for _, relPalPath := range relPalPaths { conf, err := cel.GetConf(imgName, relPalPath) if err != nil { return err } var palDir string if len(relPalPaths) > 1 { dbg.Println("using pal:", relPalPath) palDir = path.Base(relPalPath) + "/" } bar, err = barcli.New(len(squares)) if err != nil { return err } levelFrames, err := cel.DecodeAll(imgName, conf) if err != nil { return err } dumpDir := path.Clean(dumpPrefix+"_squares_/"+nameWithoutExt) + "/" + palDir // prevent directory traversal if !strings.HasPrefix(dumpDir, dumpPrefix) { return fmt.Errorf("path (%s) contains no dump prefix (%s).", dumpDir, dumpPrefix) } err = os.MkdirAll(dumpDir, 0755) if err != nil { return err } err = dumpSquares(squares, pillars, levelFrames, dumpDir) if err != nil { return err } } return nil }
// dungeonDump creates a dump directory and stores the dungeon, which has been // constructed based on the given DUN files, as a png image once for each image // config (pal). func dungeonDump(dungeonName string) (err error) { dunNames, err := dunconf.GetDunNames(dungeonName) if err != nil { return err } dungeon := dun.New() for _, dunName := range dunNames { err = dungeon.Parse(dunName) if err != nil { return fmt.Errorf("failed to parse %q: %s", dungeonName, err) } } colCount, err := dunconf.GetColCount(dungeonName) if err != nil { return err } rowCount, err := dunconf.GetRowCount(dungeonName) if err != nil { return err } nameWithoutExt, err := dun.GetLevelName(dunNames[0]) if err != nil { return err } minName := nameWithoutExt + ".min" pillars, err := min.Parse(minName) if err != nil { return err } imgName := nameWithoutExt + ".cel" relPalPaths := imgconf.GetRelPalPaths(imgName) for _, relPalPath := range relPalPaths { conf, err := cel.GetConf(imgName, relPalPath) if err != nil { return err } var palDir string if len(relPalPaths) > 1 { dbg.Println("using pal:", relPalPath) palDir = dungeonName + "/" } levelFrames, err := cel.DecodeAll(imgName, conf) if err != nil { return err } dumpDir := path.Clean(dumpPrefix+"_dungeons_/") + "/" + palDir // prevent directory traversal if !strings.HasPrefix(dumpDir, dumpPrefix) { return fmt.Errorf("path (%s) contains no dump prefix (%s).", dumpDir, dumpPrefix) } err = os.MkdirAll(dumpDir, 0755) if err != nil { return err } dungeonPath := dumpDir + dungeonName + ".png" if len(relPalPaths) > 1 { palName := path.Base(relPalPath) palNameWithoutExt := palName[:len(palName)-len(path.Ext(palName))] dungeonPath = dumpDir + dungeonName + "_" + palNameWithoutExt + ".png" } dbg.Println("Creating image:", path.Base(dungeonPath)) img := dungeon.Image(colCount, rowCount, pillars, levelFrames) err = imgutil.WriteFile(dungeonPath, img) if err != nil { return err } } return nil }