From 3bd611feab75722cf821e931611523ee0e3f33c0 Mon Sep 17 00:00:00 2001 From: Kistaro Windrider Date: Sat, 9 Dec 2023 21:00:02 -0800 Subject: [PATCH] full prototype --- apgbpal.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/apgbpal.go b/apgbpal.go index d469ab3..cd84300 100644 --- a/apgbpal.go +++ b/apgbpal.go @@ -4,6 +4,7 @@ import ( "fmt" "strings" "log" + "os" ) type RGBA struct { @@ -106,7 +107,11 @@ func (o OBJPal) Bytes(indexchar byte) [18]byte { return ret } -func MustParseOBJPal { +func MustParseOBJPal(strs []string) OBJPal { + if len(strs) == 4 { + log.Info("Discarding index 0 of OBJ pal") + strs = strs[1:] + } if len(strs) != 3 { log.Fatalf("MustParseObjPal requires length 3, got %d", len(strs)) } @@ -140,3 +145,23 @@ func (a APGBPal) Bytes() [56]byte { return ret } +func main() { + f, err := os.OpenFile("test.pal", O_WRONLY|O_CREATE|O_EXCL, 0644) + if err != nil { + log.Fatalf("can't create test.pal: %v", err) + } + aUpPal := APGBPal { + BG: MustParseBGPal([]string{"ffffff", "ff8484", "943a3a", "000000"}), + OBJ0: MustParseObjPal([]string{"7bff31", "008400", "000000"}), + OBJ1: MustParseObjPal([]string{"63a5ff", "0000ff", "000000"}), + } + n, err := f.Write(aUpPal.Bytes()[:]) + if err != nil { + log.Fatalf("can't save test.pal: %v", err) + } + if n != 56 { + log.Fatalf("unexpected write length: %d", n) + } + f.Close() + os.Exit(0) +} \ No newline at end of file