228 lines
6.7 KiB
JavaScript
228 lines
6.7 KiB
JavaScript
var MenuTypingTest = {
|
|
preload() {
|
|
game.load.image('icon_fullscreen', '../../../resources/image/icon/fullscreen_white.png');
|
|
game.load.image('space_invaders', '../../../resources/image/icon/space_invaders.png');
|
|
|
|
Animal.loadResources();
|
|
},
|
|
|
|
create() {
|
|
game.stage.backgroundColor = '#4d4d4d';
|
|
|
|
// typing app area
|
|
var typingBG = new AppAreaBG(AppAreaBG.COLOR_TYPING_APP, 1,
|
|
0, 60,
|
|
GAME_SCREEN_SIZE.x, GAME_SCREEN_SIZE.y - 110
|
|
);
|
|
|
|
// korean app area
|
|
// var koreanBG = new AppAreaBG(AppAreaBG.COLOR_TYPING_KOREAN, 1,
|
|
// 0, 60 + AppAreaBG.GAP_Y,
|
|
// GAME_SCREEN_SIZE.x, 270
|
|
// );
|
|
// koreanBG.printText(
|
|
// "한 글 타 자",
|
|
// game.world.centerX, 320,
|
|
// 36, "#000", 0.05
|
|
// );
|
|
|
|
// english app area
|
|
// var englishBG = new AppAreaBG(AppAreaBG.COLOR_TYPING_ENGLISH, 1,
|
|
// 0, 340,
|
|
// GAME_SCREEN_SIZE.x, 270
|
|
// );
|
|
// englishBG.printText(
|
|
// "영 문 타 자",
|
|
// game.world.centerX, 370,
|
|
// 36, "#000", 0.05
|
|
// );
|
|
|
|
|
|
// top ui
|
|
var screenTopUI = new ScreenTopUI();
|
|
screenTopUI.makeBackButton( function() {
|
|
location.href = '../../web/client/menu_app.html';
|
|
});
|
|
screenTopUI.makeFullScreenButton();
|
|
|
|
|
|
// typing tab buttons
|
|
var typingPracticeTabButton = new TypingTabButton(
|
|
TypingTabButton.PRACTICE_BUTTON_POS_X, TypingTabButton.BUTTON_POS_Y,
|
|
"", "타자 연습",
|
|
(function() {
|
|
location.href = '../../web/client/menu_typing_practice.html';
|
|
})
|
|
);
|
|
// typingPracticeTabButton.setInputEnabled(false);
|
|
|
|
var typingTestTabButton = new TypingTabButton(
|
|
TypingTabButton.TEST_BUTTON_POS_X, TypingTabButton.BUTTON_POS_Y,
|
|
"", "타자 시험",
|
|
(function() {
|
|
location.href = '../../web/client/menu_typing_test.html';
|
|
})
|
|
);
|
|
typingTestTabButton.setInputEnabled(false);
|
|
|
|
this.makeActiveTypingTestAppButtons();
|
|
|
|
|
|
// bottom ui
|
|
var screenBottomUI = new ScreenBottomUI();
|
|
// screenBottomUI.printLeftText("게임 진행 정보");
|
|
screenBottomUI.printCenterText("메뉴 > 타자 시험");
|
|
screenBottomUI.printRightText(sessionStorageManager.getPlayerName());
|
|
},
|
|
|
|
|
|
makeActiveTypingTestAppButtons: function() {
|
|
var dbConnectManager = new DBConnectManager();
|
|
dbConnectManager.requestTypingTestAppList(
|
|
sessionStorageManager.getMaestroID(),
|
|
sessionStorageManager.getPlayerID(),
|
|
// self.downloadListSucceeded,
|
|
// self.downloadListFailed
|
|
(function(replyJSON) {
|
|
this.downloadListSucceeded(replyJSON);
|
|
}).bind(this),
|
|
(function(replyJSON) {
|
|
this.downloadListFailed(replyJSON);
|
|
}).bind(this)
|
|
);
|
|
|
|
},
|
|
|
|
hasApp: function(appID, appList) {
|
|
for(var i = 0; i < appList.length; i++) {
|
|
if(appList[i].AppID === appID)
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
},
|
|
|
|
getBestRecord: function(jsonList, appID) {
|
|
var count = Object.keys(jsonList).length;
|
|
|
|
for(var i = 0; i < count; i++) {
|
|
if(jsonList[i].AppID === appID)
|
|
return jsonList[i].BestRecord;
|
|
}
|
|
|
|
return 0;
|
|
},
|
|
|
|
getIconImage: function(jsonList, appID) {
|
|
var bestRecord = this.getBestRecord(jsonList, appID);
|
|
|
|
if(bestRecord === 0)
|
|
return "snail_shadow";
|
|
|
|
var animalLevel = Animal.animalLevelIDByRecord(bestRecord, Animal.TYPE_TEST);
|
|
return Animal.SPECIES_DATA[animalLevel].species + Animal.SPRITE_NAMES.icon;
|
|
},
|
|
|
|
downloadListSucceeded: function(replyJSON) {
|
|
// console.log(replyJSON);
|
|
|
|
var buttonWidthGap = TypingAppButton.BUTTON_WIDTH + MenuTypingTest.BUTTON_GAP;
|
|
|
|
var koreanTypingPracticeAppCount = Object.keys(replyJSON.KoreanAppList).length;
|
|
var englishTypingPracticeAppCount = Object.keys(replyJSON.EnglishAppList).length;
|
|
|
|
for(var i = 0; i < koreanTypingPracticeAppCount; i++) {
|
|
var activeApp = replyJSON.KoreanAppList[i];
|
|
|
|
var posX = this.getButtonPosX(i, koreanTypingPracticeAppCount);
|
|
var posY = this.getButtonPosY(i, koreanTypingPracticeAppCount,
|
|
TypingAppButton.BUTTON_UPPER_POS_Y
|
|
);
|
|
|
|
var typingTestButton = new TypingAppButton(
|
|
TypingAppButton.TYPE_TEST_KOREAN,
|
|
posX, posY,
|
|
this.getIconImage(replyJSON.KoreanHighScoreList, activeApp.AppID),
|
|
activeApp.KoreanName,
|
|
{
|
|
AppID: activeApp.AppID,
|
|
AppName: activeApp.AppName,
|
|
KoreanName: activeApp.KoreanName
|
|
}
|
|
);
|
|
|
|
if(!this.hasApp(activeApp.AppID, replyJSON.KoreanActiveAppList))
|
|
typingTestButton.setInputEnabled(false);
|
|
}
|
|
|
|
for(var i = 0; i < englishTypingPracticeAppCount; i++) {
|
|
var activeApp = replyJSON.EnglishAppList[i];
|
|
|
|
var posX = this.getButtonPosX(i, englishTypingPracticeAppCount);
|
|
var posY = this.getButtonPosY(i, englishTypingPracticeAppCount,
|
|
TypingAppButton.BUTTON_LOWER_POS_Y
|
|
);
|
|
|
|
var typingTestButton = new TypingAppButton(
|
|
TypingAppButton.TYPE_TEST_ENGLISH,
|
|
posX, posY,
|
|
this.getIconImage(replyJSON.KoreanHighScoreList, activeApp.AppID),
|
|
activeApp.KoreanName,
|
|
{
|
|
AppID: activeApp.AppID,
|
|
AppName: activeApp.AppName,
|
|
KoreanName: activeApp.KoreanName
|
|
}
|
|
);
|
|
|
|
if(!this.hasApp(activeApp.AppID, replyJSON.EnglishActiveAppList))
|
|
typingTestButton.setInputEnabled(false);
|
|
}
|
|
},
|
|
|
|
getButtonPosX: function(index, buttonCount) {
|
|
var gap = TypingAppButton.BUTTON_WIDTH + TypingAppButton.BUTTON_GAP;
|
|
var maxColumnNum = Math.floor( (game.world.width - TypingAppButton.MARGIN_VERTICAL) / gap );
|
|
// console.log("maxColumnNum : " + maxColumnNum);
|
|
var rowCount = Math.ceil(buttonCount / maxColumnNum);
|
|
// console.log("rowCount : " + rowCount);
|
|
|
|
var columnIndex = index % maxColumnNum;
|
|
// console.log("columnIndex : " + columnIndex);
|
|
var rowIndex = Math.floor(index / maxColumnNum);
|
|
// console.log("rowIndex : " + rowIndex);
|
|
|
|
var columnCountForThisRow = 0;
|
|
if(rowIndex < rowCount - 1)
|
|
columnCountForThisRow = maxColumnNum;
|
|
else
|
|
columnCountForThisRow = buttonCount - (maxColumnNum * rowIndex);
|
|
// console.log("columnCountForThisRow : " + columnCountForThisRow);
|
|
|
|
var startX = game.world.width / 2 - ( (gap / 2) * (columnCountForThisRow - 1) );
|
|
return startX + gap * columnIndex;
|
|
},
|
|
|
|
getButtonPosY: function(index, buttonCount, startPosY) {
|
|
var rowGap = TypingAppButton.BUTTON_HEIGHT + TypingAppButton.BUTTON_GAP;
|
|
|
|
var columnGap = TypingAppButton.BUTTON_WIDTH + TypingAppButton.BUTTON_GAP;
|
|
var maxColumnNum = Math.floor( (game.world.width - TypingAppButton.MARGIN_VERTICAL) / columnGap );
|
|
// console.log("maxColumnNum : " + maxColumnNum);
|
|
// console.log("buttonCount : " + buttonCount);
|
|
var rowCount = Math.ceil(buttonCount / maxColumnNum);
|
|
// console.log("rowCount : " + rowCount);
|
|
|
|
var rowIndex = Math.floor(index / maxColumnNum);
|
|
// console.log("rowIndex : " + rowIndex);
|
|
|
|
var startY = startPosY - ( (rowGap / 2) * (rowCount - 1) );
|
|
return startY + rowGap * rowIndex;
|
|
},
|
|
|
|
|
|
downloadListFailed: function(replyJSON) {
|
|
console.log('download app list failed, jsonData : ' + JSON.stringify(replyJSON));
|
|
}
|
|
|
|
} |