1
0
forked from MTSR/mapserver

minecart wip

This commit is contained in:
Thomas Rudin 2019-05-04 21:16:57 +02:00
parent 3bd9a2b462
commit bd3593f13e
3 changed files with 19 additions and 18 deletions

View File

@ -1,6 +1,6 @@
mapserver = { mapserver = {
enable_crafting = minetest.settings:get("mapserver.enable_crafting") enable_crafting = minetest.settings:get("mapserver.enable_crafting"),
bridge = {} bridge = {}
} }
@ -27,7 +27,7 @@ if http then
print("[Mapserver] starting mapserver-bridge with endpoint: " .. mapserver_url) print("[Mapserver] starting mapserver-bridge with endpoint: " .. mapserver_url)
dofile(MP .. "/bridge/init.lua") dofile(MP .. "/bridge/init.lua")
mapserver.bridge_init(http, mapserver_url, mapserver_key) mapserver.bridge_init(http, mapserver_url, mapserver_key)
else else

View File

@ -10,7 +10,7 @@ var MinecartOverlay = L.LayerGroup.extend({
this.wsChannel = wsChannel; this.wsChannel = wsChannel;
this.currentObjects = {}; // name => marker this.currentObjects = {}; // name => marker
this.trains = []; this.minecarts = [];
this.reDraw = this.reDraw.bind(this); this.reDraw = this.reDraw.bind(this);
this.onMinetestUpdate = this.onMinetestUpdate.bind(this); this.onMinetestUpdate = this.onMinetestUpdate.bind(this);
@ -33,6 +33,7 @@ var MinecartOverlay = L.LayerGroup.extend({
var marker = L.marker([cart.pos.z, cart.pos.x], {icon: Icon}); var marker = L.marker([cart.pos.z, cart.pos.x], {icon: Icon});
var html = "<b>Minecart</b><hr>"; var html = "<b>Minecart</b><hr>";
html += "<b>Id: </b> " + cart.id + "<br>";
marker.bindPopup(html); marker.bindPopup(html);
@ -53,37 +54,36 @@ var MinecartOverlay = L.LayerGroup.extend({
var isInLayer = self.isCartInCurrentLayer(cart); var isInLayer = self.isCartInCurrentLayer(cart);
if (!isInLayer){ if (!isInLayer){
if (self.currentObjects[train.id]){ if (self.currentObjects[cart.id]){
//train is displayed and not on the layer anymore //cart is displayed and not on the layer anymore
//Remove the marker and reference //Remove the marker and reference
self.currentObjects[train.id].remove(); self.currentObjects[cart.id].remove();
delete self.currentObjects[train.id]; delete self.currentObjects[cart.id];
} }
return; return;
} }
if (self.currentObjects[train.id]){ if (self.currentObjects[cart.id]){
//marker exists //marker exists
self.currentObjects[train.id].setLatLng([train.pos.z, train.pos.x]); self.currentObjects[cart.id].setLatLng([cart.pos.z, cart.pos.x]);
//setPopupContent //setPopupContent
} else { } else {
//marker does not exist //marker does not exist
var marker = self.createMarker(train); var marker = self.createMarker(cart);
marker.addTo(self); marker.addTo(self);
self.currentObjects[train.id] = marker; self.currentObjects[cart.id] = marker;
} }
}); });
Object.keys(self.currentObjects).forEach(function(existingId){ Object.keys(self.currentObjects).forEach(function(existingId){
var trainIsActive = self.trains.find(function(t){ var cartIsActive = self.minecarts.find(function(t){
return t.id == existingId; return t.id == existingId;
}); });
if (!trainIsActive){ if (!cartIsActive){
//train
self.currentObjects[existingId].remove(); self.currentObjects[existingId].remove();
delete self.currentObjects[existingId]; delete self.currentObjects[existingId];
} }
@ -97,15 +97,15 @@ var MinecartOverlay = L.LayerGroup.extend({
var mapLayer = this.layerMgr.getCurrentLayer(); var mapLayer = this.layerMgr.getCurrentLayer();
this.trains.forEach(function(train){ this.minecarts.forEach(function(cart){
if (!self.isTrainInCurrentLayer(train)){ if (!self.isCartInCurrentLayer(cart)){
//not in current layer //not in current layer
return; return;
} }
var marker = self.createMarker(train); var marker = self.createMarker(cart);
marker.addTo(self); marker.addTo(self);
self.currentObjects[train.id] = marker; self.currentObjects[cart.id] = marker;
}); });
}, },

View File

@ -34,6 +34,7 @@ type Train struct {
type Minecart struct { type Minecart struct {
Pos GenericPos `json:"pos"` Pos GenericPos `json:"pos"`
Speed GenericPos `json:"speed"` Speed GenericPos `json:"speed"`
Id float64 `json:"id"`
} }
type Player struct { type Player struct {