mapserver/server/mapobject/setup.go

100 lines
2.3 KiB
Go
Raw Normal View History

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"
"mapserver/mapobjectdb"
2019-01-23 15:22:47 +03:00
)
type MapObjectListener interface {
2019-01-28 16:33:32 +03:00
onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject
}
2019-01-23 15:41:26 +03:00
type Listener struct {
2019-01-28 16:33:32 +03:00
ctx *app.App
objectlisteners map[string]MapObjectListener
}
2019-01-28 16:33:32 +03:00
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 {
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 {
2019-01-28 16:33:32 +03:00
obj := v.onMapObject(x, y, z, block)
if obj != nil {
this.ctx.Objectdb.AddMapData(obj)
this.ctx.WebEventbus.Emit("mapobject", obj)
}
}
2019-01-28 16:33:32 +03:00
} //z
} //y
} //x
}
2019-01-28 16:33:32 +03:00
} //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) {
l := Listener{
2019-01-28 16:33:32 +03:00
ctx: ctx,
objectlisteners: make(map[string]MapObjectListener),
}
2019-01-29 10:03:49 +03:00
//mapserver stuff
l.AddMapObject("mapserver:poi", &PoiBlock{})
l.AddMapObject("mapserver:train", &TrainBlock{})
2019-01-29 10:03:49 +03:00
//travelnet
l.AddMapObject("travelnet:travelnet", &TravelnetBlock{})
2019-01-29 10:03:49 +03:00
//protections
l.AddMapObject("protector:protect", &ProtectorBlock{})
l.AddMapObject("protector:protect2", &ProtectorBlock{})
2019-01-29 10:14:17 +03:00
l.AddMapObject("xp_redo:protector", &XPProtectorBlock{})
2019-01-29 10:03:49 +03:00
//builtin
2019-01-29 09:47:53 +03:00
l.AddMapObject("bones:bones", &BonesBlock{})
2019-01-29 10:03:49 +03:00
//technic
2019-01-29 09:47:53 +03:00
l.AddMapObject("technic:quarry", &QuarryBlock{})
l.AddMapObject("technic:hv_nuclear_reactor_core_active", &NuclearReactorBlock{})
l.AddMapObject("technic:admin_anchor", &TechnicAnchorBlock{})
2019-01-29 10:03:49 +03:00
//digilines
l.AddMapObject("digilines:lcd", &DigilineLcdBlock{})
2019-01-29 10:21:48 +03:00
//missions
l.AddMapObject("missions:mission", &MissionBlock{})
2019-01-29 10:26:23 +03:00
//jumpdrive, TODO: fleet controller
2019-01-29 10:24:03 +03:00
l.AddMapObject("jumpdrive:engine", &JumpdriveBlock{})
2019-01-29 10:26:23 +03:00
//TODO: atm, digiterms, signs/banners, spacecannons, shops (smart, fancy)
ctx.BlockAccessor.Eventbus.AddListener(&l)
2019-01-23 15:22:47 +03:00
}