-
Notifications
You must be signed in to change notification settings - Fork 0
/
constellation.go
132 lines (115 loc) · 2.17 KB
/
constellation.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
package universe
import (
"database/sql"
"os"
"path/filepath"
"github.com/lflux/eve-sdeloader/utils"
)
type Constellation struct {
ConstellationID int64 `yaml:"constellationID"`
Center []float64
Max []float64
Min []float64
NameID int64 `yaml:"nameID"`
Radius float64
FactionID *int64 `yaml:"factionID"`
WormholeClassID int64 `yaml:"wormholeClassID"`
tx *sql.Tx
path string
region *Region
}
func (r *Region) ImportConstellation(path string) error {
f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()
var c Constellation
err = utils.LoadFromReader(f, &c)
if err != nil {
return err
}
constStmt, err := InsertConstellationsStmt(r.tx)
if err != nil {
return err
}
constellationName, err := getItemNameByID(c.ConstellationID)
if err != nil {
return err
}
denormStmt, err := InsertOrbitalDenormStmt(r.tx)
if err != nil {
return err
}
whClassStmt, err := InsertMapWHClassesStmt(r.tx)
if err != nil {
return err
}
var factionID *int64
if c.FactionID != nil {
factionID = c.FactionID
} else {
factionID = r.FactionID
}
_, err = constStmt.Exec(r.RegionID,
c.ConstellationID,
constellationName,
c.Center[0],
c.Center[1],
c.Center[2],
c.Max[0],
c.Max[1],
c.Max[2],
c.Min[0],
c.Min[1],
c.Min[2],
c.Radius,
factionID,
)
if err != nil {
return err
}
_, err = denormStmt.Exec(
c.ConstellationID,
4,
4,
nil,
nil,
r.RegionID,
nil,
c.Center[0],
c.Center[1],
c.Center[2],
nil,
constellationName,
nil,
nil,
nil,
)
if err != nil {
return err
}
if c.WormholeClassID != 0 {
_, err = whClassStmt.Exec(c.ConstellationID, c.WormholeClassID)
if err != nil {
return err
}
}
c.tx = r.tx
c.path, _ = filepath.Split(path)
c.region = r
return c.ImportSystems()
}
func (r *Region) ImportConstellations() error {
constellations, err := filepath.Glob(filepath.Join(r.path, "*", "constellation.staticdata"))
if err != nil {
return err
}
for _, constellationFile := range constellations {
err = r.ImportConstellation(constellationFile)
if err != nil {
return err
}
}
return nil
}