generate character.kk from game data
This commit is contained in:
46
horsegen/gen.go
Normal file
46
horsegen/gen.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user