horsegen: spam vectors to try to limit type check time
This commit is contained in:
@@ -3,40 +3,29 @@ module horse/{{ $.Region }}/race
|
||||
|
||||
// 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 horse/game-id
|
||||
pub import horse/race
|
||||
|
||||
// Enumeration of all races for type-safe programming.
|
||||
pub type race
|
||||
{{- range $r := $.Races }}
|
||||
{{ kkenum $r.Name }}{{ if $r.Alternate }}-Alt{{ $r.ID }}{{ end }}
|
||||
{{- end }}
|
||||
extern create-id-table(): vector<int>
|
||||
c inline "int32_t arr[] = { {{- range $r := $.Races }}{{ $r.ID }},{{ end -}} };\nkk_vector_from_cint32array(arr, (kk_ssize_t){{ $.RaceCount }}, kk_context())"
|
||||
js inline "[{{ range $r := $.Races }}{{ $r.ID }},{{ end }}]"
|
||||
// Vector of all race IDs in order for easy iterating.
|
||||
val all = once(create-id-table)
|
||||
|
||||
// Get the race ID for a race.
|
||||
pub fun race-id(r: race): race-id
|
||||
match r
|
||||
{{- range $r := $.Races }}
|
||||
{{ kkenum $r.Name }}{{ if $r.Alternate }}-Alt{{ $r.ID }}{{ end }} -> Race-id({{ $r.ID }})
|
||||
{{- end }}
|
||||
|
||||
// List of all races in ID order for easy iterating.
|
||||
pub val all = [
|
||||
{{- range $r := $.Races }}
|
||||
{{ kkenum $r.Name }}{{ if $r.Alternate }}-Alt{{ $r.ID }}{{ end }},
|
||||
{{- end }}
|
||||
]
|
||||
|
||||
val name2id: rbmap<string, race-id> = rb-map/empty()
|
||||
{{- range $r := $.Races }}
|
||||
.set({{ printf "%q" $r.Name }}{{ if $r.Alternate }} ++ " (Alternate {{ $r.ID }})"{{ end }}, Race-id({{ $r.ID }}))
|
||||
{{- end }}
|
||||
val name2id = once()
|
||||
var m: rbmap<string, int> := empty()
|
||||
all().foreach() fn(id) m := m.set(Race-id(id).show, id)
|
||||
m
|
||||
|
||||
// Get the race ID that has the given exact name.
|
||||
// Alternate versions of races have an indication of their ID in their names.
|
||||
// If no race matches the name, the result is an invalid ID.
|
||||
pub fun from-name(name: string): race-id
|
||||
name2id.lookup(name).default(Race-id(0))
|
||||
Race-id(name2id().rb-map/lookup(name).default(0))
|
||||
|
||||
// Get the name for a race.
|
||||
// Alternate versions of races have an indication of their ID in their names.
|
||||
|
||||
Reference in New Issue
Block a user