Refactor code

This commit is contained in:
Marcel
2018-01-26 16:52:52 +01:00
parent e2abbf1964
commit 7bf336a72f
2 changed files with 126 additions and 140 deletions

View File

@@ -17,18 +17,18 @@ function scaleWindow() {
canvasContainer.height = height;
canvasContainer.width = width + 200;
bgCanvas.height = height;
bgCanvas.width = width;
bgContext.scale(width / fieldSize.x, height / fieldSize.y);
canvasBg.height = height;
canvasBg.width = width;
contextBg.scale(width / fieldSize.x, height / fieldSize.y);
canvas.height = height;
canvas.width = width;
context.scale(width / fieldSize.x, height / fieldSize.y);
holdCanvas.height = height / fieldSize.y * 4;
holdCanvas.width = holdCanvas.height;
holdCanvas.style.transform = "translateX(-" + ((width / 2) + holdCanvas.height) + "px) translate(-.4em, -.2em)";
holdContext.scale(holdCanvas.width / 6, holdCanvas.width / 6);
canvasHold.height = height / fieldSize.y * 4;
canvasHold.width = canvasHold.height;
canvasHold.style.transform = "translateX(-" + ((width / 2) + canvasHold.height) + "px) translate(-.4em, -.2em)";
contextHold.scale(canvasHold.width / 6, canvasHold.width / 6);
if(!firstRun && isPaused) {
draw();
@@ -84,26 +84,34 @@ let isActive = false;
const menuButton = document.getElementById("menu-opener");
menuButton.addEventListener("click", () => {
toggleSettings();
});
function toggleSettings() {
if (isActive) {
escState = 1;
menuButton.classList.remove('active');
document.getElementsByTagName('body')[0].classList.remove('menu-open');
} else {
escState = 2;
menuButton.classList.add('active');
document.getElementsByTagName('body')[0].classList.add('menu-open');
}
isActive = !isActive;
});
}
function toggleMenu() {
if (escState === 0) {
document.getElementsByTagName("body")[0].classList.remove("menu-open");
menuButton.classList.remove('active');
hideMenu();
} else if (escState === 1) {
document.getElementsByTagName("body")[0].classList.remove("menu-open");
menuButton.classList.remove('active');
showMenu();
} else {
document.getElementsByTagName("body")[0].classList.add("menu-open");
menuButton.classList.add('active');
}
}