Merge branch 'portalbanner-resize' into 'develop'

Moved from gim to gg for image creation

See merge request Raum0x2A/nmslib!2
This commit was merged in pull request #3.
This commit is contained in:
Raum0x2A
2021-05-18 04:57:05 +00:00
17 changed files with 236 additions and 187 deletions

4
.gitignore vendored
View File

@@ -1 +1,5 @@
assets/ assets/
.vscode/
notes.txt
Test.png
test.png

View File

@@ -6,4 +6,5 @@ test:
image: golang:1.16.3 image: golang:1.16.3
script: script:
- go test - go test
except:
- portalbanner-resize

BIN
NMH-BlueDream.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 307 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 228 KiB

View File

@@ -31,17 +31,19 @@ import (
) )
func main() { func main() {
portalcode := nmslib.RndPortal() portalcode := "21F2F8EDB94D"
galaticAddress, _ := nmslib.P2gc(portalcode) galacticCoords, err := nmslib.P2gc(portalcode)
fmt.Printf("Random portal code: %s\n", portalcode) if err != nil {
panic(err)
}
fmt.Printf("Input:\t%s\nOutput:\t%s\n", portalcode, galacticCoords)
fmt.Printf("%s >> %s\n", portalcode, galaticAddress) nmslib.CreateBanner(portalcode, "./NMH-BlueDream.png", 0)
nmslib.CreateBanner(portalcode, "./banners/"+portalcode+".png", 10) nmslib.CreateBanner(RndPortal(), "./Random.png", 0)
fmt.Printf("saving image to ./banners/%s.png\n", portalcode)
fmt.Println("Translating \"KIHTYOMOLES\" from Korvax To English: " + nmslib.Translate{Word: "KIHTYOMOLES"}.Kor2Eng()) fmt.Println(nmslib.Translate{Word: "KIHTYOMOLES"}.Kor2Eng())
korvax := nmslib.Translate{Word: "Contraband"} korvax := nmslib.Translate{Word: "Contraband"}
fmt.Println("Translating \"Contraband\" from English to Korvax: " + korvax.Eng2Kor()) fmt.Println(korvax.Eng2Kor())
} }
@@ -62,13 +64,13 @@ This function takes 3 parameters:
**Example:** **Example:**
Horizontal Layout for Galactic Hub [HUB10-6A Icarus Sun](https://nomanssky.gamepedia.com/HUB10-6A_Icarus_Sun) Eniwa 68/L3 Horizontal Layout for the NMH Capital planet [Blue Dream (aka Omins XI)](https://nomanssky.fandom.com/wiki/Omins_XI) in the [Notric-Lis XIII](https://nomanssky.fandom.com/wiki/Notric-Lis_XIII) system in the [Lahanhar Conflux](https://nomanssky.fandom.com/wiki/Lahanhar_Conflux) region
```golang ```golang
nmslib.CreateBanner("006AFA556C30", "NewLennon.png", 0) nmslib.CreateBanner("21F2F8EDB94D", "NMH-BlueDream.png", 0)
``` ```
![](NewLennon.png) ![](NMH-BlueDream.png)
Vertical layout for a random address Vertical layout for a random address
@@ -93,7 +95,7 @@ This function only takes 1 parameter and returns a string and error
**Example:** **Example:**
```golang ```golang
ga, _ := nmslib.P3gc("21F2F8EDB94D") ga, _ := nmslib.P2gc("21F2F8EDB94D")
fmt.Println(ga) fmt.Println(ga)
``` ```
@@ -103,14 +105,15 @@ Output:
### Converting Galactic coordinates to Portal codes with Gc2p() ### Converting Galactic coordinates to Portal codes with Gc2p()
This function only takes 1 parameter and returns a string and error This function only takes 2 parameters and returns a string and error
* galacticaddress: 16 char 4 block hex address * galacticaddress: 16 char 4 block hex address
* Planet ID [1-6]
**Example:** **Example:**
```golang ```golang
pc, _ := nmslib.P3gc("014C:0077:06DA:01F2") pc, _ := nmslib.Gc2p("014C:0077:06DA:01F2", 2)
fmt.Println(pc) fmt.Println(pc)
``` ```

View File

@@ -55,7 +55,7 @@ import (
func bindataRead(data []byte, name string) ([]byte, error) { func bindataRead(data []byte, name string) ([]byte, error) {
gz, err := gzip.NewReader(bytes.NewBuffer(data)) gz, err := gzip.NewReader(bytes.NewBuffer(data))
if err != nil { if err != nil {
return nil, fmt.Errorf("Read %q: %v", name, err) return nil, fmt.Errorf("read %q: %v", name, err)
} }
var buf bytes.Buffer var buf bytes.Buffer
@@ -63,7 +63,7 @@ func bindataRead(data []byte, name string) ([]byte, error) {
clErr := gz.Close() clErr := gz.Close()
if err != nil { if err != nil {
return nil, fmt.Errorf("Read %q: %v", name, err) return nil, fmt.Errorf("read %q: %v", name, err)
} }
if clErr != nil { if clErr != nil {
return nil, err return nil, err

View File

@@ -14,7 +14,7 @@ import (
/* /*
P2gc - Portal code to galactic coordinates P2gc - Portal code to galactic coordinates
Requires 1 var and returns 1 var string Requires 1 var and returns 1 var string and an error
var p string var p string
Portal Glyph hex string 12 chars in len (ex. 006afa556c30) Portal Glyph hex string 12 chars in len (ex. 006afa556c30)
Return var string Return var string
@@ -27,19 +27,19 @@ func P2gc(p string) (gc string, err error) {
var coord [4]int64 var coord [4]int64
coord[1], err = strconv.ParseInt(p[4:6], 16, 16) // Y coordinate coord[1], err = strconv.ParseInt(p[4:6], 16, 16) // Y coordinate
if err != nil { if err != nil {
panic(err) return "", errors.New("error parsing intergers from string: [4:6]")
} }
coord[2], err = strconv.ParseInt(p[6:9], 16, 16) // Z cooridnate coord[2], err = strconv.ParseInt(p[6:9], 16, 16) // Z cooridnate
if err != nil { if err != nil {
panic(err) return "", errors.New("error parsing intergers from string: [6:9]")
} }
coord[3], err = strconv.ParseInt(p[9:12], 16, 16) // X coordinate coord[3], err = strconv.ParseInt(p[9:12], 16, 16) // X coordinate
if err != nil { if err != nil {
panic(err) return "", errors.New("error parsing intergers from string: [9:12]")
} }
coord[0], err = strconv.ParseInt(p[1:4], 16, 16) // SSI (Star System Identifier) coord[0], err = strconv.ParseInt(p[1:4], 16, 16) // SSI (Star System Identifier)
if err != nil { if err != nil {
panic(err) return "", errors.New("error parsing intergers from string: [1:4]")
} }
// apply shifts to Handle the shape/boundaries of the galaxy // apply shifts to Handle the shape/boundaries of the galaxy
@@ -72,13 +72,16 @@ Requires 1 string and 1 int returns a string and error
Galactic address (ex. 042F:0079:0D55:006A) Galactic address (ex. 042F:0079:0D55:006A)
var p int var p int
Planet ID [1-6] Planet ID [1-6]
Return var string Return portalcode string
Portal Glyph hex string 12 chars in len (ex. 006afa556c30) Portal Glyph hex string 12 chars in len (ex. 006afa556c30)
*/ */
func Gc2p(gc string, p int) (portalcode string, err error) { func Gc2p(gc string, p int) (portalcode string, err error) {
// split and store string // split and store string
// coords[0] == X; coords[1] == Y coords[2] == Z; // coords[0] == X; coords[1] == Y coords[2] == Z;
// coords[3] == SSI coords[4] == P // coords[3] == SSI coords[4] == P
if len(gc) != 19 {
return "", errors.New("galatic code is the wrong length")
}
if p > 6 { if p > 6 {
p = 1 p = 1
} }
@@ -91,23 +94,23 @@ func Gc2p(gc string, p int) (portalcode string, err error) {
var hexCoords [5]int64 var hexCoords [5]int64
hexCoords[0], err = strconv.ParseInt(coords[4], 16, 16) // P hexCoords[0], err = strconv.ParseInt(coords[4], 16, 16) // P
if err != nil { if err != nil {
panic(err) return "", errors.New("error parsing intergers from string: [4]")
} }
hexCoords[1], err = strconv.ParseInt(coords[3], 16, 16) // SSI hexCoords[1], err = strconv.ParseInt(coords[3], 16, 16) // SSI
if err != nil { if err != nil {
panic(err) return "", errors.New("error parsing intergers from string: [3]")
} }
hexCoords[2], err = strconv.ParseInt(coords[1], 16, 16) // Y hexCoords[2], err = strconv.ParseInt(coords[1], 16, 16) // Y
if err != nil { if err != nil {
panic(err) return "", errors.New("error parsing intergers from string: [1]")
} }
hexCoords[3], err = strconv.ParseInt(coords[2], 16, 16) // Z hexCoords[3], err = strconv.ParseInt(coords[2], 16, 16) // Z
if err != nil { if err != nil {
panic(err) return "", errors.New("error parsing intergers from string: [2]")
} }
hexCoords[4], err = strconv.ParseInt(coords[0], 16, 16) // X hexCoords[4], err = strconv.ParseInt(coords[0], 16, 16) // X
if err != nil { if err != nil {
panic(err) return "", errors.New("error parsing intergers from string: [0]")
} }
// Apply shifts to Handle the shape/boundaries of the galaxy // Apply shifts to Handle the shape/boundaries of the galaxy
@@ -130,5 +133,5 @@ func Gc2p(gc string, p int) (portalcode string, err error) {
portalcode = portalcode + fmt.Sprintf("%03X", hexCoords[n]) portalcode = portalcode + fmt.Sprintf("%03X", hexCoords[n])
} }
} }
return portalcode, err // return formated string and error return // return formated string and error
} }

View File

@@ -1,110 +1,123 @@
package nmslib package nmslib
import ( import (
"errors"
"fmt" "fmt"
"image/png" "image"
"io/ioutil" "io/ioutil"
"os" "os"
"strconv" "strconv"
gim "github.com/ozankasikci/go-image-merge" "github.com/fogleman/gg"
) )
/*CreateBanner - Output PNG of Portal Glyphs /*CreateBanner - Output PNG of Portal Glyphs
Requires 3 vars and returns 0 var, Outputs a PNG file Requires 3 vars and returns 1 err, Outputs a PNG file
var portalex string var portalex string
Portal Glyph hex string Portal Glyph hex string
var savename string var savename string
Output name of PNG file Output name of PNG file
var opt int var opt int
00 sets horizontal banner in light mode 00 sets horizontal banner in light mode [ 00 || 0 ]
01 sets horizontal banner in dark mode [ 01 || 1 ]
10 sets vertical banner in light mode 10 sets vertical banner in light mode
01 sets horizontal banner in dark mode
11 sets vertical banner in dark mode 11 sets vertical banner in dark mode
* note first of the 2 bits sets the layout, the second bit sets the glyph color
*/ */
func CreateBanner(portalhex string, savename string, opt int) { func CreateBanner(portalhex string, savename string, opt int) (err error) {
var err error
var GlyphHex [12]int64 var GlyphHex [12]int64
var glyphImg [12]string var glyphImg [12]string
var mode string var mode string
var vert int var imgArray [12]image.Image
var horz int
// Setup temp dir // Setup temp dir
tempdir, err := ioutil.TempDir("", "nmslib-") tempdir, err := ioutil.TempDir("", "nmslib-")
if err != nil { if err != nil {
panic(err) 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"
} else if opt == 01 || opt == 11 {
mode = "dark"
} else {
// if opt is an invalid option (ie. not a 2 bit binary number default to classic mode/layout
opt = 0
mode = "light"
} }
//defer os.RemoveAll(tempdir)
// verify len of portalhex // verify len of portalhex
if len(portalhex) == 12 { if len(portalhex) == 12 {
// get hex value from each digit in given string to an array of int64 // get hex value from each digit in given string and add it to an array of int64
for i := 0; i < len(portalhex); i++ { for i := 0; i < len(portalhex); i++ {
GlyphHex[i], err = strconv.ParseInt(portalhex[i:int(i+1)], 16, 16) GlyphHex[i], err = strconv.ParseInt(portalhex[i:int(i+1)], 16, 16)
if err != nil { if err != nil {
panic(err) return errors.New("string provided is not hexadecimal ([0-9][A-F])")
} }
} }
// set options // assign image location of its glyph-hex value to an array of strings
if opt == 00 { // set vertical rendering in light mode
vert, horz = 12, 1
mode = "light"
} else if opt == 01 { // set vertival in dark mode
vert, horz = 12, 1
mode = "dark"
} else if opt == 11 { // set horizontal rendering in dark mode
vert, horz = 1, 12
mode = "dark"
} else { // set horizontal rendering in light mode (classic/default)
vert, horz = 1, 12
mode = "light"
}
// assign image location of its glyph hex value to an array of strings
for j := 0; j < len(glyphImg); j++ { for j := 0; j < len(glyphImg); j++ {
glyphImg[j] = fmt.Sprintf("assets/glyphs/%s/PORTALSYMBOL.%X.png", mode, GlyphHex[j]) glyphImg[j] = fmt.Sprintf("assets/glyphs/%s/PORTALSYMBOL.%X.png", mode, GlyphHex[j])
} }
// pull images need from glyph.go and saved them to ./glyphs/
// pull images need from assets.go and saved them to the temp directory
for k := 0; k < len(glyphImg); k++ { for k := 0; k < len(glyphImg); k++ {
data, err := Asset(glyphImg[k]) data, err := Asset(glyphImg[k])
if err != nil { if err != nil {
panic(err) return errors.New("can not load images from assets: " + glyphImg[k])
} }
_, err2 := os.Stat(tempdir + "/assets/glyphs/" + mode + "/") _, err2 := os.Stat(tempdir + "/assets/glyphs/" + mode + "/")
if os.IsNotExist(err2) { if os.IsNotExist(err2) {
errDir := os.MkdirAll(tempdir+"/assets/glyphs/"+mode, 0755) errDir := os.MkdirAll(tempdir+"/assets/glyphs/"+mode, 0755)
if errDir != nil { if errDir != nil {
panic(errDir) return errors.New("can not create temp directory")
} }
} }
// fmt.Println(tempdir + "/" + glyphImg[k]) // for debugging only
err = ioutil.WriteFile(tempdir+"/"+glyphImg[k], []byte(data), 0644) err = ioutil.WriteFile(tempdir+"/"+glyphImg[k], []byte(data), 0644)
}
// load images for processing using github.com/ozankasikci/go-image-merge
grids := []*gim.Grid{
{ImageFilePath: tempdir + "/" + glyphImg[0]}, {ImageFilePath: tempdir + "/" + glyphImg[1]},
{ImageFilePath: tempdir + "/" + glyphImg[2]}, {ImageFilePath: tempdir + "/" + glyphImg[3]},
{ImageFilePath: tempdir + "/" + glyphImg[4]}, {ImageFilePath: tempdir + "/" + glyphImg[5]},
{ImageFilePath: tempdir + "/" + glyphImg[6]}, {ImageFilePath: tempdir + "/" + glyphImg[7]},
{ImageFilePath: tempdir + "/" + glyphImg[8]}, {ImageFilePath: tempdir + "/" + glyphImg[9]},
{ImageFilePath: tempdir + "/" + glyphImg[10]}, {ImageFilePath: tempdir + "/" + glyphImg[11]},
}
// create new image from grids
rgba, err := gim.New(grids, vert, horz).Merge()
if err != nil { if err != nil {
panic(err) return errors.New("can not write file to temp directory")
}
} }
// save the output to png //Load/open images needed
file, err := os.Create(savename) for iter := 0; iter < 12; iter++ {
err = png.Encode(file, rgba) imgArray[iter], err = gg.LoadPNG(tempdir + "/" + glyphImg[iter])
if err != nil { if err != nil {
fmt.Println(err) return errors.New("can not read glyph " + glyphImg[iter])
} }
} }
//begin concatenating images
// get image size of first glyph, all glyphs have the same X && Y dimension so we only need to measure one.
imgDim := imgArray[0].Bounds().Size()
//classic horizontal layout
if opt == 01 || opt == 00 {
imgWidth := imgDim.X * 12
imgHeight := imgDim.Y
concat := gg.NewContext(imgWidth, imgHeight)
for a := 0; a < 12; a++ {
concat.DrawImage(imgArray[a], imgDim.X*a, 0)
}
concat.SavePNG(savename)
}
//Vertical layout
if opt == 10 || opt == 11 {
imgWidth := imgDim.X
imgHeight := imgDim.Y * 12
concat := gg.NewContext(imgWidth, imgHeight)
for a := 0; a < 12; a++ {
concat.DrawImage(imgArray[a], 0, imgDim.Y*a)
}
concat.SavePNG(savename)
}
} else {
return errors.New("portalcode must be exactly 12 chars")
}
return
} }

8
go.mod
View File

@@ -1,5 +1,9 @@
module gitlab.com/Raum0x2A/nmslib module gitlab.com/Raum0x2A/nmslib
go 1.15 go 1.16
require github.com/ozankasikci/go-image-merge v0.2.2 require (
github.com/fogleman/gg v1.3.0
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
golang.org/x/image v0.0.0-20210504121937-7319ad40d33e // indirect
)

9
go.sum
View File

@@ -1,2 +1,7 @@
github.com/ozankasikci/go-image-merge v0.2.2 h1:K370BLLTIsamwjAeViiPntf7GiG3h9pXzDmxXCbN8/0= github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=
github.com/ozankasikci/go-image-merge v0.2.2/go.mod h1:NQ2aN0b21buFx3p+5x4dZrKuPSLh2uBukK7F30BrYTo= github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
golang.org/x/image v0.0.0-20210504121937-7319ad40d33e h1:PzJMNfFQx+QO9hrC1GwZ4BoPGeNGhfeQEgcQFArEjPk=
golang.org/x/image v0.0.0-20210504121937-7319ad40d33e/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

View File

@@ -191,6 +191,9 @@ func openCSV(lagcsv string) [][]string {
// wirte extracted data to temp dir // wirte extracted data to temp dir
err = ioutil.WriteFile(tempdir+"/"+lagcsv, []byte(data), 0644) err = ioutil.WriteFile(tempdir+"/"+lagcsv, []byte(data), 0644)
if err != nil {
fmt.Println(err)
}
csvFile, err := os.Open(tempdir + "/" + lagcsv) csvFile, err := os.Open(tempdir + "/" + lagcsv)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)

30
nmslib-convert_test.go Normal file
View File

@@ -0,0 +1,30 @@
package nmslib
import (
"fmt"
"testing"
)
func TestPortal2Galactic(t *testing.T) {
want, err := P2gc("21F2F8EDB94D")
if err != nil {
fmt.Println(err)
}
if want != "014C:0077:06DA:01F2" {
t.Errorf("Testing P2gc(\"21F2F8EDB94D\"): got %q, want: 014C:0077:06DA:01F2.\n", want)
} else {
fmt.Printf("Testing P2gc(\"21F2F8EDB94D\"): got: %q, want: 014C:0077:06DA:01F2.\n", want)
}
}
func TestGalactic2portal(t *testing.T) {
want, err := Gc2p("014C:0077:06DA:01F2", 2)
if err != nil {
fmt.Println(err)
}
if want != "21F2F8EDB94D" {
t.Errorf("\nTesting 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)
}
}

View File

@@ -0,0 +1,21 @@
package nmslib
import (
"fmt"
"testing"
)
func TestCreateBanner(t *testing.T) {
fmt.Printf("\nTesting CreateBanner: ")
rp := "21F2F8EDB94D"
//rp := RndPortal()
fileout := "./test.png"
err := CreateBanner(rp, fileout, 0)
if err != nil {
fmt.Println(err)
}
fmt.Printf("Portal address `%s` rendered as `%s`\n", rp, fileout)
}

11
nmslib-rpcg_test.go Normal file
View File

@@ -0,0 +1,11 @@
package nmslib
import (
"fmt"
"testing"
)
func TestRndPortal(t *testing.T) {
fmt.Printf("\nRandom Portal Code: ")
fmt.Println(RndPortal())
}

35
nmslib-translate_test.go Normal file
View File

@@ -0,0 +1,35 @@
package nmslib
import (
"fmt"
"testing"
)
func TestTranslate(t *testing.T) {
want := Translate{"Paka"}
if want.Atl2Eng() != "Awake" {
t.Errorf("\nTesting Translate{\"Paka\"}.Atl2Eng(): got %q, want: %q.\n", want.Atl2Eng(), "Awake")
} else {
fmt.Printf("\nTesting Translate{\"Paka\"}.Atl2Eng(): got %q, want: %q.\n", want.Atl2Eng(), "Awake")
}
want = Translate{"hofsos"}
if want.Gek2Eng() != "answer" {
t.Errorf("Testing Translate{\"hofsos\"}.Gek2Eng(): got %q, want: %q.\n", want.Gek2Eng(), "answer")
} else {
fmt.Printf("Testing Translate{\"hofsos\"}.Gek2Eng(): got %q, want: %q.\n", want.Gek2Eng(), "answer")
}
want = Translate{"Aqo"}
if want.Vyk2Eng() != "Foes" {
t.Errorf("Testing Translate{\"Aqo\"}.Vyk2Eng(): got %q, want: %q.\n", want.Vyk2Eng(), "Foes")
} else {
fmt.Printf("Testing Translate{\"Aqo\"}.Vyk2Eng(): got %q, want: %q.\n", want.Vyk2Eng(), "Foes")
}
want = Translate{"Alinichel"}
if want.Kor2Eng() != "Emergency" {
t.Errorf("Testing Translate{\"Alinichel\"}.Kor2Eng(): got %q, want: %q.\n", want.Kor2Eng(), "Emergency")
} else {
fmt.Printf("Testing Translate{\"Alinichel\"}.Kor2Eng(): got %q, want: %q.\n", want.Kor2Eng(), "Emergency")
}
fmt.Printf("\nTesting complete.\nStatus: ")
}

View File

@@ -1,90 +0,0 @@
package nmslib
import (
"fmt"
"testing"
)
func TestRndPortal(t *testing.T) {
fmt.Printf("\nRandom Portal Code: ")
fmt.Println(RndPortal())
}
func TestCreateBanner(t *testing.T) {
fmt.Printf("\nTesting CreateBanner: ")
CreateBanner(RndPortal(), "/tmp/Test.png", 11)
fmt.Printf("Random Portal address rendered as `/tmp/Test.png`\n\n")
}
func TestPortal2Galactic(t *testing.T) {
want, err := P2gc("006afa556c30")
if err != nil {
panic(err)
}
if want != "042F:0079:0D55:006A" {
t.Errorf("Testing P2gc(\"006afa556c30\"): got %q, want: %q.\n", want, "042F:0079:0D55:006A")
} else {
fmt.Printf("Testing P2gc(\"006afa556c30\"): got: %q, want: %q.\n", want, "042F:0079:0D55:006A")
}
want, err = P2gc("41EDF9554C2F")
if err != nil {
panic(err)
}
if want != "042E:0078:0D53:01ED" {
t.Errorf("Testing P2gc(\"41EDF9554C2F\"): got %q, want: %q.\n", want, "042E:0078:0D53:01ED")
} else {
fmt.Printf("Testing P2gc(\"41EDF9554C2F\"): got: %q, want: %q.\n", want, "042E:0078:0D53:01ED")
}
}
func TestGalactic2portal(t *testing.T) {
want, err := Gc2p("042F:0079:0D55:006A", 1)
if err != nil {
panic(err)
}
if want != "106AFA556C30" {
t.Errorf("\nTesting Gc2p(\"042F:0079:0D55:006A\"): got %q, want: %q.\n", want, "106AFA556C30")
} else {
fmt.Printf("\nTesting Gc2p(\"042F:0079:0D55:006A\"): got: %q, want: %q.\n", want, "106AFA556C30")
}
want, err = Gc2p("042E:0078:0D53:01ED", 4)
if err != nil {
panic(err)
}
if want != "41EDF9554C2F" {
t.Errorf("Testing Gc2p(\"042E:0078:0D53:01ED\"): got %q, want: %q.\n", want, "41EDF9554C2F")
} else {
fmt.Printf("Testing Gc2p(\"042E:0078:0D53:01ED\"): got: %q, want: %q.\n", want, "41EDF9554C2F")
}
}
func TestTranslate(t *testing.T) {
want := Translate{"Paka"}
if want.Atl2Eng() != "Awake" {
t.Errorf("\nTesting Translate{\"Paka\"}.Atl2Eng(): got %q, want: %q.\n", want.Atl2Eng(), "Awake")
} else {
fmt.Printf("\nTesting Translate{\"Paka\"}.Atl2Eng(): got %q, want: %q.\n", want.Atl2Eng(), "Awake")
}
want = Translate{"hofsos"}
if want.Gek2Eng() != "answer" {
t.Errorf("Testing Translate{\"hofsos\"}.Gek2Eng(): got %q, want: %q.\n", want.Gek2Eng(), "answer")
} else {
fmt.Printf("Testing Translate{\"hofsos\"}.Gek2Eng(): got %q, want: %q.\n", want.Gek2Eng(), "answer")
}
want = Translate{"Aqo"}
if want.Vyk2Eng() != "Foes" {
t.Errorf("Testing Translate{\"Aqo\"}.Vyk2Eng(): got %q, want: %q.\n", want.Vyk2Eng(), "Foes")
} else {
fmt.Printf("Testing Translate{\"Aqo\"}.Vyk2Eng(): got %q, want: %q.\n", want.Vyk2Eng(), "Foes")
}
want = Translate{"Alinichel"}
if want.Kor2Eng() != "Emergency" {
t.Errorf("Testing Translate{\"Alinichel\"}.Kor2Eng(): got %q, want: %q.\n", want.Kor2Eng(), "Emergency")
} else {
fmt.Printf("Testing Translate{\"Alinichel\"}.Kor2Eng(): got %q, want: %q.\n", want.Kor2Eng(), "Emergency")
}
fmt.Printf("\nTesting complete.\nStatus: ")
}

22
rpcg.go
View File

@@ -1,11 +1,3 @@
package nmslib
import (
"fmt"
"math/rand"
"time"
)
/* /*
[P][SSS][YY][ZZZ][XXX] (P = Planet Index / S = Star System Index / Y = Height / Z = Width / X = Length) [P][SSS][YY][ZZZ][XXX] (P = Planet Index / S = Star System Index / Y = Height / Z = Width / X = Length)
@@ -23,6 +15,20 @@ import (
*/ */
package nmslib
import (
"fmt"
"math/rand"
"time"
)
/*
RndPortal - Random Portalcode generator
Requires no input required
Returns a string
*/
func RndPortal() (final string) { func RndPortal() (final string) {
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
min := 0x1 min := 0x1