Skip to content

Commit

Permalink
Multi map reworked
Browse files Browse the repository at this point in the history
Multi maps cannot be outputted yet
  • Loading branch information
dip000 committed Feb 17, 2022
1 parent d192e56 commit dad703d
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 109 deletions.
33 changes: 23 additions & 10 deletions MapBuilderForWeb/BuilderVisuals.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
let value = "646970303030";
var isClicking = false;

function AddHoverListenerToElements(elements){
function AddHoverListenerToElements(elements, callback){
for(let i=0; i<elements.length; i++){
elements[i].addEventListener('mouseenter', function(e){
currentItemPlacingInfo.positionX = e.target.parentElement.rowIndex;
currentItemPlacingInfo.positionY = e.target.cellIndex;

//console.log("Hovering: " + typeof(currentItemPlacingInfo.positionX) +","+ currentItemPlacingInfo.positionY);

currentItemPlacingInfo.level = callback();

positionX.innerHTML = currentItemPlacingInfo.positionX;
positionY.innerHTML = currentItemPlacingInfo.positionY;
levelElement.innerHTML = currentItemPlacingInfo.level.x + ", " + currentItemPlacingInfo.level.y;


printHoverVisuals();
printHoverShapeVisuals();
Expand All @@ -27,23 +28,28 @@
else{
OnGridClickAndDrag(currentItemPlacingInfo.positionX, currentItemPlacingInfo.positionY);
}

//console.log("isClicking: " + isClicking + "; isShapeEditorActive:" + isShapeEditorActive);
}


}, false);
}
}

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

function AddClickListenerToElement(element, callback){
element.addEventListener('mousedown', function(e) {
//console.log("Clicked at: " + e.target.parentElement.rowIndex + "," + e.target.cellIndex);
let x = e.target.parentElement.rowIndex;
let y = e.target.cellIndex;
topValue.innerHTML = getStatisticsTopValue(value);

isClicking = true;;
isClicking = true;

if(x == null || y == null) return;
callback(x, y);
Expand Down Expand Up @@ -90,6 +96,8 @@
coordenates = IgnoreOccupiedCoordenates(coordenates);
previusCoordenates = IgnoreOccupiedCoordenates(previusCoordenates);

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

printVisualsOfCoordenates( previusCoordenates , clearedGridColor );
printVisualsOfCoordenates( coordenates, itemShadowColor );

Expand Down Expand Up @@ -117,10 +125,15 @@
}catch{}
}

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

if(level == null)
level = levels[currentItemPlacingInfo.level.x][currentItemPlacingInfo.level.y];
//console.log( shape );

for(var i=0; i<shape.x.length; i++){
var cell = table.rows[ shape.x[i] ].cells[ shape.y[i] ];
var cell = level.rows[ shape.x[i] ].cells[ shape.y[i] ];
if(cell == null) continue;

cell.style.backgroundColor = color;
Expand Down Expand Up @@ -195,7 +208,7 @@
// put the <tbody> in the <table> and appends into <body>
tbl.appendChild(tblBody);
body.appendChild(tbl);
tbl.setAttribute("border", "2");
//tbl.setAttribute("border", "2");

return tbl;
}
Expand Down
34 changes: 16 additions & 18 deletions MapBuilderForWeb/MapBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,27 @@
}


var occupancyMap;
const OCCUPIED = true;
const FREE = false;
const OUT_OF_BOUNDS = 2;
const OBSTRUCTED = 3;
const MAP_CUT = 4;
const NULL = 5;
function GetOccupancyOfPlacingInfo(){
//If at least one coordenate is occupied, then return occupied
let mapLengthX = occupancyMap.length;
let mapLengthY = occupancyMap[0].length;

//let mapLengthX = occupancyMap.length;
//let mapLengthY = occupancyMap[0].length;

let occupancyMap = occupancyMaps[currentItemPlacingInfo.level.x][currentItemPlacingInfo.level.y];

let x = currentItemPlacingInfo.coordenates.x;
let y = currentItemPlacingInfo.coordenates.y;

try{
let state = ( occupancyMap[ currentItemPlacingInfo.positionX ][ currentItemPlacingInfo.positionY ] );

if( state == null){
return MAP_CUT;
return NULL;
}
if( state == OCCUPIED){
return OCCUPIED;
Expand All @@ -54,6 +56,7 @@


function UpdateOccupancy(coordenates, state){
let occupancyMap = occupancyMaps[currentItemPlacingInfo.level.x][currentItemPlacingInfo.level.y];
for(var i=0; i<coordenates.x.length; i++){
occupancyMap[coordenates.x[i]][coordenates.y[i]] = state;
}
Expand Down Expand Up @@ -141,8 +144,7 @@

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

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

Expand All @@ -166,7 +168,7 @@

let outputData = new OutputData();
outputData.generateFromHistory();
outputData.generateFromMap();
outputData.generateFromMap(occupancyMaps[currentItemPlacingInfo.level.x][currentItemPlacingInfo.level.y]);

let formatedCoordenates = new Vector2Array(outputData.positionsX, outputData.positionsY);
formatedCoordenates = LocalizeCoordenates(formatedCoordenates);
Expand Down Expand Up @@ -330,7 +332,7 @@ function Vector2Array(x, y) {
}
}

function ItemPlacingInfo(itemType, rotation, positionX, positionY, coordenates){
function ItemPlacingInfo(itemType, rotation, positionX, positionY, coordenates, level){

if(itemType instanceof ItemPlacingInfo){
let instance = JSON.parse(JSON.stringify(itemType));
Expand All @@ -341,14 +343,16 @@ function ItemPlacingInfo(itemType, rotation, positionX, positionY, coordenates){
this.coordenates = instance.coordenates;
this.indexInHistory = instance.indexInHistory;
this.deleted = instance.deleted;
this.level = instance.level;
}
else if(itemType == null){
this.itemType = 0;
this.rotation = 0;
this.positionX = 0;
this.positionY = 0;
this.coordenates = new Vector2Array();

this.level = {x:0, y:0};

//Internal properties
this.indexInHistory = 0;
this.deleted = false;
Expand All @@ -359,6 +363,7 @@ function ItemPlacingInfo(itemType, rotation, positionX, positionY, coordenates){
this.positionX = positionX;
this.positionY = positionY;
this.coordenates = coordenates;
this.level = level;

//Internal properties
this.indexInHistory = 0;
Expand Down Expand Up @@ -386,7 +391,6 @@ function OutputData(){
this.positionsY = [];

let j=0;


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

Expand All @@ -403,7 +407,7 @@ function OutputData(){
}
}

this.generateFromMap = function(){
this.generateFromMap = function(occupancyMap){
let mapLengthX = occupancyMap.length;
let mapLengthY = occupancyMap[0].length;
let minX = 999;
Expand Down Expand Up @@ -435,12 +439,6 @@ function OutputData(){
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 );
}

}

Expand Down
Loading

0 comments on commit dad703d

Please sign in to comment.