forked from MTSR/mapserver
add mapobject/overlay support for signs
This commit is contained in:
parent
44c653f58b
commit
2204f21169
@ -88,6 +88,7 @@ func ParseConfig(filename string) (*Config, error) {
|
||||
TrainSignal: true,
|
||||
Minecart: false,
|
||||
Locator: false,
|
||||
Signs: true,
|
||||
}
|
||||
|
||||
mapblockaccessor := MapBlockAccessorConfig{
|
||||
|
@ -60,6 +60,7 @@ type MapObjectConfig struct {
|
||||
TrainSignal bool `json:"trainsignal"`
|
||||
Minecart bool `json:"minecart"`
|
||||
Locator bool `json:"locator"`
|
||||
Signs bool `json:"signs"`
|
||||
}
|
||||
|
||||
type WebApiConfig struct {
|
||||
|
@ -162,5 +162,11 @@ func Setup(ctx *app.App) {
|
||||
l.AddMapObject("locator:beacon_3", loc)
|
||||
}
|
||||
|
||||
//signs
|
||||
if ctx.Config.MapObjects.Signs {
|
||||
l.AddMapObject("default:sign_wall_wood", &SignBlock{Material: "wood"})
|
||||
l.AddMapObject("default:sign_wall_steel", &SignBlock{Material: "steel"})
|
||||
}
|
||||
|
||||
ctx.MapBlockAccessor.Eventbus.AddListener(&l)
|
||||
}
|
||||
|
20
mapobject/sign.go
Normal file
20
mapobject/sign.go
Normal file
@ -0,0 +1,20 @@
|
||||
package mapobject
|
||||
|
||||
import (
|
||||
"mapserver/mapblockparser"
|
||||
"mapserver/mapobjectdb"
|
||||
)
|
||||
|
||||
type SignBlock struct {
|
||||
Material string
|
||||
}
|
||||
|
||||
func (this *SignBlock) onMapObject(x, y, z int, block *mapblockparser.MapBlock) *mapobjectdb.MapObject {
|
||||
md := block.Metadata.GetMetadata(x, y, z)
|
||||
|
||||
o := mapobjectdb.NewMapObject(block.Pos, x, y, z, "sign")
|
||||
o.Attributes["display_text"] = md["text"]
|
||||
o.Attributes["material"] = this.Material
|
||||
|
||||
return o
|
||||
}
|
@ -21,6 +21,7 @@ import LocatorOverlay from './overlays/LocatorOverlay.js';
|
||||
import BorderOverlay from './overlays/BorderOverlay.js';
|
||||
import TrainOverlay from './overlays/TrainOverlay.js';
|
||||
import TrainsignalOverlay from './overlays/TrainsignalOverlay.js';
|
||||
import SignOverlay from './overlays/SignOverlay.js';
|
||||
|
||||
export default function(cfg, map, overlays, wsChannel){
|
||||
|
||||
@ -191,4 +192,11 @@ export default function(cfg, map, overlays, wsChannel){
|
||||
}
|
||||
}
|
||||
|
||||
if (cfg.mapobjects.signs) {
|
||||
overlays.Signs = new SignOverlay();
|
||||
if (isDefault("signs")) {
|
||||
map.addLayer(overlays.Signs);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
33
static/js/map/overlays/SignOverlay.js
Normal file
33
static/js/map/overlays/SignOverlay.js
Normal file
@ -0,0 +1,33 @@
|
||||
import AbstractIconOverlay from './AbstractIconOverlay.js';
|
||||
|
||||
const IconWood = L.icon({
|
||||
iconUrl: 'pics/default_sign_wood.png',
|
||||
iconSize: [16, 16],
|
||||
iconAnchor: [8, 8],
|
||||
popupAnchor: [0, -8]
|
||||
});
|
||||
|
||||
const IconSteel = L.icon({
|
||||
iconUrl: 'pics/default_sign_steel.png',
|
||||
iconSize: [16, 16],
|
||||
iconAnchor: [8, 8],
|
||||
popupAnchor: [0, -8]
|
||||
});
|
||||
|
||||
export default AbstractIconOverlay.extend({
|
||||
initialize: function() {
|
||||
AbstractIconOverlay.prototype.initialize.call(this, "sign");
|
||||
},
|
||||
|
||||
getIcon: function(obj) {
|
||||
if (obj.attributes.material === "steel") {
|
||||
return IconSteel;
|
||||
} else {
|
||||
return IconWood;
|
||||
}
|
||||
},
|
||||
|
||||
createPopup: function(sign) {
|
||||
return sign.attributes.display_text;
|
||||
}
|
||||
});
|
BIN
static/pics/default_sign_steel.png
Normal file
BIN
static/pics/default_sign_steel.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 537 B |
BIN
static/pics/default_sign_wood.png
Normal file
BIN
static/pics/default_sign_wood.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 770 B |
Loading…
Reference in New Issue
Block a user