Fix: print ranking list with my rank
This commit is contained in:
@@ -7,25 +7,87 @@ class RankingBoard {
|
||||
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);
|
||||
this.requestRanking(DBConnectManager.TYPE_MY_RANKING_DAY);
|
||||
this.requestRanking(DBConnectManager.TYPE_MY_RANKING_MONTH);
|
||||
}
|
||||
|
||||
|
||||
requestRanking(type, rankingRecordManager) {
|
||||
this.dbConnectManager.requestRanking(type, (type, rankingRecordManager) => {
|
||||
console.log(type);
|
||||
console.log(rankingRecordManager);
|
||||
for(let i = 0; i < rankingRecordManager.count; i++) {
|
||||
if(i > 6)
|
||||
break;
|
||||
let beginIndex = this.getBeginIndex(rankingRecordManager);
|
||||
let endIndex = this.getEndIndex(rankingRecordManager);
|
||||
|
||||
let data = rankingRecordManager.getAt(i);
|
||||
for(let i = 0; i < endIndex - beginIndex; i++) {
|
||||
let index = beginIndex + i;
|
||||
let data = rankingRecordManager.getAt(index);
|
||||
this.printRecord(type, i, data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getMyRank(rankingRecordManager) {
|
||||
let playerUserID = Number(sessionStorageManager.playerUserID);
|
||||
|
||||
for(let i = 0; i < rankingRecordManager.count; i++) {
|
||||
let data = rankingRecordManager.getAt(i);
|
||||
let userID = Number(data["userID"]);
|
||||
if(userID === playerUserID)
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return startIndex;
|
||||
}
|
||||
|
||||
getEndIndex(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;
|
||||
}
|
||||
}
|
||||
|
||||
return endIndex;
|
||||
}
|
||||
|
||||
|
||||
printRecord(type, index, data) {
|
||||
var style = { font: "20px Arial", fill: "#fff", align: "right", boundsAlignH: "right", boundsAlignV: "top" };
|
||||
|
||||
Reference in New Issue
Block a user