From ed03e57b34add140dad45de45ead656bc00dac03 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: Mon, 4 Jun 2018 11:22:21 +0900 Subject: [PATCH] Add: menu_app_list.php --- src/game/lib/app_info_manager.js | 25 ++++---- src/game/lib/db_connect_manager.js | 43 +++++++++++-- src/game/menu/menu_app.js | 39 ++++++++---- src/web/server/app/app_data.php | 72 +++++++++++++++++++++ src/web/server/app/menu_app_list.php | 94 ++++++++++++++++++++++++++++ 5 files changed, 246 insertions(+), 27 deletions(-) create mode 100644 src/web/server/app/app_data.php create mode 100644 src/web/server/app/menu_app_list.php diff --git a/src/game/lib/app_info_manager.js b/src/game/lib/app_info_manager.js index 685037f..f129313 100644 --- a/src/game/lib/app_info_manager.js +++ b/src/game/lib/app_info_manager.js @@ -1,9 +1,10 @@ class AppInfo { - constructor(name, nameKorean, howToPlay) { - this.name = name; + constructor(appID, appName, koreanName, howToPlay) { + this.appID = appID; + this.appName = appName; - this.nameKorean = nameKorean; + this.koreanName = koreanName; this.isActivated = false; this.howToPlay = howToPlay; } @@ -51,26 +52,26 @@ class AppInfoManager { )); } - setHowToPlay(name, text) { - this.appInfoMap[name].howToPlay = text; + setHowToPlay(appName, text) { + this.appInfoMap[appName].howToPlay = text; } registerAppInfo(appInfo) { - return this.appInfoMap[appInfo.name] = appInfo; + return this.appInfoMap[appInfo.appName] = appInfo; } - getAppNameKorean(name) { - if(name === null) + getAppkoreanName(appName) { + if(appName === null) return ""; - return this.appInfoMap[name].nameKorean; + return this.appInfoMap[appName].koreanName; } - getHowToPlayText(name) { - if(name === null) + getHowToPlayText(appName) { + if(appName === null) return ""; - return this.appInfoMap[name].howToPlay; + return this.appInfoMap[appName].howToPlay; } } \ No newline at end of file diff --git a/src/game/lib/db_connect_manager.js b/src/game/lib/db_connect_manager.js index 50d0a2e..9c0056b 100644 --- a/src/game/lib/db_connect_manager.js +++ b/src/game/lib/db_connect_manager.js @@ -64,6 +64,24 @@ class DBConnectManager { xhr.send("maestro_name=" + maestroName + "&name=" + userName + "&enter_code=" + enterCode); } + /* + requestAppList(maestroID, onSucceededListener, onFailedListener) { + let xhr = new XMLHttpRequest(); + xhr.open("POST", this.phpPath + "server/app/app_data.php", true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.onreadystatechange = function() { + if(xhr.readyState == 4 && xhr.status == 200) { + let replyJSON = JSON.parse(xhr.responseText); + + if(replyJSON != null) + onSucceededListener(replyJSON); + else + onFailedListener(replyJSON); + } + }; + xhr.send("maestro_id=" + maestroID); + } + requestActiveAppList(maestroID, onSucceededListener, onFailedListener) { let xhr = new XMLHttpRequest(); xhr.open("POST", this.phpPath + "server/app/active_app.php", true); @@ -72,7 +90,25 @@ class DBConnectManager { if(xhr.readyState == 4 && xhr.status == 200) { let replyJSON = JSON.parse(xhr.responseText); - if(replyJSON != null && replyJSON.length > 0) + if(replyJSON != null) + onSucceededListener(replyJSON); + else + onFailedListener(replyJSON); + } + }; + xhr.send("maestro_id=" + maestroID); + } + */ + + requestMenuAppList(maestroID, onSucceededListener, onFailedListener) { + let xhr = new XMLHttpRequest(); + xhr.open("POST", this.phpPath + "server/app/menu_app_list.php", true); + xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); + xhr.onreadystatechange = function() { + if(xhr.readyState == 4 && xhr.status == 200) { + let replyJSON = JSON.parse(xhr.responseText); + + if(replyJSON != null) onSucceededListener(replyJSON); else onFailedListener(replyJSON); @@ -89,7 +125,7 @@ class DBConnectManager { if(xhr.readyState == 4 && xhr.status == 200) { let replyJSON = JSON.parse(xhr.responseText); - if(replyJSON != null && replyJSON.length > 0) + if(replyJSON != null) onSucceededListener(replyJSON); else onFailedListener(replyJSON); @@ -121,9 +157,8 @@ class DBConnectManager { if(xhr.readyState == 4 && xhr.status == 200) { let replyJSON = JSON.parse(xhr.responseText); - if(replyJSON != null) { + if(replyJSON != null) listener(self.parseJSONtoHistoryRecord(replyJSON)); - } else onFailedListener(replyJSON); } diff --git a/src/game/menu/menu_app.js b/src/game/menu/menu_app.js index d5ad97c..6eee9ba 100644 --- a/src/game/menu/menu_app.js +++ b/src/game/menu/menu_app.js @@ -24,28 +24,33 @@ class MenuApp { let screenBottom = new ScreenBottom(); screenBottom.makeBottomLine(); // screenBottom.printBottomLeftText("게임 진행 정보"); - let playingAppName = appInfoManager.getAppNameKorean(sessionStorageManager.playingAppName); - screenBottom.printBottomCenterText(playingAppName); + // let playingAppName = appInfoManager.getAppNameKorean(sessionStorageManager.playingAppName); + // screenBottom.printBottomCenterText(playingAppName); + screenBottom.printBottomCenterText("메뉴"); screenBottom.printBottomRightText(sessionStorageManager.playerName); - this.makeActiveAppButtons(); + this.loadAppData(); } - makeActiveAppButtons() { + loadAppData() { let dbConnectManager = new DBConnectManager(); - dbConnectManager.requestActiveAppList( + dbConnectManager.requestMenuAppList( sessionStorageManager.maestroID, - self.loginSucceeded, - self.loginFailed + self.loadSucceeded, + self.loadFailed ); - } - loginSucceeded(replyJSON) { + loadSucceeded(replyJSON) { // console.log(replyJSON); + self.makeMouseAppButtons(replyJSON.MouseAppList); + self.makeTypingButtons(replyJSON.TypingPracticeAppCount, replyJSON.TypingAppList); + + /* + let mouseAppCount = self.getAppCount(replyJSON, AppButton.TYPE_MOUSE); let typingPracticeAppCount = self.getAppCount(replyJSON, AppButton.TYPE_TYPING); @@ -74,6 +79,18 @@ class MenuApp { } ); } + */ + } + + makeMouseAppButtons(mouseAppJSON) { + console.log(mouseAppJSON); + + } + + makeTypingButtons(typingPracticeAppCount, typingAppJSON) { + console.log(typingPracticeAppCount); + console.log(typingAppJSON); + } isMouseApp(app) { @@ -96,8 +113,8 @@ class MenuApp { return appCount; } - loginFailed(replyJSON) { - console.log('login failed, jsonData : ' + JSON.stringify(replyJSON)); + loadFailed(replyJSON) { + // console.log('login failed, jsonData : ' + JSON.stringify(replyJSON)); } } \ No newline at end of file diff --git a/src/web/server/app/app_data.php b/src/web/server/app/app_data.php new file mode 100644 index 0000000..23070ad --- /dev/null +++ b/src/web/server/app/app_data.php @@ -0,0 +1,72 @@ +close(); + +if($replyJSON.length === 0) { + send_error_message($replyJSON, "앱 목록 가져오기 실패"); + $db_conn->close(); + exit; +} + +echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE); +$db_conn->close(); + + + +function get_app_list() { + global $db_conn; + + $query = "SELECT AppID, AppName, AppType FROM moty_app"; + $result = mysqli_query($db_conn, $query); + + $return_array = array(); + if ($result) { + // echo "조회된 행의 수 : ".mysqli_num_rows($result)."
"; + + $rows = array(); + while($row = mysqli_fetch_assoc($result)) { + $row_array["AppID"] = $row["AppID"]; + $row_array["AppName"] = $row["AppName"]; + $row_array["AppType"] = $row["AppType"]; + array_push($return_array, $row_array); + } + } + + return $return_array; +} + +function get_active_app_list($maestro_id) { + global $db_conn; + + $query = " + SELECT A.AppID, A.AppName, A.AppType + FROM moty_app AS A + INNER JOIN moty_active_app AS AA ON A.AppID = AA.AppID AND AA.MaestroID=?"; + $stmt = $db_conn->prepare($query); + $stmt->bind_param("i", $maestro_id); + $stmt->execute(); + $stmt->bind_result($app_id, $app_name, $app_type); + + $return_array = array(); + while($stmt->fetch()) { + $row_array["AppID"] = $app_id; + $row_array["AppName"] = $app_name; + $row_array["AppType"] = $app_type; + array_push($return_array, $row_array); + } + $stmt->close(); + + return $return_array; +} + +?> \ No newline at end of file diff --git a/src/web/server/app/menu_app_list.php b/src/web/server/app/menu_app_list.php new file mode 100644 index 0000000..87f9eef --- /dev/null +++ b/src/web/server/app/menu_app_list.php @@ -0,0 +1,94 @@ +close(); + +if($replyJSON.length === 0) { + send_error_message($replyJSON, "앱 목록 가져오기 실패"); + $db_conn->close(); + exit; +} + +echo json_encode($replyJSON, JSON_UNESCAPED_UNICODE); +$db_conn->close(); + + + +function get_mouse_app_list($maestro_id) { + global $db_conn; + + $query = " + SELECT A.AppID, A.AppName, A.KoreanName, A.AppType + FROM moty_app AS A + INNER JOIN moty_active_app AS AA ON A.AppID = AA.AppID AND A.AppType = 100 AND AA.MaestroID=?"; + $stmt = $db_conn->prepare($query); + $stmt->bind_param("i", $maestro_id); + $stmt->execute(); + $stmt->bind_result($app_id, $app_name, $korean_name, $app_type); + + $return_array = array(); + while($stmt->fetch()) { + $row_array["AppID"] = $app_id; + $row_array["AppName"] = $app_name; + $row_array["KoreanName"] = $korean_name; + $row_array["AppType"] = $app_type; + array_push($return_array, $row_array); + } + $stmt->close(); + + return $return_array; +} + +function get_typing_practice_app_count($maestro_id) { + global $db_conn; + + $query = " + SELECT COUNT(*) + FROM moty_app AS A + INNER JOIN moty_active_app AS AA ON A.AppID = AA.AppID AND A.AppType < 50 AND AA.MaestroID=?"; + $stmt = $db_conn->prepare($query); + $stmt->bind_param("i", $maestro_id); + $stmt->execute(); + $stmt->bind_result($typing_practice_app_count); + $stmt->fetch(); + $stmt->close(); + + return $typing_practice_app_count; +} + +function get_typing_app_list($maestro_id) { + global $db_conn; + + $query = " + SELECT A.AppID, A.AppName, A.KoreanName, A.AppType + FROM moty_app AS A + INNER JOIN moty_active_app AS AA ON A.AppID = AA.AppID AND A.AppType = 50 AND AA.MaestroID=?"; + $stmt = $db_conn->prepare($query); + $stmt->bind_param("i", $maestro_id); + $stmt->execute(); + $stmt->bind_result($app_id, $app_name, $korean_name, $app_type); + + $return_array = array(); + while($stmt->fetch()) { + $row_array["AppID"] = $app_id; + $row_array["AppName"] = $app_name; + $row_array["KoreanName"] = $korean_name; + $row_array["AppType"] = $app_type; + array_push($return_array, $row_array); + } + $stmt->close(); + + return $return_array; +} + +?> \ No newline at end of file