work in progress on dc6 sprite dump tool

This commit is contained in:
Alex Yatskov 2018-12-17 12:28:16 -08:00
parent 2bacae3c01
commit 0d8210e26c
2 changed files with 68 additions and 1 deletions

View File

@ -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

67
tools/dc6/dc6.go Normal file
View File

@ -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)
}
}