Skip to content

Commit

Permalink
Map cuts badly working
Browse files Browse the repository at this point in the history
  • Loading branch information
dip000 committed Feb 16, 2022
1 parent d4cf812 commit 7bee051
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 59 deletions.
24 changes: 18 additions & 6 deletions MapBuilderForWeb/BuilderCalculations.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@
}

function GlobalizeCoordenates(shape, x, y){
let coordenates = new Vector2Array(shape);
for(let i=0; i<coordenates.x.length; i++){
coordenates.x[i] += x;
coordenates.y[i] += y;
let coordenatesa = new Vector2Array(shape);

for(let i=0; i<shape.x.length; i++){
coordenatesa.x[i] += x;
coordenatesa.y[i] += y;
}
//console.log("GLOBALIZED TO TARGET VALUE: ");
//console.log(coordenates);
return coordenates;
return coordenatesa;
}

function RotateCoordenatesByAngle(coordenates, angle){
Expand Down Expand Up @@ -97,6 +97,18 @@
}


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 Down
51 changes: 14 additions & 37 deletions MapBuilderForWeb/MapBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,13 @@ function ItemPlacingInfo(itemType, rotation, positionX, positionY, coordenates){
}

function OutputData(){
this.itemTypes;
this.itemRotations;
this.positionsX;
this.positionsY;
this.mapSizeX;
this.mapSizeY;
this.mapName;
this.itemTypes = new Array();
this.itemRotations = new Array();
this.positionsX = new Array();
this.positionsY = new Array();
this.mapSizeX = 0;
this.mapSizeY = 0;
this.mapName = "unnamed";

this.generateFromHistory = function(){
let numberOfInstructions = historyOfPlacements.length;
Expand Down Expand Up @@ -390,37 +390,14 @@ function OutputData(){
this.mapSizeX = maxY - minY + 1;
this.mapSizeY = maxX - minX + 1;
}


this.addPlacementInfo = function(info){
this.itemTypes[itemTypes.length] = info.itemType;
this.itemRotations.push( info.rotation );
this.positionsX.push( info.positionX );
this.positionsY.push( info.positionY );
}

}

function Asdasd(){
let mapLengthX = occupancyMap.length;
let mapLengthY = occupancyMap[0].length;
let mapJumper = 0;
let row=0, col=0;
let mapChanger=0;;

for(col=0; col<mapLengthY; col++){
if(cutsMap[0][col] == CUT){
console.log("Horizontal map jump at: 0, " + col);
continue;
}

for(row=0; row<mapLengthX; row++){
if( cutsMap[row][col] == CUT ){
mapJumper++;
console.log("New map");
continue;
}
console.log("currently at: " + row + ", " + col);

if( occupancyMap[row][col] == OCCUPIED ){
let info = FindHistoryInfoAtPoint({x:row, y:col});
console.log("Found shape at map: " + mapJumper + "; ShapeInfo: ");
console.log(info);
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////
7 changes: 6 additions & 1 deletion MapBuilderForWeb/MapBuilderForWeb.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@
//Starts showing map editor while hidning shapes editor
GoToMapEditor();
//GoToShapesEditor();

//FOR DEBUGGING ONLY
rows(3);
cols(3);
}


Expand Down Expand Up @@ -368,7 +372,8 @@

function DownloadMap(){

let outputData = JSON.stringify( formatCoordenates() );
//let outputData = JSON.stringify( formatCoordenates() );
let outputData = FormatOutput();
let ouputShapes = formatShapes();

//console.log("DOWNLOADED:");
Expand Down
112 changes: 98 additions & 14 deletions MapBuilderForWeb/MultimapMechanics.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@

function rows(numberOfRows){

let maxRows = Math.round( occupancyMap.length/2 );
if(numberOfRows <= 0){
console.log("Applied minimum (1) instead");
numberOfRows = 1;
}
if(numberOfRows > maxRows){
console.log("Applied maximum ("+maxRows+") instead");
numberOfRows = maxRows;
}

UpdateCutsMap(TARGET_ROWS, nrows, JOIN);
UpdateCutsMap(TARGET_ROWS, numberOfRows, CUT);
Expand All @@ -23,14 +32,23 @@

function cols(numberOfCols){

let maxCols = Math.round( occupancyMap[0].length/2 );
if(numberOfCols <= 0){
console.log("Applied minimum (1) instead");
numberOfCols = 1;
}
if(numberOfCols > maxCols){
console.log("Applied maximum ("+maxCols+") instead");
numberOfCols = maxCols;
}

UpdateCutsMap(TARGET_COLS, ncols, JOIN);
UpdateCutsMap(TARGET_COLS, numberOfCols, CUT);

UpdateCutsMap(TARGET_ROWS, nrows, CUT);
ncols = numberOfCols;
}



const TARGET_ROWS = true;
const TARGET_COLS = false;
const CUT = true;
Expand All @@ -48,21 +66,10 @@
mapLengthB = occupancyMap.length;
mapLengthA = occupancyMap[0].length;
}

let increment = mapLengthA / numberOfSuch;
let incrementRounded = Math.round( increment );

if(numberOfSuch <= 0){
console.log("Cannot make that few");
return;
}
if(numberOfSuch > Math.round( mapLengthA/2 )){
console.log("Cannot make that many");
return;
}



for(let i=0; i<numberOfSuch-1; i++){
for(let j=0; j<mapLengthB; j++){
if(target == TARGET_ROWS){
Expand Down Expand Up @@ -99,6 +106,83 @@
ResetMap();
return true;
}

function FormatOutput(){
const numberOfInstructions = historyOfPlacements.length;

const mapLengthRows = occupancyMap.length;
const mapLengthCols = occupancyMap[0].length;

const islandSizeRows = Math.round(mapLengthRows/nrows) - (nrows-1) + 1;
const islandSizeCols = Math.round(mapLengthCols/ncols) - (ncols-1) + 1;

let outputData = new Array();

for(var i=0; i<numberOfInstructions; i++){

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

let row = historyOfPlacements[i].positionX;
let col = historyOfPlacements[i].positionY;

for(var r=0; r<nrows; r++){
for(var c=0; c<ncols; c++){
if( row>islandSizeRows*r && row<islandSizeRows*(r+1) && col>islandSizeCols*c && col<islandSizeCols*(c+1) ){
console.log("Found type: " + listOfShapeNames[ historyOfPlacements[i].itemType ] + " in ("+ r +","+c+") island");

if(outputData[r] == null){
outputData[r] = new Array();
}
if(outputData[r][c] == null){
outputData[r][c] = new OutputData();
}
outputData[r][c].itemTypes.push(historyOfPlacements[i].itemType);
outputData[r][c].itemRotations.push(historyOfPlacements[i].rotation);
outputData[r][c].positionsX.push(historyOfPlacements[i].positionX);
outputData[r][c].positionsY.push(historyOfPlacements[i].positionY);

outputData[r][c].mapSizeX = islandSizeRows;
outputData[r][c].mapSizeY = islandSizeCols;
}
}
}
}

let outString = "";
for(var i=0; i<outputData.length; i++){
for(var j=0; j<outputData[0].length; j++){

let formatedCoordenates = new Vector2Array( outputData[i][j].positionsX, outputData[i][j].positionsY );

console.log(outputData[i][j].positionsX+ "--" + outputData[i][j].positionsY);
//console.log(new Vector2Array(formatedCoordenates));
let globalizedCoordenates = GlobalizeCoordenates( formatedCoordenates, -i*islandSizeRows, -j*islandSizeCols );
console.log("-i*islandSizeRows: "+(-i*islandSizeRows)+"; -j*islandSizeCols: "+(-j*islandSizeCols));
//console.log(new Vector2Array(globalizedCoordenates));

let residueX = (mapLengthRows-(nrows-1)) % nrows;
let residueY = (mapLengthCols-(ncols-1)) % ncols;

let rotatedCoordenates = RotatePerfect( globalizedCoordenates, (islandSizeRows + residueX-1));
console.log(new Vector2Array(rotatedCoordenates));
console.log("residueX: " +residueX);
console.log("residueY: " +residueY);
console.log("(islandSizeRows + residueX-1): " +(islandSizeRows + residueX-1));

outputData[i][j].positionsX = rotatedCoordenates.x;
outputData[i][j].positionsY = rotatedCoordenates.y;

outString += JSON.stringify( outputData[i][j] );
outString += "&";
}
}

outString = outString.slice(0, -1);
return outString;
}



6 changes: 5 additions & 1 deletion MapBuilderForWeb/ShapeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ var isShapeEditorActive = false;

//Remove and reacomodate registry
listOfShapes.splice(shapeIndex, 1);
listOfShapeNames.splice(shapeIndex, 1);
listOfShapeNames.splice(shapeIndex, 1);

//Reset shapes visuals
let itemsArea = document.getElementById('itemsArea');
Expand All @@ -155,6 +155,10 @@ var isShapeEditorActive = false;
printVisualsOfCoordenates(historyOfPlacements[i].coordenates, clearedGridColor);
UpdateOccupancy(historyOfPlacements[i].coordenates, FREE);
}
//Higher item types must reaccomodate. Lower item types stays the same
else if(historyOfPlacements[i].itemType > shapeIndex){
historyOfPlacements[i].itemType--;
}
}

}
Expand Down

0 comments on commit 7bee051

Please sign in to comment.