Skip to content
Snippets Groups Projects
Commit 1dd93acd authored by Silas Dohm's avatar Silas Dohm
Browse files

new keyboard controls

parent 67534b81
Branches
No related tags found
No related merge requests found
......@@ -22,7 +22,7 @@ class Cell {
//draw hintNr
if (this.hintNr) {
ctx.fillStyle = "black";
ctx.font = "14px Consolas";
ctx.font = size / 5 + "px Consolas";
ctx.fillText(this.hintNr, this.x * size + 4, (this.y) * size + 15);
}
}
......@@ -213,24 +213,25 @@ function logKey(e) {
activeCell = activeCell.neighbour[0];
break;
case "I": //start of horizontal word
if (activeCell.word[0])
activeCell = activeCell.word[0].chars[0];
forceValidOrientation();
if (activeCell.word[m_orientation])
activeCell = activeCell.word[m_orientation].chars[0];
case "R":
case "i":
forceValidOrientation();
activeMode = mode.insert;
m_orientation = 0;
break;
case "O":
if (activeCell.word[1])
activeCell = activeCell.word[1].chars[0];
case "o":
activeMode = mode.insert;
m_orientation = 1;
break;
// case "O":
// if (activeCell.word[1])
// activeCell = activeCell.word[1].chars[0];
// case "o":
// activeMode = mode.insert;
// m_orientation = 1;
// break;
case "a":
activeCell = activeCell.neighbour[2];
activeCell = m_orientation ? activeCell.neighbour[3] : activeCell.neighbour[2];
forceValidOrientation();
activeMode = mode.insert;
m_orientation = 0;
break;
case "x":
activeCell.currentChar = "";
......@@ -240,15 +241,54 @@ function logKey(e) {
break;
case "B":
case "b":
activeCell = activeCell.word[m_orientation].chars[0].neighbour[m_orientation ? 1 : 0].word[m_orientation].chars[0];
var x = activeCell.x;
var y = activeCell.y;
while (true) {
if (m_orientation) { //vertical
y = (y + rows - 1) % rows;
if (y % columns == rows - 1)
x = (x + columns - 1) % columns;
}
else { //horizontal
x = (x + columns - 1) % columns;
if (x % columns == columns - 1)
y = (y + rows - 1) % rows;
}
if (mycell[x][y].word[m_orientation] && mycell[x][y].word[m_orientation] != activeCell.word[m_orientation]) {
activeCell = mycell[x][y].word[m_orientation].chars[0];
break;
}
}
break;
case "W":
case "w":
activeCell = activeCell.word[m_orientation].chars[activeCell.word[m_orientation].chars.length - 1].neighbour[m_orientation ? 3 : 2];
var x = activeCell.x;
var y = activeCell.y;
while (true) {
if (m_orientation) { //vertical
y = (y + 1) % rows;
if (y % columns == 0)
x = (x + 1) % columns;
}
else { //horizontal
x = (x + 1) % columns;
if (x % columns == 0)
y = (y + 1) % rows;
}
if (mycell[x][y].word[m_orientation] && mycell[x][y].word[m_orientation] != activeCell.word[m_orientation]) {
activeCell = mycell[x][y];
break;
}
}
break;
case "`":
activeCell.currentChar = activeCell.actualChar;
break;
case "q": //swap orientation - key still undecided
m_orientation = m_orientation ? 0 : 1; //invert orientation
break;
default:
break;
}
......@@ -267,9 +307,14 @@ aCanvas.addEventListener('mousedown', function (e) { //mouse navigation
if (activeCell == lastCell)
m_orientation = m_orientation ? 0 : 1; //invert orientation
activeMode = mode.insert;
forceValidOrientation();
endInput();
}
});
function forceValidOrientation() {
if (!activeCell.word[m_orientation]) //
m_orientation = m_orientation ? 0 : 1; //invert orientation
}
function endInput() {
if (activeMode == mode.insert) {
statusBar.style.display = 'block';
......@@ -277,8 +322,9 @@ function endInput() {
else
statusBar.style.display = 'none';
if (!activeCell.word[m_orientation]) //
m_orientation = m_orientation ? 0 : 1; //invert orientation
// if (!activeCell.word[m_orientation]) //
// m_orientation = m_orientation ? 0 : 1; //invert orientation
if (lastCell.word[0]) //clear highlight
lastCell.word[0].clearHighlight();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment