Updates and Features
This commit is contained in:
@@ -8,6 +8,8 @@ NMSlib is a GoLang package for dealing with converting Galactic coordinates to P
|
||||
|
||||
NMSlib also translates in game languages (Korvax, Gek Vy'Keen and Atlas) to english, and create portal banners.
|
||||
|
||||
[GoDoc](https://pkg.go.dev/gitlab.com/Raum0x2A/nmslib#section-documentation)
|
||||
|
||||
## Installation
|
||||
|
||||
To install this module use `go get`
|
||||
|
||||
30
convert.go
30
convert.go
@@ -1,3 +1,8 @@
|
||||
/*
|
||||
Xainesworld Video: https://www.youtube.com/watch?v=xmZbkTahw4w
|
||||
Fandom Wiki: https://nomanssky.fandom.com/wiki/Portal_address
|
||||
*/
|
||||
|
||||
package nmslib
|
||||
|
||||
import (
|
||||
@@ -7,18 +12,11 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
/*
|
||||
Xainesworld Video: https://www.youtube.com/watch?v=xmZbkTahw4w
|
||||
Fandom Wiki: https://nomanssky.fandom.com/wiki/Portal_address
|
||||
*/
|
||||
|
||||
/*
|
||||
P2gc - Portal code to galactic coordinates
|
||||
Requires 1 var and returns 1 var string and an error
|
||||
var p string
|
||||
Portal Glyph hex string 12 chars in len (ex. 006afa556c30)
|
||||
Return var string
|
||||
Galactic address (ex. 042F:0079:0D55:006A)
|
||||
var p string: Portal Glyph hex string 12 chars in len (ex. 006afa556c30)
|
||||
Returns var string: Galactic address (ex. 042F:0079:0D55:006A)
|
||||
*/
|
||||
func P2gc(p string) (gc string, err error) {
|
||||
if len(p) == 12 { // Test if length of provided string is 12 chars long
|
||||
@@ -68,12 +66,9 @@ func P2gc(p string) (gc string, err error) {
|
||||
/*
|
||||
Gc2p - Galactic coordinates to portal code
|
||||
Requires 1 string and 1 int returns a string and error
|
||||
var gc string
|
||||
Galactic address (ex. 042F:0079:0D55:006A)
|
||||
var p int
|
||||
Planet ID [1-6]
|
||||
Return portalcode string
|
||||
Portal Glyph hex string 12 chars in len (ex. 006afa556c30)
|
||||
var gc string: Galactic address (ex. 042F:0079:0D55:006A)
|
||||
var p int: Planet ID [1-6]
|
||||
Returns portalcode string: Portal Glyph hex string 12 chars in len (ex. 006afa556c30)
|
||||
*/
|
||||
func Gc2p(gc string, p int) (portalcode string, err error) {
|
||||
// split and store string
|
||||
@@ -114,6 +109,10 @@ func Gc2p(gc string, p int) (portalcode string, err error) {
|
||||
}
|
||||
|
||||
// Apply shifts to Handle the shape/boundaries of the galaxy
|
||||
/*Note:
|
||||
[P][SSS][YY][ZZZ][XXX] len == 12
|
||||
* SSS == SSI
|
||||
*/
|
||||
hexCoords[2] = hexCoords[2] + 0x81 // Y ->> shift
|
||||
hexCoords[3] = hexCoords[3] + 0x801 // Z ->> shift
|
||||
hexCoords[4] = hexCoords[4] + 0x801 // X ->> shift
|
||||
@@ -125,6 +124,7 @@ func Gc2p(gc string, p int) (portalcode string, err error) {
|
||||
}
|
||||
|
||||
// Assemble padded values as a string
|
||||
|
||||
portalcode = fmt.Sprintf("%00X%03X", hexCoords[0], hexCoords[1])
|
||||
for n := 2; n < len(hexCoords); n++ {
|
||||
if n == 2 {
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"image"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/fogleman/gg"
|
||||
@@ -13,10 +12,8 @@ import (
|
||||
|
||||
/*CreateBanner - Output PNG of Portal Glyphs
|
||||
Requires 3 vars and returns 1 err, Outputs a PNG file
|
||||
var portalex string
|
||||
Portal Glyph hex string
|
||||
var savename string
|
||||
Output name of PNG file
|
||||
var portalex string: Portal Glyph hex string
|
||||
var savename string: Output name of PNG file
|
||||
var opt int
|
||||
00 sets horizontal banner in light mode [ 00 || 0 ]
|
||||
01 sets horizontal banner in dark mode [ 01 || 1 ]
|
||||
@@ -31,14 +28,6 @@ func CreateBanner(portalhex string, savename string, opt int) (err error) {
|
||||
var mode string
|
||||
var imgArray [12]image.Image
|
||||
|
||||
// Setup temp dir
|
||||
tempdir, err := ioutil.TempDir("", "nmslib-")
|
||||
if err != nil {
|
||||
return errors.New("can not create temp directory")
|
||||
}
|
||||
// don't forget to clean up afterwords
|
||||
defer os.RemoveAll(tempdir)
|
||||
|
||||
//Set light or dark mode glyphs
|
||||
if opt == 00 || opt == 10 {
|
||||
mode = "light"
|
||||
@@ -71,14 +60,7 @@ func CreateBanner(portalhex string, savename string, opt int) (err error) {
|
||||
if err != nil {
|
||||
return errors.New("can not load images from assets: " + glyphImg[k])
|
||||
}
|
||||
_, err2 := os.Stat(tempdir + "/assets/glyphs/" + mode + "/")
|
||||
if os.IsNotExist(err2) {
|
||||
errDir := os.MkdirAll(tempdir+"/assets/glyphs/"+mode, 0755)
|
||||
if errDir != nil {
|
||||
return errors.New("can not create temp directory")
|
||||
}
|
||||
}
|
||||
err = ioutil.WriteFile(tempdir+"/"+glyphImg[k], []byte(data), 0644)
|
||||
err = ioutil.WriteFile(NmsTemp+"/"+glyphImg[k], []byte(data), 0644)
|
||||
if err != nil {
|
||||
return errors.New("can not write file to temp directory")
|
||||
}
|
||||
@@ -86,7 +68,7 @@ func CreateBanner(portalhex string, savename string, opt int) (err error) {
|
||||
|
||||
//Load/open images needed
|
||||
for iter := 0; iter < 12; iter++ {
|
||||
imgArray[iter], err = gg.LoadPNG(tempdir + "/" + glyphImg[iter])
|
||||
imgArray[iter], err = gg.LoadPNG(NmsTemp + "/" + glyphImg[iter])
|
||||
if err != nil {
|
||||
return errors.New("can not read glyph " + glyphImg[iter])
|
||||
}
|
||||
|
||||
71
init.go
Normal file
71
init.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package nmslib
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
/*NmsTemp - Global string variable
|
||||
Location of instance temporary directory
|
||||
Dir Structure:
|
||||
- NmsTemp
|
||||
-
|
||||
*/
|
||||
var NmsTemp string
|
||||
|
||||
/*Initialize temporary directory
|
||||
create a temp dir and save location to `NmsTemp` string
|
||||
*/
|
||||
func init() {
|
||||
// create temp dir
|
||||
temploc, err := ioutil.TempDir("", "nmslib-")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
NmsTemp = temploc
|
||||
|
||||
//Create directory structure
|
||||
err = os.Mkdir(NmsTemp+"/assets", 0755)
|
||||
if err != nil {
|
||||
panic(errors.New("failed to create temporary folder"))
|
||||
}
|
||||
err = os.Mkdir(NmsTemp+"/assets/lang", 0755)
|
||||
if err != nil {
|
||||
panic(errors.New("failed to create temporary folder"))
|
||||
}
|
||||
err = os.Mkdir(NmsTemp+"/assets/glyphs", 0755)
|
||||
if err != nil {
|
||||
panic(errors.New("failed to create temporary folder"))
|
||||
}
|
||||
err = os.Mkdir(NmsTemp+"/assets/glyphs/dark", 0755)
|
||||
if err != nil {
|
||||
panic(errors.New("failed to create temporary folder"))
|
||||
}
|
||||
err = os.Mkdir(NmsTemp+"/assets/glyphs/light", 0755)
|
||||
if err != nil {
|
||||
panic(errors.New("failed to create temporary folder"))
|
||||
}
|
||||
|
||||
//Write language files to temp directory
|
||||
fileloc := [4]string{"atlas-lang.csv", "gek-lang.csv", "korvax-lang.csv", "vykeen-lang.csv"}
|
||||
for x := 0; x < 4; x++ {
|
||||
data, err := Asset("assets/lang/" + fileloc[x])
|
||||
if err != nil {
|
||||
panic(errors.New("can not load: " + fileloc[x]))
|
||||
}
|
||||
err = ioutil.WriteFile(NmsTemp+"/"+fileloc[x], []byte(data), 0644)
|
||||
if err != nil {
|
||||
panic(errors.New("can not write " + fileloc[x] + " to temp dir"))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*CleanUp removes temporary directory an it's contents
|
||||
this is intended to be called in a defer statement in func main
|
||||
takes no input
|
||||
*/
|
||||
func CleanUp() {
|
||||
os.RemoveAll(NmsTemp)
|
||||
}
|
||||
11
init_test.go
Normal file
11
init_test.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package nmslib
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestInit(t *testing.T) {
|
||||
fmt.Printf("\nTesting init:\n")
|
||||
fmt.Printf("Temporary directory: %s\n\n", NmsTemp)
|
||||
}
|
||||
87
lang.go
87
lang.go
@@ -3,13 +3,29 @@ package nmslib
|
||||
import (
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func readCSV(lagcsv string) [][]string {
|
||||
fileloc := NmsTemp + "/" + lagcsv
|
||||
csvFile, err := os.Open(fileloc)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
defer csvFile.Close() // close language file when finished
|
||||
|
||||
// read csv file from memory
|
||||
csvlines, err := csv.NewReader(csvFile).ReadAll()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return csvlines
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
Translate words
|
||||
Create struct of Word string
|
||||
*/
|
||||
type Translate struct {
|
||||
Word string
|
||||
@@ -27,7 +43,7 @@ type trans0 struct {
|
||||
Kor2Eng translate korvax word to english word
|
||||
*/
|
||||
func (t Translate) Kor2Eng() (returnstring string) {
|
||||
csvlines := openCSV("korvax-lang.csv")
|
||||
csvlines := readCSV("korvax-lang.csv")
|
||||
for range csvlines {
|
||||
returnstring = (toEng(t, csvlines))
|
||||
}
|
||||
@@ -38,7 +54,7 @@ func (t Translate) Kor2Eng() (returnstring string) {
|
||||
Eng2Kor translate english word to korvax word
|
||||
*/
|
||||
func (t Translate) Eng2Kor() (returnstring string) {
|
||||
csvlines := openCSV("korvax-lang.csv")
|
||||
csvlines := readCSV("korvax-lang.csv")
|
||||
for range csvlines {
|
||||
returnstring = (toNMS(t, csvlines))
|
||||
}
|
||||
@@ -49,7 +65,7 @@ func (t Translate) Eng2Kor() (returnstring string) {
|
||||
Gek2Eng translate Gek word to english word
|
||||
*/
|
||||
func (t Translate) Gek2Eng() (returnstring string) {
|
||||
csvlines := openCSV("gek-lang.csv")
|
||||
csvlines := readCSV("gek-lang.csv")
|
||||
for range csvlines {
|
||||
returnstring = (toEng(t, csvlines))
|
||||
}
|
||||
@@ -60,7 +76,7 @@ func (t Translate) Gek2Eng() (returnstring string) {
|
||||
Eng2Gek translate english word to Gek word
|
||||
*/
|
||||
func (t Translate) Eng2Gek() (returnstring string) {
|
||||
csvlines := openCSV("gek-lang.csv")
|
||||
csvlines := readCSV("gek-lang.csv")
|
||||
for range csvlines {
|
||||
returnstring = (toNMS(t, csvlines))
|
||||
}
|
||||
@@ -68,10 +84,10 @@ func (t Translate) Eng2Gek() (returnstring string) {
|
||||
}
|
||||
|
||||
/*
|
||||
Vyk2Eng translate vykeen word to english word
|
||||
Vyk2Eng translate Vy'keen word to english word
|
||||
*/
|
||||
func (t Translate) Vyk2Eng() (returnstring string) {
|
||||
csvlines := openCSV("vykeen-lang.csv")
|
||||
csvlines := readCSV("vykeen-lang.csv")
|
||||
for range csvlines {
|
||||
returnstring = (toEng(t, csvlines))
|
||||
}
|
||||
@@ -82,7 +98,7 @@ func (t Translate) Vyk2Eng() (returnstring string) {
|
||||
Eng2Vyk translate english word to vykeen word
|
||||
*/
|
||||
func (t Translate) Eng2Vyk() (returnstring string) {
|
||||
csvlines := openCSV("vykeen-lang.csv")
|
||||
csvlines := readCSV("vykeen-lang.csv")
|
||||
for range csvlines {
|
||||
returnstring = (toNMS(t, csvlines))
|
||||
}
|
||||
@@ -93,7 +109,7 @@ func (t Translate) Eng2Vyk() (returnstring string) {
|
||||
Atl2Eng translate Atlas word to english word
|
||||
*/
|
||||
func (t Translate) Atl2Eng() (returnstring string) {
|
||||
csvlines := openCSV("atlas-lang.csv")
|
||||
csvlines := readCSV("atlas-lang.csv")
|
||||
for range csvlines {
|
||||
returnstring = (toEng(t, csvlines))
|
||||
}
|
||||
@@ -104,7 +120,7 @@ func (t Translate) Atl2Eng() (returnstring string) {
|
||||
Eng2Atl translate english word to Atlas word
|
||||
*/
|
||||
func (t Translate) Eng2Atl() (returnstring string) {
|
||||
csvlines := openCSV("atlas-lang.csv")
|
||||
csvlines := readCSV("atlas-lang.csv")
|
||||
for range csvlines {
|
||||
returnstring = (toNMS(t, csvlines))
|
||||
}
|
||||
@@ -159,52 +175,3 @@ func toNMS(t Translate, csvlines [][]string) string {
|
||||
}
|
||||
return returnstring
|
||||
}
|
||||
|
||||
/*
|
||||
func openCSV(lagcsv string) [][]string {
|
||||
csvFile, err := os.Open("./assets/lang/" + lagcsv)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
defer csvFile.Close() // close language file when finished
|
||||
|
||||
// read csv file from memory
|
||||
csvlines, err := csv.NewReader(csvFile).ReadAll()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return csvlines
|
||||
*/
|
||||
func openCSV(lagcsv string) [][]string {
|
||||
// create temp dir
|
||||
tempdir, err := ioutil.TempDir("", "nmslib-")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer os.RemoveAll(tempdir) // Clean up temp files
|
||||
|
||||
// extract language file from resources.go
|
||||
data, err := Asset("assets/lang/" + lagcsv)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// wirte extracted data to temp dir
|
||||
err = ioutil.WriteFile(tempdir+"/"+lagcsv, []byte(data), 0644)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
csvFile, err := os.Open(tempdir + "/" + lagcsv)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
defer csvFile.Close() // close language file when finished
|
||||
|
||||
// read csv file from memory
|
||||
csvlines, err := csv.NewReader(csvFile).ReadAll()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return csvlines
|
||||
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ func TestGalactic2portal(t *testing.T) {
|
||||
fmt.Println(err)
|
||||
}
|
||||
if want != "21F2F8EDB94D" {
|
||||
t.Errorf("\nTesting Gc2p(\"014C:0077:06DA:01F2\"): got %q, want: 21F2F8EDB94D.\n", want)
|
||||
t.Errorf("Testing Gc2p(\"014C:0077:06DA:01F2\"): got %q, want: 21F2F8EDB94D.\n", want)
|
||||
} else {
|
||||
fmt.Printf("\nTesting Gc2p(\"014C:0077:06DA:01F2\"): got: %q, want: 21F2F8EDB94D.\n", want)
|
||||
fmt.Printf("Testing Gc2p(\"014C:0077:06DA:01F2\"): got: %q, want: 21F2F8EDB94D.\n", want)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,3 +9,13 @@ func TestRndPortal(t *testing.T) {
|
||||
fmt.Printf("\nRandom Portal Code: ")
|
||||
fmt.Println(RndPortal())
|
||||
}
|
||||
|
||||
func TestRndAtlas(t *testing.T) {
|
||||
fmt.Printf("semi-Random Atlas Code: ")
|
||||
fmt.Println(RndAtlas())
|
||||
}
|
||||
|
||||
func TestRndBH(t *testing.T) {
|
||||
fmt.Printf("semi-Random black hole Code: ")
|
||||
fmt.Println(RndBH())
|
||||
}
|
||||
|
||||
@@ -32,4 +32,6 @@ func TestTranslate(t *testing.T) {
|
||||
fmt.Printf("Testing Translate{\"Alinichel\"}.Kor2Eng(): got %q, want: %q.\n", want.Kor2Eng(), "Emergency")
|
||||
}
|
||||
fmt.Printf("\nTesting complete.\nStatus: ")
|
||||
|
||||
CleanUp()
|
||||
}
|
||||
|
||||
49
rpcg.go
49
rpcg.go
@@ -25,8 +25,7 @@ import (
|
||||
|
||||
/*
|
||||
RndPortal - Random Portalcode generator
|
||||
Requires no input required
|
||||
Returns a string
|
||||
Requires no input required and returns a string
|
||||
*/
|
||||
|
||||
func RndPortal() (final string) {
|
||||
@@ -45,3 +44,49 @@ func RndPortal() (final string) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
/*RndAtlas genorates a semi-random atlas code
|
||||
Requires no input and returns a string
|
||||
|
||||
This is not a true random atlas genorator. Insted this will create a Planet id of 1, Solar System Index of 0x07A and random Y, Z, X
|
||||
SSI 0x07A always has an Atlas Interface.
|
||||
|
||||
REF: https://nomanssky.fandom.com/wiki/Portal_address#Solar_System_Index https://nomanssky.fandom.com/wiki/Star_system#Classification
|
||||
*/
|
||||
func RndAtlas() (final string) {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
min := 0x1
|
||||
ymax := 0xFF
|
||||
xzmax := 0xFFF
|
||||
|
||||
x := rand.Intn(xzmax-min+1) + min
|
||||
z := rand.Intn(xzmax-min+1) + min
|
||||
y := rand.Intn(ymax-min+1) + min
|
||||
|
||||
final = fmt.Sprintf("%00X%03X%02X%03X%03X", 1, 0x07A, y, z, x)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
/*RndBH genorates a semi-random atlas code
|
||||
Requires no input required and returns a string
|
||||
|
||||
This is not a true random atlas genorator. Insted this will create a Planet id of 1, Solar System Index of 0x079 and random Y, Z, X
|
||||
SSI 0x079 always has a black hole.
|
||||
|
||||
REF: https://nomanssky.fandom.com/wiki/Portal_address#Solar_System_Index https://nomanssky.fandom.com/wiki/Star_system#Classification
|
||||
*/
|
||||
func RndBH() (final string) {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
min := 0x1
|
||||
ymax := 0xFF
|
||||
xzmax := 0xFFF
|
||||
|
||||
x := rand.Intn(xzmax-min+1) + min
|
||||
z := rand.Intn(xzmax-min+1) + min
|
||||
y := rand.Intn(ymax-min+1) + min
|
||||
|
||||
final = fmt.Sprintf("%00X%03X%02X%03X%03X", 1, 0x079, y, z, x)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user