first wave of compiler errors

This commit is contained in:
Kistaro Windrider 2023-12-09 21:13:16 -08:00
parent 8bf78d1cc6
commit d78344808a
Signed by: kistaro
SSH Key Fingerprint: SHA256:TBE2ynfmJqsAf0CP6gsflA0q5X5wD5fVKWPsZ7eVUg8

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"log" "log"
"os" "os"
"strconv"
"strings" "strings"
) )
@ -15,11 +16,11 @@ type RGBA struct {
} }
func (c RGBA) Bytes() [4]byte { func (c RGBA) Bytes() [4]byte {
return [4]byte{c.R, c.G, cB, c.A} return [4]byte{c.R, c.G, c.B, c.A}
} }
func HexByteAt(str string, index int) (byte, error) { func HexByteAt(str string, index int) (byte, error) {
if len(string) < index+2 { if len(str) < index+2 {
return 0, fmt.Errorf("no hex byte at %d in too short string %q", index, str) return 0, fmt.Errorf("no hex byte at %d in too short string %q", index, str)
} }
big, err := strconv.ParseUint(str[index:index+1], 16, 8) big, err := strconv.ParseUint(str[index:index+1], 16, 8)
@ -29,7 +30,7 @@ func HexByteAt(str string, index int) (byte, error) {
return byte(big), nil return byte(big), nil
} }
func MustParseRGBA(str string) RGBA { func ParseRGBA(str string) RGBA, error {
s := strings.TrimSpace(str) s := strings.TrimSpace(str)
s = strings.ToLower(s) s = strings.ToLower(s)
s, _ = strings.CutPrefix(s, "#") s, _ = strings.CutPrefix(s, "#")
@ -41,20 +42,22 @@ func MustParseRGBA(str string) RGBA {
var err error var err error
ret.A, err = HexByteAt(s, 6) ret.A, err = HexByteAt(s, 6)
if err != nil { if err != nil {
log.Fatalf("can't parse alpha channel: %v", err) return RGBA{}, fmt.Errorf("can't parse alpha channel: %v", err)
} }
default: default:
log.Fatalf("%q is not an RGBA value: wrong length after trimming", str) return RGBA{}, fmt.Errorf("%q is not an RGBA value: wrong length after trimming", str)
} }
if ret.R, err := HexByteAt(s, 0); err != nil { var err error
log.Fatalf("can't parse red channel: %v", err) if ret.R, err = HexByteAt(s, 0); err != nil {
return RGBA{}, fmt.Errorf("can't parse red channel: %v", err)
} }
if ret.G, err := HexByteAt(s, 2); err != nil { if ret.G, err = HexByteAt(s, 2); err != nil {
log.Fatalf("can't parse green channel: %v", err) return RGBA{}, fmt.Errorf("can't parse green channel: %v", err)
} }
if ret.B, err := HexByteAt(s, 4); err != nil { if ret.B, err = HexByteAt(s, 4); err != nil {
log.Fatalf("can't parse blue channel: %v", err) return RGBA{}, fmt.Errorf("can't parse blue channel: %v", err)
} }
return ret, nil
} }
type BGPal [4]RGBA type BGPal [4]RGBA
@ -80,7 +83,7 @@ func MustParseBGPal(strs []string) BGPal {
} }
var ret BGPal var ret BGPal
for i := 0; i < 4; i++ { for i := 0; i < 4; i++ {
ret[i], err := MustParseRGBA(strs[i]) ret[i], err := ParseRGBA(strs[i])
if err != nil { if err != nil {
log.Fatalf("MustParseBGPal can't parse at %d: %v", i, err) log.Fatalf("MustParseBGPal can't parse at %d: %v", i, err)
} }
@ -109,7 +112,7 @@ func (o OBJPal) Bytes(indexchar byte) [18]byte {
func MustParseOBJPal(strs []string) OBJPal { func MustParseOBJPal(strs []string) OBJPal {
if len(strs) == 4 { if len(strs) == 4 {
log.Info("Discarding index 0 of OBJ pal") log.Println("Discarding index 0 of OBJ pal")
strs = strs[1:] strs = strs[1:]
} }
if len(strs) != 3 { if len(strs) != 3 {
@ -117,7 +120,7 @@ func MustParseOBJPal(strs []string) OBJPal {
} }
var ret OBJPal var ret OBJPal
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {
ret[i], err := MustParseRGBA(strs[i]) ret[i], err := ParseRGBA(strs[i])
if err != nil { if err != nil {
log.Fatalf("MustParseOBJPal can't parse at %d: %v", i, err) log.Fatalf("MustParseOBJPal can't parse at %d: %v", i, err)
} }