Updates and Fixes #2
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
assets/
|
||||
@@ -3,7 +3,7 @@ stages:
|
||||
|
||||
test:
|
||||
stage: test
|
||||
image: golang:1.15.3
|
||||
image: golang:1.16.3
|
||||
script:
|
||||
- go test
|
||||
|
||||
|
||||
57
README.md
57
README.md
@@ -6,7 +6,7 @@
|
||||
|
||||
NMSlib is a GoLang package for dealing with converting Galactic coordinates to Portal codes and vice versa.
|
||||
|
||||
NMSlib also translates in game languages to english.
|
||||
NMSlib also translates in game languages (Korvax, Gek Vy'Keen and Atlas) to english, and create portal banners.
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -39,10 +39,11 @@ func main() {
|
||||
fmt.Printf("Input:\t%s\nExpecting:\t014C:0077:06DA:01F2\nHave:\t%s\n", portalcode, tstvar)
|
||||
|
||||
nmslib.CreateBanner(portalcode, "NewLennon.png", 0)
|
||||
nmslib.CreateBanner(RndPortal(), "Random.png", 0)
|
||||
|
||||
fmt.Println(Translate{"KIHTYOMOLES"}.Kor2Eng())
|
||||
korvax := Translate{"Contraband"}
|
||||
fmt.Println(korvax.Eng2Kor())
|
||||
fmt.Println(nmslib.Translate{"KIHTYOMOLES"}.Kor2Eng())
|
||||
korvax := nmslib.Translate{"Contraband"}
|
||||
fmt.Println(nmslib.korvax.Eng2Kor())
|
||||
}
|
||||
|
||||
```
|
||||
@@ -53,7 +54,12 @@ This function takes 3 parameters:
|
||||
|
||||
* portalcode: 12 char hex string of portal location
|
||||
* savename: Save location and name
|
||||
* Horizontal/Vertical layout: 0 is horizontal, 1 is vertical
|
||||
* 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:**
|
||||
|
||||
@@ -65,6 +71,20 @@ 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
|
||||
@@ -117,7 +137,7 @@ This function takes only 1 parameter and returns a string
|
||||
**Example:**
|
||||
|
||||
```golang
|
||||
fmt.Println(Translate{"Paka"}.Atl2Eng())
|
||||
fmt.Println(nmslib.Translate{"Paka"}.Atl2Eng())
|
||||
```
|
||||
|
||||
Output:
|
||||
@@ -133,7 +153,7 @@ This function takes only 1 parameter and returns a string
|
||||
**Example:**
|
||||
|
||||
```golang
|
||||
korvax := Translate{"Contraband"}
|
||||
korvax := nmslib.Translate{"Contraband"}
|
||||
fmt.Println(korvax.Eng2Kor())
|
||||
```
|
||||
|
||||
@@ -145,20 +165,20 @@ Output:
|
||||
### Language commands
|
||||
|
||||
Gek:
|
||||
- ``Translate{word}.Gek2Eng()``
|
||||
- ``Translate{word}.Eng2Gek()``
|
||||
- ``Translate{string}.Gek2Eng()``
|
||||
- ``Translate{string}.Eng2Gek()``
|
||||
|
||||
Korvax:
|
||||
- ``Translate{word}.Kor2Eng()``
|
||||
- ``Translate{word}.Eng2Kor()``
|
||||
- ``Translate{string}.Kor2Eng()``
|
||||
- ``Translate{string}.Eng2Kor()``
|
||||
|
||||
Vy'keen:
|
||||
- ``Translate{word}.Vyk2Eng()``
|
||||
- ``Translate{word}.Eng2Vyk()``
|
||||
- ``Translate{string}.Vyk2Eng()``
|
||||
- ``Translate{string}.Eng2Vyk()``
|
||||
|
||||
Atlas:
|
||||
- ``Translate{word}.Atl2Eng()``
|
||||
- ``Translate{word}.Eng2Atl()``
|
||||
- ``Translate{string}.Atl2Eng()``
|
||||
- ``Translate{string}.Eng2Atl()``
|
||||
|
||||
|
||||
## Random Portal address
|
||||
@@ -167,12 +187,15 @@ Atlas:
|
||||
**Example:**
|
||||
|
||||
```golang
|
||||
fmt.Println(RndPortal())
|
||||
fmt.Println(nmslib.RndPortal())
|
||||
fmt.Println(nmslib.RndPortal())
|
||||
```
|
||||
|
||||
**Outout:**
|
||||
**Output:**
|
||||
|
||||
``10EFABDEA373``
|
||||
|
||||
``11EAB355FC8E``
|
||||
|
||||
## License
|
||||
[MIT](COPYING)
|
||||
|
||||
@@ -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,7 +60,7 @@ 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
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/nfnt/resize"
|
||||
|
||||
gim "github.com/ozankasikci/go-image-merge"
|
||||
)
|
||||
|
||||
@@ -18,14 +16,17 @@ 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
|
||||
|
||||
@@ -34,7 +35,7 @@ func CreateBanner(portalhex string, savename string, vopt int) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer os.RemoveAll(tempdir)
|
||||
//defer os.RemoveAll(tempdir)
|
||||
|
||||
// verify len of portalhex
|
||||
if len(portalhex) == 12 {
|
||||
@@ -45,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("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++ {
|
||||
@@ -55,17 +72,18 @@ func CreateBanner(portalhex string, savename string, vopt int) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
_, err2 := os.Stat(tempdir + "/glyphs/")
|
||||
_, err2 := os.Stat(tempdir + "/assets/glyphs/" + mode + "/")
|
||||
if os.IsNotExist(err2) {
|
||||
errDir := os.MkdirAll(tempdir+"/glyphs", 0755)
|
||||
errDir := os.MkdirAll(tempdir+"/assets/glyphs/"+mode, 0755)
|
||||
if errDir != nil {
|
||||
panic(errDir)
|
||||
}
|
||||
}
|
||||
|
||||
// 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: tempdir + "/" + glyphImg[0]}, {ImageFilePath: tempdir + "/" + glyphImg[1]},
|
||||
@@ -76,26 +94,17 @@ func CreateBanner(portalhex string, savename string, vopt int) {
|
||||
{ImageFilePath: tempdir + "/" + glyphImg[10]}, {ImageFilePath: tempdir + "/" + glyphImg[11]},
|
||||
}
|
||||
|
||||
if vopt == 1 { // set vertical rendering
|
||||
vert, horz = 1, 12
|
||||
} else { // set horizontal rendering (default)
|
||||
vert, horz = 12, 1
|
||||
}
|
||||
|
||||
// create new image from grids
|
||||
rgba, err := gim.New(grids, vert, horz).Merge()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Resize banner 768x64
|
||||
nuimg := resize.Resize(768, 64, rgba, resize.Lanczos3)
|
||||
|
||||
// save the output to png
|
||||
fmt.Printf("Saving %s to %s\n", portalhex, savename)
|
||||
file, err := os.Create(savename)
|
||||
err = png.Encode(file, nuimg)
|
||||
err = png.Encode(file, rgba)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
32
lang.go
32
lang.go
@@ -12,7 +12,7 @@ import (
|
||||
Translate words
|
||||
*/
|
||||
type Translate struct {
|
||||
word string
|
||||
Word string
|
||||
}
|
||||
|
||||
// trans - set up structure of a word iteration
|
||||
@@ -121,11 +121,11 @@ func toEng(t Translate, csvlines [][]string) string {
|
||||
acpword: strings.ToLower(line[3]),
|
||||
}
|
||||
// check translate struct for value
|
||||
if strings.ToLower(t.word) == lang.word {
|
||||
if strings.ToLower(t.Word) == lang.word {
|
||||
returnstring = lang.english
|
||||
} else if strings.ToLower(t.word) == lang.capword {
|
||||
} else if strings.ToLower(t.Word) == lang.capword {
|
||||
returnstring = strings.Title(strings.ToLower(lang.english))
|
||||
} else if strings.ToLower(t.word) == lang.acpword {
|
||||
} else if strings.ToLower(t.Word) == lang.acpword {
|
||||
returnstring = strings.ToUpper(lang.english)
|
||||
}
|
||||
}
|
||||
@@ -141,17 +141,17 @@ func toNMS(t Translate, csvlines [][]string) string {
|
||||
capword: line[2],
|
||||
acpword: line[3],
|
||||
}
|
||||
if t.word == lang.english {
|
||||
if t.Word == lang.english {
|
||||
if lang.word != "" {
|
||||
returnstring = lang.word
|
||||
}
|
||||
}
|
||||
if t.word == strings.Title(strings.ToLower(lang.english)) {
|
||||
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 t.Word == strings.ToUpper(lang.english) {
|
||||
if lang.acpword != "" {
|
||||
returnstring = strings.ToUpper(lang.acpword)
|
||||
}
|
||||
@@ -160,6 +160,21 @@ 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-")
|
||||
@@ -169,7 +184,7 @@ func openCSV(lagcsv string) [][]string {
|
||||
defer os.RemoveAll(tempdir) // Clean up temp files
|
||||
|
||||
// extract language file from resources.go
|
||||
data, err := Asset(lagcsv)
|
||||
data, err := Asset("assets/lang/" + lagcsv)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -188,4 +203,5 @@ func openCSV(lagcsv string) [][]string {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return csvlines
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,12 @@ func TestRndPortal(t *testing.T) {
|
||||
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 {
|
||||
@@ -54,11 +60,6 @@ func TestGalactic2portal(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateBanner(t *testing.T) {
|
||||
fmt.Printf("\nTesting CreateBanner: ")
|
||||
CreateBanner(RndPortal(), "/tmp/Test.png", 0)
|
||||
}
|
||||
|
||||
func TestTranslate(t *testing.T) {
|
||||
want := Translate{"Paka"}
|
||||
if want.Atl2Eng() != "Awake" {
|
||||
|
||||
BIN
ranportal_scaled.png
Normal file
BIN
ranportal_scaled.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
674
resources.go
674
resources.go
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user