using System.Collections.Generic;
using System.Text;
using UnityEngine;
using BackEnd;
public class BackendRank {
private static BackendRank _instance = null;
public static BackendRank Instance {
get {
if(_instance == null) {
_instance = new BackendRank();
}
return _instance;
}
}
public void RankInsert(int score) {
string rankUUID = "Copied UUID value";
string tableName = "USER_DATA";
string rowInDate = string.Empty;
Debug.Log("Attempts data lookup.");
var bro = Backend.GameData.GetMyData(tableName, new Where());
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 = Backend.GameData.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 = Backend.URank.User.UpdateUserScore(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 = Backend.URank.User.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(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);
}
}
}