///////////////////////////// // Start class Start { preload() { game.load.image('icon_fullscreen', '../../../resources/image/icon/fullscreen_white.png'); } create() { this.dbConnectManager = new DBConnectManager(); this.game.stage.backgroundColor = '#4d4d4d'; this.chartGraphics = game.add.graphics(100, game.world.height - 120); // top let backButton = new BackButton( () => { if(isTypingPracticeStage()) location.href = '../../web/client/menu_typing_practice.html'; else if(isTypingTestStage()) location.href = '../../web/client/menu_typing_test.html'; else location.href = '../../web/client/menu_app.html'; sessionStorageManager.resetPlayingAppData(); }); let fullscreenButton = new FullscreenButton(this.game); // contents // this.printHowToPlay(appInfoManager.getHowToPlayText(sessionStorageManager.playingAppName)); this.loadHowToPlay(sessionStorageManager.playingAppID); this.makeStartButton(); let today = new Date(); let date = DateUtil.getYYYYMMDD(today); this.dbConnectManager.requestPlayerHistory( sessionStorageManager.maestroID, date, historyRecordManager => { this.printChartBaseLine(); if(historyRecordManager.count == 0) { console.log("start - history record : no data"); return; } let underValue = historyRecordManager.underValueForGraph(); let upperValue = historyRecordManager.upperValueForGraph(); let minValue = underValue - (upperValue - underValue) / 10; let maxValue = upperValue;// + (upperValue - underValue) / 10; for(let i = 0; i < historyRecordManager.count; i++) { if(i > 6) break; let data = historyRecordManager.getAt(i); this.drawRecordGraph(i, data.date, data.bestRecord, minValue, maxValue); } } ); // bottom let screenBottom = new ScreenBottom(); screenBottom.makeBottomLine(); screenBottom.printBottomLeftText("오늘의 최고 기록 : "); screenBottom.printBottomCenterText(sessionStorageManager.playingAppKoreanName); screenBottom.printBottomRightText(sessionStorageManager.playerName); this.dbConnectManager.requestTodayBestRecord( sessionStorageManager.maestroID, sessionStorageManager.playerUserID, sessionStorageManager.playingAppID, replyJSON => { sessionStorageManager.bestRecord = Number(replyJSON["BestRecord"]); // let highScoreWithCommas = NumberUtil.numberWithCommas(sessionStorageManager.bestRecord); // screenBottom.printBottomLeftText("오늘의 최고 기록 : " + highScoreWithCommas); screenBottom.printBottomLeftTextWithBestRecord(sessionStorageManager.bestRecord); }, replyJSON => { // no data sessionStorageManager.bestRecord = 0; // let highScoreWithCommas = NumberUtil.numberWithCommas(sessionStorageManager.bestRecord); // screenBottom.printBottomLeftText("오늘의 최고 기록 : " + highScoreWithCommas); screenBottom.printBottomLeftTextWithBestRecord(sessionStorageManager.bestRecord); } ); } loadHowToPlay(appID) { this.dbConnectManager.requestHowToPlay( sessionStorageManager.playingAppID, // space_invaders app ID (jsonData) => { let howToPlay = jsonData["HowToPlay"].replace(/\\n/g, "\n"); this.printHowToPlay(howToPlay); }, (jsonData) => { this.printHowToPlay("No data"); } ); } printHowToPlay(text) { const style = { font: "32px Arial", fill: "#fff", align: "left", boundsAlignH: "center", boundsAlignV: "middle" }; let howToPlayText = game.add.text(0, 0, text, style); howToPlayText.setTextBounds(100, 100, game.world.width - 100, 200); howToPlayText.stroke = "#333"; howToPlayText.strokeThickness = 5; } makeStartButton() { let setting = new RoundRectButtonSetting(200, 100); setting.fontStyle.fontWeight = "bold"; let startButton = new RoundRectButton(setting, RoundRectButton.NONE_ICON, "시작", this.startStage); startButton.move(game.world.centerX, game.world.centerY); } printChartBaseLine() { this.chartGraphics.lineStyle(3, 0xffd900, 1); this.chartGraphics.moveTo(0, 0); this.chartGraphics.lineTo(game.world.width - 200, 0); } drawRecordGraph(index, date, bestRecord, min, max) { const CHART_GAP_PX = 120; const CHART_HEIGHT = 120; const style = { font: "24px Arial", fill: "#fff", align: "left", boundsAlignH: "center", boundsAlignV: "middle" }; let dateText = game.add.text( 100 + index * CHART_GAP_PX, game.world.height - 140, StringUtil.printMonthDay(date), style ); dateText.setTextBounds(0, 0, 100, 100); dateText.stroke = "#333"; dateText.strokeThickness = 1; let bestRecordText = game.add.text( 100 + index * CHART_GAP_PX, game.world.height - 300, StringUtil.getRecordTextWithUnit(bestRecord), style ); bestRecordText.setTextBounds(0, 0, 100, 100); bestRecordText.stroke = "#333"; bestRecordText.strokeThickness = 1; this.chartGraphics.lineStyle(50, 0xdddddd, 1); this.chartGraphics.moveTo(50 + index * CHART_GAP_PX, 0); this.chartGraphics.lineTo(50 + index * CHART_GAP_PX, -1 * CHART_HEIGHT * ( (bestRecord - min) / (max - min) )); } startStage() { if(isTypingPracticeStage()) location.href = "../../web/client/typing_practice.html"; else if(isTypingTestStage()) location.href = "../../web/client/typing_test.html"; else location.href = "../../web/client/" + sessionStorageManager.playingAppName + ".html"; } }