From 670d48cbc7b35ff99d2648580cde79b08263345a 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, 7 Jun 2018 08:57:10 +0900 Subject: [PATCH] Fix: typing app menu --- src/game/global/global_variables.js | 4 +- src/game/lib/db_connect_manager.js | 2 +- src/game/lib/game_app_button.js | 7 +- src/game/lib/typing_practice_button.js | 16 +- src/game/menu/menu_app.js | 8 +- src/game/menu/menu_typing_practice.js | 152 +++++++++--------- ... menu_active_typing_practice_app_list.php} | 16 +- test/test_db_connect_manager.js | 8 +- 8 files changed, 110 insertions(+), 103 deletions(-) rename src/web/server/app/{active_typing_practice_app_list.php => menu_active_typing_practice_app_list.php} (61%) diff --git a/src/game/global/global_variables.js b/src/game/global/global_variables.js index 4724ab4..f4237af 100644 --- a/src/game/global/global_variables.js +++ b/src/game/global/global_variables.js @@ -1,7 +1,7 @@ const LANGUAGE_KOREAN = "korean"; -const LANGUAGE_ENGLISH = "english"; +const LANGUAGE_ENGLISH = "english"; -const MODE_RELEASE = "release"; +const MODE_RELEASE = "release"; const MODE_DEBUG = "debug"; const runMode = MODE_DEBUG; diff --git a/src/game/lib/db_connect_manager.js b/src/game/lib/db_connect_manager.js index 46172fa..17a5517 100644 --- a/src/game/lib/db_connect_manager.js +++ b/src/game/lib/db_connect_manager.js @@ -119,7 +119,7 @@ class DBConnectManager { requestTypingPracticeAppList(maestroID, onSucceededListener, onFailedListener) { let xhr = new XMLHttpRequest(); - xhr.open("POST", this.phpPath + "server/app/active_typing_practice_app_list.php", true); + xhr.open("POST", this.phpPath + "server/app/menu_active_typing_practice_app_list.php", true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200) { diff --git a/src/game/lib/game_app_button.js b/src/game/lib/game_app_button.js index 2b407fb..6384e1b 100644 --- a/src/game/lib/game_app_button.js +++ b/src/game/lib/game_app_button.js @@ -73,10 +73,11 @@ class GameAppButton extends AppButton { } -GameAppButton.BUTTON_WIDTH = 150; -GameAppButton.BUTTON_HEIGHT = 150; +GameAppButton.BUTTON_WIDTH = 150; +GameAppButton.BUTTON_HEIGHT = 150; -GameAppButton.BUTTON_GAP = 20; +GameAppButton.BUTTON_GAP = 20; +GameAppButton.MARGIN_VERTICAL = 100; GameAppButton.BUTTON_UPPER_POS_Y = 200; GameAppButton.BUTTON_LOWER_POS_Y = 540; \ No newline at end of file diff --git a/src/game/lib/typing_practice_button.js b/src/game/lib/typing_practice_button.js index ffeccae..9f27573 100644 --- a/src/game/lib/typing_practice_button.js +++ b/src/game/lib/typing_practice_button.js @@ -1,12 +1,12 @@ class TypingPracticeButton extends AppButton { constructor(x, y, type, iconName, buttonText, clickEvent) { - let setting = new RoundRectButtonSetting(200, 100); + let setting = new RoundRectButtonSetting(TypingPracticeButton.BUTTON_WIDTH, TypingPracticeButton.BUTTON_HEIGHT); setting.fontStyle.boundsAlignH = "center"; // left, center. right setting.fontStyle.boundsAlignV = "middle"; // top, middle, bottom setting.strokeWidthPx = 5; - if(type === TypingPracticeButton.TYPE_KOREAN) { + if(type === LANGUAGE_KOREAN) { setting.setStrokeColor( 0xaa6666, 0x884444, @@ -25,7 +25,7 @@ class TypingPracticeButton extends AppButton { "#844", "#333" ); - } else { // TYPE_ENGLISH + } else { // LANGUAGE_ENGLISH setting.setStrokeColor( 0x444488, 0x6666aa, @@ -72,5 +72,11 @@ class TypingPracticeButton extends AppButton { } -TypingPracticeButton.TYPE_KOREAN = "한글"; -TypingPracticeButton.TYPE_ENGLISH = "영문"; +TypingPracticeButton.BUTTON_WIDTH = 200; +TypingPracticeButton.BUTTON_HEIGHT = 100; + +TypingPracticeButton.BUTTON_GAP = 20; +TypingPracticeButton.MARGIN_VERTICAL = 100; + +TypingPracticeButton.BUTTON_UPPER_POS_Y = 200; +TypingPracticeButton.BUTTON_LOWER_POS_Y = 540; \ No newline at end of file diff --git a/src/game/menu/menu_app.js b/src/game/menu/menu_app.js index 226d591..8126c46 100644 --- a/src/game/menu/menu_app.js +++ b/src/game/menu/menu_app.js @@ -120,7 +120,7 @@ class MenuApp { getButtonPosX(index, buttonCount) { let gap = GameAppButton.BUTTON_WIDTH + GameAppButton.BUTTON_GAP; - let maxColumnNum = Math.floor( (game.world.width - MenuApp.MARGIN_VERTICAL) / gap ); + let maxColumnNum = Math.floor( (game.world.width - GameAppButton.MARGIN_VERTICAL) / gap ); // console.log("maxColumnNum : " + maxColumnNum); let rowCount = Math.ceil(buttonCount / maxColumnNum); // console.log("rowCount : " + rowCount); @@ -143,7 +143,7 @@ class MenuApp { getButtonPosY(index, buttonCount, startPosY) { let gap = GameAppButton.BUTTON_HEIGHT + GameAppButton.BUTTON_GAP; - let maxColumnNum = Math.floor( (game.world.width - MenuApp.MARGIN_VERTICAL) / gap ); + let maxColumnNum = Math.floor( (game.world.width - GameAppButton.MARGIN_VERTICAL) / gap ); // console.log("maxColumnNum : " + maxColumnNum); let rowCount = Math.ceil(buttonCount / maxColumnNum); // console.log("rowCount : " + rowCount); @@ -159,6 +159,4 @@ class MenuApp { // console.log('login failed, jsonData : ' + JSON.stringify(replyJSON)); } -} - -MenuApp.MARGIN_VERTICAL = 100; \ No newline at end of file +} \ No newline at end of file diff --git a/src/game/menu/menu_typing_practice.js b/src/game/menu/menu_typing_practice.js index 3771ed5..4bb020c 100644 --- a/src/game/menu/menu_typing_practice.js +++ b/src/game/menu/menu_typing_practice.js @@ -23,8 +23,7 @@ class MenuTypingPractice { let screenBottom = new ScreenBottom(); screenBottom.makeBottomLine(); // screenBottom.printBottomLeftText("게임 진행 정보"); - let playingAppName = appInfoManager.getAppNameKorean(sessionStorageManager.playingAppName); - screenBottom.printBottomCenterText(playingAppName); + screenBottom.printBottomCenterText("타자 연습"); screenBottom.printBottomRightText(sessionStorageManager.playerName); @@ -43,96 +42,97 @@ class MenuTypingPractice { } loginSucceeded(replyJSON) { - console.log(replyJSON); + // console.log(replyJSON); - let buttonWidthGap = MenuTypingPractice.BUTTON_WIDTH + MenuTypingPractice.BUTTON_GAP; + let buttonWidthGap = TypingPracticeButton.BUTTON_WIDTH + MenuTypingPractice.BUTTON_GAP; - let koreanTypingPracticeAppCount = self.getAppCount(replyJSON, MenuTypingPractice.TYPE_KOREAN); - let englishTypingPracticeAppCount = self.getAppCount(replyJSON, MenuTypingPractice.TYPE_ENGLISH); + let koreanTypingPracticeAppCount = Object.keys(replyJSON.Korean).length; + let englishTypingPracticeAppCount = Object.keys(replyJSON.English).length; - let startX = game.world.width / 2 - (buttonWidthGap * koreanTypingPracticeAppCount / 2) - (buttonWidthGap / 2); - let koreanTypingPracticeAppIndex = 0; - for(let i = 0; i < replyJSON.length; i++) { - let activeApp = replyJSON[i]; - if(self.isKoreanApp(activeApp)) { - koreanTypingPracticeAppIndex++; - console.log(activeApp); - new TypingPracticeButton( - startX + buttonWidthGap * koreanTypingPracticeAppIndex, 300, - TypingPracticeButton.TYPE_KOREAN, - TypingPracticeButton.NONE_ICON, - appInfoManager.getAppNameKorean(activeApp.AppName), - () => { - sessionStorageManager.playingAppID = activeApp.AppID; - sessionStorageManager.playingAppName = activeApp.AppName; - location.href = '../../web/client/start.html'; - } - ); - } - } + // let startX = game.world.width / 2 - (buttonWidthGap * koreanTypingPracticeAppCount / 2) - (buttonWidthGap / 2); + // let koreanTypingPracticeAppIndex = 0; + for(let i = 0; i < koreanTypingPracticeAppCount; i++) { + let activeApp = replyJSON.Korean[i]; - startX = game.world.width / 2 - (buttonWidthGap * koreanTypingPracticeAppCount / 2) - (buttonWidthGap / 2); - let englishTypingPracticeAppIndex = 0; - for(let i = 0; i < replyJSON.length; i++) { - let activeApp = replyJSON[i]; - if(!self.isKoreanApp(activeApp)) { - englishTypingPracticeAppIndex++; - console.log(activeApp); - new TypingPracticeButton( - startX + buttonWidthGap * englishTypingPracticeAppIndex, 500, - TypingPracticeButton.TYPE_ENGLISH, - TypingPracticeButton.NONE_ICON, - appInfoManager.getAppNameKorean(activeApp.AppName), - () => { - sessionStorageManager.playingAppID = activeApp.AppID; - sessionStorageManager.playingAppName = activeApp.AppName; - location.href = '../../web/client/start.html'; - } - ); - } - } + let posX = self.getButtonPosX(i, koreanTypingPracticeAppCount); + let posY = self.getButtonPosY(i, koreanTypingPracticeAppCount, + TypingPracticeButton.BUTTON_UPPER_POS_Y + ); - /* - if(englishTypingPracticeAppCount > 0) { - new TypingPracticeButton(game.world.width / 2, 500, TypingPracticeButton.TYPE_KOREAN, - TypingPracticeButton.NONE_ICON, "검지 글쇠", + new TypingPracticeButton( + posX, posY, LANGUAGE_KOREAN, + TypingPracticeButton.NONE_ICON, + activeApp.KoreanName, () => { - sessionStorageManager.playingAppID = activeApp.AppID; - sessionStorageManager.playingAppName = activeApp.AppName; - location.href = '../../web/client/start.html'; + sessionStorageManager.playingAppID = activeApp.AppID; + sessionStorageManager.playingAppName = activeApp.AppName; + location.href = '../../web/client/start.html'; } ); } - */ - } - isKoreanApp(app) { - if(app.AppType === MenuTypingPractice.TYPE_KOREAN) - return true; + // startX = game.world.width / 2 - (buttonWidthGap * englishTypingPracticeAppCount / 2) - (buttonWidthGap / 2); + for(let i = 0; i < englishTypingPracticeAppCount; i++) { + let activeApp = replyJSON.English[i]; - return false; - } + let posX = self.getButtonPosX(i, englishTypingPracticeAppCount); + let posY = self.getButtonPosY(i, englishTypingPracticeAppCount, + TypingPracticeButton.BUTTON_LOWER_POS_Y + ); - getAppCount(replyJSON, type) { - let appCount = 0; - for(let i = 0; i < replyJSON.length; i++) { - let activeApp = replyJSON[i]; - if(activeApp.AppType === type) - appCount++; + new TypingPracticeButton( + posX, posY, LANGUAGE_ENGLISH, + TypingPracticeButton.NONE_ICON, + activeApp.KoreanName, + () => { + sessionStorageManager.playingAppID = activeApp.AppID; + sessionStorageManager.playingAppName = activeApp.AppName; + location.href = '../../web/client/start.html'; + } + ); } - - return appCount; } + getButtonPosX(index, buttonCount) { + let gap = TypingPracticeButton.BUTTON_WIDTH + TypingPracticeButton.BUTTON_GAP; + let maxColumnNum = Math.floor( (game.world.width - TypingPracticeButton.MARGIN_VERTICAL) / gap ); + // console.log("maxColumnNum : " + maxColumnNum); + let rowCount = Math.ceil(buttonCount / maxColumnNum); + // console.log("rowCount : " + rowCount); + + let columnIndex = index % maxColumnNum; + // console.log("columnIndex : " + columnIndex); + let rowIndex = Math.floor(index / maxColumnNum); + // console.log("rowIndex : " + rowIndex); + + let columnCountForThisRow = 0; + if(rowIndex < rowCount - 1) + columnCountForThisRow = maxColumnNum; + else + columnCountForThisRow = buttonCount - (maxColumnNum * rowIndex); + // console.log("columnCountForThisRow : " + columnCountForThisRow); + + let startX = game.world.width / 2 - ( (gap / 2) * (columnCountForThisRow - 1) ); + return startX + gap * columnIndex; + } + + getButtonPosY(index, buttonCount, startPosY) { + let gap = TypingPracticeButton.BUTTON_HEIGHT + TypingPracticeButton.BUTTON_GAP; + let maxColumnNum = Math.floor( (game.world.width - TypingPracticeButton.MARGIN_VERTICAL) / gap ); + // console.log("maxColumnNum : " + maxColumnNum); + let rowCount = Math.ceil(buttonCount / maxColumnNum); + // console.log("rowCount : " + rowCount); + + let rowIndex = Math.floor(index / maxColumnNum); + // console.log("rowIndex : " + rowIndex); + + let startY = startPosY - ( (gap / 2) * (rowCount - 1) ); + return startY + gap * rowIndex; + } + + loginFailed(replyJSON) { console.log('login failed, jsonData : ' + JSON.stringify(replyJSON)); } -} - - -MenuTypingPractice.TYPE_KOREAN = 10; -MenuTypingPractice.TYPE_ENGLISH = 20; - -MenuTypingPractice.BUTTON_WIDTH = 200; -MenuTypingPractice.BUTTON_GAP = 20; \ No newline at end of file +} \ No newline at end of file diff --git a/src/web/server/app/active_typing_practice_app_list.php b/src/web/server/app/menu_active_typing_practice_app_list.php similarity index 61% rename from src/web/server/app/active_typing_practice_app_list.php rename to src/web/server/app/menu_active_typing_practice_app_list.php index 571ba9a..9081a81 100644 --- a/src/web/server/app/active_typing_practice_app_list.php +++ b/src/web/server/app/menu_active_typing_practice_app_list.php @@ -8,7 +8,8 @@ $maestro_id = $_POST["maestro_id"]; include "./../setup/connect_db.php"; -$replyJSON = get_active_typing_practice_app_list($maestro_id); +$replyJSON["Korean"] = get_active_typing_practice_app_list($maestro_id, 10); +$replyJSON["English"] = get_active_typing_practice_app_list($maestro_id, 20); $db_conn->close(); if($replyJSON.length === 0) { @@ -22,23 +23,24 @@ $db_conn->close(); -function get_active_typing_practice_app_list($maestro_id) { +function get_active_typing_practice_app_list($maestro_id, $type) { global $db_conn; $query = " - SELECT A.AppID, A.AppName, A.AppType + SELECT A.AppID, A.AppName, A.KoreanName FROM moty_app AS A - INNER JOIN moty_active_app AS AA ON A.AppType < 50 AND A.AppID = AA.AppID AND AA.MaestroID=?"; + INNER JOIN moty_active_app AS AA ON A.AppType < 50 AND A.AppID = AA.AppID AND AA.MaestroID = ? AND A.AppType = ? + ORDER BY A.AppID ASC"; $stmt = $db_conn->prepare($query); - $stmt->bind_param('i', $maestro_id); + $stmt->bind_param('ii', $maestro_id, $type); $stmt->execute(); - $stmt->bind_result($app_id, $app_name, $app_type); + $stmt->bind_result($app_id, $app_name, $korean_name); $return_array = array(); while($stmt->fetch()) { $row_array['AppID'] = $app_id; $row_array['AppName'] = $app_name; - $row_array['AppType'] = $app_type; + $row_array['KoreanName'] = $korean_name; array_push($return_array, $row_array); } $stmt->close(); diff --git a/test/test_db_connect_manager.js b/test/test_db_connect_manager.js index 0ded091..e7363ec 100644 --- a/test/test_db_connect_manager.js +++ b/test/test_db_connect_manager.js @@ -38,12 +38,12 @@ QUnit.test( "Player history", function( assert ) { // console.log(historyRecordManager); assert.equal(historyRecordManager.getAppNameAt(0), "korean_word"); - assert.equal(historyRecordManager.getDateAt(0), "2018-05-14"); - assert.equal(historyRecordManager.getBestRecordAt(0), 101.78); + assert.equal(historyRecordManager.getDateAt(0), "2018-05-16"); + assert.equal(historyRecordManager.getBestRecordAt(0), 108.248); assert.equal(historyRecordManager.getAppNameAt(4), "korean_word"); - assert.equal(historyRecordManager.getDateAt(4), "2018-04-18"); - assert.equal(historyRecordManager.getBestRecordAt(4), 51.6102); + assert.equal(historyRecordManager.getDateAt(4), "2018-04-23"); + assert.equal(historyRecordManager.getBestRecordAt(4), 74.2234); done(); }