map objects (protectors, train, travelnet)
This commit is contained in:
parent
66bd39a943
commit
f00016e5e6
@ -41,9 +41,13 @@ func getNodePos(x, y, z int) int {
|
||||
return x + (y * 16) + (z * 256)
|
||||
}
|
||||
|
||||
func (mb *MapBlock) GetNodeName(x, y, z int) string {
|
||||
func (mb *MapBlock) GetNodeId(x, y, z int) int {
|
||||
pos := getNodePos(x, y, z)
|
||||
id := mb.Mapdata.ContentId[pos]
|
||||
return mb.Mapdata.ContentId[pos]
|
||||
}
|
||||
|
||||
func (mb *MapBlock) GetNodeName(x, y, z int) string {
|
||||
id := mb.GetNodeId(x,y,z)
|
||||
return mb.BlockMapping[id]
|
||||
}
|
||||
|
||||
|
@ -5,25 +5,17 @@ import (
|
||||
"mapserver/mapobjectdb"
|
||||
)
|
||||
|
||||
func onPoiBlock(id int, block *mapblockparser.MapBlock, odb mapobjectdb.DBAccessor) {
|
||||
type PoiBlock struct {}
|
||||
|
||||
for x := 0; x < 16; x++ {
|
||||
for y := 0; y < 16; y++ {
|
||||
for z := 0; z < 16; z++ {
|
||||
name := block.GetNodeName(x, y, z)
|
||||
if name == "mapserver:poi" {
|
||||
md := block.Metadata.GetMetadata(x, y, z)
|
||||
func (this *PoiBlock) onMapObject(x,y,z int, block *mapblockparser.MapBlock, odb mapobjectdb.DBAccessor) {
|
||||
md := block.Metadata.GetMetadata(x, y, z)
|
||||
|
||||
o := mapobjectdb.NewMapObject(&block.Pos, x, y, z, "poi")
|
||||
o.Attributes["name"] = md["name"]
|
||||
o.Attributes["category"] = md["category"]
|
||||
o.Attributes["url"] = md["url"]
|
||||
o.Attributes["active"] = md["active"]
|
||||
o.Attributes["owner"] = md["owner"]
|
||||
o := mapobjectdb.NewMapObject(&block.Pos, x, y, z, "poi")
|
||||
o.Attributes["name"] = md["name"]
|
||||
o.Attributes["category"] = md["category"]
|
||||
o.Attributes["url"] = md["url"]
|
||||
o.Attributes["active"] = md["active"]
|
||||
o.Attributes["owner"] = md["owner"]
|
||||
|
||||
odb.AddMapData(o)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
odb.AddMapData(o)
|
||||
}
|
||||
|
17
server/mapobject/protector.go
Normal file
17
server/mapobject/protector.go
Normal file
@ -0,0 +1,17 @@
|
||||
package mapobject
|
||||
|
||||
import (
|
||||
"mapserver/mapblockparser"
|
||||
"mapserver/mapobjectdb"
|
||||
)
|
||||
|
||||
type ProtectorBlock struct {}
|
||||
|
||||
func (this *ProtectorBlock) onMapObject(x,y,z int, block *mapblockparser.MapBlock, odb mapobjectdb.DBAccessor) {
|
||||
md := block.Metadata.GetMetadata(x, y, z)
|
||||
|
||||
o := mapobjectdb.NewMapObject(&block.Pos, x, y, z, "protector")
|
||||
o.Attributes["owner"] = md["owner"]
|
||||
|
||||
odb.AddMapData(o)
|
||||
}
|
@ -4,10 +4,20 @@ import (
|
||||
"mapserver/app"
|
||||
"mapserver/eventbus"
|
||||
"mapserver/mapblockparser"
|
||||
"mapserver/mapobjectdb"
|
||||
)
|
||||
|
||||
type MapObjectListener interface {
|
||||
onMapObject(x,y,z int, block *mapblockparser.MapBlock, odb mapobjectdb.DBAccessor)
|
||||
}
|
||||
|
||||
type Listener struct {
|
||||
ctx *app.App
|
||||
objectlisteners map[string]MapObjectListener
|
||||
}
|
||||
|
||||
func (this *Listener) AddMapObject(blockname string, ol MapObjectListener){
|
||||
this.objectlisteners[blockname] = ol
|
||||
}
|
||||
|
||||
func (this *Listener) OnEvent(eventtype string, o interface{}) {
|
||||
@ -23,12 +33,37 @@ func (this *Listener) OnEvent(eventtype string, o interface{}) {
|
||||
}
|
||||
|
||||
for id, name := range block.BlockMapping {
|
||||
if name == "mapserver:poi" {
|
||||
onPoiBlock(id, block, this.ctx.Objectdb)
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
func Setup(ctx *app.App) {
|
||||
ctx.BlockAccessor.Eventbus.AddListener(&Listener{ctx: ctx})
|
||||
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)
|
||||
}
|
||||
|
20
server/mapobject/train.go
Normal file
20
server/mapobject/train.go
Normal file
@ -0,0 +1,20 @@
|
||||
package mapobject
|
||||
|
||||
import (
|
||||
"mapserver/mapblockparser"
|
||||
"mapserver/mapobjectdb"
|
||||
)
|
||||
|
||||
type TrainBlock struct {}
|
||||
|
||||
func (this *TrainBlock) onMapObject(x,y,z int, block *mapblockparser.MapBlock, odb mapobjectdb.DBAccessor) {
|
||||
md := block.Metadata.GetMetadata(x, y, z)
|
||||
|
||||
o := mapobjectdb.NewMapObject(&block.Pos, x, y, z, "train")
|
||||
o.Attributes["station"] = md["station"]
|
||||
o.Attributes["line"] = md["line"]
|
||||
o.Attributes["index"] = md["index"]
|
||||
o.Attributes["owner"] = md["owner"]
|
||||
|
||||
odb.AddMapData(o)
|
||||
}
|
24
server/mapobject/travelnet.go
Normal file
24
server/mapobject/travelnet.go
Normal file
@ -0,0 +1,24 @@
|
||||
package mapobject
|
||||
|
||||
import (
|
||||
"mapserver/mapblockparser"
|
||||
"mapserver/mapobjectdb"
|
||||
)
|
||||
|
||||
type TravelnetBlock struct {}
|
||||
|
||||
func (this *TravelnetBlock) onMapObject(x,y,z int, block *mapblockparser.MapBlock, odb mapobjectdb.DBAccessor) {
|
||||
md := block.Metadata.GetMetadata(x, y, z)
|
||||
|
||||
if md["station_name"] == "" || md["owner"] == "" {
|
||||
//station not set up
|
||||
return
|
||||
}
|
||||
|
||||
o := mapobjectdb.NewMapObject(&block.Pos, x, y, z, "travelnet")
|
||||
o.Attributes["owner"] = md["owner"]
|
||||
o.Attributes["station_name"] = md["station_name"]
|
||||
o.Attributes["station_network"] = md["station_network"]
|
||||
|
||||
odb.AddMapData(o)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user