71 Commits

Author SHA1 Message Date
Raum0x2A
e078afbbe5 Merge branch 'develop' of gitlab.com:Raum0x2A/nmslib into develop 2021-05-30 08:03:19 -06:00
Raum0x2A
511331008e Minor changes 2021-05-30 08:02:55 -06:00
Raum0x2A
6fbbe0b23c Update .gitlab-ci.yml file 2021-05-26 23:31:53 +00:00
Raum0x2A
b24a16edad Update .gitlab-ci.yml 2021-05-26 23:22:26 +00:00
Raum0x2A
3588826556 minor fix 2021-05-26 15:57:04 -06:00
Raum0x2A
98d812c904 Minor changes 2021-05-26 15:49:17 -06:00
Raum0x2A
86bc493ead Updated - v1.0.0 2021-05-26 15:15:13 -06:00
Raum0x2A
3cfae880ee Updated - v1.0.0 2021-05-26 15:13:30 -06:00
Raum0x2A
b41f25646d Split up Create banner finction
nmslib.CreateBanner() now calls nmslib.GenRawBanner() for the
majority of processing createbanner now just calls the gen func
and saves the file.

GenRawBanner() returns an image.Image type for more processing by
another function. this will be used for upcoming features.

tests have been updated as needed

upddated go.mod and go.sum
2021-05-24 13:11:56 -06:00
Raum0x2A
94f9b4e15c Greatly improved translator feature
The translator feature has been completely rewritten, and can now
convert any game language to any other.
2021-05-20 19:22:17 -06:00
Raum0x2A
6d3a57d31c Revert "WIP - rebuilding translator"
This reverts commit ab420a0a44.
2021-05-20 19:05:29 -06:00
Raum0x2A
ab420a0a44 WIP - rebuilding translator 2021-05-20 14:33:33 -06:00
Raum0x2A
a0d9dbd269 Merge branch 'translator' into 'develop'
Updates and Features

See merge request Raum0x2A/nmslib!3
2021-05-19 21:23:39 +00:00
Raum0x2A
60de0ebb46 Updates and Features 2021-05-19 21:23:39 +00:00
Raum0x2A
a370e0f33d only run master/develop 2021-05-18 08:55:14 -06:00
Raum0x2A
5faa96d8a7 ignore*feat 2021-05-18 08:53:00 -06:00
Raum0x2A
c8f6d51ba1 Merge branch 'portalbanner-resize' into 'develop'
Moved from gim to gg for image creation

See merge request Raum0x2A/nmslib!2
2021-05-18 04:57:05 +00:00
Raum0x2A
2397ec9aee Moved from gim to gg for image creation 2021-05-18 04:57:05 +00:00
Raum0x2A
21360acadf Updated 2021-05-11 18:11:51 -06:00
Raum0x2A
4aded9c17f Updated README.md
Corrected usage of nmslib.Translate{}
2021-05-11 23:56:00 +00:00
Raum0x2A
8945530dbf Updated 2021-05-08 09:39:28 -06:00
Raum0x2A
73fa913292 Merge branch 'master' into develop 2021-05-08 09:35:48 -06:00
Raum0x2A
47db5b0767 Fixed namespace/go mod tidy 2021-05-07 10:29:58 -06:00
Raum0x2A
4aef1e390a Merge branch 'develop' into 'master'
Updates and Fixes


**resource.go/assets.go**
*  renamed `resources.go` to `assets.go`
*  added dark glyphs - located in assets.go -> assets/glyphs/dark/
*  moved original glyphs - located in assets.go -> assets/glyph/light/

**glyphbanner.go**
* added option to make glyphs vertical and/or dark

**rpcg.go**
* Added a random portal code generator this function takes no args and returns a string

**README.md**
* Fixed some typos (probably more to be fixed)
* Added example of vertical portal banner
* Added list of options for banner creation
* Added example of ``nmslib.RndPortal()`` usage

**go.mod**
* updated go version to 1.16

See merge request Raum0x2A/nmslib!1
2021-05-07 16:03:08 +00:00
Raum0x2A
284313eacc Updates and Fixes
**resource.go/assets.go**
*  renamed `resources.go` to `assets.go`
*  added dark glyphs - located in assets.go -> assets/glyphs/dark/
*  moved original glyphs - located in assets.go -> assets/glyph/light/

**glyphbanner.go**
* added option to make glyphs vertical and/or dark

**rpcg.go**
* Added a random portal code generator this function takes no args and returns a string

**README.md**
* Fixed some typos (probably more to be fixed)
* Added example of vertical portal banner
* Added list of options for banner creation
* Added example of ``nmslib.RndPortal()`` usage

