///////////////////////////// // Ranking board class RankingBoard { constructor() { 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); } requestRanking(type, rankingRecordManager) { 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; } 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); } } ); } getMyRank(rankingRecordManager) { let playerID = Number(sessionStorageManager.playerID); 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; } } 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" }; // rank style.boundsAlignH = "right"; game.add.text(this.getPosX(type), this.getPosY(index), data.rank, style) .setTextBounds(0, 0, 40, 40) .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); // player name game.add.text(this.getPosX(type) + 60, this.getPosY(index), data.playerName, style) .setTextBounds(0, 0, 60, 60) .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); // bestRecord let bestRecord = StringUtil.getRecordTextWithoutUnit(data.bestRecord); style.boundsAlignH = "right"; game.add.text(this.getPosX(type) + 120, this.getPosY(index), bestRecord, style) .setTextBounds(0, 0, 80, 60) .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 = 320; break; case DBConnectManager.TYPE_MY_RANKING_DAY: case DBConnectManager.TYPE_ALL_RANKING_DAY: posX = 540; break; case DBConnectManager.TYPE_MY_RANKING_MONTH: case DBConnectManager.TYPE_ALL_RANKING_MONTH: posX = 760; } return posX; } getPosY(index) { return game.world.height / 2 + 90 + 30 * index; } }