horsegen: generate alternate races/saddles with ids
This commit is contained in:
@@ -10,41 +10,41 @@ 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 }}
|
||||
{{ kkenum $r.Name }}{{ if $r.Alternate }}-Alt{{ $r.ID }}{{ 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 }})
|
||||
{{ 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 ne $r.Primary $r.ID }}-Alternate{{ end }},
|
||||
{{ 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 ne $r.Primary $r.ID }} ++ " (Alternate)"{{ end }}, Race-id({{ $r.ID }}))
|
||||
.set({{ printf "%q" $r.Name }}{{ if $r.Alternate }} ++ " (Alternate {{ $r.ID }})"{{ 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.
|
||||
// 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))
|
||||
|
||||
// Get the name for a race.
|
||||
// Alternate versions of races have " (Alternate)" in their names.
|
||||
// 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 ne $r.Primary $r.ID }} ++ " (Alternate)"{{ end }}
|
||||
{{ $r.ID }} -> {{ printf "%q" $r.Name }}{{ if $r.Alternate }} ++ " (Alternate {{ $r.ID }})"{{ end }}
|
||||
{{- end }}
|
||||
x -> "race " ++ x.show
|
||||
|
||||
@@ -72,7 +72,7 @@ pub fun thumbnail(r: race-id): race-thumbnail-id
|
||||
pub fun primary(r: race-id): race-id
|
||||
match r.game-id
|
||||
{{- range $r := $.Races }}
|
||||
{{- if ne $r.ID $r.Primary }}
|
||||
{{- if $r.Alternate }}
|
||||
{{ $r.ID }} -> Race-id({{ $r.Primary }})
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
Reference in New Issue
Block a user