2019-01-23 15:22:47 +03:00
|
|
|
package mapobject
|
|
|
|
|
|
|
|
import (
|
|
|
|
"mapserver/app"
|
2019-01-28 15:31:48 +03:00
|
|
|
"mapserver/eventbus"
|
2019-01-23 18:06:56 +03:00
|
|
|
"mapserver/mapblockparser"
|
2019-01-28 16:19:11 +03:00
|
|
|
"mapserver/mapobjectdb"
|
2019-01-23 15:22:47 +03:00
|
|
|
)
|
|
|
|
|
2019-01-28 16:19:11 +03:00
|
|
|
type MapObjectListener interface {
|
|
|
|
onMapObject(x,y,z int, block *mapblockparser.MapBlock, odb mapobjectdb.DBAccessor)
|
|
|
|
}
|
|
|
|
|
2019-01-23 15:41:26 +03:00
|
|
|
type Listener struct {
|
2019-01-23 18:06:56 +03:00
|
|
|
ctx *app.App
|
2019-01-28 16:19:11 +03:00
|
|
|
objectlisteners map[string]MapObjectListener
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *Listener) AddMapObject(blockname string, ol MapObjectListener){
|
|
|
|
this.objectlisteners[blockname] = ol
|
2019-01-23 15:41:26 +03:00
|
|
|
}
|
|
|
|
|
2019-01-28 15:31:48 +03:00
|
|
|
func (this *Listener) OnEvent(eventtype string, o interface{}) {
|
|
|
|
if eventtype != eventbus.MAPBLOCK_RENDERED {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
block := o.(*mapblockparser.MapBlock)
|
|
|
|
|
2019-01-24 10:26:28 +03:00
|
|
|
err := this.ctx.Objectdb.RemoveMapData(&block.Pos)
|
2019-01-23 18:06:56 +03:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2019-01-23 15:41:26 +03:00
|
|
|
|
2019-01-23 18:06:56 +03:00
|
|
|
for id, name := range block.BlockMapping {
|
2019-01-28 16:19:11 +03:00
|
|
|
for k, v := range this.objectlisteners {
|
|
|
|
if k == name {
|
|
|
|
//block matches
|
|
|
|
|
|
|
|
for x := 0; x < 16; x++ {
|
|
|
|
for y := 0; y < 16; y++ {
|
|
|
|
for z := 0; z < 16; z++ {
|
|
|
|
nodeid := block.GetNodeId(x, y, z)
|
|
|
|
if nodeid == id {
|
|
|
|
v.onMapObject(x, y, z, block, this.ctx.Objectdb)
|
|
|
|
}
|
|
|
|
}//z
|
|
|
|
}//y
|
|
|
|
}//x
|
|
|
|
|
|
|
|
}
|
|
|
|
}//for k,v
|
|
|
|
}//for id, name
|
2019-01-23 15:41:26 +03:00
|
|
|
}
|
|
|
|
|
2019-01-23 15:22:47 +03:00
|
|
|
func Setup(ctx *app.App) {
|
2019-01-28 16:19:11 +03:00
|
|
|
l := Listener{
|
|
|
|
ctx: ctx,
|
|
|
|
objectlisteners: make(map[string]MapObjectListener),
|
|
|
|
}
|
|
|
|
|
|
|
|
l.AddMapObject("mapserver:poi", &PoiBlock{})
|
|
|
|
l.AddMapObject("mapserver:train", &TrainBlock{})
|
|
|
|
l.AddMapObject("travelnet:travelnet", &TravelnetBlock{})
|
|
|
|
l.AddMapObject("protector:protect", &ProtectorBlock{})
|
|
|
|
l.AddMapObject("protector:protect2", &ProtectorBlock{})
|
|
|
|
|
|
|
|
ctx.BlockAccessor.Eventbus.AddListener(&l)
|
2019-01-23 15:22:47 +03:00
|
|
|
}
|