Fix: restructing session manager, ES6 -> ES5
This commit is contained in:
@@ -1,111 +1,104 @@
|
||||
/////////////////////////////
|
||||
// History board
|
||||
|
||||
class HistoryBoard {
|
||||
|
||||
constructor(type) {
|
||||
if(type === RecordBoard.TYPE_SAMPLE) {
|
||||
this.printSample();
|
||||
return;
|
||||
}
|
||||
|
||||
this.todayBestRecord = 0;
|
||||
|
||||
this.dbConnectManager = new DBConnectManager();
|
||||
|
||||
let arrayTabStyle = { font: "20px Arial", fill: "#fff", align: "left", tabs: [ 40, 80, 120 ] };
|
||||
|
||||
let posX = 40;
|
||||
let posY = game.world.height / 2 - 10;
|
||||
this.textMyRanking = game.add.text(posX, posY + 100, '', arrayTabStyle)
|
||||
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||
|
||||
let today = new Date();
|
||||
let date = DateUtil.getYYYYMMDD(today);
|
||||
this.dbConnectManager.requestPlayerHistory(
|
||||
sessionStorageManager.maestroID,
|
||||
date,
|
||||
(function(historyRecordManager) {
|
||||
if(historyRecordManager.count == 0) {
|
||||
console.log("history board - no data");
|
||||
return;
|
||||
}
|
||||
|
||||
for(let i = 0; i < historyRecordManager.count; i++) {
|
||||
let data = historyRecordManager.getAt(i);
|
||||
this.printRecord(i, data.date, data.bestRecord);
|
||||
|
||||
if(date == data.date)
|
||||
this.todayBestRecord = data.bestRecord;
|
||||
}
|
||||
})
|
||||
);
|
||||
function HistoryBoard(type) {
|
||||
if(type === RecordBoard.TYPE_SAMPLE) {
|
||||
this.printSample();
|
||||
return;
|
||||
}
|
||||
|
||||
calcDate(daysBefore) {
|
||||
let date = new Date();
|
||||
date.setDate(date.getDate() - daysBefore);
|
||||
return date;
|
||||
}
|
||||
this.todayBestRecord = 0;
|
||||
|
||||
this.dbConnectManager = new DBConnectManager();
|
||||
|
||||
var arrayTabStyle = { font: "20px Arial", fill: "#fff", align: "left", tabs: [ 40, 80, 120 ] };
|
||||
|
||||
var posX = 40;
|
||||
var posY = game.world.height / 2 - 10;
|
||||
this.textMyRanking = game.add.text(posX, posY + 100, '', arrayTabStyle)
|
||||
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||
|
||||
var today = new Date();
|
||||
var date = DateUtil.getYYYYMMDD(today);
|
||||
this.dbConnectManager.requestPlayerHistory(
|
||||
sessionStorageManager.getMaestroID(),
|
||||
date,
|
||||
(function(historyRecordManager) {
|
||||
if(historyRecordManager.getCount() == 0) {
|
||||
console.log("history board - no data");
|
||||
return;
|
||||
}
|
||||
|
||||
for(var i = 0; i < historyRecordManager.getCount(); i++) {
|
||||
var data = historyRecordManager.getAt(i);
|
||||
this.printRecord(i, data.date, data.bestRecord);
|
||||
|
||||
if(date == data.date)
|
||||
this.todayBestRecord = data.bestRecord;
|
||||
}
|
||||
}).bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
HistoryBoard.prototype.calcDate = function(daysBefore) {
|
||||
var date = new Date();
|
||||
date.setDate(date.getDate() - daysBefore);
|
||||
return date;
|
||||
}
|
||||
|
||||
|
||||
printRecord(index, date, bestRecord) {
|
||||
if(sessionStorageManager.playingAppName.indexOf("typing") < 0)
|
||||
this.printMouseAppHistory(index, date, bestRecord);
|
||||
else
|
||||
this.printTypingAppHistory(index, date, appName, bestRecord);
|
||||
}
|
||||
HistoryBoard.prototype.printRecord = function(index, date, bestRecord) {
|
||||
if(sessionStorageManager.getPlayingAppName().indexOf("typing") < 0)
|
||||
this.printMouseAppHistory(index, date, bestRecord);
|
||||
else
|
||||
this.printTypingAppHistory(index, date, appName, bestRecord);
|
||||
}
|
||||
|
||||
printMouseAppHistory(index, date, bestRecord) {
|
||||
let posX = 60;
|
||||
let posY = game.world.height / 2 + 90 + 30 * index;
|
||||
HistoryBoard.prototype.printMouseAppHistory = function(index, date, bestRecord) {
|
||||
var posX = 60;
|
||||
var posY = game.world.height / 2 + 90 + 30 * index;
|
||||
|
||||
var style = { font: "20px Arial", fill: "#ffc", align: "right", boundsAlignH: "right", boundsAlignV: "top" };
|
||||
var style = { font: "20px Arial", fill: "#ffc", align: "right", boundsAlignH: "right", boundsAlignV: "top" };
|
||||
|
||||
style.boundsAlignH = "center";
|
||||
game.add.text(posX, posY, StringUtil.printMonthDay(date), style)
|
||||
.setTextBounds(0, 0, 100, 60)
|
||||
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||
style.boundsAlignH = "center";
|
||||
game.add.text(posX, posY, StringUtil.printMonthDay(date), style)
|
||||
.setTextBounds(0, 0, 100, 60)
|
||||
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||
|
||||
style.boundsAlignH = "right";
|
||||
game.add.text(posX + 80, posY, StringUtil.getRecordTextWithoutUnit(bestRecord), style)
|
||||
.setTextBounds(0, 0, 100, 60)
|
||||
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||
}
|
||||
style.boundsAlignH = "right";
|
||||
game.add.text(posX + 80, posY, StringUtil.getRecordTextWithoutUnit(bestRecord), style)
|
||||
.setTextBounds(0, 0, 100, 60)
|
||||
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||
}
|
||||
|
||||
printTypingAppHistory(index, date, appName, bestRecord) {
|
||||
let posX = 60;
|
||||
let posY = game.world.height / 2 + 90 + 30 * index;
|
||||
HistoryBoard.prototype.printTypingAppHistory = function(index, date, appName, bestRecord) {
|
||||
var posX = 60;
|
||||
var posY = game.world.height / 2 + 90 + 30 * index;
|
||||
|
||||
var style = { font: "20px Arial", fill: "#ffc", align: "right", boundsAlignH: "right", boundsAlignV: "top" };
|
||||
var style = { font: "20px Arial", fill: "#ffc", align: "right", boundsAlignH: "right", boundsAlignV: "top" };
|
||||
|
||||
style.boundsAlignH = "center";
|
||||
game.add.text(posX, posY, date, style)
|
||||
.setTextBounds(0, 0, 40, 40)
|
||||
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||
style.boundsAlignH = "center";
|
||||
game.add.text(posX, posY, date, style)
|
||||
.setTextBounds(0, 0, 40, 40)
|
||||
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||
|
||||
game.add.text(posX + 60, posY, appName, style)
|
||||
.setTextBounds(0, 0, 60, 60)
|
||||
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||
game.add.text(posX + 60, posY, appName, style)
|
||||
.setTextBounds(0, 0, 60, 60)
|
||||
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||
|
||||
style.boundsAlignH = "right";
|
||||
game.add.text(posX + 120, posY, StringUtil.getRecordTextWithoutUnit(bestRecord), style)
|
||||
.setTextBounds(0, 0, 80, 60)
|
||||
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||
}
|
||||
style.boundsAlignH = "right";
|
||||
game.add.text(posX + 120, posY, StringUtil.getRecordTextWithoutUnit(bestRecord), style)
|
||||
.setTextBounds(0, 0, 80, 60)
|
||||
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||
}
|
||||
|
||||
printSample() {
|
||||
this.printRecord(0, DateUtil.getYYYYMMDD(this.calcDate(2)), 1270);
|
||||
this.printRecord(1, DateUtil.getYYYYMMDD(this.calcDate(3)), 1150);
|
||||
this.printRecord(2, DateUtil.getYYYYMMDD(this.calcDate(5)), 1080);
|
||||
this.printRecord(3, DateUtil.getYYYYMMDD(this.calcDate(7)), 960);
|
||||
this.printRecord(4, DateUtil.getYYYYMMDD(this.calcDate(10)), 1020);
|
||||
this.printRecord(5, DateUtil.getYYYYMMDD(this.calcDate(15)), 840);
|
||||
this.printRecord(6, DateUtil.getYYYYMMDD(this.calcDate(20)), 760);
|
||||
}
|
||||
|
||||
todayBestRecord() {
|
||||
return this.todayBestRecord;
|
||||
}
|
||||
HistoryBoard.prototype.printSample = function() {
|
||||
this.printRecord(0, DateUtil.getYYYYMMDD(this.calcDate(2)), 1270);
|
||||
this.printRecord(1, DateUtil.getYYYYMMDD(this.calcDate(3)), 1150);
|
||||
this.printRecord(2, DateUtil.getYYYYMMDD(this.calcDate(5)), 1080);
|
||||
this.printRecord(3, DateUtil.getYYYYMMDD(this.calcDate(7)), 960);
|
||||
this.printRecord(4, DateUtil.getYYYYMMDD(this.calcDate(10)), 1020);
|
||||
this.printRecord(5, DateUtil.getYYYYMMDD(this.calcDate(15)), 840);
|
||||
this.printRecord(6, DateUtil.getYYYYMMDD(this.calcDate(20)), 760);
|
||||
}
|
||||
|
||||
HistoryBoard.prototype.todayBestRecord = function() {
|
||||
return this.todayBestRecord;
|
||||
}
|
||||
Reference in New Issue
Block a user