working on train movements

This commit is contained in:
Stephan Richter
2020-09-20 16:19:05 +02:00
parent 9e36d5c0c8
commit cd022ce4a3
8 changed files with 150 additions and 72 deletions

View File

@@ -174,7 +174,7 @@ svg.left rect,
svg.right rect,
svg.straight .left,
svg.straight .right{
fill: white !important;
fill: #ddd !important;
}
.occupied .block{

View File

@@ -1,10 +1,10 @@
const ADD = 'add';
const MOVE = 'move';
const SQUARE = 30;
const BODY = '#plan';
const BODY = 'body';
const DIV = 'DIV';
const SVG = 'svg';
const PLAN = 'plan';
const PLAN = '#plan';
const POST = 'POST';
var selected = null;
var mode = null;
@@ -23,23 +23,6 @@ function addTile(x,y){
return request({action:mode,tile:selected.id,x:x,y:y});
}
function bodyClick(ev){
//console.log('bodyClick:',ev);
var x = Math.floor(ev.clientX/SQUARE);
var y = Math.floor(ev.clientY/SQUARE);
switch (mode){
case undefined:
case null:
return clickTile(x,y);
case ADD:
return addTile(x,y);
case MOVE:
return moveTile(x,y);
}
console.log('unknown action "'+mode+'" @ ('+ev.clientX+','+ev.clientY+')');
}
function clickTile(x,y){
console.log("clickTile:",x,y);
if ($('#tile-'+x+'-'+y).length > 0) request({action:'click',x:x,y:y});
@@ -113,10 +96,27 @@ function openRoute(id){
function place(data){
var tag = $(data);
$('#'+tag.attr('id')).remove();
$(BODY).append(tag);
$(PLAN).append(tag);
return false;
}
function planClick(ev){
//console.log('bodyClick:',ev);
var x = Math.floor(ev.clientX/SQUARE);
var y = Math.floor(ev.clientY/SQUARE);
switch (mode){
case undefined:
case null:
return clickTile(x,y);
case ADD:
return addTile(x,y);
case MOVE:
return moveTile(x,y);
}
console.log('unknown action "'+mode+'" @ ('+ev.clientX+','+ev.clientY+')');
}
function remove(id){
$('#'+id).remove();
return false;
@@ -124,14 +124,15 @@ function remove(id){
function request(data){
$.ajax({
url : PLAN,
url : 'plan',
method : POST,
data : data,
success: function(resp){
closeWindows();
if (resp.startsWith('<svg')){
$('#plan').append($(resp));
$(PLAN).append($(resp));
} else if (resp.startsWith('<')) {
console.log("appending to body: "+resp.substring(0,10));
$(BODY).append($(resp));
} else {
addMessage(resp);
@@ -163,11 +164,10 @@ function stream(ev){
window.onload = function () {
var isDragging = false;
console.log($(BODY).each(function(){console.log(this)}));
$('.menu > div').click(closeMenu);
$('.menu .addtile .list svg').click(enableAdding);
$('.menu .move .list div').click(enableMove);
$('.menu .actions .list > div').click(runAction);
$(BODY).click(bodyClick);
$(PLAN).click(planClick);
(new EventSource("stream")).onmessage = stream;
}