Skip to content

Commit

Permalink
clean up code & fix cursor issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Viet281101 committed Jun 3, 2024
1 parent f010495 commit c36784a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 29 deletions.
9 changes: 2 additions & 7 deletions 2D/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class MainApp {
this.gridBoard.grid[row][col] = '#000000';
}
this.redraw();
}
} else { this.isBlackening = false; this.canvas.style.cursor = 'default'; }
} else {
let clickedOnIcon = false;
if (this.selectedPolyomino) {
Expand All @@ -123,9 +123,7 @@ class MainApp {
break;
}
}
if (!selected) {
this.selectedPolyomino = null;
}
if (!selected) { this.selectedPolyomino = null; }
}
this.redraw();
}
Expand All @@ -141,9 +139,6 @@ class MainApp {
this.redraw();
};

enableBlackening() { this.isBlackening = true; document.body.style.cursor = 'url("../assets/cursor_blackend.png"), auto'; };
disableBlackening() { this.isBlackening = false; document.body.style.cursor = 'default'; };

redraw() {
if (!this.needsRedraw) return;
this.gridBoard.clear();
Expand Down
20 changes: 5 additions & 15 deletions 2D/js/polyomino.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,11 @@ export class Polyomino {

handleIconClick(type) {
switch (type) {
case 'flip':
this.flip();
break;
case 'rotateLeft':
this.rotateLeft();
break;
case 'rotateRight':
this.rotateRight();
break;
case 'duplicate':
this.app.duplicatePolyomino(this);
break;
case 'trash':
this.app.deletePolyomino(this);
break;
case 'flip': this.flip(); break;
case 'rotateLeft': this.rotateLeft(); break;
case 'rotateRight': this.rotateRight(); break;
case 'duplicate': this.app.duplicatePolyomino(this); break;
case 'trash': this.app.deletePolyomino(this); break;
}
this.app.redraw();
};
Expand Down
7 changes: 2 additions & 5 deletions 2D/js/popup/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,8 @@ export function showGridPopup(toolbar) {
toolbar.closePopup('grid');
break;
case 5:
if (toolbar.mainApp.isBlackening) {
toolbar.mainApp.disableBlackening();
} else {
toolbar.mainApp.enableBlackening();
}
toolbar.mainApp.isBlackening = true;
toolbar.mainApp.canvas.style.cursor = 'url("../../assets/cursor_blackend.png"), auto';
toolbar.closePopup('grid');
break;
}
Expand Down
4 changes: 2 additions & 2 deletions 2D/js/popup/polyomino.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export function showPolyominoPopup(toolbar) {

const getRandomPosition = (max) => Math.floor(Math.random() * max);

const canvasPaddingX = getRandomPosition(window.innerWidth < 600 ? 300 : 1200) + (window.innerWidth < 600 ? 40 : 0);
const canvasPaddingY = getRandomPosition(170) + (window.innerHeight < 600 ? 0 : 40);
const canvasPaddingX = getRandomPosition(window.innerWidth < 600 ? 300 : 1200) + (window.innerWidth < 600 ? 0 : 40);
const canvasPaddingY = getRandomPosition(170) + (window.innerHeight < 600 ? 40 : 0);

polyominoes.forEach(({ polyomino, shape, shapeSize, y }) => {
const leftColumnRect = { x: 10, y: y - shapeSize / 2, width: 180, height: shapeSize + 20 };
Expand Down

0 comments on commit c36784a

Please sign in to comment.