Skip to content

Commit

Permalink
Multimap Fixed. Not tested in Unity
Browse files Browse the repository at this point in the history
  • Loading branch information
dip000 committed Feb 19, 2022
1 parent f8ad8c9 commit 5950deb
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 32 deletions.
4 changes: 2 additions & 2 deletions MapBuilderForWeb/BuilderCalculations.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
vector2.y[i] -= minY;
}

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

return vector2;
}
Expand Down
18 changes: 9 additions & 9 deletions MapBuilderForWeb/BuilderVisuals.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
levelElement.innerHTML = currentItemPlacingInfo.level.x + ", " + currentItemPlacingInfo.level.y;



printHoverVisuals();
printHoverShapeVisuals();

Expand All @@ -30,27 +31,24 @@
}
}



}, false);
}
}

/*visualsReseteer();
function visualsReseteer(){
setInterval(function(){
printVisualsOfCoordenates( previusCoordenates , clearedGridColor );
}, 1000);
}*/


function AddClickListenerToElement(element, callback){
element.addEventListener('mousedown', function(e) {
topValue.innerHTML = getStatisticsTopValue(value);
currentItemPlacingInfo.positionX = e.target.parentElement.rowIndex;
currentItemPlacingInfo.positionY = e.target.cellIndex;

isClicking = true;

if(currentItemPlacingInfo.positionX == null || currentItemPlacingInfo.positionY == null) return;

callback();
//console.log( new ItemPlacingInfo(currentItemPlacingInfo) );

}, false);
}
Expand Down Expand Up @@ -80,6 +78,7 @@
// PRINTERS ////////////////////////////////////////////////////////////////////////

var previousLevel;
var previousMap;

function printHoverVisuals(){
//Read all from current placing info
Expand All @@ -94,7 +93,7 @@
let coordenates = GlobalizeCoordenates(shapeRotated, volumeIndex.x, volumeIndex.y);

coordenates = IgnoreOccupiedCoordenates(coordenates);
previusCoordenates = IgnoreOccupiedCoordenates(previusCoordenates);
previusCoordenates = IgnoreOccupiedCoordenates(previusCoordenates, previousMap);

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

Expand All @@ -103,6 +102,7 @@

previusCoordenates = coordenates;
previousLevel = levels[ currentItemPlacingInfo.level.x ][ currentItemPlacingInfo.level.y ];
previousMap = occupancyMaps[ currentItemPlacingInfo.level.x ][ currentItemPlacingInfo.level.y ];
}

var _x=0, _y=0;
Expand Down
22 changes: 17 additions & 5 deletions MapBuilderForWeb/MapBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,20 @@
if(historyOfPlacements[i].deleted == true){
continue;
}
let historyCoordenates = historyOfPlacements[i].coordenates;

let history = historyOfPlacements[i];
let historyCoordenates = history.coordenates;

//Skip placement if it happened in a different level
let differentLevelX = (history.level.x != currentItemPlacingInfo.level.x);
let differentLevelY = (history.level.y != currentItemPlacingInfo.level.y);
if( differentLevelX || differentLevelY ){
continue;
}

for(var j=0; j<historyCoordenates.x.length; j++){
let sameCoordenateX = (historyCoordenates.x[j] == currentItemPlacingInfo.positionX);
let sameCoordenateY = (historyCoordenates.y[j] == currentItemPlacingInfo.positionY);

if(sameCoordenateX && sameCoordenateY){
return historyOfPlacements[i];
}
Expand All @@ -104,7 +112,7 @@

return null;
}

