diff --git a/formats/dc6/dc6.go b/formats/dc6/dc6.go index 84108a3..23f607b 100644 --- a/formats/dc6/dc6.go +++ b/formats/dc6/dc6.go @@ -43,7 +43,7 @@ type Sprite struct { Directions []Direction } -func New(reader io.ReadSeeker) (*Sprite, error) { +func NewFromReader(reader io.ReadSeeker) (*Sprite, error) { sprite := new(Sprite) var fileHead fileHeader diff --git a/tools/dc6/dc6.go b/tools/dc6/dc6.go new file mode 100644 index 0000000..efa2308 --- /dev/null +++ b/tools/dc6/dc6.go @@ -0,0 +1,67 @@ +package main + +import ( + "flag" + "fmt" + "os" + "path" + + "github.com/FooSoft/lazarus/formats/dat" + "github.com/FooSoft/lazarus/formats/dc6" +) + +func loadPalette(path string) (*dat.Palette, error) { + fp, err := os.Open(path) + if err != nil { + return nil, err + } + defer fp.Close() + return dat.NewFromReader(fp) +} + +func loadSprite(path string) (*dc6.Sprite, error) { + fp, err := os.Open(path) + if err != nil { + return nil, err + } + defer fp.Close() + return dc6.NewFromReader(fp) +} + +func extractSprite(palettePath, spritePath, targetDir string) error { + _, err := loadPalette(palettePath) + if err != nil { + return err + } + + _, err = loadSprite(spritePath) + if err != nil { + return err + } + + return nil +} + +func main() { + var ( + targetDir = flag.String("target", ".", "target directory") + ) + + flag.Usage = func() { + fmt.Fprintf(os.Stderr, "Usage: %s [options] palette_file dc6_file\n", path.Base(os.Args[0])) + fmt.Fprintf(os.Stderr, "Parameters:\n\n") + flag.PrintDefaults() + } + + flag.Parse() + + if flag.NArg() < 2 { + flag.Usage() + os.Exit(2) + } + + if err := extractSprite(flag.Arg(0), flag.Arg(1), *targetDir); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +}