diff --git a/server/mapobjectdb/accessor.go b/server/mapobjectdb/accessor.go index 1c45622..ad781c0 100644 --- a/server/mapobjectdb/accessor.go +++ b/server/mapobjectdb/accessor.go @@ -44,16 +44,17 @@ func NewMapObject(MBPos *coords.MapBlockCoords, x int, y int, z int, _type strin } type SearchQuery struct { - //block position (not mapblock) - Pos1, Pos2 coords.MapBlockCoords - Type string + //mapblock position + Pos1 coords.MapBlockCoords `json:"pos1"` + Pos2 coords.MapBlockCoords `json:"pos2"` + Type string `json:"type"` } type DBAccessor interface { Migrate() error //Generic map objects (poi, etc) - GetMapData(q SearchQuery) ([]MapObject, error) + GetMapData(q SearchQuery) ([]*MapObject, error) RemoveMapData(pos *coords.MapBlockCoords) error AddMapData(data *MapObject) error diff --git a/server/mapobjectdb/sqlite_mapobjects.go b/server/mapobjectdb/sqlite_mapobjects.go index 865a793..309f7ae 100644 --- a/server/mapobjectdb/sqlite_mapobjects.go +++ b/server/mapobjectdb/sqlite_mapobjects.go @@ -4,8 +4,63 @@ import ( "mapserver/coords" ) -func (db *Sqlite3Accessor) GetMapData(q SearchQuery) ([]MapObject, error) { - return nil, nil +const getMapDataPosQuery = ` +select o.id, o.type, o.mtime, + o.x, o.y, o.z, + o.posx, o.posy, o.posz, + oa.key, oa.value +from objects o +left join object_attributes oa on o.id = oa.objectid +where o.type = ? +and o.posx >= ? and o.posy >= ? and o.posz >= ? +and o.posx <= ? and o.posy <= ? and o.posz <= ? +order by o.id +` + + +func (db *Sqlite3Accessor) GetMapData(q SearchQuery) ([]*MapObject, error) { + rows, err := db.db.Query(getMapDataPosQuery, + q.Type, + q.Pos1.X, q.Pos1.Y, q.Pos1.Z, + q.Pos2.X, q.Pos2.Y, q.Pos2.Z, + ) + + if err != nil { + return nil, err + } + + defer rows.Close() + + result := make([]*MapObject, 0) + var currentObj *MapObject + + for rows.Next() { + var id int64 + var Type string + var mtime int64 + var x, y, z int + var posx, posy, posz int + var key, value string + + + err = rows.Scan(&id, &Type, &mtime, + &x, &y, &z, &posx, &posy, &posz, + &key, &value, + ) + + if err != nil { + return nil, err + } + + if currentObj == nil { + //TODO + } else { + //TODO + } + + } + + return result, nil } const removeMapDataQuery = ` diff --git a/server/mapobjectdb/sqlite_test.go b/server/mapobjectdb/sqlite_test.go index ce780fe..6394041 100644 --- a/server/mapobjectdb/sqlite_test.go +++ b/server/mapobjectdb/sqlite_test.go @@ -101,4 +101,18 @@ func TestMapObjects(t *testing.T) { panic(err) } + q := SearchQuery{ + Pos1: pos, + Pos2: pos, + Type: "xy", + } + + _, err = db.GetMapData(q) + + if err != nil { + panic(err) + } + + + }