1
0
forked from MTSR/mapserver

working block id mappings

This commit is contained in:
Thomas Rudin 2019-01-07 19:53:05 +01:00
parent d9db2c1d67
commit a311c7c2e3
3 changed files with 46 additions and 5 deletions

View File

@ -1,15 +1,17 @@
package mapblockparser
type MapBlock struct {
Version byte
Underground bool
Mapdata []byte
Metadata Metadata
Version byte
Underground bool
Mapdata []byte
Metadata Metadata
BlockMapping map[int]string
}
func NewMapblock() MapBlock {
mb := MapBlock{}
mb.Metadata = NewMetadata()
mb.BlockMapping = make(map[int]string)
return mb
}

View File

@ -53,5 +53,39 @@ func Parse(data []byte) (*MapBlock, error) {
return nil, err
}
offset += count
//static objects
offset++ //static objects version
staticObjectsCount := readU16(data, offset)
offset += 2
for i := 0; i < staticObjectsCount; i++ {
offset += 13
dataSize := readU16(data, offset)
offset += dataSize + 2
}
//timestamp
offset += 4
//mapping version
offset++
numMappings := readU16(data, offset)
offset += 2
for i := 0; i < numMappings; i++ {
nodeId := readU16(data, offset)
offset += 2
nameLen := readU16(data, offset)
offset += 2
blockName := string(data[offset : offset+nameLen])
offset += nameLen
mapblock.BlockMapping[nodeId] = blockName
}
return &mapblock, nil
}

View File

@ -1,6 +1,7 @@
package mapblockparser
import (
"fmt"
"io/ioutil"
"strconv"
"testing"
@ -72,11 +73,15 @@ func TestParse2(t *testing.T) {
t.Error(err)
}
_, err = Parse(data)
mapblock, err := Parse(data)
if err != nil {
t.Error(err)
}
for k, v := range mapblock.BlockMapping {
fmt.Println("Key", k, "Value", v)
}
}
func TestParse3(t *testing.T) {