diff --git a/src/game/lib/keyboard_shortcut.js b/src/game/lib/keyboard_shortcut.js index 02956f9..3ceb5ae 100644 --- a/src/game/lib/keyboard_shortcut.js +++ b/src/game/lib/keyboard_shortcut.js @@ -1,8 +1,5 @@ function KeyboardShortcut() { - console.log("KeyboardShortcut"); - this.keyHandlerMapper = {}; - console.log(this.keyHandlerMapper[Phaser.KeyCode.ESC]); game.input.keyboard.addCallbacks(this, this.keyDown, this.keyUp, null); }; diff --git a/src/game/menu/menu_app.js b/src/game/menu/menu_app.js index e6f9ae3..4c01650 100644 --- a/src/game/menu/menu_app.js +++ b/src/game/menu/menu_app.js @@ -32,12 +32,18 @@ var MenuApp = { ); + // keyboard shortcut + this.keyboardShortcut = new KeyboardShortcut(); + this.keyboardShortcut.addCallback( + Phaser.KeyCode.ESC, // keyCode + null, // keyDownHandler + (function() { this.back(); }).bind(this), // keyUpHandler + "menu_app" // callerClassName + ); + // top ui var screenTopUI = new ScreenTopUI(); - screenTopUI.makeBackButton( function() { - sessionStorageManager.clear(); - location.href = '../../web/client/login.html'; - }); + screenTopUI.makeBackButton( (function() { this.back(); }).bind(this) ); screenTopUI.makeFullScreenButton(); @@ -62,6 +68,10 @@ var MenuApp = { }, + back: function() { + sessionStorageManager.clear(); + location.href = '../../web/client/login.html'; + }, loadAppData: function() { var dbConnectManager = new DBConnectManager(); diff --git a/src/game/menu/menu_typing_practice.js b/src/game/menu/menu_typing_practice.js index 2486288..075546d 100644 --- a/src/game/menu/menu_typing_practice.js +++ b/src/game/menu/menu_typing_practice.js @@ -39,6 +39,7 @@ var MenuTypingPractice = { // ); + // keyboard shortcut this.keyboardShortcut = new KeyboardShortcut(); this.keyboardShortcut.addCallback( Phaser.KeyCode.ESC, // keyCode @@ -82,11 +83,11 @@ var MenuTypingPractice = { this.makeActiveTypingPracticeAppButtons(); }, + back: function() { location.href = '../../web/client/menu_app.html'; }, - makeActiveTypingPracticeAppButtons: function() { var dbConnectManager = new DBConnectManager(); dbConnectManager.requestTypingPracticeAppList( diff --git a/src/game/menu/menu_typing_test.js b/src/game/menu/menu_typing_test.js index 73cfa31..42db56c 100644 --- a/src/game/menu/menu_typing_test.js +++ b/src/game/menu/menu_typing_test.js @@ -39,11 +39,18 @@ var MenuTypingTest = { // ); + // keyboard shortcut + this.keyboardShortcut = new KeyboardShortcut(); + this.keyboardShortcut.addCallback( + Phaser.KeyCode.ESC, // keyCode + null, // keyDownHandler + (function() { this.back(); }).bind(this), // keyUpHandler + "menu_typing_test" // callerClassName + ); + // top ui var screenTopUI = new ScreenTopUI(); - screenTopUI.makeBackButton( function() { - location.href = '../../web/client/menu_app.html'; - }); + screenTopUI.makeBackButton( function() { (function() { this.back(); }).bind(this) }); screenTopUI.makeFullScreenButton(); @@ -77,6 +84,10 @@ var MenuTypingTest = { }, + back: function() { + location.href = '../../web/client/menu_app.html'; + }, + makeActiveTypingTestAppButtons: function() { var dbConnectManager = new DBConnectManager(); dbConnectManager.requestTypingTestAppList( diff --git a/src/game/mouse/space_invaders/game.js b/src/game/mouse/space_invaders/game.js index faf16bc..01981cf 100644 --- a/src/game/mouse/space_invaders/game.js +++ b/src/game/mouse/space_invaders/game.js @@ -10,12 +10,18 @@ var Game = { (function() { this.gameOver(); }).bind(this) ); + // keyboard shortcut + this.keyboardShortcut = new KeyboardShortcut(); + this.keyboardShortcut.addCallback( + Phaser.KeyCode.ESC, // keyCode + null, // keyDownHandler + (function() { this.back(); }).bind(this), // keyUpHandler + "space invaders" // callerClassName + ); + // 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(); var scoreBoard = new ScoreBoard(); @@ -83,6 +89,12 @@ var Game = { // this.countDown(); }, + + back: function() { + sessionStorageManager.resetPlayingAppData(); + location.href = '../../web/client/menu_app.html'; + }, + initListeners: function() { }, diff --git a/src/game/ranking/ranking.js b/src/game/ranking/ranking.js index ba1ccc3..67b222d 100644 --- a/src/game/ranking/ranking.js +++ b/src/game/ranking/ranking.js @@ -19,11 +19,18 @@ var Ranking = { // phaser.alpha = 0.1; + // keyboard shortcut + this.keyboardShortcut = new KeyboardShortcut(); + this.keyboardShortcut.addCallback( + Phaser.KeyCode.ESC, // keyCode + null, // keyDownHandler + (function() { this.back(); }).bind(this), // keyUpHandler + "ranking" // callerClassName + ); + // top ui var screenTopUI = new ScreenTopUI(); - screenTopUI.makeBackButton( function() { - location.href = '../../web/client/start.html'; - }); + screenTopUI.makeBackButton( (function() { this.back(); }).bind(this) ); screenTopUI.makeFullScreenButton(); @@ -69,6 +76,11 @@ var Ranking = { game.time.events.loop(Phaser.Timer.SECOND * 10, this.getRecordToRankingServer, this); }, + + back: function() { + location.href = '../../web/client/start.html'; + }, + makeTextButton: function(x, y, buttonText, eventListener) { var setting = new RoundRectButtonSetting(x, y, 200, 100); setting.fontStyle.fontWeight = "bold"; diff --git a/src/game/result/result.js b/src/game/result/result.js index 6b8b500..4e1cd1b 100644 --- a/src/game/result/result.js +++ b/src/game/result/result.js @@ -16,18 +16,24 @@ var Result = { this.game.stage.backgroundColor = '#4d4d4d'; this.chartGraphics = game.add.graphics(100, game.world.height - 120); + // keyboard shortcut + this.keyboardShortcut = new KeyboardShortcut(); + this.keyboardShortcut.addCallback( + Phaser.KeyCode.ESC, // keyCode + null, // keyDownHandler + (function() { this.back(); }).bind(this), // keyUpHandler + "result" // callerClassName + ); + this.keyboardShortcut.addCallback( + Phaser.KeyCode.ENTER, // keyCode + null, // keyDownHandler + (function() { this.restartStage(); }).bind(this), // keyUpHandler + "result" // callerClassName + ); + // top ui var screenTopUI = new ScreenTopUI(); - screenTopUI.makeBackButton( function() { - if(isTypingPracticeApp()) - location.href = '../../web/client/menu_typing_practice.html'; - else if(isTypingTestApp()) - location.href = '../../web/client/menu_typing_test.html'; - else - location.href = '../../web/client/menu_app.html'; - - sessionStorageManager.resetPlayingAppData(); - }); + screenTopUI.makeBackButton( function() { (function() { this.back(); }).bind(this) }); screenTopUI.makeFullScreenButton(); @@ -54,6 +60,18 @@ var Result = { screenBottomUI.printRightText(sessionStorageManager.getPlayerName()); }, + + back: function() { + if(isTypingPracticeApp()) + location.href = '../../web/client/menu_typing_practice.html'; + else if(isTypingTestApp()) + location.href = '../../web/client/menu_typing_test.html'; + else + location.href = '../../web/client/menu_app.html'; + + sessionStorageManager.resetPlayingAppData(); + }, + printRecord: function() { const style = { font: "bold 38px Arial", fill: "#fff", align: "left", boundsAlignH: "center", boundsAlignV: "middle" }; var titleText = game.add.text(game.world.width / 2, 35, "결과", style); diff --git a/src/game/start/start.js b/src/game/start/start.js index a640b45..05e2c7f 100644 --- a/src/game/start/start.js +++ b/src/game/start/start.js @@ -12,18 +12,24 @@ var Start = { this.chart = new Chart(); + // keyboard shortcut + this.keyboardShortcut = new KeyboardShortcut(); + this.keyboardShortcut.addCallback( + Phaser.KeyCode.ESC, // keyCode + null, // keyDownHandler + (function() { this.back(); }).bind(this), // keyUpHandler + "start" // callerClassName + ); + this.keyboardShortcut.addCallback( + Phaser.KeyCode.ENTER, // keyCode + null, // keyDownHandler + (function() { this.startStage(); }).bind(this), // keyUpHandler + "start" // callerClassName + ); + // top ui var screenTopUI = new ScreenTopUI(); - screenTopUI.makeBackButton( function() { - if(isTypingPracticeApp()) - location.href = '../../web/client/menu_typing_practice.html'; - else if(isTypingTestApp()) - location.href = '../../web/client/menu_typing_test.html'; - else - location.href = '../../web/client/menu_app.html'; - - sessionStorageManager.resetPlayingAppData(); - }); + screenTopUI.makeBackButton( function() { (function() { this.back(); }).bind(this) }); screenTopUI.makeFullScreenButton(); @@ -63,6 +69,17 @@ var Start = { ); }, + back: function() { + if(isTypingPracticeApp()) + location.href = '../../web/client/menu_typing_practice.html'; + else if(isTypingTestApp()) + location.href = '../../web/client/menu_typing_test.html'; + else + location.href = '../../web/client/menu_app.html'; + + sessionStorageManager.resetPlayingAppData(); + }, + loadHowToPlay: function(appID) { this.dbConnectManager.requestHowToPlay( sessionStorageManager.getPlayingAppID(), // space_invaders app ID diff --git a/src/game/typing/lib/keyboard.js b/src/game/typing/lib/keyboard.js index 2fe91c4..2720304 100644 --- a/src/game/typing/lib/keyboard.js +++ b/src/game/typing/lib/keyboard.js @@ -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) { diff --git a/src/game/typing/practice/game.js b/src/game/typing/practice/game.js index 1bd6c97..e6f1cc5 100644 --- a/src/game/typing/practice/game.js +++ b/src/game/typing/practice/game.js @@ -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]; diff --git a/src/game/typing/test/game.js b/src/game/typing/test/game.js index 5448b73..6e6734d 100644 --- a/src/game/typing/test/game.js +++ b/src/game/typing/test/game.js @@ -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(); diff --git a/src/game/typing/whac_a_mole/game.js b/src/game/typing/whac_a_mole/game.js index 48bec0b..480117b 100644 --- a/src/game/typing/whac_a_mole/game.js +++ b/src/game/typing/whac_a_mole/game.js @@ -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]; diff --git a/src/web/client/login.html b/src/web/client/login.html index 5942a90..0c4e31b 100644 --- a/src/web/client/login.html +++ b/src/web/client/login.html @@ -14,6 +14,7 @@ + diff --git a/src/web/client/menu_app.html b/src/web/client/menu_app.html index e8163b0..22f0ddd 100644 --- a/src/web/client/menu_app.html +++ b/src/web/client/menu_app.html @@ -14,6 +14,7 @@ + diff --git a/src/web/client/menu_app_play_free.html b/src/web/client/menu_app_play_free.html index e4d3b27..2116b5d 100644 --- a/src/web/client/menu_app_play_free.html +++ b/src/web/client/menu_app_play_free.html @@ -14,6 +14,7 @@ + diff --git a/src/web/client/menu_typing_test.html b/src/web/client/menu_typing_test.html index cdbf9b5..6c60a27 100644 --- a/src/web/client/menu_typing_test.html +++ b/src/web/client/menu_typing_test.html @@ -14,6 +14,7 @@ + diff --git a/src/web/client/ranking.html b/src/web/client/ranking.html index 15a78ff..bb2db9c 100644 --- a/src/web/client/ranking.html +++ b/src/web/client/ranking.html @@ -16,6 +16,7 @@ + diff --git a/src/web/client/result.html b/src/web/client/result.html index 60aa7b8..d5197fa 100644 --- a/src/web/client/result.html +++ b/src/web/client/result.html @@ -14,6 +14,7 @@ + diff --git a/src/web/client/space_invaders.html b/src/web/client/space_invaders.html index 4903ac9..a1f20f7 100644 --- a/src/web/client/space_invaders.html +++ b/src/web/client/space_invaders.html @@ -16,6 +16,7 @@ + diff --git a/src/web/client/start.html b/src/web/client/start.html index 8ae1d9a..ae70850 100644 --- a/src/web/client/start.html +++ b/src/web/client/start.html @@ -14,6 +14,7 @@ + diff --git a/src/web/client/typing_practice.html b/src/web/client/typing_practice.html index e0496eb..4a74b97 100644 --- a/src/web/client/typing_practice.html +++ b/src/web/client/typing_practice.html @@ -16,6 +16,7 @@ + diff --git a/src/web/client/typing_test.html b/src/web/client/typing_test.html index 8f54c87..6183088 100644 --- a/src/web/client/typing_test.html +++ b/src/web/client/typing_test.html @@ -16,6 +16,7 @@ + diff --git a/src/web/client/whac_a_mole.html b/src/web/client/whac_a_mole.html index b74611b..ccf0021 100644 --- a/src/web/client/whac_a_mole.html +++ b/src/web/client/whac_a_mole.html @@ -16,6 +16,7 @@ +