From f132363342994662456a451add04d59a4cb6fe73 Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Thu, 24 Jan 2019 13:55:29 +0100 Subject: [PATCH] poi impl --- server/mapblockparser/mapblock.go | 4 ++++ server/mapobject/poi.go | 18 +++++++++++------- server/mapobjectdb/accessor.go | 12 ++++++------ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/server/mapblockparser/mapblock.go b/server/mapblockparser/mapblock.go index cb69356..f378d66 100644 --- a/server/mapblockparser/mapblock.go +++ b/server/mapblockparser/mapblock.go @@ -55,6 +55,10 @@ func NewMetadata() *Metadata { return &md } +func (md *Metadata) GetMetadata(x, y, z int) map[string]string { + return md.GetPairsMap(getNodePos(x, y, z)) +} + func (md *Metadata) GetPairsMap(pos int) map[string]string { pairsMap := md.Pairs[pos] if pairsMap == nil { diff --git a/server/mapobject/poi.go b/server/mapobject/poi.go index 1cb0972..74f5fc4 100644 --- a/server/mapobject/poi.go +++ b/server/mapobject/poi.go @@ -7,19 +7,23 @@ import ( func onPoiBlock(id int, block *mapblockparser.MapBlock, odb mapobjectdb.DBAccessor) { - for x:=0; x<16; x++ { - for y:=0; y<16; y++ { - for z:=0; z<16; z++ { - name := block.GetNodeName(x,y,z) + for x := 0; x < 16; x++ { + for y := 0; y < 16; y++ { + for z := 0; z < 16; z++ { + name := block.GetNodeName(x, y, z) if name == "mapserver:poi" { + md := block.Metadata.GetMetadata(x, y, z) + o := mapobjectdb.NewMapObject(&block.Pos, x, y, z, "poi") - o.Attributes["name"] = "test" + o.Attributes["name"] = md["name"] + o.Attributes["category"] = md["category"] + o.Attributes["url"] = md["url"] + o.Attributes["active"] = md["active"] + o.Attributes["owner"] = md["owner"] odb.AddMapData(o) } } } } - - panic("OK") //XXX } diff --git a/server/mapobjectdb/accessor.go b/server/mapobjectdb/accessor.go index fdad07c..1c45622 100644 --- a/server/mapobjectdb/accessor.go +++ b/server/mapobjectdb/accessor.go @@ -31,12 +31,12 @@ type MapObject struct { func NewMapObject(MBPos *coords.MapBlockCoords, x int, y int, z int, _type string) *MapObject { o := MapObject{ - MBPos: MBPos, - Type: _type, - X: MBPos.X + x, - Y: MBPos.Y + y, - Z: MBPos.Z + z, - Mtime: time.Now().Unix(), + MBPos: MBPos, + Type: _type, + X: MBPos.X + x, + Y: MBPos.Y + y, + Z: MBPos.Z + z, + Mtime: time.Now().Unix(), Attributes: make(map[string]string), }