**go.mod**
* updated go version to 1.16
2021-05-07 16:03:08 +00:00
Raum0x2A
faf72d1f7a Deleted assets/glyphs/dark/PORTALSYMBOL.0.png, assets/glyphs/dark/PORTALSYMBOL.1.png, assets/glyphs/dark/PORTALSYMBOL.2.png, assets/glyphs/dark/PORTALSYMBOL.3.png, assets/glyphs/dark/PORTALSYMBOL.4.png, assets/glyphs/dark/PORTALSYMBOL.5.png, assets/glyphs/dark/PORTALSYMBOL.6.png, assets/glyphs/dark/PORTALSYMBOL.7.png, assets/glyphs/dark/PORTALSYMBOL.8.png, assets/glyphs/dark/PORTALSYMBOL.9.png, assets/glyphs/dark/PORTALSYMBOL.A.png, assets/glyphs/dark/PORTALSYMBOL.B.png, assets/glyphs/dark/PORTALSYMBOL.C.png, assets/glyphs/dark/PORTALSYMBOL.D.png, assets/glyphs/dark/PORTALSYMBOL.E.png, assets/glyphs/dark/PORTALSYMBOL.F.png, assets/glyphs/light/PORTALSYMBOL.0.png, assets/glyphs/light/PORTALSYMBOL.1.png, assets/glyphs/light/PORTALSYMBOL.2.png, assets/glyphs/light/PORTALSYMBOL.3.png, assets/glyphs/light/PORTALSYMBOL.4.png, assets/glyphs/light/PORTALSYMBOL.5.png, assets/glyphs/light/PORTALSYMBOL.6.png, assets/glyphs/light/PORTALSYMBOL.7.png, assets/glyphs/light/PORTALSYMBOL.8.png, assets/glyphs/light/PORTALSYMBOL.9.png, assets/glyphs/light/PORTALSYMBOL.A.png, assets/glyphs/light/PORTALSYMBOL.B.png, assets/glyphs/light/PORTALSYMBOL.C.png, assets/glyphs/light/PORTALSYMBOL.D.png, assets/glyphs/light/PORTALSYMBOL.E.png, assets/glyphs/light/PORTALSYMBOL.F.png, assets/lang/atlas-lang.csv, assets/lang/gek-lang.csv, assets/lang/korvax-lang.csv, assets/lang/vykeen-lang.csv files 2021-05-07 15:53:04 +00:00
Raum0x2A
7c5d4b5ce8 Updated 2021-05-06 22:47:55 -06:00
Raum0x2A
ad42c6bb04 Updated 2021-05-06 22:02:21 -06:00
Raum0x2A
5ca88596ff Added vertical example of portal banner 2021-05-06 21:49:17 -06:00
Raum0x2A
53d85d958b modified .gitignore 2021-05-06 20:26:45 -06:00
Raum0x2A
ea51873fe3 Upddated Go version 2021-05-06 19:58:19 -06:00
Raum0x2A
90d743286f Minor Changes 2021-05-06 16:51:09 -06:00
Raum0x2A
bc0c364dcc added .gitignore 2021-05-06 16:40:48 -06:00
Raum0x2A
43496932ef removed some debug output 2021-05-06 11:32:47 -06:00
Raum0x2A
d6bfa643a9 added assets.go 2021-05-06 11:21:35 -06:00
Raum0x2A
877517b923 exported t.Word in nmslib.Translate literal 2021-05-06 09:48:53 -06:00
Raum0x2A
ccbd68aee8 Added dark mode option to CreateBanner() func
- Fixed PORTALSYMBOL file names
- Now using image files from assets/glyphs
- CreateBanner() func options tweaked
2021-05-06 00:52:01 -06:00
Raum0x2A
5077876106 Minor changes 2021-05-06 00:51:00 -06:00
Raum0x2A
9682494ce1 Removed resources.go
`resources.go` is no more! All glyphs, and Lang files have been
extracted to the assets folder. A complete rework of
`glyphbanner.go` is begining.

 - resources.go -> DELETED
2021-05-05 22:12:14 -06:00
Raum0x2A
87bec565f1 Update .gitlab-ci.yml file 2021-05-06 02:20:08 +00:00
Raum0x2A
a7069dce7e Added section for Random Portal func 2021-05-05 19:44:49 -06:00
Raum0x2A
bc4e334ecd Minor Updates 2021-05-05 19:43:05 -06:00
Raum0x2A
9358727075 added RndPoral func to create Random Portal code 2021-05-05 18:42:00 -06:00
bradley.richins
3449ae3bf3 Updated 2020-10-28 11:40:13 -06:00
Bradley Richins
023eab03b2 Update .gitlab-ci.yml 2020-10-28 17:23:00 +00:00
Bradley Richins
5f4414df03 Update README.md 2020-10-28 16:38:05 +00:00
bradley.richins
57a1d729dd added .gitlab-ci.yml 2020-10-28 10:10:08 -06:00
bradley.richins
67db2e32ef Updated README.md 2020-10-24 10:38:28 -06:00
bradley.richins
2bb7ca6ccd Updated Recources
Improved/Fixed CSV formatting issues
2020-10-23 12:19:49 -06:00
bradley.richins
2610d98ae1 Updated Translation tests 2020-10-23 12:19:16 -06:00
bradley.richins
32d533ff61 Added supprot for Gek, Vykeen and Atlas
Eng2Atl & Atl2Eng - NEW
Eng2Gek & Gek2Eng - NEW
Eng2Vyk & Vyk2Eng - NEW
Eng2Kor & Kor2Eng
2020-10-23 12:15:34 -06:00
bradley.richins
ac68a20697 Updated recources
korvax-lang.csv
glyphs/GLYPH-0.png
glyphs/GLYPH-1.png
glyphs/GLYPH-2.png
glyphs/GLYPH-3.png
glyphs/GLYPH-4.png
glyphs/GLYPH-5.png
glyphs/GLYPH-6.png
glyphs/GLYPH-7.png
glyphs/GLYPH-8.png
glyphs/GLYPH-9.png
glyphs/GLYPH-A.png
glyphs/GLYPH-B.png
glyphs/GLYPH-C.png
glyphs/GLYPH-D.png
glyphs/GLYPH-E.png
glyphs/GLYPH-F.png

