add maps to gui, fix gui for chrome

This commit is contained in:
Stefan Bühler 2012-07-14 11:28:34 +02:00
parent 685f190bf4
commit 9fe5120caa
4 changed files with 58 additions and 51 deletions

View File

@ -1,8 +1,18 @@
MAPS=$(wildcard ../maps/contest*.map ../maps/flood*.map)
MAPS=$(wildcard ../maps/flood*.map)
MAPS+=$(wildcard ../maps/contest?.map ../maps/contest10.map)
MAPS+=$(wildcard ../maps/ems*.map)
MAPS+=../maps/pacman.map ../maps/pacman2.map
all: maps.js
maps.js: mapsToJson.js $(MAPS)
./mapsToJson.js $(MAPS) > maps.js
clean:
rm -f maps.js
.PHONY: all clean
# just build it everytime
.PHONY: maps.js

View File

@ -44,68 +44,64 @@ function mineGui_start() {
for (i = 0; i < txt.length; ++i) {
if (validMoves[txt[i]]) mineGui_moves += txt[i];
}
inpMoves.blur();
mineGui_updateMine();
};
var delayInpValidate = function() { window.setTimeout(inpValidate, 0); };
var delayInpValidate = function(event) {
// console.log("input", event, event.type);
window.setTimeout(inpValidate, 0);
};
inpMoves.onchange = delayInpValidate;
inpMoves.onpaste = delayInpValidate;
inpMoves.onkeypress = delayInpValidate;
document.onkeypress = function (event) {
document.body.onkeydown = function (event) {
// console.log("body", event, event.type);
if (document.activeElement === customMapInput) return;
if (event.ctrlKey || event.altKey || event.metaKey) return;
var handled = true;
if (event.keyCode == 8 || event.charCode == 8) {
var cmd = String.fromCharCode(event.charCode || event.keyCode).toUpperCase();
if (validMoves[cmd]) {
mineGui_move(cmd);
} else if (cmd == 'C') { // clear
mineGui_moves = "";
mineGui_updateMine();
} else if (event.keyCode == 8 || event.charCode == 8) {
// backspace -> undo
mineGui_moves = mineGui_moves.slice(0,-1);
mineGui_updateMine();
} else if (event.which === 0 && event.keyCode) {
switch (event.keyCode) {
case 33: // page up
if (selMap.selectedIndex > 0) {
selMap.selectedIndex--;
selMap.onchange();
}
break;
case 34: // page down
if (selMap.selectedIndex+1 < selMap.options.length) {
selMap.selectedIndex++;
selMap.onchange();
}
break;
case 37: // left
mineGui_move('L');
break;
case 38: // up
mineGui_move('U');
break;
case 39: // right
mineGui_move('R');
break;
case 40: // down
mineGui_move('D');
break;
default:
handled = false;
break;
} else switch (event.keyCode) {
case 33: // page up
if (selMap.selectedIndex > 0) {
selMap.selectedIndex--;
selMap.onchange();
}
} else if (event.charCode) {
console.log(event.charCode);
cmd = String.fromCharCode(event.charCode).toUpperCase();
if (validMoves[cmd]) {
mineGui_move(cmd);
} else if (cmd == 'R') { // redraw
mineGui_updateMine();
} else if (cmd == 'C') { // clear
mineGui_moves = "";
mineGui_updateMine();
} else {
handled = false;
break;
case 34: // page down
if (selMap.selectedIndex+1 < selMap.options.length) {
selMap.selectedIndex++;
selMap.onchange();
}
} else {
break;
case 37: // left
mineGui_move('L');
break;
case 38: // up
mineGui_move('U');
break;
case 39: // right
mineGui_move('R');
break;
case 40: // down
mineGui_move('D');
break;
default:
handled = false;
break;
}
if (handled) {
// console.log("body handled", event, event.type);
event.preventDefault();
return true;
}
if (handled) event.preventDefault();
};
for (k in mineMaps) {
if (mineMaps.hasOwnProperty(k)) {

View File

@ -33,8 +33,9 @@
<pre>Help:
(<b>L</b>)eft/(<b>U</b>)p/(<b>R</b>)ight/(<b>D</b>)own work as expected (letter and arrow keys), (<b>A</b>)bort and (<b>W</b>)ait too.
Special keys: PageUp/PageDown for map select, Backspace for undo, (<b>C</b>)lear and (<b>R</b>)edraw
Special keys: PageUp/PageDown for map select, Backspace for undo and (<b>C</b>)lear
Be careful: a reload looses all custom maps and saved moves.
Listed highscore can be outdated.
</pre>
Build custom map: <button id="mineGui_addData">Add Map</button><br>

File diff suppressed because one or more lines are too long