diff --git a/src/game/global/global_variables.js b/src/game/global/global_variables.js index bbd7f0f..eba0cf5 100644 --- a/src/game/global/global_variables.js +++ b/src/game/global/global_variables.js @@ -33,6 +33,7 @@ let sessionStorageManager = new SessionStorageManager(); console.log("playingAppKoreanName : " + sessionStorageManager.getPlayingAppKoreanName()); console.log("record : " + sessionStorageManager.getRecord()); console.log("bestRecord : " + sessionStorageManager.getBestRecord()); + console.log("appHighestRecord : " + sessionStorageManager.getAppHighestRecord()); } if(sessionStorageManager.getMaestroID() === null && !isLogin()) { diff --git a/src/game/lib/db_connect_manager.js b/src/game/lib/db_connect_manager.js index 8827157..e66ef9d 100644 --- a/src/game/lib/db_connect_manager.js +++ b/src/game/lib/db_connect_manager.js @@ -379,6 +379,18 @@ DBConnectManager.prototype.updateTodayBestRecord = function(maestroID, playerID, ); } +DBConnectManager.prototype.updateAppHighestRecord = function(maestroID, playerID, appID, record) { + var xhr = new XMLHttpRequest(); + xhr.open("POST", this.phpPath + "server/record/update_app_highest_record.php", true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.send( + "MaestroID=" + maestroID + + "&PlayerID=" + playerID + + "&AppID=" + appID + + "&Record=" + record + ); +} + DBConnectManager.prototype.requestTodayBestRecord = function(maestroID, playerID, appID, onSucceededListener, onFailedListener) { var xhr = new XMLHttpRequest(); xhr.open("POST", this.phpPath + "server/record/request_best_record.php", true); @@ -400,6 +412,27 @@ DBConnectManager.prototype.requestTodayBestRecord = function(maestroID, playerID ); } +DBConnectManager.prototype.requestAppHighestRecord = function(maestroID, playerID, appID, onSucceededListener, onFailedListener) { + var xhr = new XMLHttpRequest(); + xhr.open("POST", this.phpPath + "server/record/request_app_highest_record.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 && replyJSON["AppHighestRecord"] != null) + onSucceededListener(replyJSON); + else + onFailedListener(replyJSON); + } + }; + xhr.send( + "MaestroID=" + maestroID + + "&PlayerID=" + playerID + + "&AppID=" + appID + ); +} + DBConnectManager.prototype.requestAppRanking = function(maestroID, appID, onSucceededListener, onFailedListener) { var xhr = new XMLHttpRequest(); xhr.open("POST", this.phpPath + "server/record/app_ranking.php", true); diff --git a/src/game/lib/screen_bottom_ui.js b/src/game/lib/screen_bottom_ui.js index 3776f6a..b8d9f48 100644 --- a/src/game/lib/screen_bottom_ui.js +++ b/src/game/lib/screen_bottom_ui.js @@ -65,7 +65,7 @@ ScreenBottomUI.prototype.printText = function(textObject, text, align) { ScreenBottomUI.prototype.printLeftTextWithBestRecord = function(bestRecord) { var roundUpBestRecord = Math.round(bestRecord); var highScoreWithCommas = NumberUtil.numberWithCommas(roundUpBestRecord); - this.printLeftText("오늘의 최고 기록 : " + highScoreWithCommas); + this.printLeftText("최고 기록 : " + highScoreWithCommas); } ScreenBottomUI.prototype.getFontStyle = function() { diff --git a/src/game/lib/session_storage_manager.js b/src/game/lib/session_storage_manager.js index bc003b2..42c013f 100644 --- a/src/game/lib/session_storage_manager.js +++ b/src/game/lib/session_storage_manager.js @@ -80,7 +80,7 @@ SessionStorageManager.prototype.setRecord = function(value) { sessionStorage.setItem("record", value); } SessionStorageManager.prototype.getRecord = function() { - return sessionStorage.getItem("record"); + return Number(sessionStorage.getItem("record")); } // best record @@ -88,7 +88,15 @@ SessionStorageManager.prototype.setBestRecord = function(value) { sessionStorage.setItem("bestRecord", value); } SessionStorageManager.prototype.getBestRecord = function() { - return sessionStorage.getItem("bestRecord"); + return Number(sessionStorage.getItem("bestRecord")); +} + +// best record +SessionStorageManager.prototype.setAppHighestRecord = function(value) { + sessionStorage.setItem("appHighestRecord", value); +} +SessionStorageManager.prototype.getAppHighestRecord = function() { + return Number(sessionStorage.getItem("appHighestRecord")); } // best record @@ -105,6 +113,7 @@ SessionStorageManager.prototype.resetPlayingAppData = function() { this.removeItem("playingAppKoreanName"); this.removeItem("record"); this.removeItem("bestRecord"); + this.removeItem("appHighestRecord"); } diff --git a/src/game/result/result.js b/src/game/result/result.js index 3924781..595431d 100644 --- a/src/game/result/result.js +++ b/src/game/result/result.js @@ -55,7 +55,7 @@ var Result = { // bottom ui var screenBottomUI = new ScreenBottomUI(); - screenBottomUI.printLeftTextWithBestRecord(Math.floor(sessionStorageManager.getBestRecord())); + screenBottomUI.printLeftTextWithBestRecord(Math.floor(sessionStorageManager.getAppHighestRecord())); screenBottomUI.printCenterText(sessionStorageManager.getPlayingAppKoreanName()); screenBottomUI.printRightText(sessionStorageManager.getPlayerName()); }, @@ -131,17 +131,23 @@ var Result = { bestRecordText.stroke = "#333"; bestRecordText.strokeThickness = 5; - if(sessionStorageManager.getBestRecord() === 'undefined') - sessionStorageManager.setBestRecord(0); + // if(sessionStorageManager.getBestRecord() == 'undefined' || sessionStorageManager.getBestRecord() == null) + // sessionStorageManager.setBestRecord(0); + + if(sessionStorageManager.getAppHighestRecord() == 'undefined' || sessionStorageManager.getAppHighestRecord() == null) + sessionStorageManager.setAppHighestRecord(0); var todayBestRecord = 0; - var flooredBestRecord = Math.floor(sessionStorageManager.getBestRecord()); + // var flooredBestRecord = Math.floor(sessionStorageManager.getBestRecord()); + var flooredBestRecord = Math.floor(sessionStorageManager.getAppHighestRecord()); var bestRecordWithCommas = NumberUtil.numberWithCommas(flooredBestRecord); - if(sessionStorageManager.getRecord() >= sessionStorageManager.getBestRecord()) { - sessionStorageManager.setBestRecord(sessionStorageManager.getRecord()); + // if(sessionStorageManager.getRecord() >= sessionStorageManager.getBestRecord()) { + // sessionStorageManager.setBestRecord(sessionStorageManager.getRecord()); + if(sessionStorageManager.getRecord() > sessionStorageManager.getAppHighestRecord()) { + sessionStorageManager.setAppHighestRecord(sessionStorageManager.getRecord()); - bestRecordText.text = "! : . 오늘 최고 기록 . : !"; + bestRecordText.text = "! : . 최고 기록 갱신 . : !"; newRecordEmitter.start(true, 2000, null, 20); } else { bestRecordText.text = ""; @@ -153,7 +159,14 @@ var Result = { return; } - this.dbConnectManager.updateTodayBestRecord( + // this.dbConnectManager.updateTodayBestRecord( + // sessionStorageManager.getMaestroID(), + // sessionStorageManager.getPlayerID(), + // sessionStorageManager.getPlayingAppID(), + // sessionStorageManager.getRecord() + // ); + + this.dbConnectManager.updateAppHighestRecord( sessionStorageManager.getMaestroID(), sessionStorageManager.getPlayerID(), sessionStorageManager.getPlayingAppID(), diff --git a/src/game/start/start.js b/src/game/start/start.js index f891374..6e87e64 100644 --- a/src/game/start/start.js +++ b/src/game/start/start.js @@ -50,21 +50,40 @@ var Start = { // bottom ui var screenBottomUI = new ScreenBottomUI(); - screenBottomUI.printLeftText("오늘의 최고 기록 : "); + screenBottomUI.printLeftText(""); screenBottomUI.printCenterText(sessionStorageManager.getPlayingAppKoreanName()); screenBottomUI.printRightText(sessionStorageManager.getPlayerName()); - this.dbConnectManager.requestTodayBestRecord( + // this.dbConnectManager.requestTodayBestRecord( + // sessionStorageManager.getMaestroID(), + // sessionStorageManager.getPlayerID(), + // sessionStorageManager.getPlayingAppID(), + // (function(replyJSON) { + // sessionStorageManager.setBestRecord(Number(replyJSON["BestRecord"])); + // screenBottomUI.printLeftTextWithBestRecord(sessionStorageManager.getBestRecord()); + // }).bind(this), + // (function(replyJSON) { // no data + // sessionStorageManager.setBestRecord(0); + // screenBottomUI.printLeftTextWithBestRecord(sessionStorageManager.getBestRecord()); + // }).bind(this) + // ); + + this.dbConnectManager.requestAppHighestRecord( sessionStorageManager.getMaestroID(), sessionStorageManager.getPlayerID(), sessionStorageManager.getPlayingAppID(), (function(replyJSON) { - sessionStorageManager.setBestRecord(Number(replyJSON["BestRecord"])); - screenBottomUI.printLeftTextWithBestRecord(sessionStorageManager.getBestRecord()); + var appHighestRecord = replyJSON["AppHighestRecord"]; + console.log("appHighestRecord : " + appHighestRecord); + // sessionStorageManager.setBestRecord(Number(appHighestRecord)); + sessionStorageManager.setAppHighestRecord(Number(appHighestRecord)); + screenBottomUI.printLeftTextWithBestRecord(appHighestRecord); }).bind(this), (function(replyJSON) { // no data - sessionStorageManager.setBestRecord(0); - screenBottomUI.printLeftTextWithBestRecord(sessionStorageManager.getBestRecord()); + var appHighestRecord = replyJSON["AppHighestRecord"]; + console.log("appHighestRecord : " + appHighestRecord); + sessionStorageManager.setAppHighestRecord(0); + screenBottomUI.printLeftTextWithBestRecord(sessionStorageManager.getAppHighestRecord()); }).bind(this) ); }, diff --git a/src/web/server/app/menu_active_typing_practice_app_list.php b/src/web/server/app/menu_active_typing_practice_app_list.php index 6442f94..8304df5 100644 --- a/src/web/server/app/menu_active_typing_practice_app_list.php +++ b/src/web/server/app/menu_active_typing_practice_app_list.php @@ -101,10 +101,10 @@ function get_high_score_list($maestro_id, $player_id, $appList) { $app_id_list = $appList[$i]['AppID']; $query = " - SELECT MAX(BR.BestRecord) + SELECT MAX(AHR.HighestRecord) FROM app AS A - INNER JOIN best_record AS BR - ON A.AppID = ? AND A.AppID = BR.AppID AND BR.MaestroID = ? AND BR.PlayerID = ? + INNER JOIN app_highest_record AS AHR + ON A.AppID = ? AND A.AppID = AHR.AppID AND AHR.MaestroID = ? AND AHR.PlayerID = ? ORDER BY A.AppID ASC"; $stmt = $db_conn->prepare($query); $stmt->bind_param('iii', $app_id_list, $maestro_id, $player_id); diff --git a/src/web/server/lib/app_highest_record.php b/src/web/server/lib/app_highest_record.php new file mode 100644 index 0000000..9828cc6 --- /dev/null +++ b/src/web/server/lib/app_highest_record.php @@ -0,0 +1,52 @@ +prepare($query); + $stmt->bind_param("iii", $maestro_id, $app_id, $player_id); + $stmt->execute(); + $stmt->bind_result($highest_record); + $stmt->fetch(); + $stmt->close(); + + return $highest_record; + + echo "\nget_app_highest_record : $highest_record"; +} + + +function remove_app_highest_record($maestro_id, $app_id, $player_id) { + global $db_conn; + + $query = " + DELETE FROM app_highest_record + WHERE MaestroID = ? AND AppID = ? AND PlayerID = ?; + "; + $stmt = $db_conn->prepare($query); + $stmt->bind_param("iii", $maestro_id, $app_id, $player_id); + $stmt->execute(); + + echo "\ndelete_app_highest_record"; +} + +function insert_app_highest_record($maestro_id, $app_id, $player_id, $highest_record) { + global $db_conn; + + $query = " + INSERT INTO app_highest_record (MaestroID, PlayerID, AppID, HighestRecord, RecordDateTime) + VALUES (?, ?, ?, ?, NOW()); + "; + $stmt = $db_conn->prepare($query); + $stmt->bind_param('iiid', $maestro_id, $player_id, $app_id, $highest_record); + $stmt->execute(); + + echo "\ninsert_app_highest_record"; +} + +?> \ No newline at end of file diff --git a/src/web/server/record/request_app_highest_record.php b/src/web/server/record/request_app_highest_record.php new file mode 100644 index 0000000..88ec7a2 --- /dev/null +++ b/src/web/server/record/request_app_highest_record.php @@ -0,0 +1,23 @@ +close(); + exit; +} + +echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE); +$db_conn->close(); + +?> \ No newline at end of file diff --git a/src/web/server/record/update_app_highest_record.php b/src/web/server/record/update_app_highest_record.php new file mode 100644 index 0000000..ffc7357 --- /dev/null +++ b/src/web/server/record/update_app_highest_record.php @@ -0,0 +1,101 @@ + $prev_best_record) { + // echo "update"; + update_best_record($prev_best_record_id, $record); + } +} + +// highest record is the highest record +$app_highest_record = get_app_highest_record($maestro_id, $app_id, $player_id); +echo "\napp_highest_record : $app_highest_record"; + +echo "\nrecord : $record"; +if($app_highest_record == null) { + insert_app_highest_record($maestro_id, $app_id, $player_id, $record); + echo "\ninsert_app_highest_record : $record"; +} +else if($record > $app_highest_record) { + remove_app_highest_record($maestro_id, $app_id, $player_id); + echo "\nremove_app_highest_record"; + insert_app_highest_record($maestro_id, $app_id, $player_id, $record); + echo "\ninsert_app_highest_record : $record"; +} + +$db_conn->close(); + + +function get_best_record($maestro_id, $app_id, $player_id) { + global $db_conn; + global $prev_best_record_id, $prev_best_record; + + $query = " + SELECT BestRecordID, BestRecord + FROM best_record + WHERE MaestroID = ? AND AppID = ? AND PlayerID = ? AND DATE(RecordDateTime) = DATE(NOW()) + /*AND HOUR(RecordDateTime) = HOUR(NOW())*/ + "; + $stmt = $db_conn->prepare($query); + $stmt->bind_param("iii", $maestro_id, $app_id, $player_id); + $stmt->execute(); + $stmt->bind_result($prev_best_record_id, $prev_best_record); + $stmt->fetch(); + $stmt->close(); + + $GLOBALS["prev_best_record_id"] = $prev_best_record_id; + $GLOBALS["prev_best_record"] = $prev_best_record; + + return $prev_best_record_id; +} + + +function insert_best_record($maestro_id, $app_id, $player_id, $record) { + global $db_conn; + + $query = " + INSERT INTO best_record (MaestroID, PlayerID, AppID, BestRecord, RecordDateTime) + VALUES (?, ?, ?, ?, NOW()); + "; + $stmt = $db_conn->prepare($query); + $stmt->bind_param('iiid', $maestro_id, $player_id, $app_id, $record); + $stmt->execute(); +} + +function update_best_record($prev_best_record_id, $record) { + global $db_conn; + + $query = " + UPDATE best_record + SET BestRecord = ?, RecordDateTime = NOW() + WHERE BestRecordID = ? AND DATE(RecordDateTime) = DATE(NOW()) + /* AND HOUR(RecordDateTime) = HOUR(NOW()) */ + "; + $stmt = $db_conn->prepare($query); + $stmt->bind_param('di', $record, $prev_best_record_id); + $stmt->execute(); +} + +?> \ No newline at end of file diff --git a/src/web/server/record/update_best_record.php b/src/web/server/record/update_best_record.php index a28ab9b..80e06f5 100644 --- a/src/web/server/record/update_best_record.php +++ b/src/web/server/record/update_best_record.php @@ -8,6 +8,8 @@ $best_record = $_POST["BestRecord"]; // echo $best_record." / "; include "./../setup/connect_db.php"; +include "./../lib/app_highest_record.php"; + $prev_best_record_id = -1; $prev_best_record = 0; @@ -26,6 +28,15 @@ if($prev_best_record_id === null || $prev_best_record_id < 0) { } } +$app_highest_record = get_app_highest_record($maestro_id, $app_id, $player_id); +if($app_highest_record == null) { + insert_app_highest_record($maestro_id, $app_id, $player_id, $best_record); +} +else if($best_record > $app_highest_record) { + remove_app_highest_record($maestro_id, $app_id, $player_id); + insert_app_highest_record($maestro_id, $app_id, $player_id, $best_record); +} + $db_conn->close(); diff --git a/src/web/sql/make_db.sql b/src/web/sql/make_db.sql index 8dab03e..fa56fe9 100644 --- a/src/web/sql/make_db.sql +++ b/src/web/sql/make_db.sql @@ -76,6 +76,19 @@ CREATE TABLE best_record ( FOREIGN KEY (PlayerID) REFERENCES player(PlayerID) ); +CREATE TABLE app_highest_record ( + AppHighestRecordID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + MaestroID INT UNSIGNED NOT NULL, + AppID INT UNSIGNED NOT NULL, + PlayerID INT UNSIGNED NOT NULL, + HighestRecord FLOAT NOT NULL, + RecordDateTime DATETIME NOT NULL, + + FOREIGN KEY (MaestroID) REFERENCES maestro(MaestroID), + FOREIGN KEY (AppID) REFERENCES app(AppID), + FOREIGN KEY (PlayerID) REFERENCES player(PlayerID) +); + CREATE TABLE ranking ( RankingID INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, MaestroID INT UNSIGNED NOT NULL,