Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4aef1e390a | ||
|
|
284313eacc | ||
|
|
87bec565f1 | ||
|
|
a7069dce7e | ||
|
|
bc4e334ecd | ||
|
|
9358727075 | ||
|
|
3449ae3bf3 | ||
|
|
023eab03b2 | ||
|
|
5f4414df03 | ||
|
|
57a1d729dd | ||
|
|
67db2e32ef | ||
|
|
2bb7ca6ccd | ||
|
|
2610d98ae1 | ||
|
|
32d533ff61 | ||
|
|
ac68a20697 | ||
|
|
0b90141dcd | ||
|
|
5bc5711f09 | ||
|
|
00411f015c | ||
|
|
ab9799b273 | ||
|
|
d8dbc66b27 | ||
|
|
08ed8866d0 | ||
|
|
620d0ef9de | ||
|
|
312d38ac6d | ||
|
|
4aec0e4e9a | ||
|
|
4f1002ee2d | ||
|
|
f291891139 | ||
|
|
230cefb85d | ||
|
|
84df8142c6 | ||
|
|
38e45c4f60 | ||
|
|
221f4e59e1 | ||
|
|
8ccafd5c0c | ||
|
|
59fcf3e2f0 | ||
|
|
59cc61105a | ||
|
|
ea438a7f40 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
assets/
|
||||
9
.gitlab-ci.yml
Normal file
9
.gitlab-ci.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
stages:
|
||||
- test
|
||||
|
||||
test:
|
||||
stage: test
|
||||
image: golang:1.16.3
|
||||
script:
|
||||
- go test
|
||||
|
||||
BIN
NewLennon.png
Normal file
BIN
NewLennon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 228 KiB |
178
README.md
178
README.md
@@ -1,9 +1,12 @@
|
||||
# NMSlib
|
||||
|
||||
**master Branch** : 
|
||||
|
||||
**develop Branch** : 
|
||||
|
||||
NMSlib is a GoLang package for dealing with converting Galactic coordinates to Portal codes and vice versa.
|
||||
|
||||
NMSlib also translates known Korvax words to English and back.
|
||||
- Gek, Vykeen, etc will be added in the future
|
||||
NMSlib also translates in game languages (Korvax, Gek Vy'Keen and Atlas) to english, and create portal banners.
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -11,33 +14,188 @@ To install this module use `go get`
|
||||
|
||||
|
||||
```bash
|
||||
go get -u gitlab.com/bradley.richins/nmslib
|
||||
go get -u gitlab.com/Raum0x2A/nmslib
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
**Example:**
|
||||
|
||||
```golang
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gitlab.com/bradley.richins/nmslib"
|
||||
"gitlab.com/Raum0x2A/nmslib"
|
||||
)
|
||||
|
||||
func main() {
|
||||
portalcode := "006afa556c30"
|
||||
portalcode := "21F2F8EDB94D"
|
||||
tstvar, err := nmslib.P2gc(portalcode)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Printf("Input: \t%s\nExpecting: \t042F:0079:0D55:006A\nHave: \t%s\n", portalcode, tstvar)
|
||||
nmslib.CreateBanner(portalcode, "NewLennon.png", 0)
|
||||
fmt.Printf("Input:\t%s\nExpecting:\t014C:0077:06DA:01F2\nHave:\t%s\n", portalcode, tstvar)
|
||||
|
||||
fmt.Println(nmslib.Korvax2Eng("eapoluch"))
|
||||
fmt.Println(nmslib.Eng2Korvax("emergency"))
|
||||
nmslib.CreateBanner(portalcode, "NewLennon.png", 0)
|
||||
nmslib.CreateBanner(RndPortal(), "Random.png", 0)
|
||||
|
||||
fmt.Println(nmslib.Translate{"KIHTYOMOLES"}.Kor2Eng())
|
||||
korvax := nmslib.Translate{"Contraband"}
|
||||
fmt.Println(nmslib.korvax.Eng2Kor())
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
### Creating a Glyph banner with CreateBanner()
|
||||
|
||||
This function takes 3 parameters:
|
||||
|
||||
* portalcode: 12 char hex string of portal location
|
||||
* savename: Save location and name
|
||||
* layout:
|
||||
* 00 or 0 is horizontal in light mode
|
||||
* 01 or 1 is horizontal in dark mode
|
||||
* 11 is vertical in dark mode
|
||||
* 10 is vertical in light mode
|
||||
|
||||
|
||||
**Example:**
|
||||
|
||||
Horizontal Layout for Galactic Hub [HUB10-6A Icarus Sun](https://nomanssky.gamepedia.com/HUB10-6A_Icarus_Sun) Eniwa 68/L3
|
||||
|
||||
```golang
|
||||
nmslib.CreateBanner("006AFA556C30", "NewLennon.png", 0)
|
||||
```
|
||||
|
||||

|
||||
|
||||
Vertical layout for a random address
|
||||
|
||||
```golang
|
||||
nmslib.CreateBanner(nmslib.RndPortal(), "ranportal.png", 11)
|
||||
```
|
||||
|
||||

|
||||
|
||||
_Note: Images shown in readme.md have been scaled down in gimp._
|
||||
|
||||
_Original Vertical: 256x3072px_
|
||||
|
||||
_Original: Horizontal: 3072x256px_
|
||||
|
||||
### Converting Portal code to Galactic address with P2gc()
|
||||
|
||||
This function only takes 1 parameter and returns a string and error
|
||||
|
||||
* portalcode: 12 char hex string of portal glyphs
|
||||
|
||||
**Example:**
|
||||
|
||||
```golang
|
||||
ga, _ := nmslib.P3gc("21F2F8EDB94D")
|
||||
fmt.Println(ga)
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
``014C:0077:06DA:01F2``
|
||||
|
||||
### Converting Galactic coordinates to Portal codes with Gc2p()
|
||||
|
||||
This function only takes 1 parameter and returns a string and error
|
||||
|
||||
* galacticaddress: 16 char 4 block hex address
|
||||
|
||||
**Example:**
|
||||
|
||||
```golang
|
||||
pc, _ := nmslib.P3gc("014C:0077:06DA:01F2")
|
||||
fmt.Println(pc)
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
``21F2F8EDB94D``
|
||||
|
||||
## Translate Words
|
||||
|
||||
Supported languages
|
||||
|
||||
- Korvax
|
||||
- Gek
|
||||
- Vy'keen
|
||||
- Atlas
|
||||
|
||||
### Translate Atlas to English with Atl2Eng()
|
||||
|
||||
This function takes only 1 parameter and returns a string
|
||||
|
||||
* Word: Any known Atlas word (ex. Paka)
|
||||
|
||||
**Example:**
|
||||
|
||||
```golang
|
||||
fmt.Println(nmslib.Translate{"Paka"}.Atl2Eng())
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
``Awake``
|
||||
|
||||
### Translate English to Korvax with Eng2Korvax()
|
||||
|
||||
This function takes only 1 parameter and returns a string
|
||||
|
||||
* engword: English word to attempt conversion
|
||||
|
||||
**Example:**
|
||||
|
||||
```golang
|
||||
korvax := nmslib.Translate{"Contraband"}
|
||||
fmt.Println(korvax.Eng2Kor())
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
``Zelidovoso``
|
||||
|
||||
|
||||
### Language commands
|
||||
|
||||
Gek:
|
||||
- ``Translate{string}.Gek2Eng()``
|
||||
- ``Translate{string}.Eng2Gek()``
|
||||
|
||||
Korvax:
|
||||
- ``Translate{string}.Kor2Eng()``
|
||||
- ``Translate{string}.Eng2Kor()``
|
||||
|
||||
Vy'keen:
|
||||
- ``Translate{string}.Vyk2Eng()``
|
||||
- ``Translate{string}.Eng2Vyk()``
|
||||
|
||||
Atlas:
|
||||
- ``Translate{string}.Atl2Eng()``
|
||||
- ``Translate{string}.Eng2Atl()``
|
||||
|
||||
|
||||
## Random Portal address
|
||||
### Create a random portal address
|
||||
|
||||
**Example:**
|
||||
|
||||
```golang
|
||||
fmt.Println(nmslib.RndPortal())
|
||||
fmt.Println(nmslib.RndPortal())
|
||||
```
|
||||
|
||||
**Output:**
|
||||
|
||||
``10EFABDEA373``
|
||||
|
||||
``11EAB355FC8E``
|
||||
|
||||
## License
|
||||
[MIT](https://choosealicense.com/licenses/mit/)
|
||||
[MIT](COPYING)
|
||||
|
||||
26
convert.go
26
convert.go
@@ -8,11 +8,8 @@ import (
|
||||
)
|
||||
|
||||
/*
|
||||
The maths are all thanks to:
|
||||
Xainesworld
|
||||
- YT Channel - https://www.youtube.com/channel/UCzTB8EBVJWkzJi2sQjdBv9g
|
||||
- Video: https://www.youtube.com/watch?v=xmZbkTahw4w
|
||||
- Website: https://www.xainesworld.com/
|
||||
Xainesworld Video: https://www.youtube.com/watch?v=xmZbkTahw4w
|
||||
Fandom Wiki: https://nomanssky.fandom.com/wiki/Portal_address
|
||||
*/
|
||||
|
||||
/*
|
||||
@@ -63,29 +60,30 @@ func P2gc(p string) (gc string, err error) {
|
||||
gc = fmt.Sprintf("%04X:%04X:%04X:%04X", coord[3], coord[1], coord[2], coord[0])
|
||||
|
||||
} else { // if len(p) != 12 return an error
|
||||
return "", errors.New("A 12char HEX string is required. example: 006afa556c30")
|
||||
return "", errors.New("a 12char HEX string is required. example: 006afa556c30")
|
||||
}
|
||||
return // return formated string
|
||||
}
|
||||
|
||||
/*
|
||||
Gc2p - Galactic coordinates to portal code
|
||||
Requires 1 string and returns a string and error
|
||||
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 var string
|
||||
Portal Glyph hex string 12 chars in len (ex. 006afa556c30)
|
||||
*/
|
||||
func Gc2p(gc string) (portalcode string, err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
/*TODO: add option for Planet choice (1-6)*/
|
||||
func Gc2p(gc string, p int) (portalcode string, err error) {
|
||||
// split and store string
|
||||
// coords[0] == X; coords[1] == Y coords[2] == Z;
|
||||
// coords[3] == SSI coords[4] == P
|
||||
coords := strings.Split(gc+":1", ":")
|
||||
if p > 6 {
|
||||
p = 1
|
||||
}
|
||||
nustring := fmt.Sprintf("%s:%d", gc, p)
|
||||
coords := strings.Split(nustring, ":")
|
||||
for n := 0; n < len(coords); n++ {
|
||||
portalcode = portalcode + coords[n]
|
||||
}
|
||||
|
||||
@@ -16,14 +16,27 @@ var portalex string
|
||||
Portal Glyph hex string
|
||||
var savename string
|
||||
Output name of PNG file
|
||||
var vopt int
|
||||
1 enables vertical banner
|
||||
0 enables horizontal banner
|
||||
var opt int
|
||||
00 sets horizontal 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
|
||||
*/
|
||||
func CreateBanner(portalhex string, savename string, vopt int) {
|
||||
func CreateBanner(portalhex string, savename string, opt int) {
|
||||
var err error
|
||||
var GlyphHex [12]int64
|
||||
var glyphImg [12]string
|
||||
var mode string
|
||||
var vert int
|
||||
var horz int
|
||||
|
||||
// Setup temp dir
|
||||
tempdir, err := ioutil.TempDir("", "nmslib-")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
//defer os.RemoveAll(tempdir)
|
||||
|
||||
// verify len of portalhex
|
||||
if len(portalhex) == 12 {
|
||||
// get hex value from each digit in given string to an array of int64
|
||||
@@ -33,9 +46,25 @@ func CreateBanner(portalhex string, savename string, vopt int) {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// set options
|
||||
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++ {
|
||||
glyphImg[j] = fmt.Sprintf("tmp.nmslib/glyphs/GLYPH-%X.png", 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/
|
||||
for k := 0; k < len(glyphImg); k++ {
|
||||
@@ -43,49 +72,39 @@ func CreateBanner(portalhex string, savename string, vopt int) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
_, err2 := os.Stat("tmp.nmslib/glyphs")
|
||||
_, err2 := os.Stat(tempdir + "/assets/glyphs/" + mode + "/")
|
||||
if os.IsNotExist(err2) {
|
||||
errDir := os.MkdirAll("tmp.nmslib/glyphs", 0755)
|
||||
errDir := os.MkdirAll(tempdir+"/assets/glyphs/"+mode, 0755)
|
||||
if errDir != nil {
|
||||
panic(errDir)
|
||||
}
|
||||
}
|
||||
err = ioutil.WriteFile(glyphImg[k], []byte(data), 0644)
|
||||
}
|
||||
// fmt.Println(tempdir + "/" + glyphImg[k]) // for debugging only
|
||||
err = ioutil.WriteFile(tempdir+"/"+glyphImg[k], []byte(data), 0644)
|
||||
|
||||
}
|
||||
|
||||
// load images for processing using github.com/ozankasikci/go-image-merge
|
||||
grids := []*gim.Grid{
|
||||
{ImageFilePath: glyphImg[0]}, {ImageFilePath: glyphImg[1]},
|
||||
{ImageFilePath: glyphImg[2]}, {ImageFilePath: glyphImg[3]},
|
||||
{ImageFilePath: glyphImg[4]}, {ImageFilePath: glyphImg[5]},
|
||||
{ImageFilePath: glyphImg[6]}, {ImageFilePath: glyphImg[7]},
|
||||
{ImageFilePath: glyphImg[8]}, {ImageFilePath: glyphImg[9]},
|
||||
{ImageFilePath: glyphImg[10]}, {ImageFilePath: glyphImg[11]},
|
||||
{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]},
|
||||
}
|
||||
if vopt == 1 {
|
||||
// Merge images horizontally
|
||||
rgba, err := gim.New(grids, 1, 12).Merge()
|
||||
|
||||
// create new image from grids
|
||||
rgba, err := gim.New(grids, vert, horz).Merge()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// save the output to png
|
||||
fmt.Printf("Saving %s to %s in vertical format\n", portalhex, savename)
|
||||
file, err := os.Create(savename)
|
||||
err = png.Encode(file, rgba)
|
||||
} else {
|
||||
// Merge images vertically
|
||||
rgba, err := gim.New(grids, 12, 1).Merge()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
fmt.Println(err)
|
||||
}
|
||||
// save the output to png
|
||||
fmt.Printf("Saving %s to %s\n", portalhex, savename)
|
||||
file, err := os.Create(savename)
|
||||
err = png.Encode(file, rgba)
|
||||
}
|
||||
// remove glyphs folder to keep it clean
|
||||
errDir := os.RemoveAll("tmp.nmslib/glyphs")
|
||||
if errDir != nil {
|
||||
panic(errDir)
|
||||
}
|
||||
}
|
||||
|
||||
9
go.mod
9
go.mod
@@ -1,5 +1,8 @@
|
||||
module gitlab.com/bradley.richins/nmslib
|
||||
module nmslib
|
||||
|
||||
go 1.15
|
||||
go 1.16
|
||||
|
||||
require github.com/ozankasikci/go-image-merge v0.2.2
|
||||
require (
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||
github.com/ozankasikci/go-image-merge v0.2.2
|
||||
)
|
||||
|
||||
2
go.sum
2
go.sum
@@ -1,2 +1,4 @@
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||
github.com/ozankasikci/go-image-merge v0.2.2 h1:K370BLLTIsamwjAeViiPntf7GiG3h9pXzDmxXCbN8/0=
|
||||
github.com/ozankasikci/go-image-merge v0.2.2/go.mod h1:NQ2aN0b21buFx3p+5x4dZrKuPSLh2uBukK7F30BrYTo=
|
||||
|
||||
270
lang.go
270
lang.go
@@ -9,119 +9,199 @@ import (
|
||||
)
|
||||
|
||||
/*
|
||||
Korvaxlang - set up structure of a word iteration
|
||||
Translate words
|
||||
*/
|
||||
type Korvaxlang struct {
|
||||
English string
|
||||
KorvaxWord string
|
||||
KWCaps string
|
||||
KWALLCAPS string
|
||||
type Translate struct {
|
||||
Word string
|
||||
}
|
||||
|
||||
// trans - set up structure of a word iteration
|
||||
type trans0 struct {
|
||||
english string // english word
|
||||
word string // no caps word
|
||||
capword string // Capitalized word
|
||||
acpword string // ALL CAPITALIZED WORD
|
||||
}
|
||||
|
||||
/*
|
||||
Korvax2Eng - convert known korvax words into english
|
||||
Kor2Eng translate korvax word to english word
|
||||
*/
|
||||
func Korvax2Eng(kvwrd string) string {
|
||||
data, err := Asset("tmp.nmslib/korvax-lang.csv")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
func (t Translate) Kor2Eng() (returnstring string) {
|
||||
csvlines := openCSV("korvax-lang.csv")
|
||||
for range csvlines {
|
||||
returnstring = (toEng(t, csvlines))
|
||||
}
|
||||
_, err2 := os.Stat("tmp.nmslib/")
|
||||
if os.IsNotExist(err2) {
|
||||
errDir := os.MkdirAll("tmp.nmslib/", 0755)
|
||||
if errDir != nil {
|
||||
panic(errDir)
|
||||
}
|
||||
}
|
||||
err = ioutil.WriteFile("tmp.nmslib/korvax-lang.csv", []byte(data), 0644)
|
||||
csvFile, err := os.Open("tmp.nmslib/korvax-lang.csv")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
defer csvFile.Close()
|
||||
CsvLines, err := csv.NewReader(csvFile).ReadAll()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
for _, line := range CsvLines {
|
||||
klang := Korvaxlang{
|
||||
English: line[0],
|
||||
KorvaxWord: line[1],
|
||||
KWCaps: line[2],
|
||||
KWALLCAPS: line[3],
|
||||
}
|
||||
if kvwrd == klang.KorvaxWord {
|
||||
errDir := os.RemoveAll("tmp.nmslib")
|
||||
if errDir != nil {
|
||||
panic(errDir)
|
||||
}
|
||||
return klang.English
|
||||
} else if kvwrd == klang.KWCaps {
|
||||
errDir := os.RemoveAll("tmp.nmslib")
|
||||
if errDir != nil {
|
||||
panic(errDir)
|
||||
}
|
||||
return strings.Title(strings.ToLower(klang.English))
|
||||
} else if kvwrd == klang.KWALLCAPS {
|
||||
errDir := os.RemoveAll("tmp.nmslib")
|
||||
if errDir != nil {
|
||||
panic(errDir)
|
||||
}
|
||||
return strings.ToUpper(klang.English)
|
||||
}
|
||||
}
|
||||
// remove recource folder to keep it clean
|
||||
errDir := os.RemoveAll("tmp.nmslib")
|
||||
if errDir != nil {
|
||||
panic(errDir)
|
||||
}
|
||||
return "*\\Kzzzzzzt\\*" // word not found default
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
Eng2Korvax - Convert (some) english words to Korvax
|
||||
Eng2Kor translate english word to korvax word
|
||||
*/
|
||||
func Eng2Korvax(enwrd string) string {
|
||||
data, err := Asset("tmp.nmslib/korvax-lang.csv")
|
||||
func (t Translate) Eng2Kor() (returnstring string) {
|
||||
csvlines := openCSV("korvax-lang.csv")
|
||||
for range csvlines {
|
||||
returnstring = (toNMS(t, csvlines))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
Gek2Eng translate Gek word to english word
|
||||
*/
|
||||
func (t Translate) Gek2Eng() (returnstring string) {
|
||||
csvlines := openCSV("gek-lang.csv")
|
||||
for range csvlines {
|
||||
returnstring = (toEng(t, csvlines))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
Eng2Gek translate english word to Gek word
|
||||
*/
|
||||
func (t Translate) Eng2Gek() (returnstring string) {
|
||||
csvlines := openCSV("gek-lang.csv")
|
||||
for range csvlines {
|
||||
returnstring = (toNMS(t, csvlines))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
Vyk2Eng translate vykeen word to english word
|
||||
*/
|
||||
func (t Translate) Vyk2Eng() (returnstring string) {
|
||||
csvlines := openCSV("vykeen-lang.csv")
|
||||
for range csvlines {
|
||||
returnstring = (toEng(t, csvlines))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
Eng2Vyk translate english word to vykeen word
|
||||
*/
|
||||
func (t Translate) Eng2Vyk() (returnstring string) {
|
||||
csvlines := openCSV("vykeen-lang.csv")
|
||||
for range csvlines {
|
||||
returnstring = (toNMS(t, csvlines))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
Atl2Eng translate Atlas word to english word
|
||||
*/
|
||||
func (t Translate) Atl2Eng() (returnstring string) {
|
||||
csvlines := openCSV("atlas-lang.csv")
|
||||
for range csvlines {
|
||||
returnstring = (toEng(t, csvlines))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
Eng2Atl translate english word to Atlas word
|
||||
*/
|
||||
func (t Translate) Eng2Atl() (returnstring string) {
|
||||
csvlines := openCSV("atlas-lang.csv")
|
||||
for range csvlines {
|
||||
returnstring = (toNMS(t, csvlines))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func toEng(t Translate, csvlines [][]string) string {
|
||||
returnstring := "*\\Kzzzzzzt\\*" // word not found default
|
||||
for _, line := range csvlines {
|
||||
lang := trans0{
|
||||
english: strings.ToLower(line[0]),
|
||||
word: strings.ToLower(line[1]),
|
||||
capword: strings.ToLower(line[2]),
|
||||
acpword: strings.ToLower(line[3]),
|
||||
}
|
||||
// check translate struct for value
|
||||
if strings.ToLower(t.Word) == lang.word {
|
||||
returnstring = lang.english
|
||||
} else if strings.ToLower(t.Word) == lang.capword {
|
||||
returnstring = strings.Title(strings.ToLower(lang.english))
|
||||
} else if strings.ToLower(t.Word) == lang.acpword {
|
||||
returnstring = strings.ToUpper(lang.english)
|
||||
}
|
||||
}
|
||||
return returnstring
|
||||
}
|
||||
|
||||
func toNMS(t Translate, csvlines [][]string) string {
|
||||
returnstring := "*\\Kzzzzzzt\\*" // word not found default
|
||||
for _, line := range csvlines {
|
||||
lang := trans0{
|
||||
english: line[0],
|
||||
word: line[1],
|
||||
capword: line[2],
|
||||
acpword: line[3],
|
||||
}
|
||||
if t.Word == lang.english {
|
||||
if lang.word != "" {
|
||||
returnstring = lang.word
|
||||
}
|
||||
}
|
||||
if t.Word == strings.Title(strings.ToLower(lang.english)) {
|
||||
if lang.capword != "" {
|
||||
returnstring = strings.Title(strings.ToLower(lang.capword))
|
||||
}
|
||||
}
|
||||
if t.Word == strings.ToUpper(lang.english) {
|
||||
if lang.acpword != "" {
|
||||
returnstring = strings.ToUpper(lang.acpword)
|
||||
}
|
||||
}
|
||||
}
|
||||
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)
|
||||
}
|
||||
_, err2 := os.Stat("tmp.nmslib/")
|
||||
if os.IsNotExist(err2) {
|
||||
errDir := os.MkdirAll("tmp.nmslib/", 0755)
|
||||
if errDir != nil {
|
||||
panic(errDir)
|
||||
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)
|
||||
}
|
||||
}
|
||||
err = ioutil.WriteFile("tmp.nmslib/korvax-lang.csv", []byte(data), 0644)
|
||||
csvFile, err := os.Open("tmp.nmslib/korvax-lang.csv")
|
||||
|
||||
// wirte extracted data to temp dir
|
||||
err = ioutil.WriteFile(tempdir+"/"+lagcsv, []byte(data), 0644)
|
||||
csvFile, err := os.Open(tempdir + "/" + lagcsv)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
defer csvFile.Close()
|
||||
CsvLines, err := csv.NewReader(csvFile).ReadAll()
|
||||
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)
|
||||
}
|
||||
for _, line := range CsvLines {
|
||||
klang := Korvaxlang{
|
||||
English: line[0],
|
||||
KorvaxWord: line[1],
|
||||
KWCaps: line[2],
|
||||
KWALLCAPS: line[3],
|
||||
}
|
||||
if enwrd == klang.English {
|
||||
errDir := os.RemoveAll("tmp.nmslib")
|
||||
if errDir != nil {
|
||||
panic(errDir)
|
||||
}
|
||||
return klang.KorvaxWord
|
||||
}
|
||||
}
|
||||
// remove recource folder to keep it clean
|
||||
errDir := os.RemoveAll("tmp.nmslib")
|
||||
if errDir != nil {
|
||||
panic(errDir)
|
||||
}
|
||||
return "*\\Kzzzzzzt\\*" // word not found default
|
||||
return csvlines
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,17 @@ import (
|
||||
"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 {
|
||||
@@ -15,64 +26,65 @@ func TestPortal2Galactic(t *testing.T) {
|
||||
} 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")
|
||||
want, err := Gc2p("042F:0079:0D55:006A", 1)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if want != "106AFA556C30" {
|
||||
t.Errorf("Testing Gc2p(\"042F:0079:0D55:006A\"): got %q, want: %q.\n", want, "106AFA556C30")
|
||||
t.Errorf("\nTesting Gc2p(\"042F:0079:0D55:006A\"): got %q, want: %q.\n", want, "106AFA556C30")
|
||||
} else {
|
||||
fmt.Printf("Testing Gc2p(\"042F:0079:0D55:006A\"): got: %q, want: %q.\n", want, "106AFA556C30")
|
||||
fmt.Printf("\nTesting Gc2p(\"042F:0079:0D55:006A\"): got: %q, want: %q.\n", want, "106AFA556C30")
|
||||
}
|
||||
|
||||
want, err = Gc2p("044B:0081:0D68:0096")
|
||||
want, err = Gc2p("042E:0078:0D53:01ED", 4)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if want != "109602569C4C" {
|
||||
t.Errorf("Testing Gc2p(\"044B:0081:0D68:0096\"): got %q, want: %q.\n", want, "109602569C4C")
|
||||
if want != "41EDF9554C2F" {
|
||||
t.Errorf("Testing Gc2p(\"042E:0078:0D53:01ED\"): got %q, want: %q.\n", want, "41EDF9554C2F")
|
||||
} else {
|
||||
fmt.Printf("Testing Gc2p(\"044B:0081:0D68:0096\"): got: %q, want: %q.\n", want, "109602569C4C")
|
||||
fmt.Printf("Testing Gc2p(\"042E:0078:0D53:01ED\"): got: %q, want: %q.\n", want, "41EDF9554C2F")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateBanner(t *testing.T) {
|
||||
fmt.Printf("Testing CreateBanner: ")
|
||||
CreateBanner("006afa556c30", "/tmp/Test.png", 0)
|
||||
}
|
||||
|
||||
func TestKorvax2Eng(t *testing.T) {
|
||||
want := Korvax2Eng("eapoluch")
|
||||
if want != "emergency" {
|
||||
t.Errorf("Testing Korvax2eng(\"eapoluch\"): got %q, want: %q.\n", want, "emergency")
|
||||
} else {
|
||||
fmt.Printf("Testing Korvax2eng(\"eapoluch\"): got %q, want: %q.\n", want, "emergency")
|
||||
}
|
||||
|
||||
want = Korvax2Eng("notaword")
|
||||
if want != "*\\Kzzzzzzt\\*" {
|
||||
t.Errorf("Testing Korvax2eng(\"notaword\"): got %q, want: %q.\n", want, "*\\Kzzzzzzt\\*")
|
||||
} else {
|
||||
fmt.Printf("Testing Korvax2eng(\"notaword\"): got %q, want: %q.\n", want, "*\\Kzzzzzzt\\*")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEng2Korvax(t *testing.T) {
|
||||
want := Eng2Korvax("emergency")
|
||||
if want != "eapoluch" {
|
||||
t.Errorf("Testing Eng2Korvax(\"emergency\"): got %q, want: %q.\n", want, "eapoluch")
|
||||
} else {
|
||||
fmt.Printf("Testing Eng2Korvax(\"emergency\"): got %q, want: %q.\n", want, "eapoluch")
|
||||
}
|
||||
|
||||
want = Eng2Korvax("notaword")
|
||||
if want != "*\\Kzzzzzzt\\*" {
|
||||
t.Errorf("Testing Eng2Korvax(\"notaword\"): got %q, want: %q.\n", want, "*\\Kzzzzzzt\\*")
|
||||
} else {
|
||||
fmt.Printf("Testing Eng2Korvax(\"notaword\"): got %q, want: %q.\n", want, "*\\Kzzzzzzt\\*")
|
||||
}
|
||||
fmt.Printf("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: ")
|
||||
}
|
||||
|
||||
BIN
ranportal_scaled.png
Normal file
BIN
ranportal_scaled.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
607
resources.go
607
resources.go
File diff suppressed because one or more lines are too long
41
rpcg.go
Normal file
41
rpcg.go
Normal file
@@ -0,0 +1,41 @@
|
||||
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)
|
||||
|
||||
`Solar System Index
|
||||
A Solar System Index is assigned to each star system in a region. It always begins at SolarSystemIndex=001
|
||||
and counts up by one for every star system. The number of star systems in a region is variable so the
|
||||
maximum value of the Solar System Index is also variable, though the two correspond directly. To date there
|
||||
is no discovered value that is higher than SolarSystemIndex=243 (Mamundi-Kate in the Baadossm Anomaly of
|
||||
Euclid galaxy), meaning that 579 is the maximum number of star systems yet discovered in a region. Based
|
||||
on the evidence that every region has a SolarSystemIndex=079 and SolarSystemIndex=07A (with the former
|
||||
always having a Black Hole and the latter always having an Atlas Station), it is known that every region has
|
||||
at least 122 star systems. SolarSystemIndex=000 always leads to the region's first system, just like
|
||||
PlanetIndex=0 always leads to the first portal of a system due to the error proximity mechanic.`
|
||||
Source https://nomanssky.fandom.com/wiki/Portal_address#Solar_System_Index
|
||||
|
||||
*/
|
||||
|
||||
func RndPortal() (final string) {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
min := 0x1
|
||||
ymax := 0xFF
|
||||
xzmax := 0xFFF
|
||||
ssimax := 0x242 // set this low to lower chances of an invalid address
|
||||
|
||||
x := rand.Intn(xzmax-min+1) + min
|
||||
z := rand.Intn(xzmax-min+1) + min
|
||||
y := rand.Intn(ymax-min+1) + min
|
||||
ssi := rand.Intn(ssimax-min+1) + min
|
||||
|
||||
final = fmt.Sprintf("%00X%03X%02X%03X%03X", 1, ssi, y, z, x)
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user