Resolve WES-117 "Persistent data handling"
This commit is contained in:
@@ -7,8 +7,6 @@ using UnityEngine.UI;
|
||||
|
||||
public class GameEndedPanel : MonoBehaviour
|
||||
{
|
||||
public UserList userList;
|
||||
|
||||
/// <summary>
|
||||
/// "VERLOREN" or "GEWONNEN"
|
||||
/// </summary>
|
||||
@@ -125,17 +123,17 @@ public class GameEndedPanel : MonoBehaviour
|
||||
// Instantiate new entries
|
||||
// Get all scores from all users
|
||||
List<Tuple<string, Score>> allScores = new List<Tuple<string, Score>>();
|
||||
foreach (User user in userList.GetUsers())
|
||||
foreach (User user in UserList.GetUsers())
|
||||
{
|
||||
// Get user's progress for this minigame
|
||||
Progress progress = user.GetMinigameProgress(MinigameIndex.SPELLING_BEE);
|
||||
var progress = user.GetMinigameProgress(MinigameIndex.SPELLING_BEE);
|
||||
if (progress != null)
|
||||
{
|
||||
// Add scores to dictionary
|
||||
List<Score> scores = progress.Get<List<Score>>("highestScores");
|
||||
List<Score> scores = progress.highestScores;
|
||||
foreach (Score score in scores)
|
||||
{
|
||||
allScores.Add(new Tuple<string, Score>(user.username, score));
|
||||
allScores.Add(new Tuple<string, Score>(user.GetUsername(), score));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -154,7 +152,7 @@ public class GameEndedPanel : MonoBehaviour
|
||||
scoreboardEntries.Add(entry);
|
||||
|
||||
// Set the player icon
|
||||
entry.transform.Find("Image").GetComponent<Image>().sprite = userList.GetUserByUsername(username).avatar;
|
||||
entry.transform.Find("Image").GetComponent<Image>().sprite = UserList.GetUserByUsername(username).GetAvatar();
|
||||
|
||||
// Set the player name
|
||||
entry.transform.Find("PlayerName").GetComponent<TMP_Text>().text = username;
|
||||
|
||||
@@ -76,11 +76,6 @@ public partial class SpellingBeeController : AbstractFeedback
|
||||
/// </summary>
|
||||
private DateTime startTime;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the user list to access the current user
|
||||
/// </summary>
|
||||
public UserList userList;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the current user
|
||||
/// </summary>
|
||||
@@ -204,18 +199,15 @@ public partial class SpellingBeeController : AbstractFeedback
|
||||
bonusTimeText.SetActive(false);
|
||||
|
||||
// Create entry in current user for keeping track of progress
|
||||
userList.Load();
|
||||
user = userList.GetCurrentUser();
|
||||
Progress progress = user.GetMinigameProgress(minigame.index);
|
||||
user = UserList.GetCurrentUser();
|
||||
var progress = user.GetMinigameProgress(minigame.index);
|
||||
if (progress == null)
|
||||
{
|
||||
progress = new Progress();
|
||||
progress.AddOrUpdate<MinigameIndex>("minigameIndex", MinigameIndex.SPELLING_BEE);
|
||||
progress.AddOrUpdate<List<Score>>("highestScores", new List<Score>());
|
||||
progress.AddOrUpdate<List<Score>>("latestScores", new List<Score>());
|
||||
user.minigames.Add(progress);
|
||||
progress = new PersistentDataController.SavedMinigameProgress();
|
||||
progress.minigameIndex = MinigameIndex.SPELLING_BEE;
|
||||
user.AddMinigameProgress(progress);
|
||||
}
|
||||
userList.Save();
|
||||
UserList.Save();
|
||||
|
||||
currentTheme = minigame.themeList.themes[minigame.themeList.currentThemeIndex];
|
||||
//feedback.signPredictor.ChangeModel(currentTheme.modelIndex);
|
||||
@@ -337,12 +329,11 @@ public partial class SpellingBeeController : AbstractFeedback
|
||||
score.time = DateTime.Now.ToString();
|
||||
|
||||
// Save the new score
|
||||
user = userList.GetCurrentUser();
|
||||
Progress progress = user.GetMinigameProgress(minigame.index);
|
||||
var progress = user.GetMinigameProgress(minigame.index);
|
||||
|
||||
// Get the current list of scores
|
||||
List<Score> latestScores = progress.Get<List<Score>>("latestScores");
|
||||
List<Score> highestScores = progress.Get<List<Score>>("highestScores");
|
||||
List<Score> latestScores = progress.latestScores;
|
||||
List<Score> highestScores = progress.highestScores;
|
||||
|
||||
// Add the new score
|
||||
latestScores.Add(score);
|
||||
@@ -352,10 +343,10 @@ public partial class SpellingBeeController : AbstractFeedback
|
||||
highestScores.Sort((a, b) => b.scoreValue.CompareTo(a.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());
|
||||
progress.latestScores = latestScores.Take(10).ToList();
|
||||
progress.highestScores = highestScores.Take(10).ToList();
|
||||
|
||||
userList.Save();
|
||||
UserList.Save();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
"GUID:1631ed2680c61245b8211d943c1639a8",
|
||||
"GUID:3444c67d5a3a93e5a95a48906078c372",
|
||||
"GUID:d0b6b39a21908f94fbbd9f2c196a9725",
|
||||
"GUID:7f2d0ee6dd21e1d4eb25b71b7a749d25",
|
||||
"GUID:58e104b97fb3752438ada2902a36dcbf"
|
||||
"GUID:58e104b97fb3752438ada2902a36dcbf",
|
||||
"GUID:e83ddf9a537a96b4a804a16bb7872ec1",
|
||||
"GUID:7f2d0ee6dd21e1d4eb25b71b7a749d25"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
||||
Reference in New Issue
Block a user