From 5186f2142163edd556bb38c9fc6c4467123f8dad 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, 13 Dec 2018 10:59:37 +0900 Subject: [PATCH] Add: license maestro password, score list --- src/game/lib/db_connect_manager.js | 51 +++++ src/game/license_timer/chart.js | 195 ++++++++++++------ src/game/license_timer/game.js | 6 +- src/game/license_timer/input_score.js | 27 ++- .../get_license_maestro_password.php | 57 +++++ .../license_timer/get_license_score.php | 46 +++++ .../update_license_maestro_password.php | 33 +++ src/web/sql/make_db_license_timer.sql | 8 + 8 files changed, 358 insertions(+), 65 deletions(-) create mode 100644 src/web/server/license_timer/get_license_maestro_password.php create mode 100644 src/web/server/license_timer/get_license_score.php create mode 100644 src/web/server/license_timer/update_license_maestro_password.php diff --git a/src/game/lib/db_connect_manager.js b/src/game/lib/db_connect_manager.js index 1fb4275..23dacc5 100644 --- a/src/game/lib/db_connect_manager.js +++ b/src/game/lib/db_connect_manager.js @@ -462,6 +462,57 @@ DBConnectManager.prototype.updateLicenseLeftTime = function(maestroID, playerID, ); } +DBConnectManager.prototype.requestLicenseMaestroPassword = function(maestroID, onSucceededListener, onFailedListener) { + var xhr = new XMLHttpRequest(); + xhr.open("POST", this.phpPath + "server/license_timer/get_license_maestro_password.php", true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.onreadystatechange = function() { + if(xhr.readyState == 4 && xhr.status == 200) { + var replyJSON = JSON.parse(xhr.responseText); + + if(replyJSON != null) + onSucceededListener(replyJSON); + else + onFailedListener(replyJSON); + } + }; + xhr.send("MaestroID=" + maestroID); +} + +DBConnectManager.prototype.updateLicenseMaestroPassword = function(maestroID, password, onSucceededListener, onFailedListener) { + var xhr = new XMLHttpRequest(); + xhr.open("POST", this.phpPath + "server/license_timer/update_license_maestro_password.php", true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.onreadystatechange = function() { + if(xhr.readyState == 4 && xhr.status == 200) { + var replyJSON = JSON.parse(xhr.responseText); + + if(replyJSON != null) + onSucceededListener(replyJSON); + else + onFailedListener(replyJSON); + } + }; + xhr.send("MaestroID=" + maestroID + "&Password=" + password); +} + +DBConnectManager.prototype.requestLicenseScore = function(maestroID, playerID, onSucceededListener, onFailedListener) { + var xhr = new XMLHttpRequest(); + xhr.open("POST", this.phpPath + "server/license_timer/get_license_score.php", true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.onreadystatechange = function() { + if(xhr.readyState == 4 && xhr.status == 200) { + var replyJSON = JSON.parse(xhr.responseText); + + if(replyJSON != null) + onSucceededListener(replyJSON); + else + onFailedListener(replyJSON); + } + }; + xhr.send("MaestroID=" + maestroID + "&PlayerID=" + playerID); +} + DBConnectManager.prototype.loadTempPlayerHistory = function(historyRecordManager) { diff --git a/src/game/license_timer/chart.js b/src/game/license_timer/chart.js index a74b793..f634dc1 100644 --- a/src/game/license_timer/chart.js +++ b/src/game/license_timer/chart.js @@ -1,13 +1,34 @@ -function Chart() { +function Chart(licenseDataManager) { this.dbConnectManager = new DBConnectManager(); + this.licenseDataManager = licenseDataManager; this.chartGraphics = game.add.graphics(0, 0); this.printChartTitle(); this.printChartBaseLine(); - this.records = []; - for(var i = 0; i < 7; i++) - this.records.push(new ChartRecord(i)); + this.recordTexts = []; + for(var i = 0; i < Chart.PAGE_MAX_RECORD_COUNT; i++) + this.recordTexts.push(new ChartRecordText(i)); + + this.scoreList = null; + this.loadScoreFromServer(); +} + + +Chart.prototype.updateScoreList = function(jsonData) { + // console.log(jsonData); + + var jsonScoreList = jsonData.scoreList; + this.scoreList = []; + for(var i = 0; i < jsonScoreList.length; i++) { + this.scoreList.push( + new ChartRecordData( + jsonScoreList[i].SubjectName, + jsonScoreList[i].Score, + jsonScoreList[i].ScoreDateTime + ) + ); + } } Chart.prototype.printChartTitle = function() { @@ -30,43 +51,16 @@ Chart.prototype.printChartBaseLine = function() { this.chartGraphics.lineStyle(1, 0x888888, 1); this.chartGraphics.moveTo( Chart.CHART_LINE_START_X, - ChartRecord.getPosY(i) + ChartRecord.RECORD_HEIGHT + ChartRecordText.getPosY(i) + ChartRecordText.RECORD_HEIGHT ); this.chartGraphics.lineTo( game.world.width - Chart.CHART_LINE_START_X, - ChartRecord.getPosY(i) + ChartRecord.RECORD_HEIGHT + ChartRecordText.getPosY(i) + ChartRecordText.RECORD_HEIGHT ); } */ } -/* -Chart.prototype.drawRecordGraph = function(index, date, bestRecord, min, max) { - var reverseIndex = (Chart.CHART_COUNT - 1) - index; - var posX = Chart.CHART_LINE_START_X + Chart.CHART_GRAPH_OFFSET_X + reverseIndex * Chart.CHART_GAP_PX; - var posY = Chart.CHART_LINE_Y; - - this.drawText( - posX, posY + Chart.CHART_DATE_OFFSET_Y, - date === "-" ? "-" : StringUtil.printMonthDay(date) - ); - - if(bestRecord === "") - return; - - this.drawText( - posX, posY - Chart.CHART_HEIGHT - Chart.CHART_RECORD_OFFSET_Y, - // StringUtil.getRecordTextWithoutUnit(bestRecord) + StringUtil.getScoreUnit(sessionStorageManager.playingAppID) - RecordUtil.getRecordValueWithUnit(bestRecord, sessionStorageManager.getPlayingAppID()) - ); - - // chart - this.chartGraphics.lineStyle(50, 0xdddddd, 1); - this.chartGraphics.moveTo(posX, posY); - this.chartGraphics.lineTo(posX, posY - Chart.CHART_HEIGHT * ( (bestRecord - min) / (max - min) )); -} -*/ - Chart.drawText = function(posX, posY, text, fontStyle) { var textObject = game.add.text( posX, posY, @@ -79,18 +73,88 @@ Chart.drawText = function(posX, posY, text, fontStyle) { return textObject; } +Chart.prototype.printPage = function(pageNo) { + var startScoreListIndex = 0; + var endScoreListIndex = Chart.PAGE_MAX_RECORD_COUNT - 1; + + for(var i = 0; i < Chart.PAGE_MAX_RECORD_COUNT; i++) { + var scoreListIndex = startScoreListIndex + i; + if(startScoreListIndex + i < this.scoreList.length) + this.printChartRecord(i, scoreListIndex); + else + this.printChartRecord(i, null); + } +} + +Chart.prototype.printChartRecord = function(chartRecordIndex, scoreListIndex) { + // console.log(chartRecordIndex); + // console.log(this.recordTexts.length); + // console.log(this.scoreList); + + if(scoreListIndex == null) { + this.recordTexts[chartRecordIndex].printDate("-"); + this.recordTexts[chartRecordIndex].printScore("-"); + this.recordTexts[chartRecordIndex].printGrade("-"); + this.recordTexts[chartRecordIndex].printSubject("-"); + } else { + this.recordTexts[chartRecordIndex].printDate(StringUtil.printMonthDay(this.scoreList[scoreListIndex].date)); + + var scoreValue = RecordUtil.getRecordValueWithUnit(this.scoreList[scoreListIndex].score, 101); + this.recordTexts[chartRecordIndex].printScore(scoreValue); + + var gradeValue = "-"; + var subjectData = this.licenseDataManager.getSubjectDataByName(this.scoreList[scoreListIndex].subject); + if(subjectData != null) + gradeValue = subjectData.getGrade(this.scoreList[scoreListIndex].score); + this.recordTexts[chartRecordIndex].printGrade(gradeValue); + + this.recordTexts[chartRecordIndex].printSubject(this.scoreList[scoreListIndex].subject); + } +} + Chart.prototype.printContents = function() { + if(this.scoreList == null || this.scoreList.length == 0) { + for(var i = 0; i < this.recordTexts.length; i++) { + this.recordTexts[i].printDate("-"); + this.recordTexts[i].printScore("-"); + this.recordTexts[i].printGrade("-"); + this.recordTexts[i].printSubject("-"); + } + return; + } + + if(isDebugMode()) { - for(var i = 0; i < this.records.length; i++) { - this.records[i].printDate("12월 10일"); - this.records[i].printScore(360); - this.records[i].printGrade("B"); - this.records[i].printSubject("ITQ 파워포인트"); + for(var i = 0; i < this.recordTexts.length; i++) { + this.recordTexts[i].printDate("12월 10일"); + this.recordTexts[i].printScore(360); + this.recordTexts[i].printGrade("B"); + this.recordTexts[i].printSubject("ITQ 파워포인트"); } } } -Chart.CHART_COUNT = 7; + +Chart.prototype.loadScoreFromServer = function() { + this.dbConnectManager.requestLicenseScore( + sessionStorageManager.getMaestroID(), + sessionStorageManager.getPlayerID(), + (function(replyJson) { + // console.log(replyJson); + + this.updateScoreList(replyJson); + this.printPage(0); + }).bind(this), + + (function(replyJson) { + console.log(replyJson); + + this.updateScoreList(null); + }) + ); +} + + Chart.CHART_LINE_START_X = 230; Chart.CHART_LINE_Y = 370; @@ -107,8 +171,21 @@ Chart.SCORE_POS_X = Chart.DATE_POS_X + 120; Chart.GRADE_POS_X = Chart.DATE_POS_X + 200; Chart.SUBJECT_POS_X = Chart.DATE_POS_X + 360; +Chart.PAGE_MAX_RECORD_COUNT = 7; -function ChartRecord(indexRow) { + + +function ChartRecordData(subject, score, date) { + this.subject = subject; + this.score = score; + this.date = date; + + return this; +} + + + +function ChartRecordText(indexRow) { this.date = new DateData(indexRow); this.score = new ScoreData(indexRow); this.grade = new GradeData(indexRow); @@ -118,23 +195,23 @@ function ChartRecord(indexRow) { } -ChartRecord.prototype.printDate = function(date) { +ChartRecordText.prototype.printDate = function(date) { this.date.text = date; } -ChartRecord.prototype.printScore = function(score) { - this.score.text = RecordUtil.getRecordValueWithUnit(score, 101); //sessionStorageManager.getPlayingAppID()); +ChartRecordText.prototype.printScore = function(score) { + this.score.text = score; //RecordUtil.getRecordValueWithUnit(score, 101); //sessionStorageManager.getPlayingAppID()); } -ChartRecord.prototype.printGrade = function(grade) { +ChartRecordText.prototype.printGrade = function(grade) { this.grade.text = grade; } -ChartRecord.prototype.printSubject = function(subject) { +ChartRecordText.prototype.printSubject = function(subject) { this.subject.text = subject; } -ChartRecord.getPosX = function(columnName) { +ChartRecordText.getPosX = function(columnName) { var posX = Chart.CHART_LINE_START_X; switch(columnName) { case "date": @@ -157,23 +234,23 @@ ChartRecord.getPosX = function(columnName) { return posX; } -ChartRecord.getPosY = function(rowIndex) { +ChartRecordText.getPosY = function(rowIndex) { var offsetY = 30; - return Chart.CHART_LINE_Y + offsetY + ChartRecord.GAP_RECORD_Y * rowIndex; + return Chart.CHART_LINE_Y + offsetY + ChartRecordText.GAP_RECORD_Y * rowIndex; } -ChartRecord.getDefaultFontStyle = function() { +ChartRecordText.getDefaultFontStyle = function() { return { font: "26px Arial", fill: "#ffc", align: "center" }; } -ChartRecord.GAP_RECORD_Y = 40; -ChartRecord.RECORD_HEIGHT = 16; +ChartRecordText.GAP_RECORD_Y = 40; +ChartRecordText.RECORD_HEIGHT = 16; function DateData(index) { this.dateText = Chart.drawText( - ChartRecord.getPosX("date"), ChartRecord.getPosY(index), - "-", ChartRecord.getDefaultFontStyle() + ChartRecordText.getPosX("date"), ChartRecordText.getPosY(index), + "-", ChartRecordText.getDefaultFontStyle() ); return this.dateText; @@ -181,8 +258,8 @@ function DateData(index) { function ScoreData(index) { this.scoreText = Chart.drawText( - ChartRecord.getPosX("score"), ChartRecord.getPosY(index), - "-", ChartRecord.getDefaultFontStyle() + ChartRecordText.getPosX("score"), ChartRecordText.getPosY(index), + "-", ChartRecordText.getDefaultFontStyle() ); return this.scoreText; @@ -190,8 +267,8 @@ function ScoreData(index) { function GradeData(index) { this.gradeText = Chart.drawText( - ChartRecord.getPosX("grade"), ChartRecord.getPosY(index), - "-", ChartRecord.getDefaultFontStyle() + ChartRecordText.getPosX("grade"), ChartRecordText.getPosY(index), + "-", ChartRecordText.getDefaultFontStyle() ); return this.gradeText; @@ -199,8 +276,8 @@ function GradeData(index) { function SubjectData(index) { this.subjectText = Chart.drawText( - ChartRecord.getPosX("subject"), ChartRecord.getPosY(index), - "-", ChartRecord.getDefaultFontStyle() + ChartRecordText.getPosX("subject"), ChartRecordText.getPosY(index), + "-", ChartRecordText.getDefaultFontStyle() ); return this.subjectText; diff --git a/src/game/license_timer/game.js b/src/game/license_timer/game.js index b6e6c07..3eb1337 100644 --- a/src/game/license_timer/game.js +++ b/src/game/license_timer/game.js @@ -23,11 +23,11 @@ var LicenseTimer = { // this.fullscreenButton = new FullscreenButton(); + this.licenseDataManager = new LicenseDataManager(); this.timer = new Timer(); - this.chart = new Chart(); - this.chart.printContents(); + this.chart = new Chart(this.licenseDataManager); - this.inputScore = new InputScore(this.timer, this.chart); + this.inputScore = new InputScore(this.licenseDataManager, this.timer, this.chart); }, back: function() { diff --git a/src/game/license_timer/input_score.js b/src/game/license_timer/input_score.js index 77d7311..2f2cbdd 100644 --- a/src/game/license_timer/input_score.js +++ b/src/game/license_timer/input_score.js @@ -1,7 +1,9 @@ -function InputScore(timer, chart) { +function InputScore(licenseDataManager, timer, chart) { + this.licenseDataManager = licenseDataManager; this.timer = timer; this.chart = chart; - this.licenseDataManager = new LicenseDataManager(); + + this.dbConnectManager = new DBConnectManager(); this.initVariables(); @@ -69,6 +71,8 @@ function InputScore(timer, chart) { this.makeSubjectPanel(); this.setVisibleCompanyPanel(false); this.setVisibleSubjectPanel(false, ""); + + this.loadMaestroPasswordFromServer(); } InputScore.prototype.initVariables = function() { @@ -79,6 +83,8 @@ InputScore.prototype.initVariables = function() { this.companyButtonList = []; this.licenseSubjectButtonList = []; + + this.maestroPassword; } InputScore.prototype.makeInputTextSetting = function(width, placeHolder) { @@ -297,7 +303,20 @@ InputScore.prototype.onClickSendToServerButton = function() { console.log(this.passwordText.value); } +InputScore.prototype.loadMaestroPasswordFromServer = function() { + this.dbConnectManager.requestLicenseMaestroPassword( + sessionStorageManager.getMaestroID(), + (function(replyJson) { + // console.log(replyJson); + this.maestroPassword = replyJson.maestroPassword; + }).bind(this), + (function(replyJson) { + // console.log(replyJson); + this.maestroPassword = InputScore.DEFAULT_MAESTRO_PASSWORD; + }) + ); +} InputScore.INPUT_SCORE_GROUP_OFFSET_Y = 70; @@ -306,4 +325,6 @@ InputScore.SUBJECT_BUTTON_WIDTH = 260; InputScore.BUTTON_GAP_WIDTH = 10; InputScore.BUTTON_GAP_HEIGHT = 64; -InputScore.SUBJECT_BUTTON_MAX_COUNT = 6; \ No newline at end of file +InputScore.SUBJECT_BUTTON_MAX_COUNT = 6; + +InputScore.DEFAULT_MAESTRO_PASSWORD = "1111"; \ No newline at end of file diff --git a/src/web/server/license_timer/get_license_maestro_password.php b/src/web/server/license_timer/get_license_maestro_password.php new file mode 100644 index 0000000..1a22a34 --- /dev/null +++ b/src/web/server/license_timer/get_license_maestro_password.php @@ -0,0 +1,57 @@ +prepare($query); + $stmt->bind_param("i", $maestro_id); + $stmt->execute(); + $stmt->bind_result($password); + $stmt->fetch(); + $stmt->close(); + + return $password; +} + +function insert_maestro_password($maestro_id, $password) { + global $db_conn; + + $query = " + INSERT INTO license_maestro_password (MaestroID, Password) + VALUES (?, ?); + "; + $stmt = $db_conn->prepare($query); + $stmt->bind_param("ii", $maestro_id, $password); + $stmt->execute(); +} + +?> \ No newline at end of file diff --git a/src/web/server/license_timer/get_license_score.php b/src/web/server/license_timer/get_license_score.php new file mode 100644 index 0000000..ff19617 --- /dev/null +++ b/src/web/server/license_timer/get_license_score.php @@ -0,0 +1,46 @@ +prepare($query); + $stmt->bind_param("ii", $maestro_id, $player_id); + $stmt->execute(); + $stmt->bind_result($subject_name, $score, $score_date_time); + + $score_list = array(); + while($stmt->fetch()) { + $score_data["SubjectName"] = $subject_name; + $score_data["Score"] = $score; + $score_data["ScoreDateTime"] = $score_date_time; + array_push($score_list, $score_data); + } + $stmt->close(); + + return $score_list; +} + +?> \ No newline at end of file diff --git a/src/web/server/license_timer/update_license_maestro_password.php b/src/web/server/license_timer/update_license_maestro_password.php new file mode 100644 index 0000000..2c99950 --- /dev/null +++ b/src/web/server/license_timer/update_license_maestro_password.php @@ -0,0 +1,33 @@ +prepare($query); + $stmt->bind_param('ii', $password, $maestro_id); + $stmt->execute(); +} + +?> \ No newline at end of file diff --git a/src/web/sql/make_db_license_timer.sql b/src/web/sql/make_db_license_timer.sql index b516090..a616775 100644 --- a/src/web/sql/make_db_license_timer.sql +++ b/src/web/sql/make_db_license_timer.sql @@ -20,4 +20,12 @@ CREATE TABLE license_score ( FOREIGN KEY (MaestroID) REFERENCES maestro(MaestroID), FOREIGN KEY (PlayerID) REFERENCES player(PlayerID) +); + +CREATE TABLE license_maestro_password ( + LicenseMaestroPasswordID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + MaestroID INT UNSIGNED NOT NULL, + Password INT UNSIGNED NOT NULL, + + FOREIGN KEY (MaestroID) REFERENCES maestro(MaestroID) ); \ No newline at end of file