nori/render_test.go

102 lines
2.2 KiB
Go
Raw Permalink Normal View History

package nori_test
2022-03-25 05:14:03 +00:00
import (
2022-03-25 06:00:01 +00:00
"bytes"
2022-03-25 18:32:40 +00:00
"fmt"
"git.tuxpa.in/a/nori"
"git.tuxpa.in/a/nori/renderer"
2022-03-25 05:14:03 +00:00
"os"
2022-03-25 18:32:40 +00:00
"strings"
2022-03-25 05:14:03 +00:00
"testing"
2022-03-25 06:00:01 +00:00
"gitlab.com/gfxlabs/gfximg/apng"
2022-03-25 05:14:03 +00:00
)
func TestParseFile1(t *testing.T) {
nori, err := nori.FromFile("./render_test/test1.nri")
2022-03-25 05:14:03 +00:00
if err != nil {
2022-03-25 07:33:23 +00:00
t.Errorf("decode: %s", err)
}
2022-03-25 18:32:40 +00:00
t.Logf("\n nori: %+v\n gawi: %+v", nori, nori.Gawi)
err = writeApng(nori, "test1")
2022-03-25 07:33:23 +00:00
if err != nil {
t.Errorf("export: %s", err)
2022-03-25 05:14:03 +00:00
}
}
func TestParseFile2(t *testing.T) {
nori, err := nori.FromFile("./render_test/test2.nri")
2022-03-25 05:14:03 +00:00
if err != nil {
2022-03-25 07:33:23 +00:00
t.Errorf("decode: %s", err)
2022-03-25 05:14:03 +00:00
}
t.Logf("\n nori: %+v\n gawi: %+v", nori, nori.Gawi)
2022-03-25 18:32:40 +00:00
err = writeApng(nori, "test2")
2022-03-25 07:33:23 +00:00
if err != nil {
t.Errorf("export: %s", err)
}
2022-03-25 05:14:03 +00:00
}
2022-03-25 06:00:01 +00:00
func TestParseFile3(t *testing.T) {
nori, err := nori.FromFile("./render_test/CharCreateNSelectUI.bac")
if err != nil {
t.Errorf("decode: %s", err)
}
t.Logf("\n nori: %+v\n gawi: %+v", nori, nori.Gawi)
err = writeApng(nori, "charcreate")
if err != nil {
t.Errorf("export: %s", err)
}
}
func TestParseFile4(t *testing.T) {
nori, err := nori.FromFile("./render_test/LoadingUI.bac")
if err != nil {
t.Errorf("decode: %s", err)
}
t.Logf("\n nori: %+v\n gawi: %+v", nori, nori.Gawi)
err = writeApng(nori, "LoadingUI")
if err != nil {
t.Errorf("export: %s", err)
}
}
2022-03-25 06:00:01 +00:00
func TestParsePalette(t *testing.T) {
nori, err := nori.FromFile("./render_test/palette.nri")
2022-03-25 06:00:01 +00:00
if err != nil {
t.Errorf("decode: %s", err)
}
t.Logf("\n nori: %+v\n gawi: %+v\n palette: %+v\n", nori, nori.Gawi, nori.Gawi.Palette)
2022-03-25 18:32:40 +00:00
err = writeApng(nori, "palette")
2022-03-25 10:23:31 +00:00
if err != nil {
t.Errorf("export: %s", err)
}
2022-03-25 06:04:20 +00:00
}
2022-03-25 06:00:01 +00:00
func writeApng(n *nori.Nori, name string) error {
2022-03-25 18:39:43 +00:00
postfix := ".example"
2022-03-25 06:00:01 +00:00
out := new(bytes.Buffer)
2022-03-25 21:00:43 +00:00
os.MkdirAll(fmt.Sprintf("./render_test/%s%s", name, postfix), 0740)
for i := range n.Animations {
a, err := renderer.RenderAnimationApng(n, i)
2022-03-25 18:32:40 +00:00
if err != nil {
if strings.Contains(err.Error(), "no frame") {
continue
}
return err
}
err = apng.Encode(out, *a)
if err != nil {
return err
}
2022-03-25 21:00:43 +00:00
err = os.WriteFile(fmt.Sprintf("./render_test/%s%s/animation_%d.png", name, postfix, i), out.Bytes(), 0740)
2022-03-25 18:32:40 +00:00
if err != nil {
return err
}
2022-03-25 18:39:43 +00:00
out.Reset()
2022-03-25 06:00:01 +00:00
}
2022-03-25 10:23:31 +00:00
return nil
2022-03-25 06:00:01 +00:00
}