forked from tmikoss/zkb-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sde2json.js
58 lines (44 loc) · 1.65 KB
/
sde2json.js
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
const yaml = require('js-yaml')
const glob = require('glob')
const fs = require('fs')
const path = require('path')
const COORDINATE_PRECISION_FACTOR = 1_000_000
const COORDINATE_SCALE_FACTOR = 1_000_000_000_000_000 / COORDINATE_PRECISION_FACTOR
const nameFile = fs.readFileSync('./sde/bsd/invNames.yaml', 'utf8')
const nameJson = yaml.safeLoad(nameFile)
let names = nameJson.reduce((lookup, item) => {
const { itemID, itemName } = item
lookup[itemID] = itemName
return lookup
}, {})
const normalize = (n) => Math.round(n / COORDINATE_SCALE_FACTOR) / COORDINATE_PRECISION_FACTOR
let systems = {}
let regions = {}
const regionFileNames = glob.sync('./sde/fsd/universe/eve/*/region.staticdata')
for (const regionFileName of regionFileNames) {
const regionFile = fs.readFileSync(regionFileName, 'utf8')
const regionJson = yaml.safeLoad(regionFile)
const { center: [x, y, z], regionID } = regionJson
regions[regionID] = {
x: normalize(x),
y: normalize(y),
z: normalize(z),
n: names[regionID]
}
const systemFileNames = glob.sync(`${path.dirname(regionFileName)}/**/solarsystem.staticdata`)
for (const systemFileName of systemFileNames) {
const systemFile = fs.readFileSync(systemFileName, 'utf8')
const systemJson = yaml.safeLoad(systemFile)
const { center: [x, y, z], radius, security, solarSystemID } = systemJson
systems[solarSystemID] = {
x: normalize(x),
y: normalize(y),
z: normalize(z),
r: normalize(radius),
s: Math.round(security * 10) / 10,
n: names[solarSystemID],
p: regionID
}
}
}
fs.writeFileSync('./public/data/universe.json', JSON.stringify({ regions, systems }))