Allow renaming of extracted stats via tag.
This commit is contained in:
parent
99e372a4db
commit
ad9e5764f1
@ -138,6 +138,10 @@ func (s statFunc[T]) Visible() bool {
|
||||
// start of another word, if it's not at the end). To insert a space between
|
||||
// consecutive capital letters, insert an underscore (`_`). This name inference
|
||||
// trims "Stat" and "HiddenStat" off the front of method names.
|
||||
//
|
||||
// To override the name extracted from a field name, add `cardsim_name:"name"`
|
||||
// to the tag, where the name part is the name you want to use. It will not be
|
||||
// formatted further - use normal spaces, capitalization, etc.
|
||||
func ExtractStats(x any) []Stat {
|
||||
v := reflect.ValueOf(x)
|
||||
for k := v.Kind(); k == reflect.Pointer || k == reflect.Interface; k = v.Kind() {
|
||||
@ -248,6 +252,9 @@ func ExtractStats(x any) []Stat {
|
||||
continue // not identifiably a stat
|
||||
}
|
||||
nm := strings.Join(explode(sf.Name), " ")
|
||||
if t := sf.Tag.Get("cardsim_name"); t != "" {
|
||||
nm = t
|
||||
}
|
||||
if known[nm] {
|
||||
continue
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ type SmokeTestCollection struct {
|
||||
|
||||
Flavor cardsim.Stored[string]
|
||||
|
||||
Things int `cardsim:"stat"`
|
||||
Things int `cardsim:"stat" cardsim_name:"A Renamed Thing"`
|
||||
MoreThings int `cardsim:"hidden"`
|
||||
FloatyThings float64 `cardsim:"round1"`
|
||||
Label string `cardsim:"stat"`
|
||||
|
Loading…
Reference in New Issue
Block a user