horsegen: generate enumerations and lists
This commit is contained in:
@@ -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 }}))
|
||||
|
||||
Reference in New Issue
Block a user