horse: move go Character type to manually generated
This commit is contained in:
6
horse/README.md
Normal file
6
horse/README.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# horse
|
||||
|
||||
This directory contains manually written code and types on which the generated code depends.
|
||||
|
||||
The generated code is in ./global; other regions will follow the same convention once they are supported.
|
||||
It is always safe to delete the entire directories and regenerate them.
|
||||
10
horse/character.go
Normal file
10
horse/character.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package horse
|
||||
|
||||
type Character struct {
|
||||
ID int16
|
||||
Name string
|
||||
}
|
||||
|
||||
func (c Character) String() string {
|
||||
return c.Name
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -4,15 +4,10 @@ package {{ $.Region }}
|
||||
// Automatically generated with horsegen; DO NOT EDIT
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Character struct {
|
||||
ID int16
|
||||
Name string
|
||||
}
|
||||
. "git.sunturtle.xyz/zephyr/horse/horse"
|
||||
)
|
||||
|
||||
var characterIDs = []int16{
|
||||
{{- range $c := $.Characters }}
|
||||
@@ -58,44 +53,6 @@ func CharacterForName(name string) Character {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Character) MarshalJSON() ([]byte, error) {
|
||||
// Only marshal legal or empty characters.
|
||||
if c.ID == 0 {
|
||||
return []byte{'0'}, nil
|
||||
}
|
||||
i, ok := characterIndex(c.ID)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("marshaling character %q with invalid ID %d", c.Name, c.ID)
|
||||
}
|
||||
if characterNames[i] != c.Name {
|
||||
return nil, fmt.Errorf("marshaling character with ID %d: name is %q but should be %q", c.ID, c.Name, characterNames[i])
|
||||
}
|
||||
return strconv.AppendInt(nil, int64(c.ID), 10), nil
|
||||
}
|
||||
|
||||
func (c *Character) UnmarshalJSON(b []byte) error {
|
||||
if string(b) == "null" {
|
||||
return nil
|
||||
}
|
||||
id, err := strconv.ParseInt(string(b), 10, 16)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unmarshaling invalid character ID %q: %w", b, err)
|
||||
}
|
||||
if id == 0 {
|
||||
*c = Character{}
|
||||
return nil
|
||||
}
|
||||
i, ok := characterIndex(int16(id))
|
||||
if !ok {
|
||||
return fmt.Errorf("unmarshaling unrecognized character ID %d", id)
|
||||
}
|
||||
*c = Character{
|
||||
ID: int16(id),
|
||||
Name: characterNames[i],
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var pairAffinity = []int8{
|
||||
{{- range $a := $.Characters -}}
|
||||
{{- range $b := $.Characters -}}
|
||||
@@ -141,5 +98,4 @@ func TrioAffinity(a, b, c Character) int {
|
||||
}
|
||||
return int(trioAffinity[i*{{ $.Count }}*{{ $.Count }} + j*{{ $.Count }} + k])
|
||||
}
|
||||
|
||||
{{ end }}
|
||||
Reference in New Issue
Block a user