generate character.kk from game data

This commit is contained in:
2026-01-06 10:25:16 -05:00
parent bfc497b6fc
commit 0cbc0f93b5
12 changed files with 75647 additions and 2178 deletions

46
horsegen/gen.go Normal file
View File

@@ -0,0 +1,46 @@
package main
import (
_ "embed"
"fmt"
"io"
"strings"
"text/template"
)
//go:embed character.kk.template
var characterKK string
// LoadTemplates sets up templates to render game data to source code.
func LoadTemplates() (*template.Template, error) {
t := template.New("root")
t.Funcs(template.FuncMap{
"kkenum": kkenum,
})
t, err := t.Parse(characterKK)
if err != nil {
return nil, fmt.Errorf("parsing characterKK: %w", err)
}
return t, nil
}
// ExecCharacterKK renders the Koka character module to w.
func ExecCharacterKK(t *template.Template, w io.Writer, c []Character, pairs, trios []AffinityRelation) error {
maxid := 0
for _, u := range c {
maxid = max(maxid, u.ID)
}
data := struct {
Characters []Character
Pairs []AffinityRelation
Trios []AffinityRelation
MaxID int
}{c, pairs, trios, maxid}
return t.ExecuteTemplate(w, "koka-character", &data)
}
func kkenum(name string) string {
name = strings.ReplaceAll(name, ".", "")
name = strings.ReplaceAll(name, " ", "-")
return name
}