81 lines
2.6 KiB
Plaintext
81 lines
2.6 KiB
Plaintext
{{- define "koka-race" -}}
|
|
module horse/{{ $.Region }}/race
|
|
|
|
// Automatically generated with horsegen; DO NOT EDIT
|
|
|
|
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 ne $r.Primary $r.ID }}-Alternate{{ end }}
|
|
{{- end }}
|
|
|
|
// Get the race ID for a race.
|
|
pub fun race-id(r: race): race-id
|
|
match r
|
|
{{- range $r := $.Races }}
|
|
{{ kkenum $r.Name }}{{ if ne $r.Primary $r.ID }}-Alternate{{ 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 ne $r.Primary $r.ID }}-Alternate{{ end }},
|
|
{{- end }}
|
|
]
|
|
|
|
val name2id: rbmap<string, race-id> = rb-map/empty()
|
|
{{- range $r := $.Races }}
|
|
.set({{ printf "%q" $r.Name }}{{ if ne $r.Primary $r.ID }} ++ " (Alternate)"{{ end }}, Race-id({{ $r.ID }}))
|
|
{{- end }}
|
|
|
|
// Get the race ID that has the given exact name.
|
|
// Alternate versions of races have " (Alternate)" 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))
|
|
|
|
// Get the name for a race.
|
|
// Alternate versions of races have " (Alternate)" in their names.
|
|
// If no race matches the ID, the result is the numeric ID.
|
|
pub fun show(r: race-id): string
|
|
match r.game-id
|
|
{{- range $r := $.Races }}
|
|
{{ $r.ID }} -> {{ printf "%q" $r.Name }}{{ if ne $r.Primary $r.ID }} ++ " (Alternate)"{{ end }}
|
|
{{- end }}
|
|
x -> "race " ++ x.show
|
|
|
|
// Get the grade for a race.
|
|
// If no race matches the ID, the result is Pre-OP.
|
|
pub fun grade(r: race-id): grade
|
|
match r.game-id
|
|
{{- range $r := $.Races }}
|
|
{{ $r.ID }} -> {{ if eq $r.Grade 100 }}G1{{ else if eq $r.Grade 200 }}G2{{ else if eq $r.Grade 300 }}G3{{ else if eq $r.Grade 400 }}OP{{ else if eq $r.Grade 700 }}Pre-OP{{ else }}??? $r.Grade={{ $r.Grade }}{{ end }}
|
|
{{- end }}
|
|
_ -> Pre-OP
|
|
|
|
// Get the thumbnail ID for a race.
|
|
// If no race matches the ID, the result is an invalid ID.
|
|
pub fun thumbnail(r: race-id): race-thumbnail-id
|
|
match r.game-id
|
|
{{- range $r := $.Races }}
|
|
{{ $r.ID }} -> Race-thumbnail-id({{ $r.ThumbnailID }})
|
|
{{- end }}
|
|
_ -> Race-thumbnail-id(0)
|
|
|
|
// Get the primary ID for a race.
|
|
// For races which are the primary version, or if no race matches the given ID,
|
|
// the result is the input.
|
|
pub fun primary(r: race-id): race-id
|
|
match r.game-id
|
|
{{- range $r := $.Races }}
|
|
{{- if ne $r.ID $r.Primary }}
|
|
{{ $r.ID }} -> Race-id({{ $r.Primary }})
|
|
{{- end }}
|
|
{{- end }}
|
|
_ -> r
|
|
{{ end }}
|