206 lines
5.4 KiB
Go
206 lines
5.4 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"`
|
|
}
|
|
|
|
// // EveSystemList asd
|
|
// type EveSystemList struct {
|
|
// Systems []EveSystem `json:"systems"`
|
|
// }
|
|
|
|
// 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)
|
|
|
|
// jsonObjJumps := gabs.New()
|
|
// jsonObjSystems := gabs.New()
|
|
|
|
List := CreateSystemList(OrigKspace)
|
|
|
|
// for _, data := range OrigKspace.Maps {
|
|
// Region := data.MapName
|
|
// if Region == "Delve" {
|
|
// for _, gate := range data.Gates {
|
|
// jsonObjSystems.Set(gate.S, "jumps", fmt.Sprintf("%v-%v", gate.S, gate.T), "s")
|
|
// jsonObjSystems.Set(gate.T, "jumps", fmt.Sprintf("%v-%v", gate.S, gate.T), "t")
|
|
// // jsonObjSystems.Set(gate.T, "jumps", "t")
|
|
// // fmt.Printf("T: %v\n", gate.T)
|
|
// // fmt.Printf("S: %v\n", gate.S)
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
// fmt.Println(jsonObjSystems.String())
|
|
|
|
err = jsonFile.Close()
|
|
if err != nil {
|
|
fmt.Printf("error closing file")
|
|
}
|
|
|
|
for _, data := range List {
|
|
fmt.Printf("[%v/%v] (%v) %v\n", data.Region, data.Name, data.Constellation, data.SystemID)
|
|
}
|
|
|
|
foo := SidToName(30004764, List)
|
|
fmt.Println(foo)
|
|
}
|
|
|
|
// 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
|
|
}
|
|
fmt.Println("in", in)
|
|
answer := ""
|
|
for _, data := range List {
|
|
if in == data.SystemID {
|
|
// fmt.Printf("%v matched to %v\n", in, data.Name)
|
|
answer = data.Name
|
|
// fmt.Printf(len(data.SystemID))
|
|
}
|
|
}
|
|
return answer
|
|
}
|
|
|
|
// CreateSystemList creates a slice of EveSystem's
|
|
func CreateSystemList(input EveEyeKspace) []EveSystem {
|
|
// FauxRegion := data.MapName
|
|
|
|
List := []EveSystem{}
|
|
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
|
|
Constellation := system.Cn
|
|
// SystemSec := system.Sec
|
|
// fmt.Println(SystemName)
|
|
|
|
// fmt.Printf("[%v/%v]: (%v) %v -> ", Region, Constellation, SystemID, SystemName)
|
|
// for _, link := range system.Links {
|
|
// // s := strconv.FormatInt(link, 10) // convert int64 into string
|
|
// // linkID := fmt.Sprint(link)
|
|
// linkName := SidToName(link, List)
|
|
// fmt.Printf(" %v", linkName)
|
|
// }
|
|
fmt.Printf("\n")
|
|
|
|
d := EveSystem{
|
|
Constellation: Constellation,
|
|
Name: SystemName,
|
|
Region: Region,
|
|
SystemID: SystemID,
|
|
}
|
|
List = append(List, d)
|
|
|
|
// jsonObjSystems.Set(SystemID, "systems", SystemName, "id")
|
|
// jsonObjSystems.Set(SystemSec, "systems", SystemName, "sec")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return List
|
|
|
|
}
|