diff --git a/src/game/global/global_variables.js b/src/game/global/global_variables.js index 0fbb623..4400653 100644 --- a/src/game/global/global_variables.js +++ b/src/game/global/global_variables.js @@ -22,13 +22,13 @@ const GAME_SCREEN_SIZE = { x: 1024, y: 768 } let sessionStorageManager = new SessionStorageManager(); { - // if(isDebugMode()) { - // sessionStorageManager.playerName = "박지상"; - // sessionStorageManager.playerUserID = 1; - // sessionStorageManager.playingAppName = "space_invaders"; - // sessionStorageManager.score = 1000; - // sessionStorageManager.highScore = 2000; - // } + if(isDebugMode()) { + sessionStorageManager.playerName = "박지상"; + sessionStorageManager.playerUserID = 24; + sessionStorageManager.playingAppName = "space_invaders"; + sessionStorageManager.score = 1000; + sessionStorageManager.highScore = 2000; + } console.log("maestroID : " + sessionStorageManager.maestroID); console.log("playerName : " + sessionStorageManager.playerName); diff --git a/src/game/lib/db_connect_manager.js b/src/game/lib/db_connect_manager.js index 6e498c2..3668120 100644 --- a/src/game/lib/db_connect_manager.js +++ b/src/game/lib/db_connect_manager.js @@ -18,30 +18,127 @@ class DBConnectManager { this.appName = appName; } + requestCheckUserLogin(userName, enterCode, onSucceededListener, onFailedListener) { + let xhr = new XMLHttpRequest(); + xhr.open("POST", "../../web/server/user/login.php", true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.onreadystatechange = function() { + if(xhr.readyState == 4 && xhr.status == 200) { + let jsonData = JSON.parse(xhr.responseText); + + if(jsonData != null && jsonData["UserID"] != null) + onSucceededListener(jsonData); + else + onFailedListener(jsonData); + } + }; + xhr.send("name=" + sessionStorageManager.playerName + "&enter_code=" + enterCode); + } + requestPlayerHistory(listener) { let historyRecordManager = new HistoryRecordManager(); - if(isDebugMode()) + /* + if(isDebugMode()) { this.loadTempPlayerHistory(historyRecordManager); - if(listener === null) - return; + if(listener !== null) + listener(historyRecordManager); - listener(historyRecordManager); + return; + } + */ + + let self = this; + + let xhr = new XMLHttpRequest(); + xhr.open("POST", "../../web/server/record/history_record.php", true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.onreadystatechange = function() { + if(xhr.readyState == 4 && xhr.status == 200) { + let jsonData = JSON.parse(xhr.responseText); + + if(jsonData != null) { + listener(self.parseJSONtoHistoryRecord(jsonData)); + } + else + onFailedListener(jsonData); + } + }; + xhr.send("UserID=" + sessionStorageManager.playerUserID + "&AppName=" + sessionStorageManager.playingAppName); + } + + parseJSONtoHistoryRecord(json) { + let historyRecordManager = new HistoryRecordManager(); + + let count = json.history.length; + for(let i = 0; i < count; i++) { + let record = new HistoryRecord( + json.history[i]["Date"], + json.history[i]["AppName"], + json.history[i]["HighScore"] + ); + historyRecordManager.push(record); + } + + return historyRecordManager; + +/* + var startIndex = 0; + var endIndex = jsonRankingList.length; + + var recordArray = []; + for(var i = startIndex; i < endIndex; i++) { + var bestRecordRow = []; + var strDate = jsonRankingList[i]['Date']; + var dateArray = strDate.split("-"); + var recordDate = new Date(dateArray[0], dateArray[1], dateArray[2]); + bestRecordRow[0] = recordDate.getMonth() + "월 " + recordDate.getDate() + "일"; + bestRecordRow[1] = Math.floor(jsonRankingList[i]['BestRecord']); + bestRecordRow[2] = getStageNameForKorean(jsonRankingList[i]['StageName']); + // console.log("$BestRecordRow : " + bestRecordRow[0] + ", " + bestRecordRow[1] + ", " + bestRecordRow[2]); + + recordArray.push(bestRecordRow); + } + + return recordArray; +*/ } requestRanking(type, listener) { let rankingRecordManager = new RankingRecordManager(); - if(isDebugMode()) - this.loadTempRanking(rankingRecordManager); + if(isDebugMode()) { + this.loadTempPlayerHistory(historyRecordManager); + + if(listener !== null) + listener(historyRecordManager); - if(listener === null) return; - - listener(rankingRecordManager); + } } + onFailed(errorMessage) { + console.log("failed : " + errorMessage); + } + + + makeXHRWithParam(url, param, onSucceededListener, onFailedListener) { + xhr.onreadystatechange = function() { + if(xhr.readyState == 4 && xhr.status == 200) { + let jsonData = JSON.parse(xhr.responseText); + + if(jsonData != null && jsonData["UserID"] != null) + onSucceededListener(jsonData); + else + onFailedListener(jsonData); + } + } + + return xhr; + } + + loadTempPlayerHistory(historyRecordManager) { historyRecordManager.push(new HistoryRecord("05/14", "space_invaders", 14460)); diff --git a/src/game/login/login.js b/src/game/login/login.js index a10e7c3..3f1ffe1 100644 --- a/src/game/login/login.js +++ b/src/game/login/login.js @@ -54,20 +54,20 @@ class Login { .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2) .boundsAlignH = 'right'; - this.inputTextBirthday = new InputTypeText(inputX, birthdayTextY); - this.inputTextBirthday.anchor.set(0.5); - this.inputTextBirthday.canvasInput.value(''); + this.inputTextEnterCode = new InputTypeText(inputX, birthdayTextY); + this.inputTextEnterCode.anchor.set(0.5); + this.inputTextEnterCode.canvasInput.value(''); if(isDebugMode()) { - this.inputTextBirthday.canvasInput.value('760621'); + this.inputTextEnterCode.canvasInput.value('760621'); } - this.inputTextBirthday.canvasInput._onkeyup = function() { + this.inputTextEnterCode.canvasInput._onkeyup = function() { if(event.keyCode == Phaser.Keyboard.ENTER) { self.startMenu(); } } this.inputTextName.canvasInput.focus(); - // this.inputTextBirthday.canvasInput.focus(); + // this.inputTextEnterCode.canvasInput.focus(); } makeButton() { @@ -80,50 +80,15 @@ class Login { startMenu() { sessionStorageManager.playerName = self.inputTextName.canvasInput._value; - let birthday = self.inputTextBirthday.canvasInput._value; + let enterCode = self.inputTextEnterCode.canvasInput._value; - let xhr = new XMLHttpRequest(); - xhr.onreadystatechange = function() { - // console.log("onreadystatechange : " + xhr); - // console.log("xhr.readyState : " + xhr.readyState); - // console.log("xhr.status : " + xhr.status); - if(xhr.readyState == 4 && xhr.status == 200) { - // console.log(xhr.responseText); - let jsonData = JSON.parse(xhr.responseText); - // console.log(JSON.stringify(jsonData)); - - // console.log(jsonData); - if(jsonData != null && jsonData["UserID"] != null) { - // login successed - - self.loginSucceeded(jsonData); - } else { - // login failed - self.loginFailed(jsonData); - } - } - } - xhr.open('POST', '../../web/client/php/check_user.php', true); - xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - let param = 'name=' + sessionStorageManager.playerName + '&birthday=' + birthday; - // console.log(param); - xhr.send(param); - - /* - let params = { - 'name': this.inputTextName.canvasInput._value, - 'birthday': this.inputTextBirthday.canvasInput._value - }; - console.log(params); - console.log(JSON.stringify(params)); - - xhr.setRequestHeader("Content-type", "application/json"); - // let data = JSON.stringify({"name":"박지상","birthday":"760621","test":101}); - xhr.send(data); - xhr.send(JSON.stringify(params)); - - // xhr.send(null); - */ + let dbConnectManager = new DBConnectManager(); + dbConnectManager.requestCheckUserLogin( + sessionStorageManager.playerName, + enterCode, + self.loginSucceeded, + self.loginFailed + ); } loginSucceeded(jsonData) { diff --git a/src/game/start/start.js b/src/game/start/start.js index 3fde5f1..bca9dad 100644 --- a/src/game/start/start.js +++ b/src/game/start/start.js @@ -25,11 +25,11 @@ class Start { // contents this.printHowToPlay(appInfoManager.getHowToPlayText(sessionStorageManager.playingAppName)); this.makeStartButton(); - this.printChartBaseLine(); this.dbConnectManager.requestPlayerHistory( historyRecordManager => { + this.printChartBaseLine(); + let underValue = historyRecordManager.underValueForGraph(); let upperValue = historyRecordManager.upperValueForGraph(); - for(let i = 0; i < historyRecordManager.count; i++) { if(i > 6) break; diff --git a/src/web/admin/activate_stage.html b/src/web/admin/activate_stage.html new file mode 100644 index 0000000..8232f01 --- /dev/null +++ b/src/web/admin/activate_stage.html @@ -0,0 +1,56 @@ + + +
+ +