Fix: restructing session manager, ES6 -> ES5

This commit is contained in:
2018-09-14 22:22:22 +09:00
parent 72e7c1a28f
commit 3f340535ac
44 changed files with 3100 additions and 3262 deletions
+231 -238
View File
@@ -1,268 +1,261 @@
/////////////////////////////
// Ranking board
class RankingBoard {
constructor(type) {
if(type === RecordBoard.TYPE_SAMPLE) {
this.printSample();
return;
}
this.makeMedalSprites();
this.dbConnectManager = new DBConnectManager();
this.requestRanking(DBConnectManager.TYPE_MY_RANKING_HOUR);
this.requestRanking(DBConnectManager.TYPE_MY_RANKING_DAY);
this.requestRanking(DBConnectManager.TYPE_MY_RANKING_MONTH);
function RankingBoard(type) {
if(type === RecordBoard.TYPE_SAMPLE) {
this.printSample();
return;
}
this.makeMedalSprites();
requestRanking(type) {
let today = new Date();
let date = DateUtil.getYYYYMMDD(today);
let time = DateUtil.getHHMMSS(today);
this.dbConnectManager.requestRanking(
type, sessionStorageManager.maestroID, date, time,
(type, rankingRecordManager) => {
if(rankingRecordManager.count == 0) {
console.log("ranking board - no data");
return;
}
this.dbConnectManager = new DBConnectManager();
this.requestRanking(DBConnectManager.TYPE_MY_RANKING_HOUR);
this.requestRanking(DBConnectManager.TYPE_MY_RANKING_DAY);
this.requestRanking(DBConnectManager.TYPE_MY_RANKING_MONTH);
}
let beginIndex = this.getBeginIndex(rankingRecordManager);
let endIndex = this.getEndIndex(rankingRecordManager);
for(let i = 0; i < endIndex - beginIndex; i++) {
let index = beginIndex + i;
let data = rankingRecordManager.getAt(index);
this.printRecord(type, i, data);
}
switch(type) {
case DBConnectManager.TYPE_MY_RANKING_HOUR:
this.showMedal(this.medalHour, this.getMyRank(rankingRecordManager));
break;
case DBConnectManager.TYPE_MY_RANKING_DAY:
this.showMedal(this.medalDay, this.getMyRank(rankingRecordManager));
break;
case DBConnectManager.TYPE_MY_RANKING_MONTH:
this.showMedal(this.medalMonth, this.getMyRank(rankingRecordManager));
break;
}
RankingBoard.prototype.requestRanking = function(type) {
var today = new Date();
var date = DateUtil.getYYYYMMDD(today);
var time = DateUtil.getHHMMSS(today);
this.dbConnectManager.requestRanking(
type, sessionStorageManager.getMaestroID(), date, time,
(function(type, rankingRecordManager) {
if(rankingRecordManager.getCount() == 0) {
console.log("ranking board - no data");
return;
}
);
}
getMyRank(rankingRecordManager) {
let playerID = Number(sessionStorageManager.playerID);
var beginIndex = this.getBeginIndex(rankingRecordManager);
var endIndex = this.getEndIndex(rankingRecordManager);
for(let i = 0; i < rankingRecordManager.count; i++) {
let data = rankingRecordManager.getAt(i);
let playerIDNo = Number(data["playerID"]);
if(playerIDNo === playerID)
return i + 1;
}
return -1;
}
getBeginIndex(rankingRecordManager) {
let rankingRecordCount = rankingRecordManager.count;
let myRank = this.getMyRank(rankingRecordManager);
let myRankIndex = myRank - 1;
let startIndex = 0;
let endIndex = rankingRecordCount;
if(rankingRecordCount > 7) {
if(myRank < rankingRecordCount - 3) { // my rank is better than the worst 3
if(myRank < 5) {
startIndex = 0;
endIndex = rankingRecordCount > 7 ? 7 : rankingRecordCount;
} else {
startIndex = myRankIndex - 3;
endIndex = myRankIndex + 4;
}
} else { // my rank is in the worst 3
startIndex = rankingRecordCount > 7 ? rankingRecordCount - 7 : 0;
endIndex = rankingRecordCount;
for(var i = 0; i < endIndex - beginIndex; i++) {
var index = beginIndex + i;
var data = rankingRecordManager.getAt(index);
this.printRecord(type, i, data);
}
}
return startIndex;
}
switch(type) {
case DBConnectManager.TYPE_MY_RANKING_HOUR:
this.showMedal(this.medalHour, this.getMyRank(rankingRecordManager));
break;
getEndIndex(rankingRecordManager) {
let rankingRecordCount = rankingRecordManager.count;
let myRank = this.getMyRank(rankingRecordManager);
let myRankIndex = myRank - 1;
case DBConnectManager.TYPE_MY_RANKING_DAY:
this.showMedal(this.medalDay, this.getMyRank(rankingRecordManager));
break;
case DBConnectManager.TYPE_MY_RANKING_MONTH:
this.showMedal(this.medalMonth, this.getMyRank(rankingRecordManager));
break;
let startIndex = 0;
let endIndex = rankingRecordCount;
if(rankingRecordCount > 7) {
if(myRank < rankingRecordCount - 3) { // my rank is better than the worst 3
if(myRank < 5) {
startIndex = 0;
endIndex = rankingRecordCount > 7 ? 7 : rankingRecordCount;
} else {
startIndex = myRankIndex - 3;
endIndex = myRankIndex + 4;
}
} else { // my rank is in the worst 3
startIndex = rankingRecordCount > 7 ? rankingRecordCount - 7 : 0;
endIndex = rankingRecordCount;
}
}).bind(this)
);
}
RankingBoard.prototype.getMyRank = function(rankingRecordManager) {
var playerID = Number(sessionStorageManager.getPlayerID());
for(var i = 0; i < rankingRecordManager.getCount(); i++) {
var data = rankingRecordManager.getAt(i);
var playerIDNo = Number(data["playerID"]);
if(playerIDNo === playerID)
return i + 1;
}
return -1;
}
RankingBoard.prototype.getBeginIndex = function(rankingRecordManager) {
var rankingRecordCount = rankingRecordManager.getCount();
var myRank = this.getMyRank(rankingRecordManager);
var myRankIndex = myRank - 1;
var startIndex = 0;
var endIndex = rankingRecordCount;
if(rankingRecordCount > 7) {
if(myRank < rankingRecordCount - 3) { // my rank is better than the worst 3
if(myRank < 5) {
startIndex = 0;
endIndex = rankingRecordCount > 7 ? 7 : rankingRecordCount;
} else {
startIndex = myRankIndex - 3;
endIndex = myRankIndex + 4;
}
} else { // my rank is in the worst 3
startIndex = rankingRecordCount > 7 ? rankingRecordCount - 7 : 0;
endIndex = rankingRecordCount;
}
return endIndex;
}
return startIndex;
}
printRecord(type, index, data) {
var style = { font: "20px Arial", fill: "#fff", align: "right", boundsAlignH: "right", boundsAlignV: "top" };
RankingBoard.prototype.getEndIndex = function(rankingRecordManager) {
var rankingRecordCount = rankingRecordManager.getCount();
var myRank = this.getMyRank(rankingRecordManager);
var myRankIndex = myRank - 1;
// rank
style.boundsAlignH = "right";
let rankText = game.add.text(this.getPosX(type), this.getPosY(index), data.rank, style);
// .setTextBounds(0, 0, 40, 40)
rankText.anchor.set(1, 0);
rankText.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
// player name
let playerNameText = game.add.text(this.getPosX(type) + 20, this.getPosY(index), data.playerName, style);
// .setTextBounds(0, 0, 60, 60)
playerNameText.anchor.set(0, 0);
playerNameText.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
// bestRecord
let bestRecord = StringUtil.getRecordTextWithoutUnit(data.bestRecord);
style.boundsAlignH = "right";
let recordText = game.add.text(this.getPosX(type) + 180, this.getPosY(index), bestRecord, style);
// .setTextBounds(0, 0, 80, 60)
recordText.anchor.set(1, 0);
recordText.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
}
getPosX(type) {
let posX = 0;
switch(type) {
case DBConnectManager.TYPE_MY_RANKING_HOUR:
case DBConnectManager.TYPE_ALL_RANKING_HOUR:
posX = 330;
break;
case DBConnectManager.TYPE_MY_RANKING_DAY:
case DBConnectManager.TYPE_ALL_RANKING_DAY:
posX = 560;
break;
case DBConnectManager.TYPE_MY_RANKING_MONTH:
case DBConnectManager.TYPE_ALL_RANKING_MONTH:
posX = 790;
var startIndex = 0;
var endIndex = rankingRecordCount;
if(rankingRecordCount > 7) {
if(myRank < rankingRecordCount - 3) { // my rank is better than the worst 3
if(myRank < 5) {
startIndex = 0;
endIndex = rankingRecordCount > 7 ? 7 : rankingRecordCount;
} else {
startIndex = myRankIndex - 3;
endIndex = myRankIndex + 4;
}
} else { // my rank is in the worst 3
startIndex = rankingRecordCount > 7 ? rankingRecordCount - 7 : 0;
endIndex = rankingRecordCount;
}
return posX;
}
getPosY(index) {
return game.world.height / 2 + 90 + 30 * index;
return endIndex;
}
RankingBoard.prototype.printRecord = function(type, index, data) {
var style = { font: "20px Arial", fill: "#fff", align: "right", boundsAlignH: "right", boundsAlignV: "top" };
// rank
style.boundsAlignH = "right";
var rankText = game.add.text(this.getPosX(type), this.getPosY(index), data.rank, style);
// .setTextBounds(0, 0, 40, 40)
rankText.anchor.set(1, 0);
rankText.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
// player name
var playerNameText = game.add.text(this.getPosX(type) + 20, this.getPosY(index), data.playerName, style);
// .setTextBounds(0, 0, 60, 60)
playerNameText.anchor.set(0, 0);
playerNameText.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
// bestRecord
var bestRecord = StringUtil.getRecordTextWithoutUnit(data.bestRecord);
style.boundsAlignH = "right";
var recordText = game.add.text(this.getPosX(type) + 180, this.getPosY(index), bestRecord, style);
// .setTextBounds(0, 0, 80, 60)
recordText.anchor.set(1, 0);
recordText.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
}
RankingBoard.prototype.getPosX = function(type) {
var posX = 0;
switch(type) {
case DBConnectManager.TYPE_MY_RANKING_HOUR:
case DBConnectManager.TYPE_ALL_RANKING_HOUR:
posX = 330;
break;
case DBConnectManager.TYPE_MY_RANKING_DAY:
case DBConnectManager.TYPE_ALL_RANKING_DAY:
posX = 560;
break;
case DBConnectManager.TYPE_MY_RANKING_MONTH:
case DBConnectManager.TYPE_ALL_RANKING_MONTH:
posX = 790;
}
printSample() {
// TYPE_MY_RANKING_HOUR
this.printRecord(
DBConnectManager.TYPE_MY_RANKING_HOUR, 0,
new RankingRecord(1, 0, "홍길동", 1080)
);
this.printRecord(
DBConnectManager.TYPE_MY_RANKING_HOUR, 1,
new RankingRecord(2, 0, "3-1김영희", 860)
);
this.printRecord(
DBConnectManager.TYPE_MY_RANKING_HOUR, 2,
new RankingRecord(3, 0, "6-3이철수", 480)
);
return posX;
}
RankingBoard.prototype.getPosY = function(index) {
return game.world.height / 2 + 90 + 30 * index;
}
RankingBoard.prototype.printSample = function() {
// TYPE_MY_RANKING_HOUR
this.printRecord(
DBConnectManager.TYPE_MY_RANKING_HOUR, 0,
new RankingRecord(1, 0, "홍길동", 1080)
);
this.printRecord(
DBConnectManager.TYPE_MY_RANKING_HOUR, 1,
new RankingRecord(2, 0, "3-1김영희", 860)
);
this.printRecord(
DBConnectManager.TYPE_MY_RANKING_HOUR, 2,
new RankingRecord(3, 0, "6-3이철수", 480)
);
// TYPE_MY_RANKING_DAY
this.printRecord(
DBConnectManager.TYPE_MY_RANKING_DAY, 0,
new RankingRecord(1, 0, "050215", 1580)
);
this.printRecord(
DBConnectManager.TYPE_MY_RANKING_DAY, 1,
new RankingRecord(2, 0, "홍길동", 1080)
);
this.printRecord(
DBConnectManager.TYPE_MY_RANKING_DAY, 2,
new RankingRecord(3, 0, "3-1김영희", 860)
);
this.printRecord(
DBConnectManager.TYPE_MY_RANKING_DAY, 3,
new RankingRecord(4, 0, "6-3이철수", 480)
);
// TYPE_MY_RANKING_DAY
this.printRecord(
DBConnectManager.TYPE_MY_RANKING_DAY, 0,
new RankingRecord(1, 0, "050215", 1580)
);
this.printRecord(
DBConnectManager.TYPE_MY_RANKING_DAY, 1,
new RankingRecord(2, 0, "홍길동", 1080)
);
this.printRecord(
DBConnectManager.TYPE_MY_RANKING_DAY, 2,
new RankingRecord(3, 0, "3-1김영희", 860)
);
this.printRecord(
DBConnectManager.TYPE_MY_RANKING_DAY, 3,
new RankingRecord(4, 0, "6-3이철수", 480)
);
// TYPE_MY_RANKING_MONTH
this.printRecord(
DBConnectManager.TYPE_MY_RANKING_MONTH, 0,
new RankingRecord(1, 0, "050215", 1580)
);
this.printRecord(
DBConnectManager.TYPE_MY_RANKING_MONTH, 1,
new RankingRecord(2, 0, "홍길동", 1080)
);
this.printRecord(
DBConnectManager.TYPE_MY_RANKING_MONTH, 2,
new RankingRecord(3, 0, "3-1김영희", 860)
);
this.printRecord(
DBConnectManager.TYPE_MY_RANKING_MONTH, 3,
new RankingRecord(4, 0, "6-3이철수", 480)
);
// TYPE_MY_RANKING_MONTH
this.printRecord(
DBConnectManager.TYPE_MY_RANKING_MONTH, 0,
new RankingRecord(1, 0, "050215", 1580)
);
this.printRecord(
DBConnectManager.TYPE_MY_RANKING_MONTH, 1,
new RankingRecord(2, 0, "홍길동", 1080)
);
this.printRecord(
DBConnectManager.TYPE_MY_RANKING_MONTH, 2,
new RankingRecord(3, 0, "3-1김영희", 860)
);
this.printRecord(
DBConnectManager.TYPE_MY_RANKING_MONTH, 3,
new RankingRecord(4, 0, "6-3이철수", 480)
);
}
RankingBoard.loadResources = function() {
game.load.image('medal_gold', '../../../resources/image/ui/medal_gold.png');
game.load.image('medal_silver', '../../../resources/image/ui/medal_silver.png');
game.load.image('medal_bronze', '../../../resources/image/ui/medal_bronze.png');
}
RankingBoard.prototype.makeMedalSprites = function() {
var rankAreaPositionY = 630;
this.medalHour = game.add.image(425, rankAreaPositionY, 'medal_gold');
this.medalHour.anchor.set(0.5);
this.medalHour.alpha = 0;
this.medalDay = game.add.image(655, rankAreaPositionY, 'medal_gold');
this.medalDay.anchor.set(0.5);
this.medalDay.alpha = 0;
this.medalMonth = game.add.image(885, rankAreaPositionY, 'medal_gold');
this.medalMonth.anchor.set(0.5);
this.medalMonth.alpha = 0;
}
RankingBoard.prototype.showMedal = function(medal, myRank) {
if(myRank > 3) {
medal.alpha = 0;
return;
}
if(myRank == 1)
medal.loadTexture("medal_gold");
else if(myRank == 2)
medal.loadTexture("medal_silver");
else if(myRank == 3)
medal.loadTexture("medal_bronze");
static loadResources() {
game.load.image('medal_gold', '../../../resources/image/ui/medal_gold.png');
game.load.image('medal_silver', '../../../resources/image/ui/medal_silver.png');
game.load.image('medal_bronze', '../../../resources/image/ui/medal_bronze.png');
}
makeMedalSprites() {
let rankAreaPositionY = 630;
this.medalHour = game.add.image(425, rankAreaPositionY, 'medal_gold');
this.medalHour.anchor.set(0.5);
this.medalHour.alpha = 0;
this.medalDay = game.add.image(655, rankAreaPositionY, 'medal_gold');
this.medalDay.anchor.set(0.5);
this.medalDay.alpha = 0;
this.medalMonth = game.add.image(885, rankAreaPositionY, 'medal_gold');
this.medalMonth.anchor.set(0.5);
this.medalMonth.alpha = 0;
}
showMedal(medal, myRank) {
if(myRank > 3) {
medal.alpha = 0;
return;
}
if(myRank == 1)
medal.loadTexture("medal_gold");
else if(myRank == 2)
medal.loadTexture("medal_silver");
else if(myRank == 3)
medal.loadTexture("medal_bronze");
medal.alpha = 1;
medal.scale.setTo(0.5);
game.add.tween(medal.scale).to( {x: 0.7, y: 0.7}, 1000, Phaser.Easing.Bounce.Out, true);
}
medal.alpha = 1;
medal.scale.setTo(0.5);
game.add.tween(medal.scale).to( {x: 0.7, y: 0.7}, 1000, Phaser.Easing.Bounce.Out, true);
}