// Get leaderboard public static async Task <LoriLeaderboard> GetLeaderboardAsync(string lbName, int count = 10) { LoriLeaderboard lb = null; string tableName; tableName = LoriLeaderboard.GetTableName(lbName); var dbCon = DBConnection.Instance(); dbCon.DatabaseName = LCommandHandler.DATABASE_NAME; if (dbCon.IsConnect()) { var cmd = new MySqlCommand($"SELECT * FROM {tableName}", dbCon.Connection); var reader = cmd.ExecuteReader(); if (reader.HasRows) { List <LeaderboardRow> rows = new List <LeaderboardRow>(); while (reader.Read()) { LeaderboardRow row = new LeaderboardRow(reader.GetUInt64(0), reader.GetString(1), reader.GetInt32(2)); rows.Add(row); } lb = new LoriLeaderboard(LoriLeaderboard.GetLeaderboardName(tableName), rows); cmd.Dispose(); reader.Dispose(); } dbCon.Close(); } return(lb); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,HackerrankUsername,LabScore,HackerrankScore")] LeaderboardRow leaderboardRow) { if (id != leaderboardRow.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(leaderboardRow); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LeaderboardRowExists(leaderboardRow.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(leaderboardRow)); }
public void GetLeaderboard(XboxLiveUser user, string statName, LeaderboardQuery query) { if (!LocalUsers.Contains(user)) { throw new ArgumentException("Local User needs to be added."); } if (!mStats.ContainsKey(statName)) { mStats[statName] = new StatisticValue() { Name = statName, AsInteger = 300, AsNumber = 300, DataType = StatisticDataType.Number }; } StatisticValue stat = mStats[statName]; List <LeaderboardRow> rows = new List <LeaderboardRow>(); uint maxScore = query.MaxItems * 100; uint rankOffset = query.SkipResultToRank == 0 ? 1 : query.SkipResultToRank; bool userDisplayed = false; for (uint i = 0; i < query.MaxItems; i++) { uint score = maxScore - i * 100; LeaderboardRow row; if (!userDisplayed && stat.DataType == StatisticDataType.Number && (stat.AsNumber >= score || stat.AsInteger >= score)) { userDisplayed = true; row = new LeaderboardRow(new List <string> { stat.AsNumber.ToString() }, i + rankOffset, 0.8, user.XboxUserId, user.Gamertag); } else { row = new LeaderboardRow(new List <string> { score.ToString() }, i + rankOffset, 0.8, string.Format("{0}{0}{0}{0}{0}{0}{0}{0}", i), string.Format("Gamertag {0}", i)); } rows.Add(row); } List <LeaderboardColumn> cols = new List <LeaderboardColumn>(); cols.Add(new LeaderboardColumn(stat.DataType == StatisticDataType.String ? LeaderboardStatType.String : LeaderboardStatType.Integer, "")); LeaderboardResult result = new LeaderboardResult(rows, cols, query.MaxItems); LeaderboardResultEventArgs args = new LeaderboardResultEventArgs(result); mStatEventList.Add(new StatisticEvent(StatisticEventType.GetLeaderboardComplete, user, args)); }
private void FillProfile(LeaderboardRow playerRow) { Properties.ProfileNameText.text = playerRow.name; Properties.RankText.text = $"{playerRow.rank.ToString()} / {playerRow.outof.ToString()}"; Properties.WinsText.text = playerRow.wins.ToString(); Properties.DrawsText.text = playerRow.draws.ToString(); Properties.LossesText.text = playerRow.losses.ToString(); Properties.RatioText.text = playerRow.ratio.ToString("0.00"); Properties.PlayedText.text = playerRow.played.ToString(); }
public async Task <IActionResult> Create([Bind("Id,Name,HackerrankUsername,LabScore,HackerrankScore")] LeaderboardRow leaderboardRow) { if (ModelState.IsValid) { _context.Add(leaderboardRow); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(leaderboardRow)); }
private static void VerifyLeaderboardRow(LeaderboardRow row, JObject rowToVerify) { Assert.AreNotEqual(row, null, "LeaderboardRow was null."); Assert.AreEqual(row.Gamertag, rowToVerify["gamertag"].ToString()); Assert.AreEqual(row.XboxUserId, rowToVerify["xuid"].ToString()); Assert.AreEqual(row.Percentile, (double)rowToVerify["percentile"]); Assert.AreEqual(row.Rank, (int)rowToVerify["rank"]); // TODO Add checks for values }
private string GetRowValuesString(LeaderboardRow row) { string output = ""; foreach (string val in row.Values) { output += (val + ", "); } return(output); }
public void SaveNewHighscore(string lifes, string points, int naveID) { LeaderboardRow row = new LeaderboardRow(); row.stringLifes = lifes; row.stringPoints = points; row.idNave = naveID; if (leaderboard.rows == null) { leaderboard.rows = new List <LeaderboardRow>(); } leaderboard.rows.Add(row); StartCoroutine(CoSave()); }
private IEnumerator InitRoutine() { LeaderboardRow basisRow = AnyStarLeaderboard.GetComponentInChildren <LeaderboardRow>(); yield return(new WaitForEndOfFrame()); Vector2 leaderboardSize = AnyStarLeaderboard.rect.size; float heightRatio = leaderboardSize.y / baseHeight; float widthRatio = leaderboardSize.x / baseWidth; textRatio = Mathf.Min(heightRatio, widthRatio); rowHeight = baseRowHeight * heightRatio; RectTransform rt = basisRow.GetComponent <RectTransform>(); var rts = rt.sizeDelta; rts.y = rowHeight; rt.sizeDelta = rts; basisRow.SetSize(textRatio); }
private IEnumerator SetScoresRoutine(Transform parent, LeaderboardEntry[] scores) { yield return(new WaitUntil(() => rowHeight > 1)); LeaderboardRow basisRow = AnyStarLeaderboard.GetComponentInChildren <LeaderboardRow>(); LeaderboardRow row = basisRow; for (int i = 0; i < scores.Length; i++) { if (!(parent == AnyStarLeaderboard && i == 0)) { row = Instantiate(basisRow, parent); } RectTransform rt = row.GetComponent <RectTransform>(); LeaderboardEntry s = scores[i]; var rtp = rt.anchoredPosition; rtp.y = -50 - rowHeight * i; rt.anchoredPosition = rtp; row.SetRow(s.Rank, s.UserName, Utils.SplitTime(s.Score / 1000f, MillisecondDisplay.Normal), s.IsUser ? userScoreMaterial : nonUserScoreMaterial); } }
public void InsertScore(Address from, Address target, string name, BigInteger score) { Runtime.Expect(Exists(name), "invalid leaderboard"); var leaderboard = _leaderboards.Get <string, Leaderboard>(name); Runtime.Expect(from == leaderboard.owner, "invalid leaderboard owner"); Runtime.Expect(Runtime.IsWitness(from), "invalid witness"); var rows = _rows.Get <string, StorageList>(name); var count = rows.Count(); var oldCount = count; int oldIndex = -1; for (int i = 0; i < count; i++) { var entry = rows.Get <LeaderboardRow>(i); if (entry.address == target) { if (entry.score > score) { return; } oldIndex = i; break; } } if (oldIndex >= 0) { count--; for (int i = oldIndex; i <= count - 1; i++) { var entry = rows.Get <LeaderboardRow>(i + 1); rows.Replace <LeaderboardRow>(i, entry); } rows.RemoveAt(count); } int bestIndex = 0; var lastIndex = (int)(count - 1); for (int i = lastIndex; i >= 0; i--) { var entry = rows.Get <LeaderboardRow>(i); if (entry.score >= score) { bestIndex = i + 1; break; } } if (bestIndex >= leaderboard.size) { rows = _rows.Get <string, StorageList>(name); count = rows.Count(); for (int i = 0; i < count; i++) { var entry = rows.Get <LeaderboardRow>(i); Runtime.Expect(entry.score >= score, "leaderboard bug"); } return; } /*for (int i = lastIndex; i > bestIndex; i--) * { * var entry = rows.Get<LeaderboardRow>(i - 1); * rows.Replace<LeaderboardRow>(i, entry); * }*/ var newRow = new LeaderboardRow() { address = target, score = score }; if (bestIndex < count) { if (count < leaderboard.size) { rows.Add <LeaderboardRow>(newRow); for (int i = (int)count; i > bestIndex; i--) { var entry = rows.Get <LeaderboardRow>(i - 1); rows.Replace <LeaderboardRow>(i, entry); } } rows.Replace(bestIndex, newRow); } else { Runtime.Expect(bestIndex == count, "invalid insertion index"); rows.Add <LeaderboardRow>(newRow); } rows = _rows.Get <string, StorageList>(name); count = rows.Count(); for (int i = 0; i < bestIndex; i++) { var entry = rows.Get <LeaderboardRow>(i); Runtime.Expect(entry.score >= score, "leaderboard bug"); } Runtime.Expect(count >= oldCount, "leaderboard bug"); Runtime.Notify(EventKind.LeaderboardInsert, target, newRow); }
public static void SetData(LeaderboardRow leaderboardRow) { UpdateLeaderboardRow(leaderboardRow); //MelonCoroutines.Start(UpdateLeaderboardRowCoroutine(leaderboardRow)); }
//The process to update a LeaderboardRow public static void UpdateLeaderboardRow(LeaderboardRow leaderboardRow) { //DoWork function is really intensive so it's called only when absolutely required //This function will calculate the total max possible score for either OST or with extras void DoWork(bool e) { Il2CppSystem.Collections.Generic.List <SongList.SongData> songs = SongList.I.songs; int totalMaxScore = 0; for (int i = 0; i < songs.Count; i++) { SongList.SongData song = songs[i]; if (e) { if (song.dlc | song.unlockable) { totalMaxScore += starThresholds.GetMaxRawScore(song.songID, KataConfig.Difficulty.Expert); } } if (song.dlc == false && song.unlockable == false && song.extrasSong == false) { totalMaxScore += starThresholds.GetMaxRawScore(song.songID, KataConfig.Difficulty.Expert); } } if (e) { extrasMaxTotalScore = totalMaxScore; } else { ostMaxTotalScore = totalMaxScore; } } float score = Convert.ToSingle(leaderboardRow.mData.score.Split('.')[0]); float percentage; if (menuState != MenuState.State.MainPage) { percentage = GetScorePercentage(selectedSong, score, KataConfig.Difficulty.Expert); } else { LeaderboardDisplay leaderboardDisplay = UnityEngine.Object.FindObjectOfType <LeaderboardDisplay>(); bool extras = leaderboardDisplay.extrasButton.IsChecked.Invoke(); DoWork(extras); if (extras) { if (extrasMaxTotalScore == 0) { DoWork(extras); } percentage = (score / extrasMaxTotalScore) * 100; } else { if (ostMaxTotalScore == 0) { DoWork(extras); } percentage = (score / ostMaxTotalScore) * 100; } } //Make pretty-ish strings leaderboardRow.username.text = "<size=" + leaderboardUsernameSize + ">" + leaderboardRow.username.text + "</size>"; string scoreString = "<size=" + leaderboardHighScoreSize + ">" + String.Format("{0:n0}", score).Replace(",", " ") + "</size>"; string percentageString = "<size=" + leaderboardPercentSize + "> (" + String.Format("{0:0.00}", percentage) + "%)</size>"; //Update label if (leaderboardRow.score.text.Contains("<color=yellow>")) { leaderboardRow.score.text = "<color=" + leaderboardUserColor + ">" + scoreString + percentageString + "</color>"; } else { leaderboardRow.score.text = scoreString + percentageString; } if (leaderboardRow.rank.text.Contains("<color=yellow>")) { leaderboardRow.rank.text = leaderboardRow.rank.text.Replace("<color=yellow>", "<color=" + leaderboardUserColor + ">"); } if (leaderboardRow.username.text.Contains("<color=yellow>")) { leaderboardRow.username.text = leaderboardRow.username.text.Replace("<color=yellow>", "<color=" + leaderboardUserColor + ">"); } }
//This is a function for the coroutine public static IEnumerator UpdateLeaderboardRowCoroutine(LeaderboardRow leaderboardRow) { UpdateLeaderboardRow(leaderboardRow); return(null); }