-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.go
42 lines (37 loc) · 861 Bytes
/
player.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
package main
import (
"gopkg.in/yaml.v3"
"os"
)
type Player struct {
Name string `yaml:"name"`
Theme string `yaml:"theme"`
Mode string `yaml:"defaultMode"`
Learning bool `yaml:"defaultLearning"`
Difficulty string `yaml:"defaultDifficulty"`
Highscore int `yaml:"highscore"`
XP int `yaml:"xp"`
}
func (p *Player) make() *Player {
p.Name = ""
p.Theme = "default"
p.Mode = ""
p.Learning = false
p.Difficulty = ""
p.Highscore = 0
p.XP = 0
return p
}
func (p *Player) load(filename string) *Player {
file, err := os.ReadFile(filename)
handle(err, "os.ReadFile")
err = yaml.Unmarshal(file, p)
handle(err, "yaml.Unmarshal")
return p
}
func (p *Player) write(filename string) {
data, err := yaml.Marshal(p)
handle(err, "yaml.Marshal")
err = os.WriteFile(filename, data, 0666)
handle(err, "WriteFile")
}