Files
chocomae/src/game/start/start.js
T

154 lines
4.5 KiB
JavaScript

/////////////////////////////
// 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.howToPlay = new HowToPlay();
this.chart = new Chart();
// top ui
let screenTopUI = new ScreenTopUI();
screenTopUI.makeBackButton( () => {
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();
});
screenTopUI.makeFullScreenButton();
// contents
this.loadHowToPlay(sessionStorageManager.playingAppID);
this.makeStartButton();
if(sessionStorageManager.maestroAccountType >= 100) { // experience account
this.printSampleChart();
this.announceBox = new AnnounceBox(50, 648);
this.announceBox.drawBox("체험 계정에서는 기록이 저장되지 않습니다.");
} else {
this.loadChart();
}
// bottom ui
let screenBottomUI = new ScreenBottomUI();
screenBottomUI.printLeftText("오늘의 최고 기록 : ");
screenBottomUI.printCenterText(sessionStorageManager.playingAppKoreanName);
screenBottomUI.printRightText(sessionStorageManager.playerName);
this.dbConnectManager.requestTodayBestRecord(
sessionStorageManager.maestroID,
sessionStorageManager.playerID,
sessionStorageManager.playingAppID,
replyJSON => {
sessionStorageManager.bestRecord = Number(replyJSON["BestRecord"]);
screenBottomUI.printLeftTextWithBestRecord(sessionStorageManager.bestRecord);
},
replyJSON => { // no data
sessionStorageManager.bestRecord = 0;
screenBottomUI.printLeftTextWithBestRecord(sessionStorageManager.bestRecord);
}
);
}
loadHowToPlay(appID) {
this.dbConnectManager.requestHowToPlay(
sessionStorageManager.playingAppID, // space_invaders app ID
(jsonData) => {
let howToPlayText = jsonData["HowToPlay"].replace(/\\n/g, "\n");
this.howToPlay.printHowToPlay(howToPlayText);
},
(jsonData) => {
this.howToPlay.printHowToPlay("No data");
}
);
}
loadChart() {
let today = new Date();
let date = DateUtil.getYYYYMMDD(today);
this.dbConnectManager.requestPlayerHistory(
sessionStorageManager.maestroID,
date,
historyRecordManager => {
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;
let countRecord = historyRecordManager.count;
for(let i = 0; i < Chart.CHART_COUNT; i++) {
// if(i > 6)
// break;
let historyRecord = historyRecordManager.getAt(i);
this.chart.drawRecordGraph(
i,
historyRecord === undefined ? "-" : historyRecord.date,
historyRecord === undefined ? "" : historyRecord.bestRecord,
minValue, maxValue
);
}
this.chart.printChartBaseLine();
}
);
}
calcDate(daysBefore) {
let date = new Date();
date.setDate(date.getDate() - daysBefore);
return date;
}
printSampleChart() {
let minValue = 0;
let maxValue = 1000;
this.chart.drawRecordGraph(0, this.calcDate(1), 980, minValue, maxValue);
this.chart.drawRecordGraph(1, this.calcDate(2), 760, minValue, maxValue);
this.chart.drawRecordGraph(2, this.calcDate(5), 740, minValue, maxValue);
this.chart.drawRecordGraph(3, this.calcDate(7), 690, minValue, maxValue);
this.chart.drawRecordGraph(4, this.calcDate(8), 710, minValue, maxValue);
this.chart.drawRecordGraph(5, this.calcDate(10), 560, minValue, maxValue);
this.chart.drawRecordGraph(6, this.calcDate(20), 480, minValue, maxValue);
this.chart.printChartBaseLine();
}
makeStartButton() {
let setting = new RoundRectButtonSetting(game.world.centerX, game.world.centerY, 200, 100);
setting.fontStyle.fontWeight = "bold";
let startButton = new RoundRectButton(setting, RoundRectButton.NONE_ICON, "시작", this.startStage);
}
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";
}
}