horsegen: spam vectors to try to limit type check time

This commit is contained in:
2026-02-16 14:06:51 -05:00
parent 2184515938
commit b0e422ac01
14 changed files with 157 additions and 6644 deletions

View File

@@ -3,42 +3,31 @@ module horse/{{ $.Region }}/skill
// Automatically generated with horsegen; DO NOT EDIT
import std/core/delayed
import std/core/vector
import std/core-extras
import std/data/rb-map
import std/num/decimal
import horse/game-id
import horse/movement
pub import horse/skill
// Enumeration of all skills for type-safe programming.
pub type skill
{{- range $s := $.Skills }}
{{ kkenum $s.Name }}{{ if $s.InheritID }}-Inherit{{ end }}
{{- end }}
extern create-id-table(): vector<int>
c inline "int32_t arr[] = { {{- range $s := $.Skills }}{{ $s.ID }},{{ end -}} };\nkk_vector_from_cint32array(arr, (kk_ssize_t){{ $.SkillCount }}, kk_context())"
js inline "[{{ range $s := $.Skills }}{{ $s.ID }},{{ end }}]"
// Vector of all skill ID values in order for easy iterating.
val all = once(create-id-table)
// Get the skill ID for a skill.
pub fun skill-id(s: skill): skill-id
match s
{{- range $s := $.Skills }}
{{ kkenum $s.Name }}{{ if $s.InheritID }}-Inherit{{ end }} -> Skill-id({{ $s.ID }})
{{- end }}
// List of all skills in ID order for easy iterating.
pub val all = [
{{- range $s := $.Skills }}
{{ kkenum $s.Name }}{{ if $s.InheritID }}-Inherit{{ end }},
{{- end }}
]
val name2id: rbmap<string, skill-id> = rb-map/empty()
{{- range $s := $.Skills }}
.set({{ printf "%q" $s.Name }}{{ if $s.InheritID }} ++ " (Inherited)"{{ end }}, Skill-id({{ $s.ID }}))
{{- end }}
val name2id = once()
var m: rbmap<string, int> := empty()
all().foreach() fn(id) m := m.set(Skill-id(id).show, id)
m
// Get the skill ID that has the given exact name.
// Inherited skills have `" (Inherited)"` appended to their names.
// If no skill matches the name, the result is an invalid ID.
pub fun from-name(name: string): skill-id
name2id.lookup(name).default(Skill-id(0))
Skill-id(name2id().rb-map/lookup(name).default(0))
// Get the name for a skill.
// Inherited skills have `" (Inherited)"` appended to their names.