forked from MTSR/mapserver
working metadata parsing
This commit is contained in:
parent
01d8fa4f56
commit
bb072bcf62
@ -34,3 +34,7 @@ func testCoordConvert(t *testing.T, mb MapBlockCoords) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestZeorCoord(t *testing.T) {
|
||||
testCoordConvert(t, NewMapBlockCoords(0,0,0))
|
||||
}
|
||||
|
@ -103,6 +103,9 @@ func parseMetadata(mapblock *MapBlock, data []byte) (int, error) {
|
||||
txt := scanner.Text()
|
||||
offset += len(txt) + 1
|
||||
|
||||
log.WithFields(logrus.Fields{"txt":txt, "position":position}).Info("Parsing inventory")
|
||||
|
||||
|
||||
if strings.HasPrefix(txt, INVENTORY_START) {
|
||||
pairs := strings.Split(txt, " ")
|
||||
currentInventoryName = &pairs[1]
|
||||
@ -138,6 +141,8 @@ func parseMetadata(mapblock *MapBlock, data []byte) (int, error) {
|
||||
item.Count = int(val)
|
||||
}
|
||||
|
||||
currentInventory.Items = append(currentInventory.Items, item)
|
||||
|
||||
}
|
||||
|
||||
} else if txt == INVENTORY_TERMINATOR {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"mapserver/coords"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
@ -94,3 +95,20 @@ func TestParse3(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseMetadata(t *testing.T) {
|
||||
|
||||
data, err := ioutil.ReadFile("testdata/mb-with-metadata.bin")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
mb, err := Parse(data, 0, coords.NewMapBlockCoords(0, 0, 0))
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
str, err := json.MarshalIndent(mb, "", " ")
|
||||
fmt.Println(string(str))
|
||||
}
|
||||
|
BIN
mapblockparser/testdata/mb-with-metadata.bin
vendored
Normal file
BIN
mapblockparser/testdata/mb-with-metadata.bin
vendored
Normal file
Binary file not shown.
@ -42,6 +42,12 @@ func CreateTestDatabase(filename string) error {
|
||||
return copy(filepath.Dir(currentfilename)+"/testdata/map.sqlite", filename)
|
||||
}
|
||||
|
||||
//DB with metadata at 0,0,0
|
||||
func CreateTestDatabase2(filename string) error {
|
||||
_, currentfilename, _, _ := runtime.Caller(0)
|
||||
return copy(filepath.Dir(currentfilename)+"/testdata/map2.sqlite", filename)
|
||||
}
|
||||
|
||||
func CreateEmptyDatabase(filename string) {
|
||||
db, err := sql.Open("sqlite3", filename)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user