From 72e7c1a28f6b636dbc735500e583dbd720f643f6 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: Fri, 14 Sep 2018 11:58:50 +0900 Subject: [PATCH] Fix: restructing sessionManager (incompleted) --- src/game/global/global_variables.js | 40 ++++---- src/game/lib/button/game_app_button.js | 6 +- src/game/lib/button/typing_app_button.js | 6 +- src/game/lib/session_storage_manager.js | 114 ++++++++++++++++++++++- src/game/menu/menu_app.js | 6 +- src/game/start/start.js | 30 +++--- 6 files changed, 157 insertions(+), 45 deletions(-) diff --git a/src/game/global/global_variables.js b/src/game/global/global_variables.js index c92d1ac..939559e 100644 --- a/src/game/global/global_variables.js +++ b/src/game/global/global_variables.js @@ -3,7 +3,7 @@ const LANGUAGE_ENGLISH = "english"; const MODE_RELEASE = "release"; const MODE_DEBUG = "debug"; -const runMode = MODE_DEBUG; +const runMode = MODE_RELEASE; function isDebugMode() { // console.log("debug mode ? " + runMode); @@ -23,19 +23,19 @@ const GAME_SCREEN_SIZE = { x: 1024, y: 768 } let sessionStorageManager = new SessionStorageManager(); { if(isDebugMode()) { - console.log("maestroID : " + sessionStorageManager.maestroID); - console.log("maestroAccountType : " + sessionStorageManager.maestroAccountType); - console.log("playerName : " + sessionStorageManager.playerName); - console.log("playerID : " + sessionStorageManager.playerID); - console.log("playerAccountType : " + sessionStorageManager.playerAccountType); - console.log("playingAppID : " + sessionStorageManager.playingAppID); - console.log("playingAppName : " + sessionStorageManager.playingAppName); - console.log("playingAppKoreanName : " + sessionStorageManager.playingAppKoreanName); - console.log("record : " + sessionStorageManager.record); - console.log("bestRecord : " + sessionStorageManager.bestRecord); + console.log("maestroID : " + sessionStorageManager.getMaestroID()); + console.log("maestroAccountType : " + sessionStorageManager.getMaestroAccountType()); + console.log("playerName : " + sessionStorageManager.getPlayerName()); + console.log("playerID : " + sessionStorageManager.getPlayerID()); + console.log("playerAccountType : " + sessionStorageManager.getPlayerAccountType()); + console.log("playingAppID : " + sessionStorageManager.getPlayingAppID()); + console.log("playingAppName : " + sessionStorageManager.getPlayingAppName()); + console.log("playingAppKoreanName : " + sessionStorageManager.getPlayingAppKoreanName()); + console.log("record : " + sessionStorageManager.getRecord()); + console.log("bestRecord : " + sessionStorageManager.getBestRecord()); } - if(sessionStorageManager.maestroID === null && !isLogin()) { + if(sessionStorageManager.getMaestroID() === null && !isLogin()) { goLogin(); } } @@ -52,17 +52,17 @@ function goLogin() { } function isTypingGame() { - if(sessionStorageManager.playingAppName === null) + if(sessionStorageManager.getPlayingAppName() === null) return false; - if(sessionStorageManager.playingAppName.indexOf("typing") < 0) + if(sessionStorageManager.getPlayingAppName().indexOf("typing") < 0) return false; return true; } function isTypingPracticeStage() { - let appName = sessionStorageManager.playingAppName; + let appName = sessionStorageManager.getPlayingAppName(); if(appName.indexOf("practice_") > -1) return true; @@ -71,7 +71,7 @@ function isTypingPracticeStage() { } function isTypingTestStage() { - let appName = sessionStorageManager.playingAppName; + let appName = sessionStorageManager.getPlayingAppName(); if(appName.indexOf("test_") > -1) return true; @@ -80,21 +80,21 @@ function isTypingTestStage() { } function isEnglishTypingStage() { - if(sessionStorageManager.playingAppName.indexOf("english") > -1) + if(sessionStorageManager.getPlayingAppName().indexOf("english") > -1) return true; return false; } function isKoreanTypingStage() { - if(sessionStorageManager.playingAppName.indexOf("korean") > -1) + if(sessionStorageManager.getPlayingAppName().indexOf("korean") > -1) return true; return false; } function isTypingWordStage() { - let appName = sessionStorageManager.playingAppName; + let appName = sessionStorageManager.getPlayingAppName(); if(appName.indexOf("_word") > -1) return true; @@ -106,7 +106,7 @@ function isTypingWordStage() { } function isTypingSentenceStage() { - let appName = sessionStorageManager.playingAppName; + let appName = sessionStorageManager.getPlayingAppName(); if(appName.indexOf("_sentence") > -1) return true; diff --git a/src/game/lib/button/game_app_button.js b/src/game/lib/button/game_app_button.js index c6c5611..79e7851 100644 --- a/src/game/lib/button/game_app_button.js +++ b/src/game/lib/button/game_app_button.js @@ -79,9 +79,9 @@ function GameAppButton(x, y, type, iconName, buttonText, appInfo) { GameAppButton.prototype.clickEvent = function() { - sessionStorageManager.playingAppID = this.appInfo.AppID; - sessionStorageManager.playingAppName = this.appInfo.AppName; - sessionStorageManager.playingAppKoreanName = this.appInfo.KoreanName; + sessionStorageManager.getPlayingAppID() = this.appInfo.AppID; + sessionStorageManager.getPlayingAppName() = this.appInfo.AppName; + sessionStorageManager.getPlayingAppKoreanName() = this.appInfo.KoreanName; location.href = '../../web/client/start.html'; } diff --git a/src/game/lib/button/typing_app_button.js b/src/game/lib/button/typing_app_button.js index 754374b..793fbc3 100644 --- a/src/game/lib/button/typing_app_button.js +++ b/src/game/lib/button/typing_app_button.js @@ -98,9 +98,9 @@ function TypingAppButton(type, x, y, iconName, buttonText, appInfo) { } TypingAppButton.prototype.clickEvent = function() { - sessionStorageManager.playingAppID = this.appInfo.AppID; - sessionStorageManager.playingAppName = this.appInfo.AppName; - sessionStorageManager.playingAppKoreanName = this.appInfo.KoreanName; + sessionStorageManager.setPlayingAppID(this.appInfo.AppID); + sessionStorageManager.setPlayingAppName(this.appInfo.AppName); + sessionStorageManager.setPlayingAppKoreanName(this.appInfo.KoreanName); location.href = '../../web/client/start.html'; } diff --git a/src/game/lib/session_storage_manager.js b/src/game/lib/session_storage_manager.js index 3396c6e..8696a42 100644 --- a/src/game/lib/session_storage_manager.js +++ b/src/game/lib/session_storage_manager.js @@ -1,3 +1,114 @@ +function SessionStorageManager() { +} + + +SessionStorageManager.prototype.clear = function() { + sessionStorage.clear(); +} + +SessionStorageManager.prototype.removeItem = function(key) { + return sessionStorage.removeItem(key); +} + + +// maestro ID +SessionStorageManager.prototype.setMaestroID = function(value) { + sessionStorage.setItem("maestroID", value); +} +SessionStorageManager.prototype.getMaestroID = function() { + return sessionStorage.getItem("maestroID"); +} + +// maestro account type +SessionStorageManager.prototype.setMaestroAccountType = function(value) { + sessionStorage.setItem("maestroAccountType", value); +} +SessionStorageManager.prototype.getMaestroAccountType = function() { + return sessionStorage.getItem("maestroAccountType"); +} + +// player name +SessionStorageManager.prototype.setPlayerName = function(value) { + sessionStorage.setItem("playerName", value); +} +SessionStorageManager.prototype.getPlayerName = function() { + return sessionStorage.getItem("playerName"); +} + +// player player ID +SessionStorageManager.prototype.setPlayerID = function(value) { + sessionStorage.setItem("playerID", value); +} +SessionStorageManager.prototype.getPlayerID = function() { + return sessionStorage.getItem("playerID"); +} + +// player account type +SessionStorageManager.prototype.setPlayerAccountType = function(value) { + sessionStorage.setItem("playerAccountType", value); +} +SessionStorageManager.prototype.getPlayerAccountType = function() { + return sessionStorage.getItem("playerAccountType"); +} + +// playing app id +SessionStorageManager.prototype.setPlayingAppID = function(value) { + sessionStorage.setItem("playingAppID", value); +} +SessionStorageManager.prototype.getPlayingAppID = function() { + return sessionStorage.getItem("playingAppID"); +} + +// playing app name +SessionStorageManager.prototype.setPlayingAppName = function(value) { + sessionStorage.setItem("playingAppName", value); +} +SessionStorageManager.prototype.getPlayingAppName = function() { + return sessionStorage.getItem("playingAppName"); +} + +// playing app korean name +SessionStorageManager.prototype.setPlayingAppKoreanName = function(value) { + sessionStorage.setItem("playingAppKoreanName", value); +} +SessionStorageManager.prototype.getPlayingAppKoreanName = function() { + return sessionStorage.getItem("playingAppKoreanName"); +} + +// record +SessionStorageManager.prototype.setRecord = function(value) { + sessionStorage.setItem("record", value); +} +SessionStorageManager.prototype.getRecord = function() { + return sessionStorage.getItem("record"); +} + +// best record +SessionStorageManager.prototype.setBestRecord = function(value) { + sessionStorage.setItem("bestRecord", value); +} +SessionStorageManager.prototype.getBestRecord = function() { + return sessionStorage.getItem("bestRecord"); +} + +// best record +SessionStorageManager.prototype.setIsNewBestRecord = function(value) { + sessionStorage.setItem("isNewBestRecord", value); +} +SessionStorageManager.prototype.getIsNewBestRecord = function() { + return sessionStorage.getItem("isNewBestRecord"); +} + +SessionStorageManager.prototype.resetPlayingAppData = function() { + this.removeItem(playingAppID); + this.removeItem(playingAppName); + this.removeItem(playingAppKoreanName); + this.removeItem(record); + this.removeItem(bestRecord); +} + + +/* class SessionStorageManager { constructor() { @@ -108,4 +219,5 @@ class SessionStorageManager { } -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/src/game/menu/menu_app.js b/src/game/menu/menu_app.js index 2e9618d..3f2a711 100644 --- a/src/game/menu/menu_app.js +++ b/src/game/menu/menu_app.js @@ -47,9 +47,9 @@ var MenuApp = { // var playingAppName = appInfoManager.getAppNameKorean(sessionStorageManager.playingAppName); // ScreenBottomUI.printCenterText(playingAppName); screenBottomUI.printCenterText("메뉴"); - screenBottomUI.printRightText(sessionStorageManager.playerName); + screenBottomUI.printRightText(sessionStorageManager.getPlayerName()); - new WelcomePlayerText(sessionStorageManager.playerName); + new WelcomePlayerText(sessionStorageManager.getPlayerName()); this.loadAppData(); @@ -60,7 +60,7 @@ var MenuApp = { loadAppData: function() { var dbConnectManager = new DBConnectManager(); dbConnectManager.requestMenuAppList( - sessionStorageManager.maestroID, + sessionStorageManager.getMaestroID(), (function(replyJSON) { this.loadSucceeded(replyJSON); }).bind(this), diff --git a/src/game/start/start.js b/src/game/start/start.js index 3520c40..a5b03dd 100644 --- a/src/game/start/start.js +++ b/src/game/start/start.js @@ -31,11 +31,11 @@ class Start { // contents - this.loadHowToPlay(sessionStorageManager.playingAppID); + this.loadHowToPlay(sessionStorageManager.getPlayingAppID()); this.makeStartButton(); this.makeRankingButton(); - if(sessionStorageManager.maestroAccountType >= 100) { // experience account + if(sessionStorageManager.getMaestroAccountType() >= 100) { // experience account this.printSampleChart(); this.announceBox = new AnnounceBox(50, 648); this.announceBox.drawBox("체험 계정에서는 기록이 저장되지 않습니다."); @@ -47,27 +47,27 @@ class Start { // bottom ui var screenBottomUI = new ScreenBottomUI(); screenBottomUI.printLeftText("오늘의 최고 기록 : "); - screenBottomUI.printCenterText(sessionStorageManager.playingAppKoreanName); - screenBottomUI.printRightText(sessionStorageManager.playerName); + screenBottomUI.printCenterText(sessionStorageManager.getPlayingAppKoreanName()); + screenBottomUI.printRightText(sessionStorageManager.getPlayerName()); this.dbConnectManager.requestTodayBestRecord( - sessionStorageManager.maestroID, - sessionStorageManager.playerID, - sessionStorageManager.playingAppID, + sessionStorageManager.getMaestroID(), + sessionStorageManager.getPlayerID(), + sessionStorageManager.getPlayingAppID(), (function(replyJSON) { - sessionStorageManager.bestRecord = Number(replyJSON["BestRecord"]); - screenBottomUI.printLeftTextWithBestRecord(sessionStorageManager.bestRecord); + sessionStorageManager.getBestRecord() = Number(replyJSON["BestRecord"]); + screenBottomUI.printLeftTextWithBestRecord(sessionStorageManager.getBestRecord()); }).bind(this), (function(replyJSON) { // no data - sessionStorageManager.bestRecord = 0; - screenBottomUI.printLeftTextWithBestRecord(sessionStorageManager.bestRecord); + sessionStorageManager.getBestRecord() = 0; + screenBottomUI.printLeftTextWithBestRecord(sessionStorageManager.getBestRecord()); }).bind(this) ); } loadHowToPlay(appID) { this.dbConnectManager.requestHowToPlay( - sessionStorageManager.playingAppID, // space_invaders app ID + sessionStorageManager.getPlayingAppID(), // space_invaders app ID (function(jsonData) { var howToPlayText = jsonData["HowToPlay"].replace(/\\n/g, "\n"); this.howToPlay.printHowToPlay(howToPlayText); @@ -83,7 +83,7 @@ class Start { var today = new Date(); var date = DateUtil.getYYYYMMDD(today); this.dbConnectManager.requestPlayerHistory( - sessionStorageManager.maestroID, + sessionStorageManager.getMaestroID(), date, (function(historyRecordManager) { if(historyRecordManager.count == 0) { @@ -158,7 +158,7 @@ class Start { location.href = '../../web/client/ranking.html'; }) ); - if(sessionStorageManager.maestroAccountType == 100) + if(sessionStorageManager.getMaestroAccountType() == 100) rankingButton.inputEnabled = false; } @@ -169,7 +169,7 @@ class Start { else if(isTypingTestStage()) location.href = "../../web/client/typing_test.html"; else - location.href = "../../web/client/" + sessionStorageManager.playingAppName + ".html"; + location.href = "../../web/client/" + sessionStorageManager.getPlayingAppName() + ".html"; } } \ No newline at end of file