Skip to content

Commit

Permalink
Prelude and textMode
Browse files Browse the repository at this point in the history
Now respects prelude content and doesn't work without respective entries. Can click stuff on main menu and messages.
  • Loading branch information
ThatScar committed Sep 28, 2018
1 parent d8fbd51 commit 88ead97
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 86 deletions.
78 changes: 43 additions & 35 deletions js/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,53 +383,59 @@ function generateExtraMembers(state) {
state.backgroundlayer=backgroundlayer;

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

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

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

Level.prototype.calcBackgroundMask = function(state) {
Expand Down Expand Up @@ -1893,7 +1899,9 @@ function getMaskFromName(state,name) {
objectMask.ibitset(o.id);
}

if (objectMask.iszero()) {
if (!state.metadata.includes("nokeyboard") && objectMask.iszero()) {
consolePrint("yes " + (state.metadata.includes("nokeyboard")), true);
consolePrint(state.metadata, true);
logErrorNoLine("error, didn't find any object called player, either in the objects section, or the legends section. there must be a player!");
}
return objectMask;
Expand Down
127 changes: 77 additions & 50 deletions js/inputoutput.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,36 +325,62 @@ function levelEditorRightClick(event,click) {
var lastCoord;

function mouseLeft(event,click,id) {
/*if (false) {
consolePrint("no mouse, textmode",true);
console.log("no mouse, textmode");
} else */{
if (mouseCoordX>-1&&mouseCoordY>-1&&mouseCoordX<screenwidth-0&&mouseCoordY<screenheight-0) {
var coordIndex = mouseCoordY + mouseCoordX*level.height;

if (click || lastCoord!==coordIndex) {
if (againing) {
//consolePrint("no mouse, againing",false);
} else {
try {
var bak = backupLevel();
var cell = level.getCell(coordIndex);
cell.ibitset(id);
level.setCell(coordIndex, cell);
var inputdir = 5;
//moveEntitiesAtIndex(coordIndex,level.getCell(coordIndex),16);
pushInput(inputdir);
if (processInput(inputdir,false,false,bak)) {
redraw();
}
} catch(e) {
console.log(e);
consolePrint(e,true);

if (textMode) {
if (!click)
return;
if (titleScreen) {
if (titleMode===0) {
if (mouseCoordY===6) {
titleButtonSelected();
}
} else {
if (mouseCoordY===5) {
if (titleSelection!==0) {
titleSelection=0;
generateTitleScreen();
redraw();
} else {
titleButtonSelected();
}
} else if (mouseCoordY===7) {
titleSelection=1;
titleButtonSelected();
}
}
lastCoord = coordIndex;
} else if (messageselected===false) {
messageselected=true;
timer=0;
quittingMessageScreen=true;
tryPlayCloseMessageSound();
titleScreen=false;
drawMessageScreen();
}
} else if (mouseCoordX>-1&&mouseCoordY>-1&&mouseCoordX<screenwidth-0&&mouseCoordY<screenheight-0) {
var coordIndex = mouseCoordY + mouseCoordX*level.height;

if (click || lastCoord!==coordIndex) {
if (againing) {
//consolePrint("no mouse, againing",false);
} else {
try {
var bak = backupLevel();
var cell = level.getCell(coordIndex);
cell.ibitset(id);
level.setCell(coordIndex, cell);
var inputdir = 5;
//moveEntitiesAtIndex(coordIndex,level.getCell(coordIndex),16);
pushInput(inputdir);
if (processInput(inputdir,false,false,bak)) {
redraw();
}
} catch(e) {
console.log(e);
consolePrint(e,true);
}
}
}
lastCoord = coordIndex;
}
}

Expand All @@ -371,8 +397,8 @@ function onMouseDown(event) {
anyEditsSinceMouseDown=false;
if (levelEditorOpened) {
return levelEditorClick(event,true);
} else {
return mouseLeft(event,true,state.lmbID);
} else if ("mouse_left" in state.metadata) {
return mouseLeft(event,true,state.lmbID); // must break to not execute dragging=false;
}
}
dragging=false;
Expand Down Expand Up @@ -500,21 +526,26 @@ function setMouseCoord(e){
}

function onMouseMove(event) {
try {
if (levelEditorOpened) {
setMouseCoord(event);
if (dragging) {
levelEditorClick(event,false);
} else if (rightdragging){
levelEditorRightClick(event,false);
levelEditorRightClick(event,false);
}
redraw();
} else {
} else if ("mouse_drag" in state.metadata) {
setMouseCoord(event);
if (dragging) {
mouseLeft(event,false,state.dragID);
}
redraw();
}
} catch(e) {
console.log(e);
consolePrint(e);
}

//window.console.log("showcoord ("+ canvas.width+","+canvas.height+") ("+x+","+y+")");
}
Expand All @@ -540,6 +571,18 @@ function prevent(e) {
return false;
}

function titleButtonSelected() {
if (titleSelected===false) {
tryPlayStartGameSound();
titleSelected=true;
messageselected=false;
timer=0;
quittingTitleScreen=true;
generateTitleScreen();
canvasResize();
}
}

function checkKey(e,justPressed) {

if (winning) {
Expand Down Expand Up @@ -679,33 +722,17 @@ function checkKey(e,justPressed) {
} else if (titleScreen) {
if (titleMode===0) {
if (inputdir===4&&justPressed) {
if (titleSelected===false) {
tryPlayStartGameSound();
titleSelected=true;
messageselected=false;
timer=0;
quittingTitleScreen=true;
generateTitleScreen();
canvasResize();
}
titleButtonSelected();
}
} else {
if (inputdir==4&&justPressed) {
if (titleSelected===false) {
tryPlayStartGameSound();
titleSelected=true;
messageselected=false;
timer=0;
quittingTitleScreen=true;
generateTitleScreen();
redraw();
}
titleButtonSelected();
}
else if (inputdir===0||inputdir===2) {
if (inputdir===0){
titleSelection=0;
titleSelection=0;
} else {
titleSelection=1;
titleSelection=1;
}
generateTitleScreen();
redraw();
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'].indexOf(token)>=0) {
'mouse_left','mouse_drag','mouse_right','mouse_up','nokeyboard'].indexOf(token)>=0) {
state.metadata.push(token);
state.metadata.push("true");
state.tokenIndex=-1;
Expand Down

0 comments on commit 88ead97

Please sign in to comment.