-
Notifications
You must be signed in to change notification settings - Fork 0
/
manifestClass.go
38 lines (31 loc) · 1.03 KB
/
manifestClass.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
package goBungieNet
import (
"fmt"
"errors"
"encoding/json"
)
type DestinyClassDefinition struct {
DisplayProperties DestinyDisplayProperties
Index int32
GenderedClassNames map[string]string
Redacted bool
}
func manifestClassDefinition(languageCode string, hash uint32) (*DestinyClassDefinition, error) {
dataFile := fmt.Sprintf("%s-%s", manifestWorld, languageCode)
db, err := manifestOpenData(dataFile)
if err != nil { return nil, err }
rows, err := db.Query("SELECT json FROM DestinyClassDefinition WHERE id = $1", int32(hash))
if err != nil { return nil, err }
defer rows.Close()
if !rows.Next() { return nil, errors.New("No Results!") }
var jsonData string
err = rows.Scan(&jsonData)
if err != nil { return nil, err }
result := DestinyClassDefinition{}
err = json.Unmarshal([]byte(jsonData), &result)
if err != nil { return nil, err }
return &result, nil
}
func (base *Character)Class(languageCode string) (*DestinyClassDefinition, error) {
return manifestClassDefinition(languageCode, base.ClassHash)
}