atlas-lang.csv  - NEW
gek-lang.csv    - NEW
vykeen-lang.csv - NEW
2020-10-23 09:48:14 -06:00
bradley.richins
0b90141dcd Updated README.md
https://gitlab.com/bradley.richins/nmslib/-/tree/develop#translate-korvax-to-english-with-korvax2eng
https://gitlab.com/bradley.richins/nmslib/-/tree/develop#translate-english-to-korvax-with-eng2korvax

https://gitlab.com/bradley.richins/nmslib/-/tree/develop#usage
2020-10-22 13:43:26 -06:00
bradley.richins
5bc5711f09 Updated README.md
https://gitlab.com/bradley.richins/nmslib/-/tree/develop#translate-korvax-to-english-with-korvax2eng
https://gitlab.com/bradley.richins/nmslib/-/tree/develop#translate-english-to-korvax-with-eng2korvax
2020-10-22 13:38:16 -06:00
bradley.richins
00411f015c Complete redesign of lang.go
Some code is now reusable

- openCSV()
- toKor()
- toEng()

the new translation syantax is

```golang
korvax := Translate{"Contraband"}
fmt.Println(korvax.Eng2Kor())
// or
fmt.Println(Translate{"KIHTYOMOLES"}.Kor2Eng())
```

output:

`Zelidovoso`
2020-10-22 13:11:03 -06:00
bradley.richins
ab9799b273 Rewrite on all lang translation tests 2020-10-22 13:10:59 -06:00
bradley.richins
d8dbc66b27 Added/Changed tests
Changed or added the fallowing tests
TestPortal2Galactic:
	P2gc("41EDF9554C2F")

TestGalactic2portal:
	Gc2p("042F:0079:0D55:006A", 1)
	Gc2p("042E:0078:0D53:01ED", 4)

TestKorvax2Eng:
	Korvax2Eng("rodiashikhv")
	Korvax2Eng("KIHTYOMOLES")
	Korvax2Eng("Zelidovoso")
	Eng2Korvax("contraband")
	Eng2Korvax("CONTRABAND")
	Eng2Korvax("Contraband")
2020-10-21 11:36:20 -06:00
bradley.richins
08ed8866d0 Improved translations
Upper case and CAPLOCK words are now properly translated

Began prepering code for rewrite
TODO:   make code reusable\
	add support for:
		Gek
		Vykeen
		Atlas

added some annotations
2020-10-21 11:28:26 -06:00
bradley.richins
620d0ef9de Improved Galactic coords to protal code conversion
Removed un-needed error check

Added ability to pick planet id (0-6)
   Gc2p(gc string) ->> Gc2p(gc string, p int)
2020-10-21 11:26:54 -06:00
bradley.richins
312d38ac6d Updated: add package module github.com/nfnt/resize 2020-10-20 19:17:54 -06:00
bradley.richins
4aec0e4e9a Auto resize image to 768x64
Using http://github.com/nfnt/resize to resize banners
2020-10-20 19:15:06 -06:00
bradley.richins
4f1002ee2d Optimized 2020-10-20 16:23:57 -06:00
bradley.richins
f291891139 Temp directory renamed to nms-{SEED} 2020-10-20 15:14:42 -06:00
bradley.richins
230cefb85d Temp files are now stored in system temp dir 2020-10-20 14:47:04 -06:00
bradley.richins
84df8142c6 Updated 2020-10-20 14:45:49 -06:00
bradley.richins
38e45c4f60 Minnor change
Renamed strut Korvaxlang to KorvaxWord and
English > english
KorvaxWord > korvax
KWCaps > kwcaps
KWALLCAPS > kwallcaps
2020-10-20 12:43:19 -06:00
bradley.richins
221f4e59e1 Updated README.md 2020-10-20 00:08:37 -06:00
bradley.richins
8ccafd5c0c Renamed from LICENSE 2020-10-20 00:06:19 -06:00
bradley.richins
59fcf3e2f0 Renamed to COPYING 2020-10-20 00:05:33 -06:00
bradley.richins
59cc61105a Updated README.md 2020-10-19 22:37:00 -06:00
bradley.richins
ea438a7f40 Example Glyph Banner 2020-10-19 22:36:42 -06:00
21 changed files with 1842 additions and 908 deletions

