Skip to content

Commit

Permalink
Downloadable
Browse files Browse the repository at this point in the history
Minor visual bugs
Uploadable shapes
Maps not uploadables yet
  • Loading branch information
dip000 committed Feb 18, 2022
1 parent 54b347f commit 6ea4925
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 166 deletions.
58 changes: 29 additions & 29 deletions MapBuilderForWeb/BuilderCalculations.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@


function DictionaryToVector2(dictionary){
let arrayX = [];
let arrayY = [];

for(let i=0; i<Object.keys(dictionary).length; i++){
arrayX[i] = dictionary[ Object.keys(dictionary)[i] ].x;
arrayY[i] = dictionary[ Object.keys(dictionary)[i] ].y;
}

console.log("VECTOR TO DOUBLE ARRAY: ");
console.log(arrayX)
console.log(arrayY)

return new Vector2Array(arrayX, arrayY);
}


function OccupancyMapToCoordenates(occupancyMap){
if(occupancyMap == null) return;

if(occupancyMap == null) return;
let coordenates = new Vector2Array();
let k = 0;
let mapLengthX = occupancyMap.length;
Expand All @@ -36,11 +21,11 @@

return coordenates;
}

function LocalizeCoordenates(vector2){
var minX = 999;
var minY = 999;

for(var i=0; i<vector2.x.length; i++){
if(vector2.x[i] < minX){
minX = vector2.x[i];
Expand All @@ -49,22 +34,22 @@
minY = vector2.y[i];
}
}

for(var i=0; i<vector2.x.length; i++){
vector2.x[i] -= minX;
vector2.y[i] -= minY;
}

console.log("LOCALIZED TO MIN VALUE: ");
console.log("minX " + minX + "; minY " + minY);
console.log(vector2);

return vector2;
}

function GlobalizeCoordenates(shape, x, y){
let coordenatesa = new Vector2Array(shape);

for(let i=0; i<shape.x.length; i++){
coordenatesa.x[i] += x;
coordenatesa.y[i] += y;
Expand Down Expand Up @@ -102,15 +87,15 @@
function RotatePerfect(vector2, maxX){
var tempX = vector2.x;
vector2.x = vector2.y;

for(var i=0; i<vector2.x.length; i++){
tempX[i] = maxX - tempX[i];
}
vector2.y = tempX;

return vector2;
}

function RotateCoordenates90Clockwise(vector2){

//Flip axis. This actually mirors coordenates by 45 degrees
Expand All @@ -119,12 +104,12 @@
var switchReg = vector2.x[i];
vector2.x[i] = vector2.y[i];
vector2.y[i] = switchReg;

if(vector2.y[i] > maxY){
maxY = vector2.y[i];
}
}

//Miror y axis. Both instructions actually rotate the coordenates 90° counteclockwise
// and that can be seen as switching from row-cols system to x-y cartesian system
for(var i=0; i<vector2.x.length; i++){
Expand Down Expand Up @@ -154,7 +139,7 @@
}

function GetMinValuesOfCoordenates(coordenates){
let minValue = {x:0, y:99};
let minValue = {x:0, y:999};

for( let i=0; i<coordenates.x.length; i++ ){
if(coordenates.x[i] > minValue.x){
Expand All @@ -168,6 +153,21 @@
return minValue;
}

function GetMaxValuesOfCoordenates(coordenates){
let maxValue = {x:0, y:0};

for( let i=0; i<coordenates.x.length; i++ ){
if(coordenates.x[i] > maxValue.x){
maxValue.x = coordenates.x[i];
}
if(coordenates.y[i] > maxValue.y){
maxValue.y = coordenates.y[i];
}
}

return maxValue;
}

function getStatisticsTopValue(val)
{
var stat = '';
Expand Down
32 changes: 16 additions & 16 deletions MapBuilderForWeb/MapBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,10 @@
/////////// KEY COMBOS //////////////////////////////////////////////////////////////
const keyLog = {}
const handleKeyboard = ({ type, key, repeat, metaKey }) => {
if (repeat) return
if( repeat ) return;
if( isShapeEditorActive ) return;

if (type === 'keydown') {
if( type === 'keydown' ){
keyLog[key] = true

//Create cuts on rows and cols with Ctrl + arrow keys
Expand Down Expand Up @@ -326,8 +327,11 @@ function OutputData(){
this.mapSizeY = 0;
this.mapName = "unnamed";

this.generateFromHistory = function(){
let numberOfInstructions = historyOfPlacements.length;
this.generateFromHistory = function( history=historyOfPlacements ){

//if(history == null) history = ;

let numberOfInstructions = history.length;
this.itemTypes = [];
this.itemRotations = [];
this.positionsX = [];
Expand All @@ -338,14 +342,14 @@ function OutputData(){
for(var i=0; i<numberOfInstructions; i++){

//Skip the search if it was marked as deleted
if(historyOfPlacements[i].deleted == true){
if(history[i].deleted == true){
continue;
}

this.itemTypes[j] = historyOfPlacements[i].itemType;
this.itemRotations[j] = historyOfPlacements[i].rotation;
this.positionsX[j] = historyOfPlacements[i].positionX;
this.positionsY[j] = historyOfPlacements[i].positionY;
this.itemTypes[j] = history[i].itemType;
this.itemRotations[j] = history[i].rotation;
this.positionsX[j] = history[i].positionX;
this.positionsY[j] = history[i].positionY;
j++;
}
}
Expand Down Expand Up @@ -380,6 +384,8 @@ function OutputData(){

this.mapSizeX = maxY - minY + 1;
this.mapSizeY = maxX - minX + 1;

return {"minX":minX, "maxX":maxX, "minY":minY, "maxY":maxY};
}


Expand All @@ -400,7 +406,7 @@ function Point(x, y){
let shapesString = mapsAndShapesString[1].split("&");

uploadShapes(shapesString);
//uploadMaps(mapsString);
uploadMaps(mapsString);

/*console.log(mapsString)
console.log(shapesString)
Expand Down Expand Up @@ -438,9 +444,6 @@ function Point(x, y){

// Simplified version with a non cutted map
if(mapsString.length == 1){
rows(1);
cols(1);

maps = JSON.parse(mapsString[0]);
updateMap(maps);
return;
Expand All @@ -452,9 +455,6 @@ function Point(x, y){
maps[i] = JSON.parse(mapsString[i]);
}

let mapSizeX = maps[0].maps.mapSizeX;
rows(1);
cols(1);

}

Expand Down
7 changes: 1 addition & 6 deletions MapBuilderForWeb/MapBuilderForWeb.html
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,7 @@

function DownloadMap(){

let outputData;
if(ncols == 1 && nrows == 1)
outputData = JSON.stringify( formatCoordenates() );
else
outputData = FormatOutput();

let outputData = formatHistoryData();
let ouputShapes = formatShapes();

//console.log("DOWNLOADED:");
Expand Down
4 changes: 2 additions & 2 deletions MapBuilderForWeb/MapBuilderStyles.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
--light: #95E02F;
--lighter: #B9F51B;
*/

/*
--TITLE: VISUAL STUDIO PALETTE;
--blue: #569CD6;
--light-blue: #9CDCFE;
Expand All @@ -18,7 +18,7 @@
--yellow: #DCDCAA;
--pink: #D8A0D1;
--orange: #D69D85;

*/

--background: #1E1E1E;
--table-shadow: #111111;
Expand Down
Loading

0 comments on commit 6ea4925

Please sign in to comment.