diff --git a/MapBuilderForWeb/MapBuilder.js b/MapBuilderForWeb/MapBuilder.js index b8e736d..27a8677 100644 --- a/MapBuilderForWeb/MapBuilder.js +++ b/MapBuilderForWeb/MapBuilder.js @@ -259,21 +259,34 @@ const keyLog = {} const handleKeyboard = ({ type, key, repeat, metaKey }) => { - if (repeat) return - - if (type === 'keydown') { - keyLog[key] = true - - - if (/*keyLog.c &&*/ key === "ArrowLeft") - cols(ncols-1); - if (/*keyLog.c &&*/ key === "ArrowRight") - cols(ncols+1); - if (/*keyLog.r &&*/ key === "ArrowDown") - rows(nrows-1); - if (/*keyLog.r &&*/ key === "ArrowUp") - rows(nrows+1); - } + if (repeat) return + + if (type === 'keydown') { + keyLog[key] = true + + //Create cuts on rows and cols with Ctrl + arrow keys + if(keyLog.Control){ + if (key === "ArrowLeft") + cols(ncols-1); + if (key === "ArrowRight") + cols(ncols+1); + if (key === "ArrowDown") + rows(nrows-1); + if (key === "ArrowUp") + rows(nrows+1); + } + else{ + //Rebuild map rows and cols with arrow keys + if (key === "ArrowLeft") + map( occupancyMap.length, occupancyMap[0].length-1 ); + if (key === "ArrowRight") + map( occupancyMap.length, occupancyMap[0].length+1 ); + if (key === "ArrowDown") + map( occupancyMap.length+1, occupancyMap[0].length ); + if (key === "ArrowUp") + map( occupancyMap.length-1, occupancyMap[0].length ); + } +} // Remove the key from the log on keyup. if (type === 'keyup') delete keyLog[key]; @@ -431,4 +444,84 @@ function OutputData(){ } +//////////////////////////////////////////////////////////////////////////////////// + +/////////////////////////// UPLOAD ///////////////////////////////////////////////// + + function upload(uploadString){ + let mapsAndShapesString = uploadString.split("$"); + let mapsString = mapsAndShapesString[0].split("&"); + let shapesString = mapsAndShapesString[1].split("&"); + + uploadShapes(shapesString); + //uploadMaps(mapsString); + + /*console.log(mapsString) + console.log(shapesString) + + console.log(maps) + console.log(shapes)*/ + } + + function uploadShapes(shapesString){ + listOfShapes = []; + let shapes = []; + for(let i=0; i= ncols-1){ + mapSizeX += residueCols; + } + if(r >= nrows-1){ + mapSizeY += residueRows; + } + + //Apply map size + outputData[r][c].mapSizeX = mapSizeX; + outputData[r][c].mapSizeY = mapSizeY; + + //Map name is its position + outputData[r][c].mapName = "Level " + r + ", " + c; + //string output and add the separator character outString += JSON.stringify( outputData[r][c] ); outString += "&"; - - console.log("----------------------------"); } }