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
|
// 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
|
// consecutive capital letters, insert an underscore (`_`). This name inference
|
||||||
// trims "Stat" and "HiddenStat" off the front of method names.
|
// 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 {
|
func ExtractStats(x any) []Stat {
|
||||||
v := reflect.ValueOf(x)
|
v := reflect.ValueOf(x)
|
||||||
for k := v.Kind(); k == reflect.Pointer || k == reflect.Interface; k = v.Kind() {
|
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
|
continue // not identifiably a stat
|
||||||
}
|
}
|
||||||
nm := strings.Join(explode(sf.Name), " ")
|
nm := strings.Join(explode(sf.Name), " ")
|
||||||
|
if t := sf.Tag.Get("cardsim_name"); t != "" {
|
||||||
|
nm = t
|
||||||
|
}
|
||||||
if known[nm] {
|
if known[nm] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ type SmokeTestCollection struct {
|
|||||||
|
|
||||||
Flavor cardsim.Stored[string]
|
Flavor cardsim.Stored[string]
|
||||||
|
|
||||||
Things int `cardsim:"stat"`
|
Things int `cardsim:"stat" cardsim_name:"A Renamed Thing"`
|
||||||
MoreThings int `cardsim:"hidden"`
|
MoreThings int `cardsim:"hidden"`
|
||||||
FloatyThings float64 `cardsim:"round1"`
|
FloatyThings float64 `cardsim:"round1"`
|
||||||
Label string `cardsim:"stat"`
|
Label string `cardsim:"stat"`
|
||||||
|
Loading…
Reference in New Issue
Block a user