-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsdemap.go
More file actions
93 lines (75 loc) · 2.07 KB
/
Copy pathsdemap.go
File metadata and controls
93 lines (75 loc) · 2.07 KB
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
package sdetools
import (
"github.com/boltdb/bolt"
"github.com/evecentral/sdetools/regions"
"gopkg.in/vmihailenco/msgpack.v2"
"log"
"os"
"path/filepath"
"strings"
)
type Stargate struct {
Destination int `yaml:"destination"`
TypeID int `yaml:"typeID"`
}
type SolarSystem struct {
Id int `yaml:"solarSystemID"`
NameId int `yaml:"solarSystemNameID"`
Name string
Region *regions.Region
Constellation string
Security float64 `yaml:"security"`
Corridor bool `yaml:"corridor"`
Fringe bool `yaml:"fringe"`
Hub bool `yaml:"hub"`
Border bool `yaml:"border"`
International bool `yaml:"international"`
Stargates map[int]Stargate `yaml:"stargates"`
}
func (s *SDE) loadUniverse() {
log.Println("loading universe...")
defer log.Println("done loading universe")
loadFunc := func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
return nil
}
dir, fname := filepath.Split(path)
if fname != "solarsystem.staticdata" {
return nil
}
dirParts := strings.Split(dir, "/")
ssName := dirParts[len(dirParts)-2]
constellation := dirParts[len(dirParts)-3]
regionName := dirParts[len(dirParts)-4]
var solarsystem SolarSystem
err = LoadYamlFile(path, &solarsystem)
if err != nil {
log.Printf("regions load failure %v at path %v", err, path)
return err
}
solarsystem.Name = ssName
solarsystem.Region = regions.Get().ByName(regionName)
solarsystem.Constellation = constellation
s.db.Update(func(tx *bolt.Tx) error {
key := boltKey(solarsystem.Id)
bucket := tx.Bucket([]byte(solarSystemIdsBucket))
data, err := msgpack.Marshal(&solarsystem)
if err != nil {
log.Println("encoding error: %v", err)
return err
}
err = bucket.Put(key, data)
if err != nil {
return err
}
sKey := []byte(solarsystem.Name)
sBucket := tx.Bucket([]byte(solarSystemNamesBucket))
return sBucket.Put(sKey, data)
})
return nil
}
err := filepath.Walk(filepath.Join(s.BaseDir, "fsd/universe/eve"), loadFunc)
if err != nil {
log.Println("file walking error %v", err)
}
}