map obj data stub

This commit is contained in:
NatureFreshMilk 2019-01-23 14:05:17 +01:00
parent 4d1426a466
commit e2cfa9857a
3 changed files with 40 additions and 4 deletions

View File

@ -24,7 +24,6 @@ type MapObject struct {
X, Y, Z int X, Y, Z int
Type string Type string
Data string
Mtime int64 Mtime int64
Attributes map[string]string Attributes map[string]string
} }

View File

@ -8,10 +8,48 @@ func (db *Sqlite3Accessor) GetMapData(q SearchQuery) ([]MapObject, error) {
return nil, nil return nil, nil
} }
const removeMapDataQuery = `
delete from objects where posx = ? and posy = ? and posz = ?
`
func (db *Sqlite3Accessor) RemoveMapData(pos coords.MapBlockCoords) error { func (db *Sqlite3Accessor) RemoveMapData(pos coords.MapBlockCoords) error {
return nil _, err := db.db.Exec(removeMapDataQuery, pos.X, pos.Y, pos.Z)
return err
} }
const addMapDataQuery = `
insert into
objects(x,y,z,posx,posy,posz,type,mtime)
values(?, ?, ?, ?, ?, ?, ?, ?)
returning id
`
const addMapDataAttributeQuery = `
insert into
object_attributes(objectid, key, value)
values(?, ?, ?)
`
func (db *Sqlite3Accessor) AddMapData(data MapObject) error { func (db *Sqlite3Accessor) AddMapData(data MapObject) error {
_, err := db.db.Exec(addMapDataQuery,
data.X, data.Y, data.Z,
data.MBPos.X, data.MBPos.Y, data.MBPos.Z,
data.Type, data.Mtime)
if err != nil {
return err
}
//TODO
id := 1
for k, v := range data.Attributes {
_, err := db.db.Exec(addMapDataAttributeQuery, id, k, v)
if err != nil {
return err
}
}
return nil return nil
} }

View File

@ -21,7 +21,6 @@ create table if not exists objects(
posy int, posy int,
posz int, posz int,
type varchar, type varchar,
data blob,
mtime bigint mtime bigint
); );
@ -29,11 +28,11 @@ create index if not exists objects_pos on objects(posx,posy,posz);
create index if not exists objects_pos_type on objects(posx,posy,posz,type); create index if not exists objects_pos_type on objects(posx,posy,posz,type);
create table if not exists object_attributes( create table if not exists object_attributes(
id integer primary key autoincrement,
objectid integer not null, objectid integer not null,
key varchar not null, key varchar not null,
value varchar not null, value varchar not null,
FOREIGN KEY (objectid) references objects(id) ON DELETE CASCADE FOREIGN KEY (objectid) references objects(id) ON DELETE CASCADE
primary key(objectid, key)
); );
create table if not exists tiles( create table if not exists tiles(