Skip to content

Commit

Permalink
Right click and flickscreen
Browse files Browse the repository at this point in the history
Fixes #11 Fixes #8
Right click and right drag are now a thing.
  • Loading branch information
ThatScar committed Oct 12, 2018
1 parent 88ead97 commit 7958bc8
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
19 changes: 18 additions & 1 deletion js/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,6 @@ function generateExtraMembers(state) {
}

var rmbID;
// NOT IMPLEMENTED
if (state.metadata.includes("mouse_right")) {
if (state.objects.rmb===undefined) {
if ('rmb' in state.synonymsDict) {
Expand Down Expand Up @@ -436,6 +435,24 @@ function generateExtraMembers(state) {
}
state.dragID=dragID;
}

var rdragID;
if (state.metadata.includes("mouse_rdrag")) {
if (state.objects.rdrag===undefined) {
if ('rdrag' in state.synonymsDict) {
var n = state.synonymsDict['rdrag'];
var o = state.objects[n];
rdragID = o.id;
} else {
var o=state.objects[state.idDict[1]];
rdragID=o.id;
logError("rdrag object/alias has to be defined");
}
} else {
rdragID = state.objects.rdrag.id;
}
state.rdragID=rdragID;
}
}

Level.prototype.calcBackgroundMask = function(state) {
Expand Down
2 changes: 2 additions & 0 deletions js/graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ function redraw() {
}
}

screenOffsetX = mini;
screenOffsetY = minj;

for (var i = mini; i < maxi; i++) {
for (var j = minj; j < maxj; j++) {
Expand Down
31 changes: 19 additions & 12 deletions js/inputoutput.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ function levelEditorRightClick(event,click) {

var lastCoord;

function mouseLeft(event,click,id) {
function mouseAction(event,click,id) {

if (textMode) {
if (!click)
Expand Down Expand Up @@ -357,7 +357,7 @@ function mouseLeft(event,click,id) {
drawMessageScreen();
}
} else if (mouseCoordX>-1&&mouseCoordY>-1&&mouseCoordX<screenwidth-0&&mouseCoordY<screenheight-0) {
var coordIndex = mouseCoordY + mouseCoordX*level.height;
var coordIndex = screenOffsetY+mouseCoordY + (screenOffsetX+mouseCoordX)*level.height;

if (click || lastCoord!==coordIndex) {
if (againing) {
Expand Down Expand Up @@ -398,7 +398,7 @@ function onMouseDown(event) {
if (levelEditorOpened) {
return levelEditorClick(event,true);
} else if ("mouse_left" in state.metadata) {
return mouseLeft(event,true,state.lmbID); // must break to not execute dragging=false;
return mouseAction(event,true,state.lmbID); // must break to not execute dragging=false;
}
}
dragging=false;
Expand All @@ -409,8 +409,13 @@ function onMouseDown(event) {
rightdragging=true;
if (levelEditorOpened) {
return levelEditorRightClick(event,true);
}
}
} else if ("mouse_right" in state.metadata) {
return mouseAction(event,true,state.rmbID);
}
} else {
dragging=false;
rightdragging=false;
}
} else if (event.button===1) {
//undo
if (textMode===false) {
Expand Down Expand Up @@ -526,7 +531,11 @@ function setMouseCoord(e){
}

function onMouseMove(event) {
try {
if (event.target!==canvas) {
dragging = false;
rightdragging = false;
return;
}
if (levelEditorOpened) {
setMouseCoord(event);
if (dragging) {
Expand All @@ -538,14 +547,12 @@ function onMouseMove(event) {
} else if ("mouse_drag" in state.metadata) {
setMouseCoord(event);
if (dragging) {
mouseLeft(event,false,state.dragID);
}
mouseAction(event,false,state.dragID);
} else if (rightdragging) {
mouseAction(event,false,state.rdragID);
}
redraw();
}
} catch(e) {
console.log(e);
consolePrint(e);
}

//window.console.log("showcoord ("+ canvas.width+","+canvas.height+") ("+x+","+y+")");
}
Expand Down
2 changes: 1 addition & 1 deletion js/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ var codeMirrorFn = function() {
state.tokenIndex=1;
return 'METADATA';
} else if ( ['run_rules_on_level_start','norepeat_action','require_player_movement','debug','verbose_logging','throttle_movement','noundo','noaction','norestart','scanline',
'mouse_left','mouse_drag','mouse_right','mouse_up','nokeyboard'].indexOf(token)>=0) {
'mouse_left','mouse_drag','mouse_right','mouse_rdrag','mouse_up','nokeyboard'].indexOf(token)>=0) {
state.metadata.push(token);
state.metadata.push("true");
state.tokenIndex=-1;
Expand Down

0 comments on commit 7958bc8

Please sign in to comment.