Resolve WES-95 "User progress"

This commit is contained in:
Dries Van Schuylenbergh
2023-03-18 10:25:49 +00:00
parent 5e26970bad
commit 9dfadece44
39 changed files with 4208 additions and 69 deletions

View File

@@ -210,13 +210,13 @@ public partial class GameController : MonoBehaviour
// Create entry in current user for keeping track of progress
user = userList.GetCurrentUser();
progress = user.minigames.Find((p) => p != null && p.Get<MinigameIndex>("minigameIndex") == minigame.index);
progress = user.GetMinigameProgress(minigame.index);
if (progress == null)
{
progress = new Progress();
progress.AddOrUpdate<MinigameIndex>("minigameIndex", MinigameIndex.SPELLING_BEE);
progress.AddOrUpdate<int>("highscore", 0);
progress.AddOrUpdate<List<Score>>("scores", new List<Score>());
progress.AddOrUpdate<List<Score>>("highestScores", new List<Score>());
progress.AddOrUpdate<List<Score>>("latestScores", new List<Score>());
user.minigames.Add(progress);
}
userList.Save();
@@ -392,28 +392,24 @@ public partial class GameController : MonoBehaviour
// Save the new score
user = userList.GetCurrentUser();
progress = user.minigames.Find((p) => p != null && p.Get<MinigameIndex>("minigameIndex") == minigame.index);
if (progress != null)
{
// Get the current list of scores
List<Score> scores = progress.Get<List<Score>>("scores");
progress = user.GetMinigameProgress(minigame.index);
// Add the new score
scores.Add(score);
// Get the current list of scores
List<Score> latestScores = progress.Get<List<Score>>("latestScores");
List<Score> highestScores = progress.Get<List<Score>>("highestScores");
// Sort the scores
scores.Sort((a, b) => b.scoreValue.CompareTo(a.scoreValue));
// Add the new score
latestScores.Add(score);
highestScores.Add(score);
// Only save the top 10 scores, so this list doesn't keep growing endlessly
progress.AddOrUpdate<List<Score>>("scores", scores.Take(10).ToList());
}
// Sort the scores
highestScores.Sort((a, b) => b.scoreValue.CompareTo(a.scoreValue));
// Update the highscore
int highscore = progress.Get<int>("highscore");
if (score.scoreValue < highscore)
{
progress.AddOrUpdate<int>("highscore", score.scoreValue);
}
// Only save the top 10 scores, so this list doesn't keep growing endlessly
progress.AddOrUpdate<List<Score>>("latestScores", latestScores.Take(10).ToList());
progress.AddOrUpdate<List<Score>>("highestScores", highestScores.Take(10).ToList());
Debug.Log(progress.Get<List<Score>>("highestScores"));
userList.Save();
}
@@ -436,11 +432,11 @@ public partial class GameController : MonoBehaviour
foreach (User user in userList.GetUsers())
{
// Get user's progress for this minigame
progress = user.minigames.Find((p) => p != null && p.Get<MinigameIndex>("minigameIndex") == minigame.index);
progress = user.GetMinigameProgress(minigame.index);
if (progress != null)
{
// Add scores to dictionary
List<Score> scores = progress.Get<List<Score>>("scores");
List<Score> scores = progress.Get<List<Score>>("highestScores");
foreach (Score score in scores)
{
allScores.Add(new Tuple<string, Score>(user.username, score));

View File

@@ -1,14 +0,0 @@
using System;
public partial class GameController
{
/// <summary>
/// Score class TODO: Move to separate file
/// </summary>
[Serializable]
public class Score
{
public int scoreValue;
public string time;
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 44c1f8e0fa862b44485ebaa3c81698fc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: