Skip to content

Commit

Permalink
Minor fixes and typos
Browse files Browse the repository at this point in the history
  • Loading branch information
dip000 committed Feb 20, 2022
1 parent 5950deb commit 01afdb6
Show file tree
Hide file tree
Showing 12 changed files with 531 additions and 417 deletions.
100 changes: 50 additions & 50 deletions MapBuilderForWeb/BuilderCalculations.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@



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

let coordenates = new Vector2Array();
let coordinates = new Vector2Array();
let k = 0;
let mapLengthX = occupancyMap.length;
let mapLengthY = occupancyMap[0].length;

for(var i=0; i<mapLengthX; i++){
for(var j=0; j<mapLengthY; j++){
if(occupancyMap[i][j] == true){
coordenates.x[k] = i;
coordenates.y[k] = j;
coordinates.x[k] = i;
coordinates.y[k] = j;
k++;
}
}
}

return coordenates;
return coordinates;
}

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

Expand All @@ -47,19 +47,19 @@
return vector2;
}

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

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

function RotateCoordenatesByAngle(coordenates, angle){
function RotateCoordinatesByAngle(coordinates, angle){
//console.log("RESULT angle: " + angle);

if(angle<0){
Expand All @@ -71,16 +71,16 @@

angle = Math.round(angle);

if(angle == 4) return coordenates;
if(angle == 4) return coordinates;

let rotatedCoordenates = new Vector2Array(coordenates);
let rotatedCoordinates = new Vector2Array(coordinates);

//console.log("RESULT times: " + angle);
for(let i=0; i<angle; i++){
rotatedCoordenates = RotateCoordenates90Clockwise(rotatedCoordenates);
rotatedCoordinates = RotateCoordinates90Clockwise(rotatedCoordinates);
}

return rotatedCoordenates;
return rotatedCoordinates;
}


Expand All @@ -96,9 +96,9 @@
return vector2;
}

function RotateCoordenates90Clockwise(vector2){
function RotateCoordinates90Clockwise(vector2){

//Flip axis. This actually mirors coordenates by 45 degrees
//Flip axis. This actually mirors coordinates by 45 degrees
var maxY = 0;
for(var i=0; i<vector2.x.length; i++){
var switchReg = vector2.x[i];
Expand All @@ -110,7 +110,7 @@
}
}

//Miror y axis. Both instructions actually rotate the coordenates 90° counteclockwise
//Miror y axis. Both instructions actually rotate the coordinates 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++){
vector2.y[i] = maxY - vector2.y[i];
Expand All @@ -123,60 +123,60 @@
}


function GetMaxValueOfCoordenates(coordenates){
function GetMaxValueOfCoordinates(coordinates){
let maxValue = 0;

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

return maxValue;
}

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

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

return minValue;
}

function GetMinValues(coordenates){
function GetMinValues(coordinates){
let minValue = {x:999, y:999};

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

return minValue;
}

function GetMaxValuesOfCoordenates(coordenates){
function GetMaxValuesOfCoordinates(coordinates){
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];
for( let i=0; i<coordinates.x.length; i++ ){
if(coordinates.x[i] > maxValue.x){
maxValue.x = coordinates.x[i];
}
if(coordenates.y[i] > maxValue.y){
maxValue.y = coordenates.y[i];
if(coordinates.y[i] > maxValue.y){
maxValue.y = coordinates.y[i];
}
}

Expand All @@ -199,15 +199,15 @@
return Math.floor(Math.random()*number);;
}

function AverageVolume(coordenates){
function AverageVolume(coordinates){
let average = {x:0, y:0};
for(let i=0; i<coordenates.x.length; i++){
average.x += coordenates.x[i];
average.y += coordenates.y[i];
for(let i=0; i<coordinates.x.length; i++){
average.x += coordinates.x[i];
average.y += coordinates.y[i];
}

average.x /= coordenates.x.length;
average.y /= coordenates.y.length;
average.x /= coordinates.x.length;
average.y /= coordinates.y.length;

return average;
}
28 changes: 14 additions & 14 deletions MapBuilderForWeb/BuilderVisuals.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// LISTENERS //////////////////////////////////////////////////////////////////////

var previusCoordenates;
var previusCoordinates;
let value = "646970303030";
var isClicking = false;

Expand Down Expand Up @@ -83,24 +83,24 @@
function printHoverVisuals(){
//Read all from current placing info
let shape = listOfShapes[currentItemPlacingInfo.itemType];
let shapeRotated = RotateCoordenatesByAngle(shape, currentItemPlacingInfo.rotation);
let shapeRotated = RotateCoordinatesByAngle(shape, currentItemPlacingInfo.rotation);

//Reformat to volume average
let averageVolume = AverageVolume(shapeRotated);
let roundedAverageVolume = { x:Math.round(averageVolume.x), y:Math.round(averageVolume.y) };
let volumeIndex = { x:(currentItemPlacingInfo.positionX-roundedAverageVolume.x), y:(currentItemPlacingInfo.positionY - roundedAverageVolume.y) };

let coordenates = GlobalizeCoordenates(shapeRotated, volumeIndex.x, volumeIndex.y);
let coordinates = GlobalizeCoordinates(shapeRotated, volumeIndex.x, volumeIndex.y);

coordenates = IgnoreOccupiedCoordenates(coordenates);
previusCoordenates = IgnoreOccupiedCoordenates(previusCoordenates, previousMap);
coordinates = IgnoreOccupiedCoordinates(coordinates);
previusCoordinates = IgnoreOccupiedCoordinates(previusCoordinates, previousMap);

//console.log(new Vector2Array(coordenates));
//console.log(new Vector2Array(coordinates));

printVisualsOfCoordenates( previusCoordenates , clearedGridColor, previousLevel );
printVisualsOfCoordenates( coordenates, itemShadowColor );
printVisualsOfCoordinates( previusCoordinates , clearedGridColor, previousLevel );
printVisualsOfCoordinates( coordinates, itemShadowColor );

previusCoordenates = coordenates;
previusCoordinates = coordinates;
previousLevel = levels[ currentItemPlacingInfo.level.x ][ currentItemPlacingInfo.level.y ];
previousMap = occupancyMaps[ currentItemPlacingInfo.level.x ][ currentItemPlacingInfo.level.y ];
}
Expand All @@ -109,13 +109,13 @@
function printHoverShapeVisuals(){
try{

if(GetOccupancyOfShapesEditorCoordenates(_x, _y) == FREE){
if(GetOccupancyOfShapesEditorCoordinates(_x, _y) == FREE){
let _cell = tableShapes.rows[ _x ].cells[ _y ];
if(_cell == null) return;
_cell.style.backgroundColor = clearedGridColor;
}

if(GetOccupancyOfShapesEditorCoordenates(currentItemPlacingInfo.positionX, currentItemPlacingInfo.positionY) == FREE){
if(GetOccupancyOfShapesEditorCoordinates(currentItemPlacingInfo.positionX, currentItemPlacingInfo.positionY) == FREE){
let cell = tableShapes.rows[ currentItemPlacingInfo.positionX ].cells[ currentItemPlacingInfo.positionY ];
if(cell == null) return;
cell.style.backgroundColor = itemShadowColor;
Expand All @@ -126,7 +126,7 @@
}catch{}
}

function printVisualsOfCoordenates(shape, color, level){
function printVisualsOfCoordinates(shape, color, level){
if(shape==null) return;

if(level == null)
Expand All @@ -141,12 +141,12 @@
}
}

function printVisualsOfShapeEditorCoordenates(x, y, color){
function printVisualsOfShapeEditorCoordinates(x, y, color){
var cell = tableShapes.rows[ x ].cells[ y ];
cell.style.backgroundColor = color;
}

function printVisualsOfCoordenatesOnTable(shape, color, table){
function printVisualsOfCoordinatesOnTable(shape, color, table){
if(shape==null) return;
for(var i=0; i<shape.x.length; i++){
var cell = table.rows[ shape.x[i] ].cells[ shape.y[i] ];
Expand Down
Loading

0 comments on commit 01afdb6

Please sign in to comment.