{{- define "koka-race" -}} 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 extern create-id-table(): vector 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) val name2id = once() var m: rbmap := 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 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. // 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 $r.Alternate }} ++ " (Alternate {{ $r.ID }})"{{ 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 $r.Alternate }} {{ $r.ID }} -> Race-id({{ $r.Primary }}) {{- end }} {{- end }} _ -> r {{ end }}