6
.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
assets/
.vscode/
notes.txt
Test.png
test.png
coverage.txt

30
.gitlab-ci.yml Normal file
View File

@@ -0,0 +1,30 @@
# This file is a template, and might need editing before it works on your project.
image: golang:latest
include:
- template: Security/License-Scanning.gitlab-ci.yml
variables:
# Please edit to your GitLab project
REPO_NAME: gitlab.com/Raum0x2A/nmslib
# The problem is that to be able to use go get, one needs to put
# the repository in the $GOPATH. So for example if your gitlab domain
# is gitlab.com, and that your repository is namespace/project, and
# the default GOPATH being /go, then you'd need to have your
# repository in /go/src/gitlab.com/namespace/project
# Thus, making a symbolic link corrects this.
before_script:
- mkdir -p $GOPATH/src/$(dirname $REPO_NAME)
- ln -svf $CI_PROJECT_DIR $GOPATH/src/$REPO_NAME
- cd $GOPATH/src/$REPO_NAME
stages:
- test
format:
stage: test
script:
- go fmt $(go list ./...)
- go vet $(go list ./...)
- go test

View File

BIN
NMH-BlueDream.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 307 KiB

216
README.md
View File

@@ -1,43 +1,233 @@
# NMSlib # NMSlib
[![](https://img.shields.io/badge/License%20-MIT-green)](COPYING)
[![GoDoc](https://godoc.org/gitlab.com/Raum0x2A/nmslib?status.svg)](https://godoc.org/gitlab.com/Raum0x2A/nmslib)
[![](https://img.shields.io/gitlab/pipeline/Raum0x2A/nmslib/master?label=Master&logo=go)](https://gitlab.com/Raum0x2A/nmslib)
[![](https://img.shields.io/gitlab/pipeline/Raum0x2A/nmslib/develop?label=Develop&logo=go)](https://gitlab.com/Raum0x2A/nmslib/-/tree/develop)
[![](https://img.shields.io/badge/Release-v1.0.1-blue?style=flat&logo=go)](https://gitlab.com/Raum0x2A/nmslib/-/releases/v1.0.1)
[![Go Report Card](https://goreportcard.com/badge/gitlab.com/Raum0x2A/nmslib)](https://goreportcard.com/report/gitlab.com/Raum0x2A/nmslib)
NMSlib is a GoLang package for dealing with converting Galactic coordinates to Portal codes and vice versa. 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. NMSlib also translates in game languages (Korvax, Gek Vy'Keen and Atlas) to english, and create portal banners.
- Gek, Vykeen, etc will be added in the future
## Installation ## Installation
To install this module use `go get` To install this module use `go get`
```bash ```golang
go get -u gitlab.com/bradley.richins/nmslib go get -u gitlab.com/Raum0x2A/nmslib
``` ```
## Usage ## Usage
### Example:
```golang ```golang
package main package main
import ( import (
"fmt" "fmt"
"gitlab.com/bradley.richins/nmslib" "gitlab.com/Raum0x2A/nmslib"
) )
func main() { func main() {
portalcode := "006afa556c30" portalcode := "21F2F8EDB94D"
tstvar, err := nmslib.P2gc(portalcode) galacticCoords, err := nmslib.P2gc(portalcode)
if err != nil { if err != nil {
panic(err) panic(err)
} }
fmt.Printf("Input: \t%s\nExpecting: \t042F:0079:0D55:006A\nHave: \t%s\n", portalcode, tstvar) fmt.Printf("Input:\t%s\nOutput:\t%s\n", portalcode, galacticCoords)
nmslib.CreateBanner(portalcode, "NewLennon.png", 0)
fmt.Println(nmslib.Korvax2Eng("eapoluch")) g2p, err := nmslib.Gc2p("014C:0077:06DA:01F2", 2)
fmt.Println(nmslib.Eng2Korvax("emergency")) if err != nil {
panic(err)
}
fmt.Printf("Input:\t014C:0077:06DA:01F2\nOutput:\t%s\n", g2p)
_ := nmslib.CreateBanner(portalcode, "./NMH-BlueDream.png", 0)
_ := nmslib.CreateBanner(nmslib.RndPortal(), "./Random.png", 0)
fmt.Println(nmslib.Translate{Lang: "korvax"}.ToEng("KIHTYOMOLES"))
korvax := nmslib.Translate{"english"}
fmt.Println(korvax.ToKorvax("Contraband"))
}
```
## Creating a Glyph banner
This function takes 3 parameters and reurns an error
* 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 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
err := nmslib.CreateBanner("21F2F8EDB94D", "NMH-BlueDream.png", 0)
if err !=nil {
panic(err)
} }
``` ```
## License ![](NMH-BlueDream.png)
[MIT](https://choosealicense.com/licenses/mit/)
Vertical layout for a random address
```golang
err := nmslib.CreateBanner(nmslib.RndPortal(), "ranportal.png", 11)
if err != nil {
panic(err)
}
```
![](ranportal_scaled.png)
_Note: Image shown in readme.md's vertical example have been scaled down in gimp for easier viewing on gitlab._
_Original ranportal.png: 256x3072px_
### Converting Portal code to Galactic address
This function only takes 1 parameter and returns a string and error
* portalcode: 12 char hex string of portal glyphs
**Example:**
```golang
ga, _ := nmslib.P2gc("21F2F8EDB94D")
fmt.Println(ga)
```
Output:
``014C:0077:06DA:01F2``
### Converting Galactic coordinates to Portal codes
This function only takes 2 parameters and returns a string and error
* galacticaddress: 16 char 4 block hex address
* Planet ID [1-6]
**Example:**
```golang
pc, _ := nmslib.Gc2p("014C:0077:06DA:01F2", 2)
fmt.Println(pc)
```
Output:
``21F2F8EDB94D``
## Translate Words
Supported languages
- Korvax
- Gek
- Vy'keen
- Atlas
### Translate Atlas to English
This function takes only 1 parameter and returns a string
* Word: Any known Atlas word (ex. Paka)
_note: Translating to english will **always** result in the lowercase equivilent word_
**Example:**
```golang
fmt.Println(nmslib.Translate{Lang: "atlas"}.ToEng("Paka"))
```
Output:
``awake``
### Translate English to Korvax
This function takes only 1 parameter and returns a string
* engword: English word to attempt conversion
**Example:**
```golang
korvax := nmslib.Translate{"english"}
fmt.Println(korvax.ToKorvax("Contraband"))
```
Output:
``Zelidovoso``
### Language commands
- ``Translate{Lang: ``string``}.ToEng(``string``)``
- ``Translate{Lang: ``string``}.ToKorvax(``string``)``
- ``Translate{Lang: ``string``}.ToGek(``string``)``
- ``Translate{Lang: ``string``}.ToVykeen(``string``)``
- ``Translate{Lang: ``string``}.ToAtlat(``string``)``
#### Possible Lang string options
- ``"english"``
- ``"korvax"``
- ``"gek"``
- ``"vykeen"``
- ``"atlas"``
## Random Portal address
Generate random portal codes
- Atlas Station
- Black Hole
- Random address
All random address created will default to the planet index 1 to help ensure there the address is valid
**Example:**
```golang
fmt.Println(nmslib.RndPortal())
fmt.Println(nmslib.RndPortal())
fmt.Println(nmslib.RndAtlas())
fmt.Println(nmslib.RndBH())
```
**Output examples:**
``10EFABDEA373``
``11EAB355FC8E``
``107AC0E190D1``
``10796D57AE15``
<hr>
## A Proud member of NMH Hub
### [![NMH Official Page](https://static.wikia.nocookie.net/nomanssky_gamepedia/images/5/5a/NMH_Banner_Hub.png/revision/latest/scale-to-width-down/85?cb=20201210044657)](https://nomanssky.fandom.com/wiki/No_Man%27s_High_Hub) [![Discord Server](https://img.shields.io/badge/Discord-Invite-blue?&logo=discord&logoColor=white)](https://discord.gg/mhRxf29hns)

1050
assets.go Normal file

File diff suppressed because one or more lines are too long

View File

@@ -1,3 +1,8 @@
/*
Xainesworld Video: https://www.youtube.com/watch?v=xmZbkTahw4w
Fandom Wiki: https://nomanssky.fandom.com/wiki/Portal_address
*/
package nmslib package nmslib
import ( import (
@@ -7,21 +12,11 @@ import (
"strings" "strings"
) )
/*
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/
*/
/* /*
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) Returns var string: Galactic address (ex. 042F:0079:0D55:006A)
Return var string
Galactic address (ex. 042F:0079:0D55:006A)
*/ */
func P2gc(p string) (gc string, err error) { func P2gc(p string) (gc string, err error) {
if len(p) == 12 { // Test if length of provided string is 12 chars long if len(p) == 12 { // Test if length of provided string is 12 chars long
@@ -30,19 +25,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
@@ -63,29 +58,30 @@ func P2gc(p string) (gc string, err error) {
gc = fmt.Sprintf("%04X:%04X:%04X:%04X", coord[3], coord[1], coord[2], coord[0]) gc = fmt.Sprintf("%04X:%04X:%04X:%04X", coord[3], coord[1], coord[2], coord[0])
} else { // if len(p) != 12 return an error } 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 return // return formated string
} }
/* /*
Gc2p - Galactic coordinates to portal code 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 var gc string: Galactic address (ex. 042F:0079:0D55:006A)
Galactic address (ex. 042F:0079:0D55:006A) var p int: Planet ID [1-6]
Return var string Returns 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) (portalcode string, err error) { func Gc2p(gc string, p int) (portalcode string, err error) {
if err != nil {
panic(err)
}
/*TODO: add option for Planet choice (1-6)*/
// 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
coords := strings.Split(gc+":1", ":") if len(gc) != 19 {
return "", errors.New("galatic code is the wrong length")
}
if p > 6 {
p = 1
}
nustring := fmt.Sprintf("%s:%d", gc, p)
coords := strings.Split(nustring, ":")
for n := 0; n < len(coords); n++ { for n := 0; n < len(coords); n++ {
portalcode = portalcode + coords[n] portalcode = portalcode + coords[n]
} }
@@ -93,26 +89,30 @@ func Gc2p(gc string) (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
/*Note:
[P][SSS][YY][ZZZ][XXX] len == 12
* SSS == SSI
*/
hexCoords[2] = hexCoords[2] + 0x81 // Y ->> shift hexCoords[2] = hexCoords[2] + 0x81 // Y ->> shift
hexCoords[3] = hexCoords[3] + 0x801 // Z ->> shift hexCoords[3] = hexCoords[3] + 0x801 // Z ->> shift
hexCoords[4] = hexCoords[4] + 0x801 // X ->> shift hexCoords[4] = hexCoords[4] + 0x801 // X ->> shift
@@ -124,6 +124,7 @@ func Gc2p(gc string) (portalcode string, err error) {
} }
// Assemble padded values as a string // Assemble padded values as a string
portalcode = fmt.Sprintf("%00X%03X", hexCoords[0], hexCoords[1]) portalcode = fmt.Sprintf("%00X%03X", hexCoords[0], hexCoords[1])
for n := 2; n < len(hexCoords); n++ { for n := 2; n < len(hexCoords); n++ {
if n == 2 { if n == 2 {
@@ -132,5 +133,5 @@ func Gc2p(gc string) (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,91 +1,128 @@
package nmslib package nmslib
import ( import (
"errors"
"fmt" "fmt"
"image/png" "image"
"io/ioutil" "io/ioutil"
"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: Output name of PNG file
var savename string var opt int
Output name of PNG file 00 sets horizontal banner in light mode [ 00 || 0 ]
var vopt int 01 sets horizontal banner in dark mode [ 01 || 1 ]
1 enables vertical banner 10 sets vertical banner in light mode
0 enables horizontal banner 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, vopt int) { func CreateBanner(portalhex string, savename string, opt int) (err error) {
var err error out, err := GenRawBanner(portalhex, opt)
if err != nil {
return
}
gg.SavePNG(savename+".png", out)
//gg.SaveJPG(savename+".jpg", out, 50)
return
}
/*GenRawBanner - Returns image.Image of genorated image
Requires 2 vars and returns image.Image (raw image data) and an error
var portalex string: Portal Glyph hex string
var opt int
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
11 sets vertical banner in dark mode
* note first of the 2 bits sets the layout, the second bit sets the glyph color
*/
func GenRawBanner(portalhex string, layout int) (portalbanner image.Image, err error) {
var GlyphHex [12]int64 var GlyphHex [12]int64
var glyphImg [12]string var glyphImg [12]string
var mode string
var imgArray [12]image.Image
//Set light or dark mode glyphs
if layout == 00 || layout == 10 {
mode = "light"
} else if layout == 01 || layout == 11 {
mode = "dark"
} else {
// if layout is an invalid option (ie. not a 2 bit binary number default to classic mode/layout
layout = 0
mode = "light"
}
// 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 nil, errors.New("string provided is not hexadecimal ([0-9][A-F])")
} }
} }
// assign image location of its glyph hex value to an array of strings
// 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("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/
// 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 nil, errors.New("can not load images from assets: " + glyphImg[k])
} }
_, err2 := os.Stat("tmp.nmslib/glyphs") err = ioutil.WriteFile(NmsTemp+"/"+glyphImg[k], []byte(data), 0644)
if os.IsNotExist(err2) {
errDir := os.MkdirAll("tmp.nmslib/glyphs", 0755)
if errDir != nil {
panic(errDir)
}
}
err = ioutil.WriteFile(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]},
}
if vopt == 1 {
// Merge images horizontally
rgba, err := gim.New(grids, 1, 12).Merge()
if err != nil { if err != nil {
panic(err) return nil, errors.New("can not write file to temp directory")
}
}
//Load/open images needed
for iter := 0; iter < 12; iter++ {
imgArray[iter], err = gg.LoadPNG(NmsTemp + "/" + glyphImg[iter])
if err != nil {
return nil, 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()
//Set Layout
//classic horizontal layout
if layout == 01 || layout == 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)
}
return concat.Image(), nil
}
//Vertical layout
if layout == 10 || layout == 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)
}
return concat.Image(), nil
} }
// 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 { } else {
// Merge images vertically return nil, errors.New("portalcode must be exactly 12 chars")
rgba, err := gim.New(grids, 12, 1).Merge()
if err != nil {
panic(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)
} }
return
} }

10
go.mod
View File

@@ -1,5 +1,9 @@
module gitlab.com/bradley.richins/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.1-0.20210131172831-af4cd580789b
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.1-0.20210131172831-af4cd580789b h1:gqOBIAmkc/ZxXzFrM4wTub7tD0xYaOsaOQ5wOA74lJQ=
github.com/ozankasikci/go-image-merge v0.2.2/go.mod h1:NQ2aN0b21buFx3p+5x4dZrKuPSLh2uBukK7F30BrYTo= github.com/fogleman/gg v1.3.1-0.20210131172831-af4cd580789b/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=

71
init.go Normal file
View 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+"/assets/lang/"+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
View 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)
}

226
lang.go
View File

@@ -2,126 +2,140 @@ package nmslib
import ( import (
"encoding/csv" "encoding/csv"
"fmt"
"io/ioutil"
"os" "os"
"strings" "strings"
) )
/* /*Translate Game languages and english
Korvaxlang - set up structure of a word iteration Translate.Lang sets source language for translations
options are:
korvax
gek
vykeen
atlas
english
*/ */
type Korvaxlang struct { type Translate struct {
English string Lang string
KorvaxWord string
KWCaps string
KWALLCAPS string
} }
/* /*Translate source language to english
Korvax2Eng - convert known korvax words into english Translate any NMS language (ie. Korvax) to english
*/ */
func Korvax2Eng(kvwrd string) string { func (t Translate) ToEng(word string) (translation string) {
data, err := Asset("tmp.nmslib/korvax-lang.csv") //return translate2english(word, langFile(t.Lang))
return Translator(word, t.Lang, "english")
}
/*Translate source language to Korvax
Translate any NMS language or english (ie. Gek) to Korvax
*/
func (t Translate) ToKorvax(word string) (translation string) {
return Translator(word, t.Lang, "korvax")
}
/*Translate source language to Vy'Keen
Translate any NMS language or english (ie. Atlas) to Vy'Keen
*/
func (t Translate) ToVykeen(word string) (translation string) {
return Translator(word, t.Lang, "vykeen")
}
/*Translate source language to Gek
Translate any NMS language or english (ie. Vy'Keen) to Gek
*/
func (t Translate) ToGek(word string) (translation string) {
return Translator(word, t.Lang, "Gek")
}
/*Translate source language to Atlas
Translate any NMS language or english (ie. Korvax) to Atlas
*/
func (t Translate) ToAtlas(word string) (translation string) {
return Translator(word, t.Lang, "atlas")
}
// read language files
func langFile(lang string) [][]string {
filepath := NmsTemp + "/assets/lang/" + lang + "-lang.csv"
csvFile, err := os.Open(filepath)
if err != nil { if err != nil {
panic(err) panic(err)
} }
_, 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() 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
}
/* lines, err := csv.NewReader(csvFile).ReadAll()
Eng2Korvax - Convert (some) english words to Korvax
*/
func Eng2Korvax(enwrd string) string {
data, err := Asset("tmp.nmslib/korvax-lang.csv")
if err != nil { if err != nil {
panic(err) panic(err)
} }
_, err2 := os.Stat("tmp.nmslib/") return lines
if os.IsNotExist(err2) { }
errDir := os.MkdirAll("tmp.nmslib/", 0755)
if errDir != nil { /*Translate any in game language to another including english (ie. Korvax to Gek)
panic(errDir) Translating from english to a game language will alway default to all lower case for now
} */
} func Translator(word string, source string, target string) string {
err = ioutil.WriteFile("tmp.nmslib/korvax-lang.csv", []byte(data), 0644) var sourcekey [4]string
csvFile, err := os.Open("tmp.nmslib/korvax-lang.csv") var targetkey [4]string
if err != nil { var dmy string
fmt.Println(err) var rt string
}
defer csvFile.Close() rt = "*\\Kzzzzzzt\\*"
CsvLines, err := csv.NewReader(csvFile).ReadAll()
if err != nil { if source == "english" {
fmt.Println(err) dmy = target
} } else {
for _, line := range CsvLines { dmy = source
klang := Korvaxlang{ }
English: line[0], for _, line := range langFile(dmy) {
KorvaxWord: line[1], for _, trans := range line {
KWCaps: line[2], if trans == word {
KWALLCAPS: line[3], sourcekey[0] = line[0]
} sourcekey[1] = line[1]
if enwrd == klang.English { sourcekey[2] = line[2]
errDir := os.RemoveAll("tmp.nmslib") sourcekey[3] = line[3]
if errDir != nil { }
panic(errDir) }
} if target != "english" {
return klang.KorvaxWord for _, line := range langFile(target) {
} if strings.EqualFold(line[0], sourcekey[0]) {
} targetkey[0] = line[0]
// remove recource folder to keep it clean targetkey[1] = line[1]
errDir := os.RemoveAll("tmp.nmslib") targetkey[2] = line[2]
if errDir != nil { targetkey[3] = line[3]
panic(errDir) }
} }
return "*\\Kzzzzzzt\\*" // word not found default if strings.EqualFold(word, sourcekey[0]) {
if targetkey[0] != "" {
rt = targetkey[0]
}
} else if strings.EqualFold(word, sourcekey[1]) {
if targetkey[1] != "" {
rt = targetkey[1]
}
} else if strings.EqualFold(word, sourcekey[2]) {
if targetkey[2] != "" {
rt = targetkey[2]
}
} else if strings.EqualFold(word, sourcekey[3]) {
if targetkey[3] != "" {
rt = targetkey[3]
}
}
if source == "english" {
rt = targetkey[1]
}
} else {
if strings.EqualFold(word, sourcekey[0]) {
rt = sourcekey[0]
} else if strings.EqualFold(word, sourcekey[1]) {
rt = strings.ToLower(sourcekey[0])
} else if strings.EqualFold(word, sourcekey[2]) {
rt = strings.Title(sourcekey[0])
} else if strings.EqualFold(word, sourcekey[3]) {
rt = strings.ToUpper(sourcekey[0])
}
}
}
return rt
} }

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("Testing Gc2p(\"014C:0077:06DA:01F2\"): got %q, want: 21F2F8EDB94D.\n", want)
} else {
fmt.Printf("Testing 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"
err := CreateBanner(rp, fileout, 0)
if err != nil {
fmt.Println(err)
}
fmt.Printf("Portal address `%s` rendered as `%s`\n", rp, fileout)
}

21
nmslib-rpcg_test.go Normal file
View File

@@ -0,0 +1,21 @@
package nmslib
import (
"fmt"
"testing"
)
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())
}

36
nmslib-translate_test.go Normal file
View File

@@ -0,0 +1,36 @@
package nmslib
import (
"fmt"
"testing"
)
func TestTranslate(t *testing.T) {
kor2eng := Translate{Lang: "korvax"}
if kor2eng.ToEng("Alinichel") != "Emergency" {
t.Errorf("\nTesting Translate{Lang: \"korvax\"}.ToEng(\"Alinichel\"): got %q, want: %q.\n", kor2eng.ToEng("Alinichel"), "Emergency")
} else {
fmt.Printf("\nTesting Translate{Lang: \"korvax\"}.ToEng(\"Alinichel\"): got %q, want: %q.\n", kor2eng.ToEng("Alinichel"), "Emergency")
}
vyk2eng := Translate{"vykeen"}
if vyk2eng.ToEng("Aqo") != "Foes" {
t.Errorf("Testing Translate{Lang: \"vykeen\"}.ToEng(\"Aqo\"): got %q, want: %q.\n", vyk2eng.ToEng("Aqo"), "Foes")
} else {
fmt.Printf("Testing Translate{Lang: \"vykeen\"}.ToEng(\"Aqo\"): got %q, want: %q.\n", vyk2eng.ToEng("Aqo"), "Foes")
}
engWord := Translate{"english"}
if engWord.ToKorvax("learn") != "achi" {
t.Errorf("Testing Translate{Lang: \"english\"}.ToKor(\"learn\"): got %q, want: %q.\n", engWord.ToKorvax("learn"), "achi")
} else {
fmt.Printf("Testing Translate{Lang: \"english\"}.ToKor(\"learn\"): got %q, want: %q.\n", engWord.ToKorvax("learn"), "achi")
}
fmt.Println("Blind Test: " + Translate{"gek"}.ToAtlas("baturk")) // word does not exist in Atlas lang
fmt.Println("Blind Test: " + Translate{"gek"}.ToAtlas("Tor")) // word exists
fmt.Println("Running CleanUp()")
CleanUp()
fmt.Printf("\nTesting complete.\nStatus: ")
}

View File

@@ -1,78 +0,0 @@
package nmslib
import (
"fmt"
"testing"
)
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")
}
}
func TestGalactic2portal(t *testing.T) {
want, err := Gc2p("042F:0079:0D55:006A")
if err != nil {
panic(err)
}
if want != "106AFA556C30" {
t.Errorf("Testing 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")
}
want, err = Gc2p("044B:0081:0D68:0096")
if err != nil {
panic(err)
}
if want != "109602569C4C" {
t.Errorf("Testing Gc2p(\"044B:0081:0D68:0096\"): got %q, want: %q.\n", want, "109602569C4C")
} else {
fmt.Printf("Testing Gc2p(\"044B:0081:0D68:0096\"): got: %q, want: %q.\n", want, "109602569C4C")
}
}
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: ")
}

BIN
ranportal_scaled.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

File diff suppressed because one or more lines are too long

92
rpcg.go Normal file
View File

@@ -0,0 +1,92 @@
/*
[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
*/
package nmslib
import (
"fmt"
"math/rand"
"time"
)
/*
RndPortal - Random Portalcode generator
Requires no input required and returns a string
*/
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
}
/*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
}