private void OnLoaPlayrScoresComplete(FB_Result result) { if (result.IsFailed) { OnPlayerScoresRequestCompleteAction(result); return; } Dictionary <string, object> JSON = ANMiniJSON.Json.Deserialize(result.RawData) as Dictionary <string, object>; List <object> data = JSON["data"] as List <object>; foreach (object row in data) { FB_Score score = new FB_Score(); Dictionary <string, object> dataRow = row as Dictionary <string, object>; Dictionary <string, object> userInfo = dataRow["user"] as Dictionary <string, object>; score.UserId = System.Convert.ToString(userInfo["id"]); score.UserName = System.Convert.ToString(userInfo["name"]); score.value = System.Convert.ToInt32(dataRow["score"]); score.AppId = System.Convert.ToString(FB.AppId); AddToUserScores(score); } OnPlayerScoresRequestCompleteAction(result); }
private void OnAppScoresComplete(FB_Result result) { if (result.IsFailed) { OnAppScoresRequestCompleteAction(result); return; } Dictionary <string, object> JSON = ANMiniJSON.Json.Deserialize(result.RawData) as Dictionary <string, object>; List <object> data = JSON["data"] as List <object>; foreach (object row in data) { FB_Score score = new FB_Score(); Dictionary <string, object> dataRow = row as Dictionary <string, object>; if (dataRow.ContainsKey("user")) { Dictionary <string, object> userInfo = dataRow["user"] as Dictionary <string, object>; if (userInfo.ContainsKey("id")) { score.UserId = System.Convert.ToString(userInfo["id"]); } if (userInfo.ContainsKey("name")) { score.UserName = System.Convert.ToString(userInfo["name"]); } } if (dataRow.ContainsKey("score")) { score.value = System.Convert.ToInt32(dataRow["score"]); } if (dataRow.ContainsKey("application")) { Dictionary <string, object> AppInfo = dataRow["application"] as Dictionary <string, object>; if (AppInfo.ContainsKey("id")) { score.AppId = System.Convert.ToString(AppInfo["id"]); } if (AppInfo.ContainsKey("name")) { score.AppName = System.Convert.ToString(AppInfo["name"]); } } AddToAppScores(score); } OnAppScoresRequestCompleteAction(result); }
//-------------------------------------- // PUBLIC METHODS //-------------------------------------- public FB_Score GetCurrentPlayerScoreByAppId(string appId) { if (_userScores.ContainsKey(appId)) { return(_userScores[appId]); } else { FB_Score score = new FB_Score(); score.UserId = FB.UserId; score.AppId = appId; score.value = 0; return(score); } }
private void AddToAppScores(FB_Score score) { if (_appScores.ContainsKey(score.UserId)) { _appScores[score.UserId] = score; } else { _appScores.Add(score.UserId, score); } if (_userScores.ContainsKey(score.AppId)) { _userScores[score.AppId] = score; } else { _userScores.Add(score.AppId, score); } }
private void OnScoreSubmited(FB_Result result) { if (result.IsFailed) { OnSubmitScoreRequestCompleteAction(result); return; } if (result.RawData.Equals("true")) { FB_Score score = new FB_Score(); score.AppId = AppId; score.UserId = UserId; score.value = lastSubmitedScore; if (_appScores.ContainsKey(UserId)) { _appScores[UserId].value = lastSubmitedScore; } else { _appScores.Add(score.UserId, score); } if (_userScores.ContainsKey(AppId)) { _userScores[AppId].value = lastSubmitedScore; } else { _userScores.Add(AppId, score); } } OnSubmitScoreRequestCompleteAction(result); }