Skip to content

Commit

Permalink
development halted
Browse files Browse the repository at this point in the history
New branch opened for rework
  • Loading branch information
dip000 committed Feb 17, 2022
1 parent 96d0660 commit d192e56
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 31 deletions.
123 changes: 108 additions & 15 deletions MapBuilderForWeb/MapBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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<shapesString.length; i++){
shapes[i] = JSON.parse(shapesString[i]);

let shape = new Vector2Array(shapes[i].localCoordenatesX, shapes[i].localCoordenatesY);
let shapeRotated = RotateCoordenatesByAngle( shape, 90 );

listOfShapes[i] = shapeRotated;
listOfShapeNames[i] = shapes[i].itemName;
listOfShapeColors[i] = randomColor();
}

//Reset shapes visuals
let itemsArea = document.getElementById('itemsArea');
itemsArea.innerHTML = "";

//Show all current shapes
initializeMapEditorShapes(listOfShapes.length-1);

}

function uploadMaps(mapsString){
let maps = [];
let mapSize;

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

maps = JSON.parse(mapsString[0]);
updateMap(maps);
return;
}

// First parse all
let nmaps = mapsString.length;
for(let i=0; i<nmaps; i++){
maps[i] = JSON.parse(mapsString[i]);
}

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

}

function updateMap(maps){
map(maps.mapSizeX, maps.mapSizeY);

for(let i=0; i<maps.positionsX.length; i++){
ChangeItem(maps.itemTypes[i]);
currentItemPlacingInfo.rotation = maps.itemRotations[i];
OnGridClick(maps.positionsX[i], maps.positionsY[i]);
}
}



////////////////////////////////////////////////////////////////////////////////////
8 changes: 6 additions & 2 deletions MapBuilderForWeb/MapBuilderForWeb.html
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,12 @@

function DownloadMap(){

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

let ouputShapes = formatShapes();

//console.log("DOWNLOADED:");
Expand Down
42 changes: 28 additions & 14 deletions MapBuilderForWeb/MultimapMechanics.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,33 @@
function UpdateCutsMap(target, numberOfSuch, state){
let x, y;
let mapLengthB, mapLengthA;
let nSuch;

if(target == TARGET_ROWS){
mapLengthA = occupancyMap.length;
mapLengthB = occupancyMap[0].length;
nSuch = nrows;
}
else{
mapLengthB = occupancyMap.length;
mapLengthA = occupancyMap[0].length;
nSuch = ncols;
}

let increment = mapLengthA / numberOfSuch;
let incrementRounded = Math.round( increment );
const available = mapLengthA-(nSuch-1);
const islandSize = available / numberOfSuch;
const islandSizeWithCut = islandSize + 1;
const increment = Math.floor( islandSizeWithCut );

for(let i=0; i<numberOfSuch-1; i++){
for(let j=0; j<mapLengthB; j++){
if(target == TARGET_ROWS){
y = j;
x = incrementRounded*(i+1)-1;
x = increment*(i+1)-1;
}
else{
x = j;
y = incrementRounded*(i+1)-1;
y = increment*(i+1)-1;
}

if(state == CUT){
Expand Down Expand Up @@ -196,9 +201,6 @@
outputData[r][c].positionsX.push(historyOfPlacements[i].positionX);
outputData[r][c].positionsY.push(historyOfPlacements[i].positionY);

//NOTE: Redoundant here
outputData[r][c].mapSizeX = islandSizeRows;
outputData[r][c].mapSizeY = islandSizeCols;
}
}
}
Expand All @@ -219,25 +221,37 @@
let originCols = (islandSizeCols+1) * c;

//Reference each points in map from its local origin
console.log("r: " +r + "; c: " + c);
console.log(outputData[r][c].positionsX+ "--" + outputData[r][c].positionsY);
//console.log(new Vector2Array( new Vector2Array(formatedCoordenates)) );
let globalizedCoordenates = GlobalizeCoordenates( formatedCoordenates, -originRows, -originCols);
//console.log(new Vector2Array(globalizedCoordenates));

//Switch axis from (rwo,col) to (x,y). To rotate all points in a fixed area is needed a reference to the highest point in rows axis, which is size-1
let rotatedCoordenates = RotatePerfect( globalizedCoordenates, islandSizeRows-1 );
console.log(new Vector2Array(rotatedCoordenates));

//Coordenates are formated and sent back to output data
outputData[r][c].positionsX = rotatedCoordenates.x;
outputData[r][c].positionsY = rotatedCoordenates.y;

//Switched map dimentions to match with the (x,y) system
let mapSizeX = islandSizeCols;
let mapSizeY = islandSizeRows;

//If the map was not sliced evenly, compenzate residues in last row and col
if(c >= 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("----------------------------");
}
}

Expand Down

0 comments on commit d192e56

Please sign in to comment.