From 2204f2116987a935599fb997e1004e3aad69ae19 Mon Sep 17 00:00:00 2001 From: Kenneth Watson Date: Tue, 5 Jan 2021 16:52:22 +0200 Subject: [PATCH] add mapobject/overlay support for signs --- app/config.go | 1 + app/types.go | 1 + mapobject/setup.go | 6 +++++ mapobject/sign.go | 20 ++++++++++++++++ static/js/map/Overlaysetup.js | 8 +++++++ static/js/map/overlays/SignOverlay.js | 33 ++++++++++++++++++++++++++ static/pics/default_sign_steel.png | Bin 0 -> 537 bytes static/pics/default_sign_wood.png | Bin 0 -> 770 bytes 8 files changed, 69 insertions(+) create mode 100644 mapobject/sign.go create mode 100644 static/js/map/overlays/SignOverlay.js create mode 100644 static/pics/default_sign_steel.png create mode 100644 static/pics/default_sign_wood.png diff --git a/app/config.go b/app/config.go index df61c01..df94970 100644 --- a/app/config.go +++ b/app/config.go @@ -88,6 +88,7 @@ func ParseConfig(filename string) (*Config, error) { TrainSignal: true, Minecart: false, Locator: false, + Signs: true, } mapblockaccessor := MapBlockAccessorConfig{ diff --git a/app/types.go b/app/types.go index 28bfb92..8f0aab2 100644 --- a/app/types.go +++ b/app/types.go @@ -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 { diff --git a/mapobject/setup.go b/mapobject/setup.go index 375418f..416142c 100644 --- a/mapobject/setup.go +++ b/mapobject/setup.go @@ -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) } diff --git a/mapobject/sign.go b/mapobject/sign.go new file mode 100644 index 0000000..83caec8 --- /dev/null +++ b/mapobject/sign.go @@ -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 +} diff --git a/static/js/map/Overlaysetup.js b/static/js/map/Overlaysetup.js index 374ae9c..7fe67d9 100644 --- a/static/js/map/Overlaysetup.js +++ b/static/js/map/Overlaysetup.js @@ -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); + } + } + } diff --git a/static/js/map/overlays/SignOverlay.js b/static/js/map/overlays/SignOverlay.js new file mode 100644 index 0000000..5aef51a --- /dev/null +++ b/static/js/map/overlays/SignOverlay.js @@ -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; + } +}); diff --git a/static/pics/default_sign_steel.png b/static/pics/default_sign_steel.png new file mode 100644 index 0000000000000000000000000000000000000000..3ca0c59d3eea1b096d01ef6031b3a58a634e3108 GIT binary patch literal 537 zcmV+!0_OdRP)Su2!W6a%{WjL z1@F{uw?ita-y#DjsS%sa24H;00w8qTwg4;^i*L6XV=%^`wWetrj>jVaGLB=vsVvJM z$@~4@t8~txCzFW>E|<$6H$O1rIQ~=cnQ%Uz0jR19V+?g&18_JTu-1B2xAZQ>v=+xW4b{`yPF{TwY}7d5$rL`Fu{(G^A+?K$c}M zSSh7MO6f!V?D<*tbI?Kvgb?^M0<2c6Z^_R=E2RL?kESe3|2#qnlv3PoH-=%L?|bg| zyH~2U{@*7_LKH>ftNTl(2}4O3hA*=?j_JA%9Yqn_?Ur|{C<=7fb*$HGq?Et1aJ^oc bPN#eTi=whxbD8&}00000NkvXXu0mjfuoBh^ literal 0 HcmV?d00001 diff --git a/static/pics/default_sign_wood.png b/static/pics/default_sign_wood.png new file mode 100644 index 0000000000000000000000000000000000000000..d0559dac36e74f6a23df27e7c5c8f97969d7db1f GIT binary patch literal 770 zcmV+d1O5DoP)y{D4^000SaNLh0L01FcU01FcV0GgZ_00076 zNkl9}J3BL(EQTO?sEtjC5+XzdLC{LO6p`p(5cCH`(b85# zuu_O!Py~x$p{NK#ga{JELX8@d>~1#6OlD^H&ch-SYy{1LuQ|;*-+5?xo^$KcNdRQU zBnl!rVMvzc0FdZAPy4>j^_|Z0dE$U z0WjA>(vHF?SAdi>P03UY!k`;R0937*O1Vn0BoVDv8$kPC-2NV|)oN2PE0P1+4+Z|BU}E+