Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Right Click as Erase #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions a.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,23 +681,32 @@ function refreshCheatButtonText() {
document.getElementById("cheatCollisionButton").textContent = isCollisionEnabled ? "Collision: ON" : "Collision: OFF";
document.getElementById("cheatCollisionButton").style.background = isCollisionEnabled ? "" : "#f88";
}
// suppress right-click menu
canvas.addEventListener("contextmenu", function(event) {
event.preventDefault();
});


// be careful with location vs rowcol, because this variable is used when resizing
var lastDraggingRowcol = null;
var hoverLocation = null;
var draggingChangeLog = null;
var mouseButton = null;
canvas.addEventListener("mousedown", function(event) {
if (event.altKey) return;
if (event.button !== 0) return;
if (!(event.button === 0 || event.button === 2)) return;
event.preventDefault();
mouseButton = event.button;
var location = getLocationFromEvent(event);
if (persistentState.showEditor && paintBrushTileCode != null) {
// editor tool
lastDraggingRowcol = getRowcol(level, location);
if (paintBrushTileCode === "select") selectionStart = location;
if (paintBrushTileCode === "resize") resizeDragAnchorRowcol = lastDraggingRowcol;
draggingChangeLog = [];
paintAtLocation(location, draggingChangeLog);
if (mouseButton === 0) paintAtLocation(location, draggingChangeLog);
else if (mouseButton === 2) eraseAtLocation(location, draggingChangeLog);
else throw unreachable();
} else {
// playtime
var object = findObjectAtLocation(location);
Expand Down Expand Up @@ -744,6 +753,7 @@ function stopDragging() {
resizeDragAnchorRowcol = null;
pushUndo(uneditStuff, draggingChangeLog);
draggingChangeLog = null;
mouseButton = null;
}
}
canvas.addEventListener("mousemove", function(event) {
Expand All @@ -759,7 +769,10 @@ canvas.addEventListener("mousemove", function(event) {
});
path.forEach(function(rowcol) {
// convert to location at the last minute in case each of these steps is changing the coordinate system.
paintAtLocation(getLocation(level, rowcol.r, rowcol.c), draggingChangeLog);
var location = getLocation(level, rowcol.r, rowcol.c);
if (mouseButton === 0) paintAtLocation(location, draggingChangeLog);
else if (mouseButton === 2) eraseAtLocation(location, draggingChangeLog);
else throw unreachable();
});
lastDraggingRowcol = mouseRowcol;
hoverLocation = null;
Expand Down Expand Up @@ -1187,6 +1200,12 @@ function paintTileAtLocation(location, tileCode, changeLog) {
level.map[location] = tileCode;
}

function eraseAtLocation(location, changeLog) {
removeAnyObjectAtLocation(location, changeLog);
paintTileAtLocation(location, SPACE, changeLog);
render();
}

function pushUndo(undoStuff, changeLog) {
// changeLog = [
// ["i", 0, -1, 0, animationQueue, freshlyRemovedAnimatedObjects],
Expand Down