You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
package models
type StatEntry struct { ID int `json:"id"` Name string `json:"name"` Weight float64 `json:"weight"` }
type StatProgressEntry struct { StatEntry
Acquired int `json:"acquired"` Required int `json:"required"` }
type Stat struct { StatEntry
Description string `json:"description"` AllowedAmounts map[string]int `json:"allowedAmounts"` }
func (stat *Stat) Update(update StatUpdate) { if update.Name != nil { stat.Name = *update.Name } if update.Description != nil { stat.Description = *update.Description } if update.Weight != nil { stat.Weight = *update.Weight } for key, value := range update.AllowedAmounts { if stat.AllowedAmounts == nil { stat.AllowedAmounts = make(map[string]int, len(update.AllowedAmounts)) } if value <= 0 { delete(stat.AllowedAmounts, key) } else { stat.AllowedAmounts[key] = value } } if len(stat.AllowedAmounts) == 0 { stat.AllowedAmounts = nil } }
type StatUpdate struct { Name *string `json:"name"` Description *string `json:"description"` Weight *float64 `json:"weight"` AllowedAmounts map[string]int `json:"allowedAmounts"` }
func (stat *Stat) AllowsAmount(amount int) bool { if stat == nil { return false } if stat.AllowedAmounts == nil || len(stat.AllowedAmounts) == 0 { return true }
for _, v := range stat.AllowedAmounts { if v == amount { return true } }
return false }
|