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
type CharacterID int16
type Character struct {
ID int16
ID CharacterID
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
import (
"slices"
import . "git.sunturtle.xyz/zephyr/horse/horse"
. "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 }}
{{ $c.ID }}, // {{ $c.Name }}
Character{{ goenum $c.Name }}: { {{- $c.ID }}, {{ printf "%q" $c.Name -}} },
{{- end }}
}
var characterNames = []string{
{{- range $c := $.Characters }}
{{ printf "%q" $c.Name }},
{{- end }}
}
var characterNameToID = map[string]int16{
var CharacterNameToID = map[string]CharacterID{
{{- range $c := $.Characters }}
{{ printf "%q" $c.Name }}: {{ $c.ID }},
{{- 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{
{{- range $a := $.Characters -}}
{{- range $b := $.Characters -}}
@@ -71,31 +41,26 @@ var trioAffinity = []int8{
{{- end -}}
}
func PairAffinity(a, b Character) int {
i, ok := characterIndex(a.ID)
if !ok {
func PairAffinity(a, b CharacterID) int {
if _, ok := Characters[a]; !ok {
return 0
}
j, ok := characterIndex(b.ID)
if !ok {
if _, ok := Characters[b]; !ok {
return 0
}
return int(pairAffinity[i*{{ $.Count }} + j])
return int(pairAffinity[a*{{ $.Count }} + b])
}
func TrioAffinity(a, b, c Character) int {
i, ok := characterIndex(a.ID)
if !ok {
func TrioAffinity(a, b, c CharacterID) int {
if _, ok := Characters[a]; !ok {
return 0
}
j, ok := characterIndex(b.ID)
if !ok {
if _, ok := Characters[b]; !ok {
return 0
}
k, ok := characterIndex(c.ID)
if !ok {
if _, ok := Characters[c]; !ok {
return 0
}
return int(trioAffinity[i*{{ $.Count }}*{{ $.Count }} + j*{{ $.Count }} + k])
return int(trioAffinity[a*{{ $.Count }}*{{ $.Count }} + b*{{ $.Count }} + c])
}
{{ end }}
{{ end }}