function FindHistoryInfoAtPoint(point){
for(var i=0; i<historyOfPlacements.length; i++){

Expand All @@ -129,12 +137,15 @@



function IgnoreOccupiedCoordenates(coordenates){
function IgnoreOccupiedCoordenates(coordenates, map){
if(coordenates == null) return null;

newCoordenates = new Vector2Array();
let j=0;
let occupancyMap = occupancyMaps[currentItemPlacingInfo.level.x][currentItemPlacingInfo.level.y];

let occupancyMap = map;
if( occupancyMap == null )
occupancyMap = occupancyMaps[currentItemPlacingInfo.level.x][currentItemPlacingInfo.level.y];

for(let i=0; i<coordenates.x.length; i++){

Expand Down Expand Up @@ -409,6 +420,7 @@ function Point(x, y){

uploadShapes(shapesString);
uploadMaps(mapsString);
ChangeItem(0);
}

function uploadShapes(shapesString){
Expand Down
12 changes: 11 additions & 1 deletion MapBuilderForWeb/MapBuilderForWeb.html
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@

if ( state == OUT_OF_BOUNDS){
//console.log("OUT_OF_BOUNDS");
return;
}
else if (state == OCCUPIED){
//console.log("OCCUPIED");
Expand Down Expand Up @@ -372,6 +371,10 @@

function RemoveCurrentItemInfo(){
let infoToRemove = FindHistoryInfoAtCurrentPlacement();

//console.log("infoToRemove: ");
//console.log(new ItemPlacingInfo(infoToRemove));

DeleteFromHistoryOfPlacements(infoToRemove);
printVisualsOfCoordenates(infoToRemove.coordenates, clearedGridColor);
UpdateOccupancy(infoToRemove.coordenates, FREE);
Expand All @@ -381,9 +384,16 @@
function PlaceCurrentItemInfo(){
//Standar (x,y) system for ouputting
let minValues = GetMinValuesOfCoordenates(currentItemPlacingInfo.coordenates);

currentItemPlacingInfo.x = currentItemPlacingInfo.positionX;
currentItemPlacingInfo.y = currentItemPlacingInfo.positionY;

currentItemPlacingInfo.positionX = minValues.x;
currentItemPlacingInfo.positionY = minValues.y;

//console.log("infoToPlace: ");
//console.log(new ItemPlacingInfo(currentItemPlacingInfo));

printVisualsOfCoordenates(currentItemPlacingInfo.coordenates, listOfShapeColors[currentItemPlacingInfo.itemType]);
UpdateOccupancy(currentItemPlacingInfo.coordenates, OCCUPIED);
RegisterHistoryOfPlacements(currentItemPlacingInfo);
Expand Down
3 changes: 2 additions & 1 deletion MapBuilderForWeb/MapBuilderStyles.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@

.items .item{
display: inline-block;
padding: 5px;
padding: 10px;
margin-left: 20px;
cursor: pointer;
box-shadow: none;
border-radius: 5px;
transition: 0.1s ease-in-out;
color: var(--white);
background-color: var(--background);
}
.item:hover {
box-shadow: 0px 0px 15px var(--item-click);
Expand Down
1 change: 1 addition & 0 deletions MapBuilderForWeb/MultimapMechanics.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@

reader.onload = function( event ){
upload( event.target.result );
document.querySelector('input[type=file]').value = "";
}

try{ reader.readAsText( file ); } catch{}
Expand Down
30 changes: 16 additions & 14 deletions MapBuilderForWeb/ShapeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,31 +141,33 @@ var isShapeEditorActive = false;

function RemoveShapeFromMap(shapeIndex){

for(var i=0; i<historyOfPlacements.length; i++){
for(let i=0; i<historyOfPlacements.length; i++){

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

let history = historyOfPlacements[i];
let historyCoordenates = history.coordenates;

//Item type is the shape index
if(historyOfPlacements[i].itemType == shapeIndex){
//find all matching types
if(history.itemType == shapeIndex){

for (let r=0; r<gridRows; r++) {
for (let c=0; c<gridCols; c++) {
let occupancyMap = occupancyMaps[r][c];
let level = levels[r][c];
//Delete from its level
let r = history.level.x;
let c = history.level.y;
let occupancyMap = occupancyMaps[r][c];
let level = levels[r][c];

printVisualsOfCoordenates(historyOfPlacements[i].coordenates, clearedGridColor, level);
UpdateOccupancy(historyOfPlacements[i].coordenates, FREE, occupancyMap);
}
}
printVisualsOfCoordenates(historyCoordenates, clearedGridColor, level);
UpdateOccupancy(historyCoordenates, FREE, occupancyMap);

DeleteFromHistoryOfPlacements( historyOfPlacements[i] );
DeleteFromHistoryOfPlacements( history );
}
//Higher item types must reaccomodate. Lower item types stays the same
else if(historyOfPlacements[i].itemType > shapeIndex){
historyOfPlacements[i].itemType--;
else if(history.itemType > shapeIndex){
history.itemType--;
}
}

Expand Down

0 comments on commit 5950deb

Please sign in to comment.