horsegen: generate enumerations and lists

This commit is contained in:
2026-01-27 21:50:57 -05:00
parent 98afe7384a
commit 542d4198e7
4 changed files with 1712 additions and 0 deletions

View File

@@ -9,6 +9,26 @@ import std/data/rb-map
import horse/game-id
pub import horse/character
// Enumeration of all characters for type-safe programming.
pub type character
{{- range $uma := $.Characters }}
{{ kkenum $uma.Name }}
{{- end }}
// Get the character ID for a character.
pub fun character-id(c: character): character-id
match c
{{- range $uma := $.Characters }}
{{ kkenum $uma.Name }} -> Character-id({{ $uma.ID }})
{{- end }}
// List of all characters in ID order for easy iterating.
pub val all = [
{{- range $uma := $.Characters }}
{{ kkenum $uma.Name }},
{{- end }}
]
val name2id: rbmap<string, character-id> = rb-map/empty()
{{- range $uma := $.Characters }}
.set({{ printf "%q" $uma.Name }}, Character-id({{ $uma.ID}}))

View File

@@ -9,6 +9,26 @@ 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 }}
// 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 }}))