diff --git a/mapserver_mod/mapserver/bridge.lua b/mapserver_mod/mapserver/bridge.lua index 57a04f7..34d709e 100644 --- a/mapserver_mod/mapserver/bridge.lua +++ b/mapserver_mod/mapserver/bridge.lua @@ -51,6 +51,9 @@ function send_stats() --print(dump(train))--XXX local t = { + text_outside = train.text_outside, + text_inside = train.text_inside, + line = train.line, pos = train.last_pos, velocity = train.velocity, off_track = train.off_track, diff --git a/pics/trains.png b/pics/trains.png new file mode 100644 index 0000000..617f988 Binary files /dev/null and b/pics/trains.png differ diff --git a/pics/trains2.png b/pics/trains2.png new file mode 100644 index 0000000..dcda1d1 Binary files /dev/null and b/pics/trains2.png differ diff --git a/server/app/config.go b/server/app/config.go index 3fff624..1de7e73 100644 --- a/server/app/config.go +++ b/server/app/config.go @@ -42,6 +42,7 @@ type MapObjectConfig struct { Smartshop bool `json:"smartshop"` Fancyvend bool `json:"fancyvend"` ATM bool `json:"atm"` + Train bool `json:"train"` } type WebApiConfig struct { @@ -110,6 +111,7 @@ func ParseConfig(filename string) (*Config, error) { Smartshop: true, Fancyvend: true, ATM: true, + Train: true, } mapblockaccessor := MapBlockAccessorConfig{ diff --git a/server/static/index.html b/server/static/index.html index 73f053b..5d0e060 100644 --- a/server/static/index.html +++ b/server/static/index.html @@ -1,5 +1,5 @@ - + @@ -36,6 +36,7 @@ + diff --git a/server/static/js/Overlaysetup.js b/server/static/js/Overlaysetup.js index 7288d7b..68f63ca 100644 --- a/server/static/js/Overlaysetup.js +++ b/server/static/js/Overlaysetup.js @@ -45,4 +45,8 @@ function Overlaysetup(cfg, map, overlays, wsChannel, layerMgr){ if (cfg.mapobjects.mission) { overlays["Missions"] = new MissionOverlay(wsChannel, layerMgr); } + + if (cfg.mapobjects.train) { + overlays["Trains"] = new TrainOverlay(wsChannel, layerMgr); + } } diff --git a/server/static/js/overlays/TrainOverlay.js b/server/static/js/overlays/TrainOverlay.js index 69725ec..d74abb0 100644 --- a/server/static/js/overlays/TrainOverlay.js +++ b/server/static/js/overlays/TrainOverlay.js @@ -1,13 +1,24 @@ 'use strict'; -//TODO -var TrainIcon = L.icon({ - iconUrl: 'pics/sam.png', - - iconSize: [16, 32], - iconAnchor: [8, 16], - popupAnchor: [0, -16] -}); +function getTrainImageUrlForType(type){ + switch(type){ + case "advtrains:subway_wagon": + return "pics/advtrains/advtrains_subway_wagon_inv.png"; + case "advtrains:engine_japan": + return "pics/advtrains/advtrains_engine_japan_inv.png"; + case "advtrains:engine_steam": + return "pics/advtrains/advtrains_engine_steam_inv.png"; + case "advtrains:engine_industrial": + return "pics/advtrains/advtrains_engine_industrial_inv.png"; + case "advtrains:wagon_wood": + return "pics/advtrains/advtrains_wagon_wood_inv.png"; + case "advtrains:wagon_box": + return "pics/advtrains/advtrains_wagon_box_inv.png"; + default: + //TODO: fallback image + return "pics/advtrains/advtrains_subway_wagon_inv.png"; + } +} var TrainOverlay = L.LayerGroup.extend({ initialize: function(wsChannel, layerMgr) { @@ -29,8 +40,40 @@ var TrainOverlay = L.LayerGroup.extend({ }, createMarker: function(train){ - var marker = L.marker([train.pos.z, train.pos.x], {icon: TrainIcon}); - marker.bindPopup("Train"); + + //search for wagin in front (whatever "front" is...) + var type; + var lowest_pos = 100; + train.wagons.forEach(function(w){ + if (w.pos_in_train < lowest_pos){ + lowest_pos = w.pos_in_train; + type = w.type; + } + }); + + var Icon = L.icon({ + iconUrl: getTrainImageUrlForType(type), + + iconSize: [16, 16], + iconAnchor: [8, 8], + popupAnchor: [0, -16] + }); + + var marker = L.marker([train.pos.z, train.pos.x], {icon: Icon}); + + var html = "Train
"; + + html += "Name: " + train.text_outside + "
"; + html += "Line: " + train.line + "
"; + html += "Velocity: "+ Math.floor(train.velocity*10)/10 + "
"; + + html += "Composition: "; + train.wagons.forEach(function(w){ + var iconUrl = getTrainImageUrlForType(w.type); + html += ""; + }); + + marker.bindPopup(html); return marker; }, diff --git a/server/static/pics/advtrains/advtrains_subway_wagon_inv.png b/server/static/pics/advtrains/advtrains_subway_wagon_inv.png index 1d0e809..f7168e1 100644 Binary files a/server/static/pics/advtrains/advtrains_subway_wagon_inv.png and b/server/static/pics/advtrains/advtrains_subway_wagon_inv.png differ diff --git a/server/web/minetest.go b/server/web/minetest.go index 4b6a47d..afadfbd 100644 --- a/server/web/minetest.go +++ b/server/web/minetest.go @@ -21,11 +21,14 @@ type Wagon struct { } type Train struct { - Pos GenericPos `json:"pos"` - Id string `json:"id"` - Wagons []*Wagon `json:"wagons"` - OffTrack bool `json:"off_track"` - Velocity float64 `json:"velocity"` + Pos GenericPos `json:"pos"` + Id string `json:"id"` + Wagons []*Wagon `json:"wagons"` + OffTrack bool `json:"off_track"` + Velocity float64 `json:"velocity"` + Line string `json:"line"` + TextOutside string `json:"text_outside"` + TextInside string `json:"text_inside"` } type Player struct {