/
profiles.go
55 lines (47 loc) · 1.19 KB
/
profiles.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package data
import (
"fmt"
"github.com/rs/zerolog/log"
)
type Profile struct {
Source string
Type string
Category string
Melee Melee
Move Move
Missile Missile
FightingStrength FightingStrength `mapstructure:"fighting_strength"`
Resolve int
Toughness int
Traits []string
Points int
}
type Profiler interface {
Name() string
}
func (profile *Profile) Name() string {
return fmt.Sprintf("%s %s", profile.Type, profile.Category)
}
func (profile Profile) WithSource(source string) Profile {
profile.Source = source
return profile
}
func GetProfile(name string, profileList []Profile) (Profile, error) {
log.Trace().Msgf("searching for profile '%s'", name)
for _, profile := range profileList {
if profile.Name() == name {
return profile, nil
}
}
return Profile{}, fmt.Errorf("no profile found that matches name '%s'", name)
}
func GetProfileTraits(profile Profile, traitList []Trait) []Trait {
traits := []Trait{}
for _, traitName := range profile.Traits {
trait := GetTraitByName(traitName, traitList)
if trait.Name != "" {
traits = append(traits, trait)
}
}
return traits
}