-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
|
||
var cutsMap; | ||
var nrows=1, ncols=1; | ||
|
||
function map(x, y){ | ||
if(x == 0 || y == 0) | ||
return; | ||
|
||
if( !AskForReset() ) return; | ||
|
||
initializeMapEditorGrid(x, y); | ||
} | ||
|
||
function rows(numberOfRows){ | ||
|
||
|
||
UpdateCutsMap(TARGET_ROWS, nrows, JOIN); | ||
UpdateCutsMap(TARGET_ROWS, numberOfRows, CUT); | ||
|
||
UpdateCutsMap(TARGET_COLS, ncols, CUT); | ||
nrows = numberOfRows; | ||
} | ||
|
||
function cols(numberOfCols){ | ||
|
||
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; | ||
const JOIN = false; | ||
|
||
function UpdateCutsMap(target, numberOfSuch, state){ | ||
let x, y; | ||
let mapLengthB, mapLengthA; | ||
|
||
if(target == TARGET_ROWS){ | ||
mapLengthA = occupancyMap.length; | ||
mapLengthB = occupancyMap[0].length; | ||
} | ||
else{ | ||
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){ | ||
y = j; | ||
x = incrementRounded*(i+1)-1; | ||
} | ||
else{ | ||
x = j; | ||
y = incrementRounded*(i+1)-1; | ||
} | ||
|
||
if(state == CUT){ | ||
printVisualsOfCoordenates(new Vector2Array(x, y), mapCutColor); | ||
cutsMap[x][y] = true; | ||
occupancyMap[x][y] = null; | ||
} | ||
else{ | ||
printVisualsOfCoordenates(new Vector2Array(x, y), clearedGridColor); | ||
cutsMap[x][y] = false; | ||
occupancyMap[x][y] = FREE; | ||
} | ||
} | ||
} | ||
} | ||
|
||
function AskForReset(){ | ||
let coordenates = OccupancyMapToCoordenates(occupancyMap); | ||
if( (coordenates.x.length != 0) && (confirm("Requires a reset. Continue?") == false) ) | ||
return false; | ||
|
||
if(table != null) | ||
document.getElementById("GridGraphics").removeChild(table); | ||
|
||
ResetMap(); | ||
return true; | ||
} | ||
|
||
|
||
|