-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
tools.go
136 lines (108 loc) · 2.81 KB
/
tools.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//go:build tools
package main
import (
"compress/gzip"
"encoding/json"
"os"
"github.com/Vilsol/timeless-jewels/calculator"
"github.com/Vilsol/timeless-jewels/data"
"github.com/Vilsol/timeless-jewels/wasm/exposition"
)
// Uses separate steps so finder step has the new data loaded by data package
//go:generate go run tools.go find
//go:generate go run tools.go types
func main() {
if len(os.Args) < 2 {
return
}
switch os.Args[1] {
case "find":
findAll()
case "types":
generateTypes()
}
}
func writeZipped(path string, data interface{}) {
b, err := json.Marshal(data)
if err != nil {
panic(err)
}
out, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0777)
if err != nil {
panic(err)
}
writer := gzip.NewWriter(out)
if _, err := writer.Write(b); err != nil {
panic(err)
}
if err := writer.Close(); err != nil {
panic(err)
}
}
func findAll() {
foundStats := make(map[data.JewelType]map[uint32]int)
applicable := data.GetApplicablePassives()
for jewelType := range data.TimelessJewelConquerors {
foundStats[jewelType] = make(map[uint32]int)
var firstConqueror data.Conqueror
for conqueror := range data.TimelessJewelConquerors[jewelType] {
firstConqueror = conqueror
break
}
println(jewelType.String())
min := data.TimelessJewelSeedRanges[jewelType].Min
max := data.TimelessJewelSeedRanges[jewelType].Max
if data.TimelessJewelSeedRanges[jewelType].Special {
min /= 20
max /= 20
}
for seed := min; seed <= max; seed++ {
realSeed := seed
if data.TimelessJewelSeedRanges[jewelType].Special {
realSeed *= 20
}
if realSeed%500 == 0 {
println(realSeed)
}
for _, skill := range applicable {
if skill.IsKeystone {
continue
}
results := calculator.Calculate(skill.Index, realSeed, jewelType, firstConqueror)
if results.AlternatePassiveSkill != nil {
for _, key := range results.AlternatePassiveSkill.StatsKeys {
foundStats[jewelType][key]++
}
}
for _, info := range results.AlternatePassiveAdditionInformations {
if info.AlternatePassiveAddition != nil {
for _, key := range info.AlternatePassiveAddition.StatsKeys {
foundStats[jewelType][key]++
}
}
}
}
}
}
writeZipped("./data/possible_stats.json.gz", foundStats)
}
func generateTypes() {
e := exposition.Expose()
tsFile, jsFile, err := e.Build()
if err != nil {
panic(err)
}
tsFile = "/* eslint-disable */\n" + tsFile
jsFile = "/* eslint-disable */\n" + jsFile
if err := os.MkdirAll("./frontend/src/lib/types", 0777); err != nil {
if !os.IsExist(err) {
panic(err)
}
}
if err := os.WriteFile("./frontend/src/lib/types/index.js", []byte(jsFile), 0777); err != nil {
panic(err)
}
if err := os.WriteFile("./frontend/src/lib/types/index.d.ts", []byte(tsFile), 0777); err != nil {
panic(err)
}
}