mapobj db impl

This commit is contained in:
NatureFreshMilk 2019-01-25 11:02:36 +01:00
parent 46936ad178
commit 75bf921b54
3 changed files with 27 additions and 11 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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)
}
}