1
0
forked from MTSR/mapserver

add mapobject/overlay support for signs

This commit is contained in:
Kenneth Watson 2021-01-05 16:52:22 +02:00 committed by Buckaroo Banzai
parent 44c653f58b
commit 2204f21169
8 changed files with 69 additions and 0 deletions

View File

@ -88,6 +88,7 @@ func ParseConfig(filename string) (*Config, error) {
TrainSignal: true,
Minecart: false,
Locator: false,
Signs: true,
}
mapblockaccessor := MapBlockAccessorConfig{

View File

@ -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 {

View File

@ -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
View 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
}

View File

@ -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);
}
}
}

View 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;
}
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 537 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 770 B