From 8d0fcebb173cb0dce9129eb6cde2e4450b92144b Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Fri, 18 Jan 2019 15:18:42 +0100 Subject: [PATCH] mapblock size --- mapblockparser/mapblock.go | 1 + mapblockparser/parse.go | 7 ++++--- mapdb/accessor.go | 8 ++++---- mapobject/clearmapdata.go | 6 +++--- mapobject/poi.go | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/mapblockparser/mapblock.go b/mapblockparser/mapblock.go index b59ebd4..57225af 100644 --- a/mapblockparser/mapblock.go +++ b/mapblockparser/mapblock.go @@ -1,6 +1,7 @@ package mapblockparser type MapBlock struct { + Size int `json:"size"` Version byte `json:"version"` Underground bool `json:"underground"` Mapdata []byte `json:"mapdata"` diff --git a/mapblockparser/parse.go b/mapblockparser/parse.go index 4658a8b..4a384e7 100644 --- a/mapblockparser/parse.go +++ b/mapblockparser/parse.go @@ -6,13 +6,14 @@ import ( ) func Parse(data []byte, mtime int64) (*MapBlock, error) { - mapblock := NewMapblock() - mapblock.Mtime = mtime - if len(data) == 0 { return nil, errors.New("no data") } + mapblock := NewMapblock() + mapblock.Mtime = mtime + mapblock.Size = len(data) + offset := 0 // version diff --git a/mapdb/accessor.go b/mapdb/accessor.go index e2be14f..1c4c9c4 100644 --- a/mapdb/accessor.go +++ b/mapdb/accessor.go @@ -7,13 +7,13 @@ import ( type MapData struct { //mapblock position MBPos coords.MapBlockCoords - + //block position X, Y, Z int - Type string - Data string - Mtime int64 + Type string + Data string + Mtime int64 } type SearchQuery struct { diff --git a/mapobject/clearmapdata.go b/mapobject/clearmapdata.go index 7bb1117..8cafd88 100644 --- a/mapobject/clearmapdata.go +++ b/mapobject/clearmapdata.go @@ -12,7 +12,7 @@ type ClearMapData struct { func (this *ClearMapData) OnParsedMapBlock(block *mapblockparser.MapBlock, pos coords.MapBlockCoords) { err := this.db.RemoveMapData(pos) - if err != nil { - panic(err) - } + if err != nil { + panic(err) + } } diff --git a/mapobject/poi.go b/mapobject/poi.go index 7663a52..5229dbc 100644 --- a/mapobject/poi.go +++ b/mapobject/poi.go @@ -12,7 +12,7 @@ type POI struct { func (this *POI) OnParsedMapBlock(block *mapblockparser.MapBlock, pos coords.MapBlockCoords) { var found bool - for _, v := range(block.BlockMapping) { + for _, v := range block.BlockMapping { if v == "mapserver:poi" { found = true break