206 lines
5.1 KiB
Go
206 lines
5.1 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
)
|
|
|
|
// EveEyeKspace + https://mholt.github.io/json-to-go/
|
|
// NOTE.. don't paste the whole json file in here.. just one region or else the tool won't notice gates
|
|
|
|
type EveEyeKspace struct {
|
|
Maps []struct {
|
|
AvgSec float64 `json:"avgSec"`
|
|
Fid int64 `json:"fid"`
|
|
Gates []struct {
|
|
P int `json:"p"`
|
|
Q int `json:"q"`
|
|
S int `json:"s"`
|
|
T int `json:"t"`
|
|
} `json:"gates"`
|
|
MapID int64 `json:"mapID"`
|
|
MapName string `json:"mapName"`
|
|
MaxSec float64 `json:"maxSec"`
|
|
MinSec float64 `json:"minSec"`
|
|
Npc int64 `json:"npc"`
|
|
Scale float64 `json:"scale"`
|
|
Systems []struct {
|
|
Bnode interface{} `json:"bnode"`
|
|
Cel []int64 `json:"cel"`
|
|
Cfid bool `json:"cfid"`
|
|
Cid int64 `json:"cid"`
|
|
Cn string `json:"cn"`
|
|
D float64 `json:"d"`
|
|
Ext []int64 `json:"ext"`
|
|
Fid int64 `json:"fid"`
|
|
Fw bool `json:"fw"`
|
|
Index int64 `json:"index"`
|
|
Links []int `json:"links"`
|
|
Pi []int64 `json:"pi"`
|
|
Rid int64 `json:"rid"`
|
|
Rn string `json:"rn"`
|
|
Sec float64 `json:"sec"`
|
|
Sid int `json:"sid"`
|
|
Sn string `json:"sn"`
|
|
Snode int64 `json:"snode"`
|
|
Sta int64 `json:"sta"`
|
|
Stasrv []int64 `json:"stasrv"`
|
|
Tnode string `json:"tnode"`
|
|
Vnode int64 `json:"vnode"`
|
|
X float64 `json:"x"`
|
|
Y float64 `json:"y"`
|
|
} `json:"systems"`
|
|
X float64 `json:"x"`
|
|
Y int64 `json:"y"`
|
|
} `json:"maps"`
|
|
}
|
|
|
|
// EveSystem ss
|
|
type EveSystem struct {
|
|
Constellation string `json:"constellation"`
|
|
Links []string `json:"links"`
|
|
Name string `json:"name"`
|
|
Sec float64 `json:"sec"`
|
|
Region string `json:"region"`
|
|
SystemID int `json:"sid"`
|
|
}
|
|
|
|
// we'll record both directions here in-memory
|
|
// then add each dest to System struct in a
|
|
type Jump struct {
|
|
Type string `json:"type"` // gate, bridge
|
|
Source string `json:"source"`
|
|
Target string `json:"target"`
|
|
}
|
|
|
|
func main() {
|
|
// we're gonna read these json files and create something sensible..
|
|
jsonFile, err := os.Open("kspace.json")
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
|
|
byteValue, _ := ioutil.ReadAll(jsonFile)
|
|
var OrigKspace EveEyeKspace
|
|
|
|
json.Unmarshal(byteValue, &OrigKspace)
|
|
|
|
List := CreateSystemList(OrigKspace)
|
|
|
|
err = jsonFile.Close()
|
|
if err != nil {
|
|
fmt.Printf("error closing file")
|
|
}
|
|
|
|
for _, data := range List {
|
|
fmt.Printf("[%v/%v] (const: %v, sec: %v) %v ->", data.Region, data.Name, data.Constellation, data.Sec, data.SystemID)
|
|
for _, link := range data.Links {
|
|
fmt.Printf(" {%v}", link)
|
|
}
|
|
fmt.Printf("\n")
|
|
}
|
|
|
|
}
|
|
|
|
// SidToName returns the system name from a SystemID
|
|
func SidToName(in int, List []EveSystem) string {
|
|
|
|
// if the input number is not one of the 3000XXXX ones, we assume its a shorter one.. add 30,000,000
|
|
// This way the function will work for (EG) "30004764" or 4764
|
|
if in < 10000 {
|
|
in = in + 30000000
|
|
}
|
|
answer := ""
|
|
for _, data := range List {
|
|
if in == data.SystemID {
|
|
answer = data.Name
|
|
|
|
}
|
|
}
|
|
return answer
|
|
}
|
|
|
|
// CreateSystemList creates a slice of EveSystem's
|
|
func CreateSystemList(input EveEyeKspace) []EveSystem {
|
|
// FauxRegion := data.MapName
|
|
|
|
TmpList := []EveSystem{}
|
|
ReturnList := []EveSystem{}
|
|
|
|
// First loop.. just the system IDs and SystemNames
|
|
for _, input := range input.Maps {
|
|
FauxRegion := input.MapName
|
|
|
|
for _, system := range input.Systems {
|
|
|
|
// TODO: learning.. this chained if sucks.. find correct pattern and learn/use it
|
|
// filter only for systems in the regional area of the data/map
|
|
Region := system.Rn
|
|
if Region == FauxRegion {
|
|
// exclude the Jove system
|
|
if Region != "J7HZ-F" {
|
|
// excude this.. no connections whatever it is
|
|
if Region != "A821-A" {
|
|
// and this.. whatever it is
|
|
if Region != "UUA-F4" {
|
|
|
|
// if Region == "Delve" {
|
|
SystemName := system.Sn
|
|
SystemID := system.Sid
|
|
|
|
d := EveSystem{
|
|
Name: SystemName,
|
|
SystemID: SystemID,
|
|
}
|
|
TmpList = append(TmpList, d)
|
|
// }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Now we have a list of system names and ID's we can loop again and change the Links to system names
|
|
for _, input := range input.Maps {
|
|
FauxRegion := input.MapName
|
|
for _, system := range input.Systems {
|
|
Region := system.Rn
|
|
if Region == FauxRegion {
|
|
if Region != "J7HZ-F" {
|
|
if Region != "A821-A" {
|
|
if Region != "UUA-F4" {
|
|
// if Region == "Delve" {
|
|
SystemName := system.Sn
|
|
SystemID := system.Sid
|
|
SystemSec := system.Sec
|
|
Constellation := system.Cn
|
|
linkList := []string{}
|
|
|
|
for _, link := range system.Links {
|
|
linkName := SidToName(link, TmpList)
|
|
linkList = append(linkList, linkName)
|
|
}
|
|
|
|
d := EveSystem{
|
|
Constellation: Constellation,
|
|
Name: SystemName,
|
|
Region: Region,
|
|
SystemID: SystemID,
|
|
Sec: SystemSec,
|
|
Links: linkList,
|
|
}
|
|
ReturnList = append(ReturnList, d)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return ReturnList
|
|
|
|
}
|