gonx

package module
v0.0.0-...-50be359 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2020 License: MIT Imports: 7 Imported by: 2

README

gonx

Parse NX files and extract data from a the tree.

Usage

package main

import "github.com/Hucaru/gonx"

func main() {
    nodes, textLookup, bitmaps, audio, err := gonx.Parse(fname)

    if err != nil {
        panic(err)
    }

    found := gonx.FindNode("element/childEment/grandchildElement", nodes, textLookup, func(node *gonx.Node) {
        // if image
        img, x, y, err := node.GetBitmap(bitmaps)

        // if audio
        sound, err := node.GetAudio(audio)

        // node.Type - 1 = int64, 2 = float64
        data = node.Data
    })

    if !found {
        panic(fmt.Errorf("Not a valid node"))
    }
}

Benchmarks

To run the benchmark tests type go test -run=XXX -bench=.

i5-3570k @ 3.40GHz

goos: windows
goarch: amd64
pkg: github.com/Hucaru/gonx
BenchmarkParse-4              20          86080150 ns/op
BenchmarkExtract-4            30          33965990 ns/op
PASS
ok      github.com/Hucaru/gonx  4.463s

i5 @ 2.40GHz

goos: darwin
goarch: amd64
pkg: github.com/Hucaru/gonx
BenchmarkParse-4   	      10	 113918050 ns/op
PASS
ok  	github.com/Hucaru/gonx	2.040s

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DataToBool

func DataToBool(data byte) bool

DataToBool the nx payload

func DataToFloat64

func DataToFloat64(data [8]byte) float64

DataToFloat64 the nx payload

func DataToInt16

func DataToInt16(data [8]byte) int16

DataToInt16 the nx payload

func DataToInt32

func DataToInt32(data [8]byte) int32

DataToInt32 the nx payload

func DataToInt64

func DataToInt64(data [8]byte) int64

DataToInt64 the nx payload

func DataToUint16

func DataToUint16(data [8]byte) uint16

DataToUint16 the nx payload

func DataToUint32

func DataToUint32(data [8]byte) uint32

DataToUint32 the nx payload

func DataToUint64

func DataToUint64(data [8]byte) uint64

DataToUint64 the nx payload

func FindNode

func FindNode(search string, nodes []Node, textLookup []string, fnc func(*Node)) bool

FindNode with certain name e.g. element/sublement/grandchild

Types

type Node

type Node struct {
	NameID     uint32
	ChildID    uint32
	ChildCount uint16
	Type       uint16
	Data       [8]byte
}

Node in nx file

func Parse

func Parse(fname string) ([]Node, []string, [][]byte, [][]byte, error)

Parse the nx file

func (Node) GetAudio

func (n Node) GetAudio(audio [][]byte) ([]byte, error)

GetAudio from the audio corresponding to this node

func (Node) GetBitmap

func (n Node) GetBitmap(bitmaps [][]byte) ([]byte, uint16, uint16, error)

GetBitmap data along with x,y information

type Vector

type Vector struct {
	X, Y int32
}

Vector type

func DataToVector

func DataToVector(data [8]byte) Vector

DataToVector the nx payload

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL