horsegen: generate go characters like skills

This commit is contained in:
2026-01-15 15:08:53 -05:00
parent 49d809d695
commit 7e06c23175
3 changed files with 132 additions and 200 deletions

View File

@@ -1,7 +1,9 @@
package horse package horse
type CharacterID int16
type Character struct { type Character struct {
ID int16 ID CharacterID
Name string Name string
} }

File diff suppressed because one or more lines are too long

View File

@@ -3,56 +3,26 @@ package {{ $.Region }}
// Automatically generated with horsegen; DO NOT EDIT // Automatically generated with horsegen; DO NOT EDIT
import ( import . "git.sunturtle.xyz/zephyr/horse/horse"
"slices"
. "git.sunturtle.xyz/zephyr/horse/horse" const (
{{- range $c := $.Characters }}
Character{{ goenum $c.Name }} = {{ $c.ID }} // {{ $c.Name }}
{{- end }}
) )
var characterIDs = []int16{ var Characters = map[CharacterID]Character{
{{- range $c := $.Characters }} {{- range $c := $.Characters }}
{{ $c.ID }}, // {{ $c.Name }} Character{{ goenum $c.Name }}: { {{- $c.ID }}, {{ printf "%q" $c.Name -}} },
{{- end }} {{- end }}
} }
var characterNames = []string{ var CharacterNameToID = map[string]CharacterID{
{{- range $c := $.Characters }}
{{ printf "%q" $c.Name }},
{{- end }}
}
var characterNameToID = map[string]int16{
{{- range $c := $.Characters }} {{- range $c := $.Characters }}
{{ printf "%q" $c.Name }}: {{ $c.ID }}, {{ printf "%q" $c.Name }}: {{ $c.ID }},
{{- end }} {{- end }}
} }
func characterIndex(id int16) (int, bool) {
return slices.BinarySearch(characterIDs, id)
}
func CharacterForID(id int16) Character {
i, ok := characterIndex(id)
if !ok {
return Character{}
}
return Character{
ID: id,
Name: characterNames[i],
}
}
func CharacterForName(name string) Character {
id, ok := characterNameToID[name]
if !ok {
return Character{}
}
return Character{
ID: id,
Name: name,
}
}
var pairAffinity = []int8{ var pairAffinity = []int8{
{{- range $a := $.Characters -}} {{- range $a := $.Characters -}}
{{- range $b := $.Characters -}} {{- range $b := $.Characters -}}
@@ -71,31 +41,26 @@ var trioAffinity = []int8{
{{- end -}} {{- end -}}
} }
func PairAffinity(a, b Character) int { func PairAffinity(a, b CharacterID) int {
i, ok := characterIndex(a.ID) if _, ok := Characters[a]; !ok {
if !ok {
return 0 return 0
} }
j, ok := characterIndex(b.ID) if _, ok := Characters[b]; !ok {
if !ok {
return 0 return 0
} }
return int(pairAffinity[i*{{ $.Count }} + j]) return int(pairAffinity[a*{{ $.Count }} + b])
} }
func TrioAffinity(a, b, c Character) int { func TrioAffinity(a, b, c CharacterID) int {
i, ok := characterIndex(a.ID) if _, ok := Characters[a]; !ok {
if !ok {
return 0 return 0
} }
j, ok := characterIndex(b.ID) if _, ok := Characters[b]; !ok {
if !ok {
return 0 return 0
} }
k, ok := characterIndex(c.ID) if _, ok := Characters[c]; !ok {
if !ok {
return 0 return 0
} }
return int(trioAffinity[i*{{ $.Count }}*{{ $.Count }} + j*{{ $.Count }} + k]) return int(trioAffinity[a*{{ $.Count }}*{{ $.Count }} + b*{{ $.Count }} + c])
} }
{{ end }} {{ end }}