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
+88 -95
View File
@@ -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;
}
+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);
}
+45 -51
View File
@@ -1,58 +1,52 @@
/////////////////////////////
// Record board
function RecordBoard(type) {
this.chartGraphics = game.add.graphics(0, 0);
class RecordBoard {
constructor(type) {
this.chartGraphics = game.add.graphics(0, 0);
this.printRecordBoardHeader();
this.printSeperator();
let historyBoard = new HistoryBoard(type);
let rankingBoard = new RankingBoard(type);
}
printRecordBoardHeader() {
let posX = 60;
let posY = game.world.height / 2 + 20;
var bar = game.add.graphics();
bar.beginFill(0x444444);
bar.drawRect(0, posY, game.world.width, RecordBoard.HEADER_BAR_HEIGHT_PX);
const style = { font: "32px Arial", fill: "#ffc", align: "left", boundsAlignH: "center", boundsAlignV: "middle" };
this.printHeader(posX, posY, "최근의 내 기록", style);
posX = 320;
style.fill = "#fff";
this.printHeader(posX, posY, "수업시간 순위", style);
posX = 550;
this.printHeader(posX, posY, "오늘의 순위", style);
posX = 770;
this.printHeader(posX, posY, "이달의 순위", style);
}
printHeader(x, y, title, style) {
game.add.text(x, y, title, style)
.setTextBounds(0, 0, 200, RecordBoard.HEADER_BAR_HEIGHT_PX)
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
}
printSeperator() {
const posX = 290;
const posY = 480;
this.chartGraphics.lineStyle(3, 0x444444, 1);
this.chartGraphics.moveTo(posX, posY);
this.chartGraphics.lineTo(posX, posY + 200);
}
this.printRecordBoardHeader();
this.printSeperator();
var historyBoard = new HistoryBoard(type);
var rankingBoard = new RankingBoard(type);
}
RecordBoard.prototype.printRecordBoardHeader = function() {
var posX = 60;
var posY = game.world.height / 2 + 20;
var bar = game.add.graphics();
bar.beginFill(0x444444);
bar.drawRect(0, posY, game.world.width, RecordBoard.HEADER_BAR_HEIGHT_PX);
const style = { font: "32px Arial", fill: "#ffc", align: "left", boundsAlignH: "center", boundsAlignV: "middle" };
this.printHeader(posX, posY, "최근의 내 기록", style);
posX = 320;
style.fill = "#fff";
this.printHeader(posX, posY, "수업시간 순위", style);
posX = 550;
this.printHeader(posX, posY, "오늘의 순위", style);
posX = 770;
this.printHeader(posX, posY, "이달의 순위", style);
}
RecordBoard.prototype.printHeader = function(x, y, title, style) {
game.add.text(x, y, title, style)
.setTextBounds(0, 0, 200, RecordBoard.HEADER_BAR_HEIGHT_PX)
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
}
RecordBoard.prototype.printSeperator = function() {
const posX = 290;
const posY = 480;
this.chartGraphics.lineStyle(3, 0x444444, 1);
this.chartGraphics.moveTo(posX, posY);
this.chartGraphics.lineTo(posX, posY + 200);
}
RecordBoard.HEADER_BAR_HEIGHT_PX = 60;
RecordBoard.TYPE_SAMPLE = "sample";
+61 -64
View File
@@ -1,25 +1,22 @@
/////////////////////////////
// Result
var Result = {
class Result {
preload() {
preload: function() {
game.load.image('icon_fullscreen', '../../../resources/image/icon/fullscreen_white.png');
Animal.loadResources();
RankingBoard.loadResources();
game.load.image('star', '../../../resources/image/ui/star_particle.png');
}
},
create() {
create: function() {
this.dbConnectManager = new DBConnectManager();
this.game.stage.backgroundColor = '#4d4d4d';
this.chartGraphics = game.add.graphics(100, game.world.height - 120);
// top ui
let screenTopUI = new ScreenTopUI();
var screenTopUI = new ScreenTopUI();
screenTopUI.makeBackButton( function() {
if(isTypingPracticeStage())
location.href = '../../web/client/menu_typing_practice.html';
@@ -39,126 +36,126 @@ class Result {
this.makeRestartButton();
if(sessionStorageManager.maestroAccountType >= 100) { // experience account
let recordBoard = new RecordBoard(RecordBoard.TYPE_SAMPLE);
if(sessionStorageManager.getMaestroAccountType() >= 100) { // experience account
var recordBoard = new RecordBoard(RecordBoard.TYPE_SAMPLE);
this.announceBox = new AnnounceBox(50, 648);
this.announceBox.drawBox("체험 계정에서는 기록이 저장되지 않습니다.");
} else {
let recordBoard = new RecordBoard(RecordBoard.TYPE_DB);
var recordBoard = new RecordBoard(RecordBoard.TYPE_DB);
this.printTodayBestRecord();
}
// bottom ui
let screenBottomUI = new ScreenBottomUI();
screenBottomUI.printLeftTextWithBestRecord(Math.floor(sessionStorageManager.bestRecord));
screenBottomUI.printCenterText(sessionStorageManager.playingAppKoreanName);
screenBottomUI.printRightText(sessionStorageManager.playerName);
}
var screenBottomUI = new ScreenBottomUI();
screenBottomUI.printLeftTextWithBestRecord(Math.floor(sessionStorageManager.getBestRecord()));
screenBottomUI.printCenterText(sessionStorageManager.getPlayingAppKoreanName());
screenBottomUI.printRightText(sessionStorageManager.getPlayerName());
},
printRecord() {
printRecord: function() {
const style = { font: "bold 38px Arial", fill: "#fff", align: "left", boundsAlignH: "center", boundsAlignV: "middle" };
let titleText = game.add.text(game.world.width / 2, 35, "결과", style);
var titleText = game.add.text(game.world.width / 2, 35, "결과", style);
titleText.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
titleText.anchor.set(0.5);
let x = game.world.width / 2;
let y = 150;
if(sessionStorageManager.record === null)
sessionStorageManager.record = 0;
let record = NumberUtil.numberWithCommas(Math.floor(sessionStorageManager.record));
var x = game.world.width / 2;
var y = 150;
if(sessionStorageManager.getRecord() === null)
sessionStorageManager.setRecord(0);
var record = NumberUtil.numberWithCommas(Math.floor(sessionStorageManager.getRecord()));
style.font = "80px Arial";
if(sessionStorageManager.playingAppID < 100) {
let leftAnimal = new Animal(Animal.TYPE_ANIMATION, game.world.centerX - 200, 150);
let animalLevelID = 0;
if(sessionStorageManager.playingAppID < 20)
animalLevelID = Animal.animalLevelIDByRecord(sessionStorageManager.record, Animal.TYPE_PRACTICE);
if(sessionStorageManager.getPlayingAppID() < 100) {
var leftAnimal = new Animal(Animal.TYPE_ANIMATION, game.world.centerX - 200, 150);
var animalLevelID = 0;
if(sessionStorageManager.getPlayingAppID() < 20)
animalLevelID = Animal.animalLevelIDByRecord(sessionStorageManager.getRecord(), Animal.TYPE_PRACTICE);
else
animalLevelID = Animal.animalLevelIDByRecord(sessionStorageManager.record, Animal.TYPE_TEST);
animalLevelID = Animal.animalLevelIDByRecord(sessionStorageManager.getRecord(), Animal.TYPE_TEST);
leftAnimal.setSpecies(Animal.SPECIES_DATA[animalLevelID]);;
// leftAnimal.tweenAnimation(Animal.ANIMATION_TYPE_CHANGE);
leftAnimal.startAnimation();
let rightAnimal = new Animal(Animal.TYPE_ANIMATION, game.world.centerX + 200, 150);
var rightAnimal = new Animal(Animal.TYPE_ANIMATION, game.world.centerX + 200, 150);
rightAnimal.setSpecies(Animal.SPECIES_DATA[animalLevelID]);;
// rightAnimal.tweenAnimation(Animal.ANIMATION_TYPE_CHANGE);
rightAnimal.startAnimation();
}
let scoreText = game.add.text(
var scoreText = game.add.text(
x, y,
record + StringUtil.getScoreUnit(sessionStorageManager.playingAppID),
record + StringUtil.getScoreUnit(sessionStorageManager.getPlayingAppID()),
style
);
scoreText.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
scoreText.anchor.set(0.5);
}
},
recordUnit() {
let recordUnit = "";
if(sessionStorageManager.playingAppID >= 100)
recordUnit: function() {
var recordUnit = "";
if(sessionStorageManager.getPlayingAppID() >= 100)
return "점";
else
return "타";
}
},
printTodayBestRecord() {
let newRecordEmitter = game.add.emitter(game.world.centerX, 140, 300);
printTodayBestRecord: function() {
var newRecordEmitter = game.add.emitter(game.world.centerX, 140, 300);
newRecordEmitter.makeParticles('star');
newRecordEmitter.gravity = 300;
let style = { font: "32px Arial", fill: "#ff0", align: "left", boundsAlignH: "center", boundsAlignV: "middle" };
let bestRecordText = game.add.text(game.world.centerX, 220, "", style);
var style = { font: "32px Arial", fill: "#ff0", align: "left", boundsAlignH: "center", boundsAlignV: "middle" };
var bestRecordText = game.add.text(game.world.centerX, 220, "", style);
bestRecordText.anchor.set(0.5);
bestRecordText.stroke = "#333";
bestRecordText.strokeThickness = 5;
if(sessionStorageManager.bestRecord === null)
sessionStorageManager.bestRecord = 0;
if(sessionStorageManager.getBestRecord() === 'undefined')
sessionStorageManager.setBestRecord(0);
let todayBestRecord = 0;
let flooredBestRecord = Math.floor(sessionStorageManager.bestRecord);
let bestRecordWithCommas = NumberUtil.numberWithCommas(flooredBestRecord);
var todayBestRecord = 0;
var flooredBestRecord = Math.floor(sessionStorageManager.getBestRecord());
var bestRecordWithCommas = NumberUtil.numberWithCommas(flooredBestRecord);
if(sessionStorageManager.record >= sessionStorageManager.bestRecord) {
sessionStorageManager.bestRecord = sessionStorageManager.record;
if(sessionStorageManager.getRecord() >= sessionStorageManager.getBestRecord()) {
sessionStorageManager.setBestRecord(sessionStorageManager.getRecord());
bestRecordText.text = "! : . 오늘 최고 기록 . : !";
newRecordEmitter.start(true, 2000, null, 20);
} else {
bestRecordText.text = "";
}
}
},
uploadRecord() {
if(sessionStorageManager.maestroAccountType >= 100) { // experience account
uploadRecord: function() {
if(sessionStorageManager.getMaestroAccountType() >= 100) { // experience account
return;
}
this.dbConnectManager.updateTodayBestRecord(
sessionStorageManager.maestroID,
sessionStorageManager.playerID,
sessionStorageManager.playingAppID,
sessionStorageManager.record
sessionStorageManager.getMaestroID(),
sessionStorageManager.getPlayerID(),
sessionStorageManager.getPlayingAppID(),
sessionStorageManager.getRecord()
);
}
},
makeRestartButton() {
let setting = new RoundRectButtonSetting(game.world.centerX, game.world.height / 2 - 70, 200, 100);
makeRestartButton: function() {
var setting = new RoundRectButtonSetting(game.world.centerX, game.world.height / 2 - 70, 200, 100);
setting.fontStyle.fontWeight = "bold";
let startButton = new RoundRectButton(setting, RoundRectButton.NONE_ICON, "다시 시작", this.restartStage);
}
var startButton = new RoundRectButton(setting, RoundRectButton.NONE_ICON, "다시 시작", this.restartStage);
},
restartStage() {
if(sessionStorageManager.playingAppName.indexOf("practice_") == 0) {
restartStage: function() {
if(sessionStorageManager.getPlayingAppName().indexOf("practice_") == 0) {
location.href = "../../web/client/typing_practice.html";
} else if(sessionStorageManager.playingAppName.indexOf("test_") == 0) {
} else if(sessionStorageManager.getPlayingAppName().indexOf("test_") == 0) {
location.href = "../../web/client/typing_test.html";
} else {
location.href = "../../web/client/" + sessionStorageManager.playingAppName + ".html";
location.href = "../../web/client/" + sessionStorageManager.getPlayingAppName() + ".html";
}
}