-
Notifications
You must be signed in to change notification settings - Fork 0
/
manifestActivityModifiers.go
48 lines (40 loc) · 1.27 KB
/
manifestActivityModifiers.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
package goBungieNet
import (
"fmt"
"encoding/json"
)
type DestinyActivityModifierDefinition struct {
DisplayProperties DestinyDisplayProperties
Index int32
Redacted bool
}
func (base *DestinyMilestoneActivity)Modifiers(languageCode string) (*[]DestinyActivityModifierDefinition, error) {
dataFile := fmt.Sprintf("%s-%s", manifestWorld, languageCode)
db, err := manifestOpenData(dataFile)
if err != nil { return nil, err }
queryStr := "SELECT json FROM DestinyActivityModifierDefinition WHERE id IN ("
params := make([]interface{}, len(base.ModifierHashes))
for index, value := range(base.ModifierHashes) {
params[index] = int32(value)
if index + 1 < len(base.ModifierHashes) {
queryStr += "?,"
} else {
queryStr += "?"
}
}
queryStr += ")"
rows, err := db.Query(queryStr, params...)
if err != nil { return nil, err }
defer rows.Close()
var jsonData string
modifiers := make([]DestinyActivityModifierDefinition, 0, 5)
for rows.Next() {
err = rows.Scan(&jsonData)
if err != nil { return nil, err }
modifier := DestinyActivityModifierDefinition{}
err = json.Unmarshal([]byte(jsonData), &modifier)
if err != nil { return nil, err }
modifiers = append(modifiers, modifier)
}
return &modifiers, nil
}