Files
chocomae/src/game/start/start.js
T
2018-09-14 23:32:50 +09:00

172 lines
5.5 KiB
JavaScript

var Start = {
preload: function() {
game.load.image('icon_fullscreen', '../../../resources/image/icon/fullscreen_white.png');
},
create: function() {
this.dbConnectManager = new DBConnectManager();
this.game.stage.backgroundColor = '#4d4d4d';
this.howToPlay = new HowToPlay();
this.chart = new Chart();
// top ui
var screenTopUI = new ScreenTopUI();
screenTopUI.makeBackButton( function() {
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.getPlayingAppID());
this.makeStartButton();
this.makeRankingButton();
if(sessionStorageManager.getMaestroAccountType() >= 100) { // experience account
this.printSampleChart();
this.announceBox = new AnnounceBox(50, 648);
this.announceBox.drawBox("체험 계정에서는 기록이 저장되지 않습니다.");
} else {
this.loadChart();
}
// bottom ui
var screenBottomUI = new ScreenBottomUI();
screenBottomUI.printLeftText("오늘의 최고 기록 : ");
screenBottomUI.printCenterText(sessionStorageManager.getPlayingAppKoreanName());
screenBottomUI.printRightText(sessionStorageManager.getPlayerName());
this.dbConnectManager.requestTodayBestRecord(
sessionStorageManager.getMaestroID(),
sessionStorageManager.getPlayerID(),
sessionStorageManager.getPlayingAppID(),
(function(replyJSON) {
sessionStorageManager.setBestRecord(Number(replyJSON["BestRecord"]));
screenBottomUI.printLeftTextWithBestRecord(sessionStorageManager.getBestRecord());
}).bind(this),
(function(replyJSON) { // no data
sessionStorageManager.setBestRecord(0);
screenBottomUI.printLeftTextWithBestRecord(sessionStorageManager.getBestRecord());
}).bind(this)
);
},
loadHowToPlay: function(appID) {
this.dbConnectManager.requestHowToPlay(
sessionStorageManager.getPlayingAppID(), // space_invaders app ID
(function(jsonData) {
var howToPlayText = jsonData["HowToPlay"].replace(/\\n/g, "\n");
this.howToPlay.printHowToPlay(howToPlayText);
}).bind(this),
(function(jsonData) {
this.howToPlay.printHowToPlay("No data");
}).bind(this)
);
},
loadChart: function() {
var today = new Date();
var date = DateUtil.getYYYYMMDD(today);
this.dbConnectManager.requestPlayerHistory(
sessionStorageManager.getMaestroID(),
date,
(function(historyRecordManager) {
if(historyRecordManager.count == 0) {
console.log("start - history record : no data");
return;
}
var underValue = historyRecordManager.underValueForGraph();
var upperValue = historyRecordManager.upperValueForGraph();
var minValue = underValue - (upperValue - underValue) / 10;
var maxValue = upperValue;// + (upperValue - underValue) / 10;
var countRecord = historyRecordManager.count;
for(var i = 0; i < Chart.CHART_COUNT; i++) {
// if(i > 6)
// break;
var historyRecord = historyRecordManager.getAt(i);
this.chart.drawRecordGraph(
i,
historyRecord === undefined ? "-" : historyRecord.date,
historyRecord === undefined ? "" : historyRecord.bestRecord,
minValue, maxValue
);
}
this.chart.printChartBaseLine();
}).bind(this)
);
},
calcDate: function(daysBefore) {
var date = new Date();
date.setDate(date.getDate() - daysBefore);
return date;
},
printSampleChart: function() {
var minValue = 0;
var maxValue = 1000;
this.chart.drawRecordGraph(0, DateUtil.getYYYYMMDD(this.calcDate(1)), 980, minValue, maxValue);
this.chart.drawRecordGraph(1, DateUtil.getYYYYMMDD(this.calcDate(2)), 760, minValue, maxValue);
this.chart.drawRecordGraph(2, DateUtil.getYYYYMMDD(this.calcDate(5)), 740, minValue, maxValue);
this.chart.drawRecordGraph(3, DateUtil.getYYYYMMDD(this.calcDate(7)), 690, minValue, maxValue);
this.chart.drawRecordGraph(4, DateUtil.getYYYYMMDD(this.calcDate(8)), 710, minValue, maxValue);
this.chart.drawRecordGraph(5, DateUtil.getYYYYMMDD(this.calcDate(10)), 560, minValue, maxValue);
this.chart.drawRecordGraph(6, DateUtil.getYYYYMMDD(this.calcDate(20)), 480, minValue, maxValue);
this.chart.printChartBaseLine();
},
makeStartButton: function() {
var setting = new RoundRectButtonSetting(game.world.centerX, game.world.centerY, 200, 100);
setting.fontStyle.fontWeight = "bold";
var startButton = new RoundRectButton(setting, RoundRectButton.NONE_ICON, "시작", this.startStage);
},
makeRankingButton: function() {
var setting = new RoundRectButtonSetting(game.world.centerX + 160, game.world.centerY, 60, 60);
setting.fontStyle = {
font: "18px Arial",
boundsAlignH: "center", // left, center. right
boundsAlignV: "middle", // top, middle, bottom
fill: "#fff"
};
var rankingButton = new RoundRectButton(
setting, RoundRectButton.NONE_ICON, "순위\n보기",
(function() {
location.href = '../../web/client/ranking.html';
})
);
if(sessionStorageManager.getMaestroAccountType() == 100)
rankingButton.inputEnabled = false;
},
startStage: function() {
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.getPlayingAppName() + ".html";
}
}