using System.Collections.Generic;
using System.Text;
using UnityEngine;
using BACKND;
public class BackndRank {
private static BackndRank _instance = null;
public static BackndRank Instance {
get {
if(_instance == null) {
_instance = new BackndRank();
}
return _instance;
}
}
public void LeaderboardInsert(int score) {
string rankUUID = "Copied UUID value";
string tableName = "USER_DATA";
string rowInDate = string.Empty;
Debug.Log("Attempts data lookup.");
var bro = Backnd.PlayerTable.GetMyData(tableName);
if(bro.IsSuccess() == false) {
Debug.LogError("An error has occurred while looking up data : " + bro);
return;
}
Debug.Log("Data lookup successful : " + bro);
if(bro.FlattenRows().Count > 0) {
rowInDate = bro.FlattenRows()[0]["inDate"].ToString();
} else {
Debug.Log("The data does not exist. Attempting data insertion.");
var bro2 = Backnd.PlayerTable.Insert(tableName);
if(bro2.IsSuccess() == false) {
Debug.LogError("An error occurred while inserting data : " + bro2);
return;
}
Debug.Log("Data insertion successful : " + bro2);
rowInDate = bro2.GetInDate();
}
Debug.Log("rowInDate of my game information : " + rowInDate);
Param param = new Param();
param.Add("level", score);
Debug.Log("Attempting ranking insertion.");
var rankBro = Backnd.Leaderboard.Player.UpdateMyDataAndRefreshLeaderboard(rankUUID, tableName, rowInDate, param);
if(rankBro.IsSuccess() == false) {
Debug.LogError("An error has occurred while registering the ranking. : " + rankBro);
return;
}
Debug.Log("Successfully inserted the ranking. : " + rankBro);
}
public void RankGet() {
string rankUUID = "Copied UUID value";
var bro = Backnd.Leaderboard.Player.GetRankList(rankUUID);
if(bro.IsSuccess() == false) {
Debug.LogError("An error occurred while looking up rankings. : " + bro);
return;
}
Debug.Log("Ranking lookup successful. : " + bro);
Debug.Log("Total number of users registered to the ranking : " + bro.GetFlattenJSON()["totalCount"].ToString());
foreach(BACKND.LitJson.JsonData jsonData in bro.FlattenRows()) {
StringBuilder info = new StringBuilder();
info.AppendLine("Ranking : " + jsonData["rank"].ToString());
info.AppendLine("Nickname : " + jsonData["nickname"].ToString());
info.AppendLine("Score : " + jsonData["score"].ToString());
info.AppendLine("gamerInDate : " + jsonData["gamerInDate"].ToString());
info.AppendLine("Sort code : " + jsonData["index"].ToString());
info.AppendLine();
Debug.Log(info);
}
}
}