From 75bf921b54bc800a6b8d151b4e28f3d97e060da7 Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Fri, 25 Jan 2019 11:02:36 +0100 Subject: [PATCH] mapobj db impl --- server/mapobjectdb/accessor.go | 12 +++++++----- server/mapobjectdb/sqlite_mapobjects.go | 19 +++++++++++++++---- server/mapobjectdb/sqlite_test.go | 7 +++++-- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/server/mapobjectdb/accessor.go b/server/mapobjectdb/accessor.go index ad781c0..f7e6645 100644 --- a/server/mapobjectdb/accessor.go +++ b/server/mapobjectdb/accessor.go @@ -19,14 +19,16 @@ type Tile struct { type MapObject struct { //mapblock position - MBPos *coords.MapBlockCoords + MBPos *coords.MapBlockCoords `json:"mapblock"` //block position - X, Y, Z int + X int `json:"x"` + Y int `json:"y"` + Z int `json:"z"` - Type string - Mtime int64 - Attributes map[string]string + Type string `json:"type"` + Mtime int64 `json:"mtime"` + Attributes map[string]string `json:"attributes"` } func NewMapObject(MBPos *coords.MapBlockCoords, x int, y int, z int, _type string) *MapObject { diff --git a/server/mapobjectdb/sqlite_mapobjects.go b/server/mapobjectdb/sqlite_mapobjects.go index 309f7ae..0cf6aeb 100644 --- a/server/mapobjectdb/sqlite_mapobjects.go +++ b/server/mapobjectdb/sqlite_mapobjects.go @@ -33,6 +33,7 @@ func (db *Sqlite3Accessor) GetMapData(q SearchQuery) ([]*MapObject, error) { result := make([]*MapObject, 0) var currentObj *MapObject + var currentId *int64 for rows.Next() { var id int64 @@ -52,12 +53,22 @@ func (db *Sqlite3Accessor) GetMapData(q SearchQuery) ([]*MapObject, error) { return nil, err } - if currentObj == nil { - //TODO - } else { - //TODO + if currentId == nil || *currentId != id { + pos := coords.NewMapBlockCoords(posx, posy, posz) + mo := NewMapObject( + &pos, + x, y, z, + Type, + ) + + currentObj = mo + currentId = &id + + result = append(result, currentObj) + } + currentObj.Attributes[key] = value } return result, nil diff --git a/server/mapobjectdb/sqlite_test.go b/server/mapobjectdb/sqlite_test.go index 6394041..9ec35ec 100644 --- a/server/mapobjectdb/sqlite_test.go +++ b/server/mapobjectdb/sqlite_test.go @@ -4,6 +4,7 @@ import ( "io/ioutil" "mapserver/coords" "os" + "fmt" "testing" ) @@ -107,12 +108,14 @@ func TestMapObjects(t *testing.T) { Type: "xy", } - _, err = db.GetMapData(q) + objs, err := db.GetMapData(q) if err != nil { panic(err) } - + for _, mo := range objs { + fmt.Println(mo) + } }