-
Notifications
You must be signed in to change notification settings - Fork 2
/
achievements.go
81 lines (74 loc) · 2.24 KB
/
achievements.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"bufio"
"os"
"strconv"
"strings"
)
// Achievement represents the information pertaining to a given Afterbirth+ achievement
type Achievement struct {
Name string
Category int
Description string
Icon string
UnlockedBy string
}
// Global variables to cache information about achievements and their categories.
var allCategories map[int]string
var allAchievements map[int]Achievement
// readAllCategories reads from disk data about all achievement categories and stores the information
// in the global variable `allCategories`.
func readAllCategories() {
allCategories = make(map[int]string)
file, _ := os.Open("data/categories.csv")
defer file.Close()
scanner := bufio.NewScanner(file)
firstLine := true
for scanner.Scan() {
if firstLine {
firstLine = false
continue
}
line := strings.Split(scanner.Text(), ";")
id, _ := strconv.Atoi(line[0])
name := line[1]
allCategories[id] = name
}
}
// readAllAchievements reads from disk data about all achievements and stores the information
// in the global variable `allAchievements`.
func readAllAchievements() {
allAchievements = make(map[int]Achievement)
file, _ := os.Open("data/achievements.csv")
defer file.Close()
scanner := bufio.NewScanner(file)
firstLine := true
for scanner.Scan() {
if firstLine {
firstLine = false
continue
}
line := strings.Split(scanner.Text(), ";")
id, _ := strconv.Atoi(line[0])
category, _ := strconv.Atoi(line[1])
description := line[2]
name := line[3]
icon := line[4]
unlockedBy := line[5]
achievement := Achievement{Name: name, Category: category, Description: description, Icon: icon, UnlockedBy: unlockedBy}
allAchievements[id] = achievement
}
}
// getAchievementByID finds the achievement with a given id (as an integer between 1 and 339)
func getAchievementByID(id int) Achievement {
return allAchievements[id]
}
// categorizeAchievements takes a slice of achievements and puts them in their appropriate categories.
func categorizeAchievements(achievements []Achievement) map[string][]Achievement {
result := make(map[string][]Achievement)
for _, achievement := range achievements {
cat := allCategories[achievement.Category]
result[cat] = append(result[cat], achievement)
}
return result
}