diff --git a/cardsim/stats.go b/cardsim/stats.go index 543699b..54ddae7 100644 --- a/cardsim/stats.go +++ b/cardsim/stats.go @@ -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 } diff --git a/smoketest/collection.go b/smoketest/collection.go index 995dd3b..c242a18 100644 --- a/smoketest/collection.go +++ b/smoketest/collection.go @@ -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"`