Resolve WES-117 "Persistent data handling"
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using DigitalRuby.Tween;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -5,7 +6,6 @@ using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using DigitalRuby.Tween;
|
||||
|
||||
public class HangmanController : AbstractFeedback
|
||||
{
|
||||
@@ -162,11 +162,6 @@ public class HangmanController : AbstractFeedback
|
||||
/// </summary>
|
||||
public MinigameList minigamelist;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the user list to access the current user
|
||||
/// </summary>
|
||||
public UserList userList;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the current user
|
||||
/// </summary>
|
||||
@@ -175,7 +170,7 @@ public class HangmanController : AbstractFeedback
|
||||
/// <summary>
|
||||
/// Reference to the minigame progress of the current user
|
||||
/// </summary>
|
||||
private Progress progress = null;
|
||||
private PersistentDataController.SavedMinigameProgress progress = null;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the scoreboard
|
||||
@@ -262,18 +257,15 @@ public class HangmanController : AbstractFeedback
|
||||
playerPanel.SetActive(true);
|
||||
|
||||
// Create entry in current user for keeping track of progress
|
||||
userList.Load();
|
||||
user = userList.GetCurrentUser();
|
||||
Progress progress = user.GetMinigameProgress(minigame.index);
|
||||
user = UserList.GetCurrentUser();
|
||||
progress = user.GetMinigameProgress(minigame.index);
|
||||
if (progress == null)
|
||||
{
|
||||
progress = new Progress();
|
||||
progress.AddOrUpdate<MinigameIndex>("minigameIndex", minigame.index);
|
||||
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 = minigame.index;
|
||||
user.AddMinigameProgress(progress);
|
||||
}
|
||||
userList.Save();
|
||||
UserList.Save();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -577,12 +569,11 @@ public class HangmanController : AbstractFeedback
|
||||
score.time = DateTime.Now.ToString();
|
||||
|
||||
// Save the new score
|
||||
user = userList.GetCurrentUser();
|
||||
Progress progress = user.GetMinigameProgress(minigame.index);
|
||||
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);
|
||||
@@ -592,10 +583,10 @@ public class HangmanController : 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>
|
||||
@@ -654,17 +645,17 @@ public class HangmanController : AbstractFeedback
|
||||
// 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 = 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>>("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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -682,7 +673,7 @@ public class HangmanController : AbstractFeedback
|
||||
GameObject entry = Instantiate(scoreboardEntry, EntriesGrid);
|
||||
entries.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;
|
||||
|
||||
21
Assets/Hangman/Scripts/HangmanScripts.asmdef
Normal file
21
Assets/Hangman/Scripts/HangmanScripts.asmdef
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "HangmanScripts",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:e83ddf9a537a96b4a804a16bb7872ec1",
|
||||
"GUID:6055be8ebefd69e48b49212b09b47b2f",
|
||||
"GUID:1631ed2680c61245b8211d943c1639a8",
|
||||
"GUID:d0b6b39a21908f94fbbd9f2c196a9725",
|
||||
"GUID:58e104b97fb3752438ada2902a36dcbf",
|
||||
"GUID:7f2d0ee6dd21e1d4eb25b71b7a749d25"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
7
Assets/Hangman/Scripts/HangmanScripts.asmdef.meta
Normal file
7
Assets/Hangman/Scripts/HangmanScripts.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99b7a088eba870d4486dbdc5ad359f27
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user