From 0d8210e26cb0e7d3042bc39e4e9fd7d20685a7d1 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 17 Dec 2018 12:28:16 -0800 Subject: [PATCH] work in progress on dc6 sprite dump tool --- formats/dc6/dc6.go | 2 +- tools/dc6/dc6.go | 67 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 tools/dc6/dc6.go 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) + } +}