Add: ESC key back(), Enter key start/restart to all features
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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() {
|
||||
},
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
+28
-10
@@ -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);
|
||||
|
||||
+27
-10
@@ -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
|
||||
|
||||
@@ -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