Add: ESC key back(), Enter key start/restart to all features
This commit is contained in:
@@ -2,6 +2,8 @@ function Keyboard(keyMapper, language, offsetY) {
|
||||
this.keyMapper = keyMapper;
|
||||
this.language = language;
|
||||
|
||||
this.keyHandlerMapper = {};
|
||||
|
||||
this.keyIndex = 0;
|
||||
this.keyDataList = [];
|
||||
this.keyList = [];
|
||||
@@ -44,6 +46,20 @@ function Keyboard(keyMapper, language, offsetY) {
|
||||
}
|
||||
}
|
||||
|
||||
Keyboard.prototype.addCallback = function(keyCode, keyDownHandler, keyUpHandler, callerClassName) {
|
||||
if(this.keyHandlerMapper[keyCode] != undefined) {
|
||||
this.keyHandlerMapper[keyCode] = null;
|
||||
}
|
||||
|
||||
this.keyHandlerMapper[keyCode] = {
|
||||
"keyDownHandler": keyDownHandler,
|
||||
"keyUpHandler": keyUpHandler,
|
||||
"callerClassName": callerClassName
|
||||
}
|
||||
|
||||
// console.log(this.keyHandlerMapper);
|
||||
}
|
||||
|
||||
Keyboard.prototype.hideHighlight = function(text) {
|
||||
var keyID = this.keyMapper.getKeyIDOfText(text);
|
||||
this.allKeyHash[keyID].hideHighlight();
|
||||
@@ -76,13 +92,27 @@ Keyboard.prototype.getKey = function(keyID) {
|
||||
Keyboard.prototype.keyDown = function(char) {
|
||||
var keyCode = char.code;
|
||||
this.setPressedSprite(keyCode);
|
||||
|
||||
if(this.keyHandlerMapper[char.keyCode] == undefined) {
|
||||
// console.log(keyCode + " is down but not registered to KeyMapper");
|
||||
return;
|
||||
}
|
||||
|
||||
var keyMapper = this.keyHandlerMapper[char.keyCode];
|
||||
var keyDownHandler = keyMapper["keyDownHandler"];
|
||||
if(keyDownHandler == undefined)
|
||||
return;
|
||||
|
||||
if(isDebugMode())
|
||||
console.log(keyCode + " key is down (" + keyMapper["callerClassName"] + ")");
|
||||
keyDownHandler();
|
||||
}
|
||||
|
||||
Keyboard.prototype.setPressedSprite = function(keyCode) {
|
||||
var keyID = this.keyMapper.getKeyIDOfText(keyCode);
|
||||
var key = this.allKeyHash[keyID];
|
||||
if(key === undefined) {
|
||||
console.log(keyCode+ " is pressed but not registered to KeyMapper");
|
||||
console.log(keyCode + " is pressed but not registered to KeyMapper");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -101,6 +131,20 @@ Keyboard.prototype.setPressedSprite = function(keyCode) {
|
||||
Keyboard.prototype.keyUp = function(char) {
|
||||
var keyCode = char.code;
|
||||
this.setNormalSprite(keyCode);
|
||||
|
||||
if(this.keyHandlerMapper[char.keyCode] == undefined) {
|
||||
// console.log(keyCode + " is up but not registered to KeyMapper");
|
||||
return;
|
||||
}
|
||||
|
||||
var keyMapper = this.keyHandlerMapper[char.keyCode];
|
||||
var keyUpHandler = keyMapper["keyUpHandler"];
|
||||
if(keyUpHandler == undefined)
|
||||
return;
|
||||
|
||||
if(isDebugMode())
|
||||
console.log(keyCode + " key is up (" + keyMapper["callerClassName"] + ")");
|
||||
keyUpHandler();
|
||||
}
|
||||
|
||||
Keyboard.prototype.setNormalSprite = function(keyCode) {
|
||||
|
||||
@@ -17,10 +17,7 @@ var TypingPractice = {
|
||||
|
||||
// top ui
|
||||
var screenTopUI = new ScreenTopUI();
|
||||
screenTopUI.makeBackButton( function() {
|
||||
sessionStorageManager.resetPlayingAppData();
|
||||
location.href = '../../web/client/menu_typing_practice.html';
|
||||
});
|
||||
screenTopUI.makeBackButton( (function() { this.back(); }).bind(this) );
|
||||
screenTopUI.makeFullScreenButton();
|
||||
|
||||
|
||||
@@ -86,8 +83,14 @@ var TypingPractice = {
|
||||
this.keyboard = new Keyboard(this.keyMapper, Keyboard.KOREAN, Keyboard.NO_OFFSET_POS_Y);
|
||||
else
|
||||
this.keyboard = new Keyboard(this.keyMapper, Keyboard.ENGLISH, Keyboard.NO_OFFSET_POS_Y);
|
||||
this.keyboard.addCallback(
|
||||
Phaser.KeyCode.ESC, // keyCode
|
||||
null, // keyDownHandler
|
||||
(function() { this.back(); }).bind(this), // keyUpHandler
|
||||
"typing_practice" // callerClassName
|
||||
);
|
||||
|
||||
game.input.keyboard.processKeyPress = (function() {
|
||||
game.input.keyboard.processKeyPress = (function(event) {
|
||||
if(self.isOnStage === false)
|
||||
return;
|
||||
|
||||
@@ -112,6 +115,12 @@ var TypingPractice = {
|
||||
// this.countDown();
|
||||
},
|
||||
|
||||
|
||||
back: function() {
|
||||
sessionStorageManager.resetPlayingAppData();
|
||||
location.href = '../../web/client/menu_typing_practice.html';
|
||||
},
|
||||
|
||||
startGame: function() {
|
||||
this.isOnStage = true;
|
||||
this.stageTimer.start();
|
||||
@@ -353,7 +362,7 @@ var TypingPractice = {
|
||||
return true;
|
||||
},
|
||||
|
||||
checkTypingContents: function(evnet) {
|
||||
checkTypingContents: function(event) {
|
||||
var inputContent = event.key;
|
||||
var typingContent = this.typingRandomContents[this.typingIndex];
|
||||
|
||||
|
||||
@@ -13,12 +13,18 @@ var TypingTest = {
|
||||
|
||||
game.stage.backgroundColor = '#4d4d4d';
|
||||
|
||||
// keyboard shortcut
|
||||
this.keyboardShortcut = new KeyboardShortcut();
|
||||
this.keyboardShortcut.addCallback(
|
||||
Phaser.KeyCode.ESC, // keyCode
|
||||
null, // keyDownHandler
|
||||
(function() { this.back(); }).bind(this), // keyUpHandler
|
||||
"keyboard_test" // callerClassName
|
||||
);
|
||||
|
||||
// top ui
|
||||
var screenTopUI = new ScreenTopUI();
|
||||
screenTopUI.makeBackButton( function() {
|
||||
sessionStorageManager.resetPlayingAppData();
|
||||
location.href = '../../web/client/menu_typing_test.html';
|
||||
});
|
||||
screenTopUI.makeBackButton( (function() { this.back(); }).bind(this) );
|
||||
screenTopUI.makeFullScreenButton();
|
||||
|
||||
|
||||
@@ -144,6 +150,12 @@ var TypingTest = {
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
back: function() {
|
||||
sessionStorageManager.resetPlayingAppData();
|
||||
location.href = '../../web/client/menu_typing_test.html';
|
||||
},
|
||||
|
||||
startGame: function() {
|
||||
this.averageTypingSpeedText.print(0);
|
||||
|
||||
@@ -311,7 +323,7 @@ var TypingTest = {
|
||||
this.inputTextContent.canvasInput.value('');
|
||||
},
|
||||
|
||||
checkTypingContents: function(evnet) {
|
||||
checkTypingContents: function(event) {
|
||||
if(event.keyCode == Phaser.Keyboard.ENTER) {
|
||||
// console.log("### enter ###");
|
||||
var inputContent = this.inputTextContent.canvasInput.value();
|
||||
|
||||
@@ -17,10 +17,7 @@ var WhacAMole = {
|
||||
|
||||
// top ui
|
||||
var screenTopUI = new ScreenTopUI();
|
||||
screenTopUI.makeBackButton( function() {
|
||||
sessionStorageManager.resetPlayingAppData();
|
||||
location.href = '../../web/client/menu_app.html';
|
||||
});
|
||||
screenTopUI.makeBackButton( (function() { this.back(); }).bind(this) );
|
||||
screenTopUI.makeFullScreenButton();
|
||||
|
||||
|
||||
@@ -115,6 +112,12 @@ var WhacAMole = {
|
||||
this.keyboard = new Keyboard(this.keyMapper, Keyboard.KOREAN, Keyboard.WHAC_A_MOLE_OFFSET_POS_Y);
|
||||
else
|
||||
this.keyboard = new Keyboard(this.keyMapper, Keyboard.ENGLISH, Keyboard.WHAC_A_MOLE_OFFSET_POS_Y);
|
||||
this.keyboard.addCallback(
|
||||
Phaser.KeyCode.ESC, // keyCode
|
||||
null, // keyDownHandler
|
||||
(function() { this.back(); }).bind(this), // keyUpHandler
|
||||
"whac a mole" // callerClassName
|
||||
);
|
||||
|
||||
game.input.keyboard.processKeyPress = (function() {
|
||||
if(self.isOnStage === false)
|
||||
@@ -138,6 +141,12 @@ var WhacAMole = {
|
||||
// this.countDown();
|
||||
},
|
||||
|
||||
|
||||
back: function() {
|
||||
sessionStorageManager.resetPlayingAppData();
|
||||
location.href = '../../web/client/menu_app.html';
|
||||
},
|
||||
|
||||
startGame: function() {
|
||||
this.isOnStage = true;
|
||||
this.stageTimer.start();
|
||||
@@ -415,7 +424,7 @@ var WhacAMole = {
|
||||
return true;
|
||||
},
|
||||
|
||||
checkTypingContents: function(evnet) {
|
||||
checkTypingContents: function(event) {
|
||||
var inputContent = event.key;
|
||||
var typingContent = this.typingRandomLetters[this.typingIndex];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user