Fix: restructing session manager, ES6 -> ES5

This commit is contained in:
2018-09-14 22:22:22 +09:00
parent 72e7c1a28f
commit 3f340535ac
44 changed files with 3100 additions and 3262 deletions
+72 -78
View File
@@ -1,20 +1,16 @@
/////////////////////////////
// TypingPractice
class TypingPractice {
create() {
self = this;
var TypingPractice = {
create: function() {
var self = this;
this.isOnStage = false;
this.initTypingData();
sessionStorageManager.isNewBestRecrd = false;
sessionStorageManager.setIsNewBestRecord(false);
game.stage.backgroundColor = '#4d4d4d';
// top ui
let screenTopUI = new ScreenTopUI();
var screenTopUI = new ScreenTopUI();
screenTopUI.makeBackButton( function() {
sessionStorageManager.resetPlayingAppData();
location.href = '../../web/client/menu_typing_practice.html';
@@ -38,10 +34,10 @@ class TypingPractice {
// typing content
let typingContentBG = new TypingContentBG();
var typingContentBG = new TypingContentBG();
typingContentBG.makePracticeContentBG();
let TYPING_CONTENT_Y = 200;
var TYPING_CONTENT_Y = 200;
textStyleBasic.font = "bold 84px Times New Roman";
this.textTypingContent = game.add.text(game.world.centerX, TYPING_CONTENT_Y, "", textStyleBasic)
@@ -56,11 +52,11 @@ class TypingPractice {
// textStyleBasic.font = "32px Arial";
let OFFSET_WORD_X = 70;
var OFFSET_WORD_X = 70;
let textDoneColor = [ '#99994d', '#77774d', '#66664d' ];
var textDoneColor = [ '#99994d', '#77774d', '#66664d' ];
this.textTypingContentsDone = [];
for(let i = 0; i < TypingPractice.TYPING_CONTENT_DONE_COUNT; i++) {
for(var i = 0; i < TypingPractice.TYPING_CONTENT_DONE_COUNT; i++) {
this.textTypingContentsDone[i] = game.add.text(
game.world.centerX - 200 - i * OFFSET_WORD_X, TYPING_CONTENT_Y,
"", textStyleBasic
@@ -69,9 +65,9 @@ class TypingPractice {
this.textTypingContentsDone[i].anchor.set(0.5);
}
let textPreviewColor = [ '#666666', '#888888', '#777777' ];
var textPreviewColor = [ '#666666', '#888888', '#777777' ];
this.textTypingContentPreview = [];
for(let i = 0; i < TypingPractice.TYPING_CONTENT_PREVIEW_COUNT; i++) {
for(var i = 0; i < TypingPractice.TYPING_CONTENT_PREVIEW_COUNT; i++) {
this.textTypingContentPreview[i] = game.add.text(
game.world.centerX + 200 + i * OFFSET_WORD_X,
TYPING_CONTENT_Y, "", textStyleBasic
@@ -83,7 +79,7 @@ class TypingPractice {
// keyboard
this.keyMapper = new KeyMapper();
this.keyboard = null;
if(sessionStorageManager.playingAppName.indexOf("korean") > 0)
if(sessionStorageManager.getPlayingAppName().indexOf("korean") > 0)
this.keyboard = new Keyboard(this.keyMapper, Keyboard.KOREAN);
else
this.keyboard = new Keyboard(this.keyMapper, Keyboard.ENGLISH);
@@ -103,29 +99,29 @@ class TypingPractice {
// bottom ui
let screenBottomUI = new ScreenBottomUI();
var screenBottomUI = new ScreenBottomUI();
// screenBottomUI.printBottomUILeftText("");
screenBottomUI.printCenterText(sessionStorageManager.playingAppKoreanName);
screenBottomUI.printRightText(sessionStorageManager.playerName);
screenBottomUI.printCenterText(sessionStorageManager.getPlayingAppKoreanName());
screenBottomUI.printRightText(sessionStorageManager.getPlayerName());
this.startGame();
// this.countDown();
}
},
startGame() {
startGame: function() {
this.isOnStage = true;
this.stageTimer.start();
this.showTypingPracticeContents();
this.showHighlightKey();
this.moveHands();
}
},
gameOver() {
gameOver: function() {
this.isOnStage = false;
for(let i = 0; i < TypingPractice.TYPING_CONTENT_DONE_COUNT; i++) {
for(var i = 0; i < TypingPractice.TYPING_CONTENT_DONE_COUNT; i++) {
this.textTypingContentsDone[i].text = "";
}
@@ -135,7 +131,7 @@ class TypingPractice {
this.textTypingContent.addColor(TypingPractice.COLOR_CONTENT_RIGHT, 0);
this.textTypingContent.text = "= 연습 끝 =";
for(let i = 0; i < TypingPractice.TYPING_CONTENT_PREVIEW_COUNT; i++) {
for(var i = 0; i < TypingPractice.TYPING_CONTENT_PREVIEW_COUNT; i++) {
this.textTypingContentPreview[i].text = "";
}
@@ -144,22 +140,22 @@ class TypingPractice {
this.animalOnTitle.stopAnimation();
let gameOverText = new GameOverText();
var gameOverText = new GameOverText();
game.time.events.add(Phaser.Timer.SECOND * 2, this.goResult, this);
}
},
goResult() {
sessionStorageManager.record = this.typingScore.score();
if(sessionStorageManager.record > sessionStorageManager.bestRecord)
sessionStorageManager.bestRecord = sessionStorageManager.record;
goResult: function() {
sessionStorageManager.setRecord(this.typingScore.score());
if(sessionStorageManager.getRecord() > sessionStorageManager.getBestRecord())
sessionStorageManager.setBestRecord(sessionStorageManager.getRecord());
location.href = '../../web/client/result.html';
}
},
initTypingData() {
let typingTextMan = new TypingTextManager();
initTypingData: function() {
var typingTextMan = new TypingTextManager();
let typingPracticeContents = this.loadPracticeContent();
var typingPracticeContents = this.loadPracticeContent();
// console.log(typingPracticeContents);
typingTextMan.makePracticeContents(typingPracticeContents, 30);
this.typingRandomContents = typingTextMan.getContents();
@@ -168,17 +164,17 @@ class TypingPractice {
this.typingIndex = 0;
this.playingAnimalIndex = 0;
}
},
loadPracticeContent() {
let appName = "";
loadPracticeContent: function() {
var appName = "";
if(isTypingTestStage())
appName = sessionStorageManager.playingAppName.substring(5);
appName = sessionStorageManager.getPlayingAppName().substring(5);
else if(isTypingPracticeStage())
appName = sessionStorageManager.playingAppName.substring(9);
appName = sessionStorageManager.getPlayingAppName().substring(9);
let testContent = [];
var testContent = [];
switch(appName) {
case "korean_basic":
@@ -260,11 +256,11 @@ class TypingPractice {
}
return testContent;
}
},
showTypingPracticeContents() {
for(let i = 0; i < TypingPractice.TYPING_CONTENT_DONE_COUNT; i++) {
let doneIndex = this.typingIndex - i - 1;
showTypingPracticeContents: function() {
for(var i = 0; i < TypingPractice.TYPING_CONTENT_DONE_COUNT; i++) {
var doneIndex = this.typingIndex - i - 1;
if(doneIndex < 0) {
this.textTypingContentsDone[i].text = "";
} else {
@@ -279,43 +275,43 @@ class TypingPractice {
this.textTypingContent.text = this.typingRandomContents[this.typingIndex];
for(let i = 0; i < TypingPractice.TYPING_CONTENT_PREVIEW_COUNT; i++) {
let previewIndex = this.typingIndex + i + 1;
for(var i = 0; i < TypingPractice.TYPING_CONTENT_PREVIEW_COUNT; i++) {
var previewIndex = this.typingIndex + i + 1;
if(previewIndex < this.typingRandomContents.length)
this.textTypingContentPreview[i].text = this.typingRandomContents[previewIndex];
else
this.textTypingContentPreview[i].text = "";
}
}
},
hideHighlightKey() {
let prevText = this.typingRandomContents[this.typingIndex];
hideHighlightKey: function() {
var prevText = this.typingRandomContents[this.typingIndex];
if(prevText === undefined)
return;
this.keyboard.hideHighlight(prevText);
}
},
showHighlightKey() {
let typingText = this.typingRandomContents[this.typingIndex];
showHighlightKey: function() {
var typingText = this.typingRandomContents[this.typingIndex];
if(typingText === undefined)
return;
this.keyboard.showHighlight(typingText, this.leftHand, this.rightHand);
}
},
moveHands() {
let typingText = this.typingRandomContents[this.typingIndex];
moveHands: function() {
var typingText = this.typingRandomContents[this.typingIndex];
if(typingText === undefined)
return;
let key = this.keyboard.getKeyOfText(typingText);
let handSide = key.handSide;
var key = this.keyboard.getKeyOfText(typingText);
var handSide = key.handSide;
if(handSide === KeyButton.LEFT_HAND) {
this.leftHand.moveTo(key);
if(this.keyMapper.isShiftText(typingText)) {
let shiftRightKey = this.keyboard.getKey("ShiftRight");
var shiftRightKey = this.keyboard.getKey("ShiftRight");
shiftRightKey.showHighlight();
this.rightHand.moveTo(shiftRightKey);
} else {
@@ -325,42 +321,42 @@ class TypingPractice {
this.rightHand.moveTo(key);
if(this.keyMapper.isShiftText(typingText)) {
let shiftLeftKey = this.keyboard.getKey("ShiftLeft");
var shiftLeftKey = this.keyboard.getKey("ShiftLeft");
shiftLeftKey.showHighlight();
this.leftHand.moveTo(shiftLeftKey);
} else {
this.leftHand.moveToDefaultPosition();
}
}
}
},
getKeyCode(text) {
getKeyCode: function(text) {
return this.keyMapper.getKeyIDOfText(text);
}
},
isKeyPressed(inputContent, typingContent) {
let inputContentKeyCode = this.getKeyCode(inputContent);
let typingContentKeyCode = this.getKeyCode(typingContent);
isKeyPressed: function(inputContent, typingContent) {
var inputContentKeyCode = this.getKeyCode(inputContent);
var typingContentKeyCode = this.getKeyCode(typingContent);
if(inputContentKeyCode !== typingContentKeyCode)
return false;
let isShiftInputContent = this.shiftKey.isDown;
let isShiftTypingContent = this.keyMapper.isShiftText(typingContent);
var isShiftInputContent = this.shiftKey.isDown;
var isShiftTypingContent = this.keyMapper.isShiftText(typingContent);
if(isShiftInputContent !== isShiftTypingContent)
return false;
return true;
}
},
checkTypingContents(evnet) {
let inputContent = event.key;
let typingContent = this.typingRandomContents[this.typingIndex];
checkTypingContents: function(evnet) {
var inputContent = event.key;
var typingContent = this.typingRandomContents[this.typingIndex];
if(this.isKeyPressed(inputContent, typingContent)) {
this.typingScore.increase();
let animalLevelID = Animal.animalLevelIDByRecord(this.typingScore.score(), Animal.TYPE_PRACTICE);
var animalLevelID = Animal.animalLevelIDByRecord(this.typingScore.score(), Animal.TYPE_PRACTICE);
if(animalLevelID > this.playingAnimalIndex) {
this.playingAnimalIndex = animalLevelID;
this.animalOnTitle.setSpecies(Animal.SPECIES_DATA[this.playingAnimalIndex]);;
@@ -380,10 +376,9 @@ class TypingPractice {
this.animalOnTitle.startAnimation();
this.animalOnTitle.tweenAnimation(Animal.ANIMATION_TYPE_DAMAGE);
}
}
},
playNextContent() {
playNextContent: function() {
this.hideHighlightKey();
this.typingIndex++;
@@ -391,7 +386,6 @@ class TypingPractice {
this.showHighlightKey();
this.moveHands();
}
}