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.
49 lines
1.4 KiB
49 lines
1.4 KiB
package entities
|
|
|
|
import "git.aiterp.net/stufflog3/stufflog3/models"
|
|
|
|
type Stat struct {
|
|
ID int `json:"id"`
|
|
ScopeID int `json:"scopeId"`
|
|
Name string `json:"name"`
|
|
Weight float64 `json:"weight"`
|
|
Description string `json:"description"`
|
|
Primary bool `json:"primary"`
|
|
AllowedAmounts []models.StatAllowedAmount `json:"allowedAmounts"`
|
|
}
|
|
|
|
func (stat *Stat) Update(update models.StatUpdate) {
|
|
if update.Name != nil {
|
|
stat.Name = *update.Name
|
|
}
|
|
if update.Weight != nil {
|
|
stat.Weight = *update.Weight
|
|
}
|
|
if update.Primary != nil {
|
|
stat.Primary = *update.Primary
|
|
}
|
|
if update.Description != nil {
|
|
stat.Description = *update.Description
|
|
}
|
|
|
|
stat.AllowedAmounts = append(make([]models.StatAllowedAmount, 0, 8), stat.AllowedAmounts...)
|
|
for _, amount := range update.AllowedAmounts {
|
|
found := false
|
|
for i, existing := range stat.AllowedAmounts {
|
|
if existing.Label == amount.Label {
|
|
if amount.Value <= 0 {
|
|
stat.AllowedAmounts = append(stat.AllowedAmounts[:i], stat.AllowedAmounts[i+1:]...)
|
|
} else {
|
|
stat.AllowedAmounts[i].Value = amount.Value
|
|
}
|
|
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
|
|
if !found && amount.Value > 0 {
|
|
stat.AllowedAmounts = append(stat.AllowedAmounts, amount)
|
|
}
|
|
}
|
|
}
|