From 72ea114cc8ba4cddae8f1688ddec99a9bf97c522 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: Tue, 29 May 2018 17:13:12 +0900 Subject: [PATCH] Add: active_app.php --- resources/image/icon/space_invaders.png | Bin 0 -> 1956 bytes src/game/lib/app_button.js | 4 +- src/game/lib/db_connect_manager.js | 67 ++++++---- src/game/menu/menu_app.js | 129 ++++++++------------ src/web/client/menu_app.html | 1 + src/web/client/menu_typing_app.html | 46 +++++++ src/web/server/app/activated_stage_list.php | 38 ------ src/web/server/app/active_app.php | 72 +++++++++++ src/web/server/setup/connect_db.php | 1 + src/web/server/user/login.php | 3 +- src/web/sql/insert_app.sql | 2 +- src/web/sql/make_db.sql | 4 +- 12 files changed, 223 insertions(+), 144 deletions(-) create mode 100644 resources/image/icon/space_invaders.png create mode 100644 src/web/client/menu_typing_app.html delete mode 100644 src/web/server/app/activated_stage_list.php create mode 100644 src/web/server/app/active_app.php diff --git a/resources/image/icon/space_invaders.png b/resources/image/icon/space_invaders.png new file mode 100644 index 0000000000000000000000000000000000000000..d5b52d136437afc11b5a25d874ca85c6e83978ae GIT binary patch literal 1956 zcmX|Cdpy(YAO8*qxn+jAl{JLezD6cvE}7dhxh$*;W|ro%&9+?A=q1T59G5s!?$;kF zDo3MJI!a9=CrUSx>nS;r7U|6So!9x}^E}Vzc|M=_`~7*I=k@xW_wjaDR?txZ06^K( zgWxBb5nCoND;c>-Nh<&V(PfZ>ctIpD9E}x&riQb^=;(wPw&WZD>>U%>R9Y0BhX|ub zFqnAcQcoWe!3f7A1FcCGB(@9v1j8eVL-$YeCexClXtv=N9 z9vcUO@$vEKcq=rE69HmuZEZmdOVH91C5b?B6PY|}0*c8s*n;>!27%6{aTshKgT+K_ zVN%0bCwX`z65JvI|7DTL1^?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rtT3Xo(SF;1lE;uIbo*IqJDyRa+z|H`2clmE47Hq73Eg`rBI>A3VUrFqLVxJf1bFk}HFP~r+aG%7Z-DV*x&QzG literal 0 HcmV?d00001 diff --git a/src/game/lib/app_button.js b/src/game/lib/app_button.js index c0b5d56..c1d99c4 100644 --- a/src/game/lib/app_button.js +++ b/src/game/lib/app_button.js @@ -1,6 +1,6 @@ class AppButton { - constructor(type, iconName, clickEvent) { + constructor(x, y, type, iconName, clickEvent) { let setting = new RoundRectButtonSetting(150, 150); setting.fontStyle.boundsAlignH = "center"; // left, center. right setting.fontStyle.boundsAlignV = "middle"; // top, middle, bottom @@ -52,6 +52,8 @@ class AppButton { this.button = new RoundRectButton(setting, "", clickEvent); this.button.setIcon(icon_fullscreen); + + this.move(x, y); } move(x, y) { diff --git a/src/game/lib/db_connect_manager.js b/src/game/lib/db_connect_manager.js index 03b1ade..f6694aa 100644 --- a/src/game/lib/db_connect_manager.js +++ b/src/game/lib/db_connect_manager.js @@ -53,17 +53,34 @@ class DBConnectManager { 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); + let replyJSON = JSON.parse(xhr.responseText); - if(jsonData != null && jsonData["UserID"] != null) - onSucceededListener(jsonData); + if(replyJSON != null && replyJSON["UserID"] != null) + onSucceededListener(replyJSON); else - onFailedListener(jsonData); + onFailedListener(replyJSON); } }; xhr.send("maestro_name=" + maestroName + "&name=" + userName + "&enter_code=" + enterCode); } + requestActiveAppList(maestroID, onSucceededListener, onFailedListener) { + let xhr = new XMLHttpRequest(); + xhr.open("POST", this.phpPath + "server/app/active_app.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 && replyJSON.length > 0) + onSucceededListener(replyJSON); + else + onFailedListener(replyJSON); + } + }; + xhr.send("maestro_id=" + maestroID); + } + requestPlayerHistory(date, listener) { let historyRecordManager = new HistoryRecordManager(); @@ -85,13 +102,13 @@ class DBConnectManager { 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); + let replyJSON = JSON.parse(xhr.responseText); - if(jsonData != null) { - listener(self.parseJSONtoHistoryRecord(jsonData)); + if(replyJSON != null) { + listener(self.parseJSONtoHistoryRecord(replyJSON)); } else - onFailedListener(jsonData); + onFailedListener(replyJSON); } }; let params = "UserID=" + sessionStorageManager.playerUserID @@ -164,13 +181,13 @@ class DBConnectManager { 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); + let replyJSON = JSON.parse(xhr.responseText); - if(jsonData != null) { - listener(type, self.parseJSONtoRankingRecord(type, jsonData)); + if(replyJSON != null) { + listener(type, self.parseJSONtoRankingRecord(type, replyJSON)); } else - onFailedListener(jsonData); + onFailedListener(replyJSON); } }; let params = "UserID=" + sessionStorageManager.playerUserID @@ -209,34 +226,34 @@ class DBConnectManager { if(typeof json === "undefined") return rankingRecordManager; - let jsonData = null; + let replyJSON = null; switch(type) { case DBConnectManager.TYPE_MY_RANKING_HOUR: case DBConnectManager.TYPE_ALL_RANKING_HOUR: - jsonData = json.rankingHour; + replyJSON = json.rankingHour; break; case DBConnectManager.TYPE_MY_RANKING_DAY: case DBConnectManager.TYPE_ALL_RANKING_DAY: - jsonData = json.rankingDay; + replyJSON = json.rankingDay; break; case DBConnectManager.TYPE_MY_RANKING_MONTH: case DBConnectManager.TYPE_ALL_RANKING_MONTH: - jsonData = json.rankingMonth; + replyJSON = json.rankingMonth; break; } - if(jsonData === null) + if(replyJSON === null) return rankingRecordManager; - let count = jsonData.length; + let count = replyJSON.length; for(let i = 0; i < count; i++) { let record = new RankingRecord( i + 1, - jsonData[i]["UserID"], - jsonData[i]["Name"], - jsonData[i]["HighScore"] + replyJSON[i]["UserID"], + replyJSON[i]["Name"], + replyJSON[i]["HighScore"] ); rankingRecordManager.push(record); } @@ -253,12 +270,12 @@ class DBConnectManager { makeXHRWithParam(url, param, onSucceededListener, onFailedListener) { xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200) { - let jsonData = JSON.parse(xhr.responseText); + let replyJSON = JSON.parse(xhr.responseText); - if(jsonData != null && jsonData["UserID"] != null) - onSucceededListener(jsonData); + if(replyJSON != null && replyJSON["UserID"] != null) + onSucceededListener(replyJSON); else - onFailedListener(jsonData); + onFailedListener(replyJSON); } } diff --git a/src/game/menu/menu_app.js b/src/game/menu/menu_app.js index 7be910c..ee70480 100644 --- a/src/game/menu/menu_app.js +++ b/src/game/menu/menu_app.js @@ -5,38 +5,21 @@ class MenuApp { preload() { game.load.image('icon_fullscreen', '../../../resources/image/icon/fullscreen_white.png'); + game.load.image('space_invaders', '../../../resources/image/icon/space_invaders.png'); } create() { + self = this; this.game.stage.backgroundColor = '#4d4d4d'; // top let backButton = new BackButton( () => { sessionStorageManager.clear(); - location.href = '../../web/client/login.html'; }); - let fullscreenButton = new FullscreenButton(this.game); - // app icons - let space_invaders = new AppButton(AppButton.TYPE_MOUSE, "icon_fullscreen", - () => { - sessionStorageManager.playingAppName = "space_invaders"; - location.href = '../../web/client/start.html'; - } - ); - space_invaders.move(400, 400); - - let typing_practice = new AppButton(AppButton.TYPE_TYPING, "icon_fullscreen", - () => { - console.log("typing practice"); - } - ); - typing_practice.move(600, 400); - - // bottom let screenBottom = new ScreenBottom(); screenBottom.makeBottomLine(); @@ -45,77 +28,73 @@ class MenuApp { screenBottom.printBottomCenterText(playingAppName); screenBottom.printBottomRightText(sessionStorageManager.playerName); - // this.loadTypingStageData(); + + this.makeActiveAppButtons(); } - loadTypingStageData() { - var self = this; - 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); - var jsonData = JSON.parse(xhr.responseText); - self.updateStageButton(jsonData); + makeActiveAppButtons() { + let dbConnectManager = new DBConnectManager(); + dbConnectManager.requestActiveAppList( + sessionStorageManager.maestroID, + self.loginSucceeded, + self.loginFailed + ); + + } + + loginSucceeded(replyJSON) { + // console.log(replyJSON); + + let mouseAppCount = self.getAppCount(replyJSON, AppButton.TYPE_MOUSE); + let typingAppCount = self.getAppCount(replyJSON, AppButton.TYPE_TYPING); + + let startX = game.world.width / 2 - (150 * mouseAppCount / 2) - (150 / 2); + let mouseAppIndex = 0; + for(let i = 0; i < replyJSON.length; i++) { + let activeApp = replyJSON[i]; + if(self.isMouseApp(activeApp)) { + mouseAppIndex++; + new AppButton(startX + 150 * mouseAppIndex, 300, AppButton.TYPE_MOUSE, activeApp.AppName, + () => { + sessionStorageManager.playingAppName = activeApp.AppName; + location.href = '../../web/client/start.html'; + } + ); } } - xhr.open('GET', 'activated_stage_list.php', true); - xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - xhr.send(); - } - updateStageButton(jsonData) { - // console.log(JSON.stringify(jsonData)); - - for(var i = 0; i < jsonData.length; i++) { - // console.log(jsonData[i]["StageName"] + " : " + jsonData[i]["Activated"]); - - this.activateStageButton( - // jsonData[i]["Language"], - jsonData[i]["StageName"], - jsonData[i]["Activated"] + if(typingAppCount > 0) { + new AppButton(game.world.width / 2, 500, AppButton.TYPE_TYPING, "icon_fullscreen", + () => { + location.href = '../../web/client/menu_typing_app.html'; + } ); } } - activateStageButton(stageName, isActivated) { - for(var i = 0; i < this.stageButtonArray.length; i++) { - var buttonName = this.stageButtonArray[i].name; - var buttonLanguage = buttonName.charAt(0) == "k" ? "korean" : "english"; - var buttonStageName = getStageCodeByStageNo(buttonName.substring(1)); - var buttonNewName = buttonLanguage + "_" + buttonStageName; - // console.log("buttonNewName : " + buttonNewName); + isMouseApp(app) { + if(app.AppType > 100) + return true; - if(buttonNewName == stageName) { - if(isActivated == true) { - // console.log("stageName : " + stageName); - - this.stageButtonArray[i].startButton.alpha = 1; - this.stageButtonArray[i].startButton.inputEnabled = true; - return; - } else { - // console.log("this.stageButtonArray[" + i + "].name : " + this.stageButtonArray[i].name); - // console.log("buttonNewName : " + buttonNewName); - - this.stageButtonArray[i].startButton.alpha = 0.3; - this.stageButtonArray[i].startButton.inputEnabled = false; - return; - } - } - } + return false; } - startStage() { - var language = this.name.substring(0, 1) == "k" ? LANGUAGE_KOREAN : LANGUAGE_ENGLISH; - var level = this.name.substring(1); + getAppCount(replyJSON, type) { + let appCount = 0; + for(let i = 0; i < replyJSON.length; i++) { + let activeApp = replyJSON[i]; + if(type == AppButton.TYPE_TYPING && activeApp.AppType <= 100) + appCount++; + else if(type == AppButton.TYPE_MOUSE && activeApp.AppType > 100) + appCount++; + } - playingStageData = new StageData(language, level); - // console.log(playingStageData); + return appCount; + } - this.startState('TypingTestStage'); + loginFailed(replyJSON) { + console.log('login failed, jsonData : ' + JSON.stringify(replyJSON)); } } \ No newline at end of file diff --git a/src/web/client/menu_app.html b/src/web/client/menu_app.html index b663ca0..857c079 100644 --- a/src/web/client/menu_app.html +++ b/src/web/client/menu_app.html @@ -21,6 +21,7 @@ + diff --git a/src/web/client/menu_typing_app.html b/src/web/client/menu_typing_app.html new file mode 100644 index 0000000..857c079 --- /dev/null +++ b/src/web/client/menu_typing_app.html @@ -0,0 +1,46 @@ + + + + + 메뉴 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +