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 { type MapObject struct {
//mapblock position //mapblock position
MBPos *coords.MapBlockCoords MBPos *coords.MapBlockCoords `json:"mapblock"`
//block position //block position
X, Y, Z int X int `json:"x"`
Y int `json:"y"`
Z int `json:"z"`
Type string Type string `json:"type"`
Mtime int64 Mtime int64 `json:"mtime"`
Attributes map[string]string Attributes map[string]string `json:"attributes"`
} }
func NewMapObject(MBPos *coords.MapBlockCoords, x int, y int, z int, _type string) *MapObject { 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) result := make([]*MapObject, 0)
var currentObj *MapObject var currentObj *MapObject
var currentId *int64
for rows.Next() { for rows.Next() {
var id int64 var id int64
@ -52,12 +53,22 @@ func (db *Sqlite3Accessor) GetMapData(q SearchQuery) ([]*MapObject, error) {
return nil, err return nil, err
} }
if currentObj == nil { if currentId == nil || *currentId != id {
//TODO pos := coords.NewMapBlockCoords(posx, posy, posz)
} else { mo := NewMapObject(
//TODO &pos,
x, y, z,
Type,
)
currentObj = mo
currentId = &id
result = append(result, currentObj)
} }
currentObj.Attributes[key] = value
} }
return result, nil return result, nil

View File

@ -4,6 +4,7 @@ import (
"io/ioutil" "io/ioutil"
"mapserver/coords" "mapserver/coords"
"os" "os"
"fmt"
"testing" "testing"
) )
@ -107,12 +108,14 @@ func TestMapObjects(t *testing.T) {
Type: "xy", Type: "xy",
} }
_, err = db.GetMapData(q) objs, err := db.GetMapData(q)
if err != nil { if err != nil {
panic(err) panic(err)
} }
for _, mo := range objs {
fmt.Println(mo)
}
} }