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-02-06 20:28:24 +03:00
|
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
2019-01-23 15:22:47 +03:00
|
|
|
)
|
|
|
|
|
2019-01-28 16:19:11 +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-28 16:19:11 +03:00
|
|
|
}
|
|
|
|
|
2019-02-08 13:45:56 +03:00
|
|
|
type MapMultiObjectListener interface {
|
|
|
|
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
|
2019-01-28 16:19:11 +03:00
|
|
|
objectlisteners map[string]MapObjectListener
|
2019-02-08 13:45:56 +03:00
|
|
|
multiobjectlisteners map[string]MapMultiObjectListener
|
2019-01-28 16:19:11 +03:00
|
|
|
}
|
|
|
|
|
2019-01-28 16:33:32 +03:00
|
|
|
func (this *Listener) AddMapObject(blockname string, ol MapObjectListener) {
|
2019-01-28 16:19:11 +03:00
|
|
|
this.objectlisteners[blockname] = ol
|
2019-01-23 15:41:26 +03:00
|
|
|
}
|
|
|
|
|
2019-02-08 13:45:56 +03:00
|
|
|
func (this *Listener) AddMapMultiObject(blockname string, ol MapMultiObjectListener) {
|
|
|
|
this.multiobjectlisteners[blockname] = ol
|
|
|
|
}
|
|
|
|
|
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-02-06 10:38:08 +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-29 20:00:00 +03:00
|
|
|
this.ctx.WebEventbus.Emit("mapobjects-cleared", block.Pos)
|
|
|
|
|
2019-01-23 18:06:56 +03:00
|
|
|
for id, name := range block.BlockMapping {
|
2019-02-08 13:45:56 +03:00
|
|
|
|
|
|
|
for k, v := range this.multiobjectlisteners {
|
|
|
|
if k == name {
|
|
|
|
//block matches
|
|
|
|
mapblockparser.IterateMapblock(func(x,y,z int){
|
|
|
|
nodeid := block.GetNodeId(x, y, z)
|
|
|
|
if nodeid == id {
|
|
|
|
fields := logrus.Fields{
|
|
|
|
"mbpos": block.Pos,
|
|
|
|
"x": x,
|
|
|
|
"y": y,
|
|
|
|
"z": z,
|
|
|
|
"type": name,
|
|
|
|
"nodeid": nodeid,
|
|
|
|
}
|
|
|
|
log.WithFields(fields).Debug("OnEvent()")
|
|
|
|
|
|
|
|
objs := v.onMapObject(x, y, z, block)
|
|
|
|
|
|
|
|
if len(objs) > 0 {
|
|
|
|
for _, obj := range objs {
|
|
|
|
this.ctx.Objectdb.AddMapData(obj)
|
|
|
|
this.ctx.WebEventbus.Emit("mapobject-created", obj)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} // k==name
|
|
|
|
} //for k,v
|
|
|
|
|
2019-01-28 16:19:11 +03:00
|
|
|
for k, v := range this.objectlisteners {
|
|
|
|
if k == name {
|
|
|
|
//block matches
|
2019-02-08 13:23:04 +03:00
|
|
|
mapblockparser.IterateMapblock(func(x,y,z int){
|
|
|
|
nodeid := block.GetNodeId(x, y, z)
|
|
|
|
if nodeid == id {
|
|
|
|
fields := logrus.Fields{
|
|
|
|
"mbpos": block.Pos,
|
|
|
|
"x": x,
|
|
|
|
"y": y,
|
|
|
|
"z": z,
|
|
|
|
"type": name,
|
|
|
|
"nodeid": nodeid,
|
|
|
|
}
|
|
|
|
log.WithFields(fields).Debug("OnEvent()")
|
|
|
|
|
|
|
|
obj := v.onMapObject(x, y, z, block)
|
|
|
|
|
|
|
|
if obj != nil {
|
|
|
|
this.ctx.Objectdb.AddMapData(obj)
|
|
|
|
this.ctx.WebEventbus.Emit("mapobject-created", obj)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
} // k==name
|
2019-01-28 16:33:32 +03:00
|
|
|
} //for k,v
|
2019-02-08 13:45:56 +03:00
|
|
|
|
2019-01-28 16:33:32 +03:00
|
|
|
} //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{
|
2019-01-28 16:33:32 +03:00
|
|
|
ctx: ctx,
|
2019-01-28 16:19:11 +03:00
|
|
|
objectlisteners: make(map[string]MapObjectListener),
|
2019-02-08 13:45:56 +03:00
|
|
|
multiobjectlisteners: make(map[string]MapMultiObjectListener),
|
2019-01-28 16:19:11 +03:00
|
|
|
}
|
|
|
|
|
2019-01-29 10:03:49 +03:00
|
|
|
//mapserver stuff
|
2019-01-28 16:19:11 +03:00
|
|
|
l.AddMapObject("mapserver:poi", &PoiBlock{})
|
|
|
|
l.AddMapObject("mapserver:train", &TrainBlock{})
|
2019-02-08 12:28:33 +03:00
|
|
|
l.AddMapObject("mapserver:border", &BorderBlock{})
|
|
|
|
l.AddMapObject("mapserver:label", &LabelBlock{})
|
2019-01-29 10:03:49 +03:00
|
|
|
|
|
|
|
//travelnet
|
2019-01-28 16:19:11 +03:00
|
|
|
l.AddMapObject("travelnet:travelnet", &TravelnetBlock{})
|
2019-01-29 10:03:49 +03:00
|
|
|
|
|
|
|
//protections
|
2019-01-28 16:19:11 +03:00
|
|
|
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-28 16:19:11 +03:00
|
|
|
|
2019-01-29 10:03:49 +03:00
|
|
|
//digilines
|
|
|
|
l.AddMapObject("digilines:lcd", &DigilineLcdBlock{})
|
|
|
|
|
2019-02-08 11:11:25 +03:00
|
|
|
//mesecons
|
|
|
|
luac := &LuaControllerBlock{}
|
|
|
|
// mesecons_luacontroller:luacontroller0000 2^4=16
|
|
|
|
l.AddMapObject("mesecons_luacontroller:luacontroller1111", luac)
|
|
|
|
l.AddMapObject("mesecons_luacontroller:luacontroller1110", luac)
|
|
|
|
l.AddMapObject("mesecons_luacontroller:luacontroller1100", luac)
|
|
|
|
l.AddMapObject("mesecons_luacontroller:luacontroller1010", luac)
|
|
|
|
l.AddMapObject("mesecons_luacontroller:luacontroller1000", luac)
|
|
|
|
l.AddMapObject("mesecons_luacontroller:luacontroller1101", luac)
|
|
|
|
l.AddMapObject("mesecons_luacontroller:luacontroller1001", luac)
|
|
|
|
l.AddMapObject("mesecons_luacontroller:luacontroller1011", luac)
|
|
|
|
l.AddMapObject("mesecons_luacontroller:luacontroller0111", luac)
|
|
|
|
l.AddMapObject("mesecons_luacontroller:luacontroller0110", luac)
|
|
|
|
l.AddMapObject("mesecons_luacontroller:luacontroller0100", luac)
|
|
|
|
l.AddMapObject("mesecons_luacontroller:luacontroller0010", luac)
|
|
|
|
l.AddMapObject("mesecons_luacontroller:luacontroller0000", luac)
|
|
|
|
l.AddMapObject("mesecons_luacontroller:luacontroller0101", luac)
|
|
|
|
l.AddMapObject("mesecons_luacontroller:luacontroller0001", luac)
|
|
|
|
l.AddMapObject("mesecons_luacontroller:luacontroller0011", luac)
|
|
|
|
l.AddMapObject("mesecons_luacontroller:luacontroller_burnt", luac)
|
|
|
|
|
2019-02-08 12:07:59 +03:00
|
|
|
//digiterms
|
|
|
|
digiterms := &DigitermsBlock{}
|
2019-02-08 12:39:18 +03:00
|
|
|
l.AddMapObject("digiterms:lcd_monitor", digiterms)
|
|
|
|
l.AddMapObject("digiterms:cathodic_beige_monitor", digiterms)
|
|
|
|
l.AddMapObject("digiterms:cathodic_white_monitor", digiterms)
|
|
|
|
l.AddMapObject("digiterms:cathodic_black_monitor", digiterms)
|
|
|
|
l.AddMapObject("digiterms:scifi_glassscreen", digiterms)
|
|
|
|
l.AddMapObject("digiterms:scifi_widescreen", digiterms)
|
|
|
|
l.AddMapObject("digiterms:scifi_tallscreen", digiterms)
|
|
|
|
l.AddMapObject("digiterms:scifi_keysmonitor", digiterms)
|
2019-02-08 12:07:59 +03:00
|
|
|
|
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-02-08 13:45:56 +03:00
|
|
|
//smartshop
|
|
|
|
l.AddMapMultiObject("smartshop:shop", &SmartShopBlock{})
|
|
|
|
|
|
|
|
//TODO: atm, shops (smart, fancy)
|
2019-01-29 10:26:23 +03:00
|
|
|
|
2019-01-28 16:19:11 +03:00
|
|
|
ctx.BlockAccessor.Eventbus.AddListener(&l)
|
2019-01-23 15:22:47 +03:00
|
|
|
}
|