From 5d1090e652790298fdeda2a6c3829ef20b67a97e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Thu, 11 Jul 2019 21:57:05 +0900 Subject: [PATCH] Add: writing_info.php --- src/game/lib/button/typing_exam_button.js | 4 +- src/game/lib/db_service.js | 17 ++++ src/game/menu/menu_typing_exam.js | 113 ---------------------- src/game/typing/examination/game.js | 34 +++++-- src/web/client/typing_examination.html | 9 +- src/web/php/db/writing_collection.php | 23 +++++ src/web/php/writing/writing_info.php | 35 +++++++ test/tdd.js | 4 +- 8 files changed, 112 insertions(+), 127 deletions(-) create mode 100644 src/web/php/writing/writing_info.php diff --git a/src/game/lib/button/typing_exam_button.js b/src/game/lib/button/typing_exam_button.js index 4993242..14c2896 100644 --- a/src/game/lib/button/typing_exam_button.js +++ b/src/game/lib/button/typing_exam_button.js @@ -37,8 +37,8 @@ function TypingExamButton(x, y, iconName, buttonText, writingID) { TypingExamButton.prototype.onClick = function() { sessionStorageManager.setWritingID(this.writingID); - // location.href = '../../web/client/typing_examination.html'; - printSessionStorage(); + location.href = '../../web/client/typing_examination.html'; + // printSessionStorage(); } diff --git a/src/game/lib/db_service.js b/src/game/lib/db_service.js index bf941ca..c573fef 100644 --- a/src/game/lib/db_service.js +++ b/src/game/lib/db_service.js @@ -71,4 +71,21 @@ DBService.prototype.requestWritingPlayerList = function(onSucceededListener, onF }).bind(this) ); xhr.send("maestroID=" + this.maestroID + "&playerID=" + this.playerID); +} + +DBService.prototype.requestWritingInfo = function(writingID, onSucceededListener, onFailedListener) { + var xhr = this.makeXhr( + "php/writing/writing_info.php", + (function() { // onreadystatechange + if(xhr.readyState == 4 && xhr.status == 200) { + var replyJSON = JSON.parse(xhr.responseText); + + if(replyJSON != null) + onSucceededListener(replyJSON); + else + onFailedListener(replyJSON); + } + }).bind(this) + ); + xhr.send("writingID=" + writingID); } \ No newline at end of file diff --git a/src/game/menu/menu_typing_exam.js b/src/game/menu/menu_typing_exam.js index d4cea86..e7281e1 100644 --- a/src/game/menu/menu_typing_exam.js +++ b/src/game/menu/menu_typing_exam.js @@ -109,23 +109,6 @@ var MenuTypingExam = { this.downloadListFailed(jsonData); } ); - - /* - 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) { @@ -190,104 +173,8 @@ var MenuTypingExam = { indexEnglishWriting++; } } - - /* - var buttonWidthGap = TypingAppButton.BUTTON_WIDTH + MenuTypingExam.BUTTON_GAP; - - var koreanTypingPracticeAppCount = replyJSON.KoreanAppList.length; // Object.keys(replyJSON.KoreanAppList).length; - var englishTypingPracticeAppCount = replyJSON.EnglishAppList.length; // 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.getAnimalSprite(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.getAnimalSprite(replyJSON.EnglishHighScoreList, 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)); } diff --git a/src/game/typing/examination/game.js b/src/game/typing/examination/game.js index 6510cb6..0f9af3f 100644 --- a/src/game/typing/examination/game.js +++ b/src/game/typing/examination/game.js @@ -272,7 +272,7 @@ var TypingExamination = { back: function() { sessionStorageManager.resetPlayingAppData(); - location.href = '../../web/client/menu_typing_test.html'; + location.href = '../../web/client/menu_typing_exam.html'; }, startGame: function() { @@ -333,15 +333,33 @@ var TypingExamination = { loadExaminationContent: function() { - var path = "./../../../resources/file/typing_exam/"; + var dbService = new DBService(); + dbService.setMaestroID(sessionStorageManager.getMaestroID()); + dbService.setPlayerID(sessionStorageManager.getPlayerID()); - // get the writing data from session storage - // get the writing data from DB + dbService.requestWritingInfo( + sessionStorageManager.getWritingID(), + (function(jsonData) { // onSucceeded + this.downloadListSucceeded(jsonData); + }).bind(this), + (function(jsonData) { // onFailed + this.downloadListFailed(jsonData); + }).bind(this) + ); + }, - var filename = "korean_heoseng.txt"; - var writer = "system"; + downloadListSucceeded: function(jsonData) { + console.log(jsonData); + var writingInfo = jsonData["writingInfo"]; + console.log(writingInfo); + + var writer = writingInfo["writer"]; var writerID = ""; + writingInfo["writerID"] == null ? writerID = "" : writerID = writingInfo["writerID"]; + + var path = "./../../../resources/file/typing_exam/"; var directory = writer + writerID + "/"; + var filename = writingInfo["filename"]; var url = path + directory + filename; game.load.onLoadComplete.add(this.completeLoadingWriting, this); @@ -351,6 +369,10 @@ var TypingExamination = { game.load.start(); }, + downloadListFailed: function(jsonData) { + console.log(jsonData); + }, + completeLoadingWriting: function() { game.load.onFileComplete.remove(this.loadExaminationContent, this); game.load.onLoadComplete.remove(this.completeLoadingWriting, this); diff --git a/src/web/client/typing_examination.html b/src/web/client/typing_examination.html index 05fc738..51e4907 100644 --- a/src/web/client/typing_examination.html +++ b/src/web/client/typing_examination.html @@ -45,7 +45,7 @@ - + @@ -57,13 +57,14 @@ + - + - - + +