Resolve WES-117 "Persistent data handling"
This commit is contained in:
42
Assets/Accounts/ScriptableObjects/UserAvatarList.asset
Normal file
42
Assets/Accounts/ScriptableObjects/UserAvatarList.asset
Normal file
@@ -0,0 +1,42 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 81765ea55baf15d45b01b02187b02429, type: 3}
|
||||
m_Name: UserAvatarList
|
||||
m_EditorClassIdentifier:
|
||||
avatars:
|
||||
- {fileID: 21300000, guid: 6feaaea4b64633f49b4538bfd4b3755c, type: 3}
|
||||
- {fileID: 21300000, guid: 399cc241fc79bd74db314f146e7fb6b9, type: 3}
|
||||
- {fileID: 21300000, guid: 4654657a2ebea444898fa6eeaefcd18d, type: 3}
|
||||
- {fileID: 21300000, guid: 0cc198f1cde659246a199b30459720b1, type: 3}
|
||||
- {fileID: 21300000, guid: 7f105a09a3d164547925ee1bdfa595ca, type: 3}
|
||||
- {fileID: 21300000, guid: 313c22e5834595645989d609fe9d8853, type: 3}
|
||||
- {fileID: 21300000, guid: e5f3d99cdf5298d4f86d42dd019a6bad, type: 3}
|
||||
- {fileID: 21300000, guid: b67b99d98d1ceb1489743bcd78b9ab70, type: 3}
|
||||
- {fileID: 21300000, guid: e4af402f37099cd4195d7d2654519744, type: 3}
|
||||
- {fileID: 21300000, guid: 73f4e028d9efb644aa23538a749667c5, type: 3}
|
||||
- {fileID: 21300000, guid: 61e56570163833e448037bc353ada0ac, type: 3}
|
||||
- {fileID: 21300000, guid: 8e69dfd19237abb4f98eb11e74153109, type: 3}
|
||||
- {fileID: 21300000, guid: bc11ff9d6cc35de45ab58f39f13d7142, type: 3}
|
||||
- {fileID: 21300000, guid: f989719a5c45c7a4183b2bc12c1c4905, type: 3}
|
||||
- {fileID: 21300000, guid: 1392922567cd59d4fb0beceea3f5917a, type: 3}
|
||||
- {fileID: 21300000, guid: 3c314ae9e10eafb49b57c98c9e779bd8, type: 3}
|
||||
- {fileID: 21300000, guid: 33509e453b5093e43a148a668a961c56, type: 3}
|
||||
- {fileID: 21300000, guid: 39ac3b86729423846be1fbd56b8d92d6, type: 3}
|
||||
- {fileID: 21300000, guid: 1118d67f50622cc4ab02aa23c6dc1fd4, type: 3}
|
||||
- {fileID: 21300000, guid: e519f0f7b00e6834187963a0131cae52, type: 3}
|
||||
- {fileID: 21300000, guid: eefb367ff44256d43a14cde2c3924321, type: 3}
|
||||
- {fileID: 21300000, guid: 83d6525e4efa4954091e08095349f45a, type: 3}
|
||||
- {fileID: 21300000, guid: db31bca6363270441ab54421f55c1263, type: 3}
|
||||
- {fileID: 21300000, guid: 9d5771baa6ea6e041b066135d6798e1c, type: 3}
|
||||
- {fileID: 21300000, guid: 2b01165a5836ab14593d7a5862bd6793, type: 3}
|
||||
- {fileID: 21300000, guid: 8c304fe460423214ea0bb6ebc235ed2d, type: 3}
|
||||
- {fileID: 21300000, guid: b203b4e5f8568ff46b2277ce6d61017a, type: 3}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 017ec1af3b6cc4d4ab2b506911a4edad
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -3,6 +3,7 @@
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:6055be8ebefd69e48b49212b09b47b2f",
|
||||
"GUID:e83ddf9a537a96b4a804a16bb7872ec1",
|
||||
"GUID:7f2d0ee6dd21e1d4eb25b71b7a749d25"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
|
||||
@@ -22,11 +22,6 @@ public class ChangeUserScreen : MonoBehaviour
|
||||
/// </summary>
|
||||
public GameObject error;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the user list
|
||||
/// </summary>
|
||||
public UserList userList;
|
||||
|
||||
/// <summary>
|
||||
/// Index of the current selected user in the UserList
|
||||
/// </summary>
|
||||
@@ -42,7 +37,7 @@ public class ChangeUserScreen : MonoBehaviour
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
userList.Load();
|
||||
PersistentDataController.GetInstance().Load();
|
||||
error.SetActive(false);
|
||||
DisplayUsers();
|
||||
}
|
||||
@@ -57,8 +52,8 @@ public class ChangeUserScreen : MonoBehaviour
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
|
||||
List<User> users = userList.GetUsers();
|
||||
currentUserIndex = userList.GetCurrentUserIndex();
|
||||
List<User> users = UserList.GetUsers();
|
||||
int currentUserIndex = UserList.IndexOf(UserList.GetCurrentUser().GetUsername());
|
||||
for (int i = 0; i < users.Count; i++)
|
||||
{
|
||||
User user = users[i];
|
||||
@@ -99,8 +94,7 @@ public class ChangeUserScreen : MonoBehaviour
|
||||
/// </summary>
|
||||
public void IChooseYou()
|
||||
{
|
||||
userList.ChangeCurrentUser(currentUserIndex);
|
||||
userList.Save();
|
||||
UserList.ChangeCurrentUser(currentUserIndex);
|
||||
SystemController.GetInstance().BackToPreviousScene();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public class CourseProgressCard : MonoBehaviour
|
||||
/// <summary>
|
||||
/// Reference to the progress so we can display a progress bar
|
||||
/// </summary>
|
||||
public Progress courseProgress;
|
||||
public PersistentDataController.SavedCourseProgress courseProgress;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the list of courses so we can query the correct course
|
||||
@@ -48,11 +48,11 @@ public class CourseProgressCard : MonoBehaviour
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
Course course = courseList.GetCourseByIndex(courseProgress.Get<CourseIndex>("courseIndex"));
|
||||
Course course = courseList.GetCourseByIndex(courseProgress.courseIndex);
|
||||
|
||||
thumbnail.sprite = course.thumbnail;
|
||||
title.text = course.title;
|
||||
progressBar.value = courseProgress.Get<float>("courseProgress");
|
||||
progressBar.value = courseProgress.progress;
|
||||
button.onClick.AddListener(selectActivity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class MinigameProgressCard : MonoBehaviour
|
||||
/// <summary>
|
||||
/// Reference to the minigame progress
|
||||
/// </summary>
|
||||
public Progress minigameProgress;
|
||||
public PersistentDataController.SavedMinigameProgress minigameProgress;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the minigame list
|
||||
@@ -49,11 +49,11 @@ public class MinigameProgressCard : MonoBehaviour
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
Minigame minigame = minigameList.GetMinigameByIndex(minigameProgress.Get<MinigameIndex>("minigameIndex"));
|
||||
Minigame minigame = minigameList.GetMinigameByIndex(minigameProgress.minigameIndex);
|
||||
|
||||
thumbnail.sprite = minigame.thumbnail;
|
||||
title.text = minigame.title;
|
||||
List<Score> highscores = minigameProgress.Get<List<Score>>("highestScores");
|
||||
List<Score> highscores = minigameProgress.highestScores;
|
||||
int score = highscores.Count > 0 ? highscores[0].scoreValue : 0;
|
||||
highscore.text = $"Topscore: {score}";
|
||||
button.onClick.AddListener(selectActivity);
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// A class for holding all progress belonging to a user
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class Progress
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper class for handling the stored progress
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
protected class DataEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// The key, used to reference the data object
|
||||
/// </summary>
|
||||
public string key;
|
||||
|
||||
/// <summary>
|
||||
/// The object, representated as a list of byte (which can be serialized)
|
||||
/// </summary>
|
||||
public List<byte> bytes = new List<byte>();
|
||||
|
||||
public DataEntry(string key, byte[] data)
|
||||
{
|
||||
this.key = key;
|
||||
this.bytes = new List<byte>(data);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Entries in the <c>Progress</c> object
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
private List<DataEntry> entries = new List<DataEntry>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Update the value of a certain key,
|
||||
/// or add a new value if the key was not present
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the data to be added/updated</typeparam>
|
||||
/// <param name="key">The key, used for referencing the data</param>
|
||||
/// <param name="data">The object of type <typeparamref name="T"/></param>
|
||||
/// <returns><c>true</c> if successful, <c>false</c> otherwise</returns>
|
||||
public bool AddOrUpdate<T>(string key, T data)
|
||||
{
|
||||
if (data == null)
|
||||
return false;
|
||||
|
||||
DataEntry entry = entries.Find(x => x.key == key);
|
||||
|
||||
// Hacky serialization stuff
|
||||
BinaryFormatter bf = new BinaryFormatter();
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
bf.Serialize(ms, data);
|
||||
if (entry != null)
|
||||
{
|
||||
entry.bytes.Clear();
|
||||
entry.bytes.AddRange(ms.ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
entries.Add(new DataEntry(key, ms.ToArray()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the data object of a certain key
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the data object</typeparam>
|
||||
/// <param name="key">The key referencing the data object</param>
|
||||
/// <returns>The data, cast to a type <typeparamref name="T"/></returns>
|
||||
/// <exception cref="KeyNotFoundException"></exception>
|
||||
public T Get<T>(string key)
|
||||
{
|
||||
BinaryFormatter bf = new BinaryFormatter();
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
// Find the correct key
|
||||
foreach (DataEntry entry in entries)
|
||||
{
|
||||
if (entry.key == key)
|
||||
{
|
||||
// Hacky serialization stuff
|
||||
byte[] data = entry.bytes.ToArray();
|
||||
ms.Write(data, 0, data.Length);
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
return (T)bf.Deserialize(ms);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Raise an exception when key is not found
|
||||
throw new KeyNotFoundException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check whether a key is present
|
||||
/// </summary>
|
||||
/// <param name="key">The key to check</param>
|
||||
/// <returns>true if a item can be found with the specified key</returns>
|
||||
public bool Has(string key)
|
||||
{
|
||||
return entries.Find(x => x.key == key) != null;
|
||||
}
|
||||
}
|
||||
@@ -2,40 +2,45 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using static PersistentDataController;
|
||||
|
||||
/// <summary>
|
||||
/// A class holding all information of a user
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class User
|
||||
{
|
||||
/// <summary>
|
||||
/// User nickname
|
||||
/// Reference to the user stored data record
|
||||
/// </summary>
|
||||
public string username;
|
||||
private SavedUserData storedUserData;
|
||||
|
||||
/// <summary>
|
||||
/// The avatar of the user
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public Sprite avatar;
|
||||
/// <param name="data">Reference to the user stored data record</param>
|
||||
public User(SavedUserData data)
|
||||
{
|
||||
this.storedUserData = data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The total playtime of the user
|
||||
/// Get the username
|
||||
/// </summary>
|
||||
/// <remarks>TODO: needs to be implemented</remarks>
|
||||
public double playtime;
|
||||
/// <returns></returns>
|
||||
public string GetUsername() { return storedUserData.username; }
|
||||
|
||||
/// <summary>
|
||||
/// List of courses a user started/completed
|
||||
/// Get the total playtime
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
public List<Progress> courses = new List<Progress>();
|
||||
/// <returns></returns>
|
||||
public double GetPlaytime() { return storedUserData.playtime; }
|
||||
|
||||
/// <summary>
|
||||
/// List of minigames a user played
|
||||
/// Get the avatar
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
public List<Progress> minigames = new List<Progress>();
|
||||
/// <returns></returns>
|
||||
public Sprite GetAvatar() { return UserList.AVATARS[storedUserData.avatarIndex]; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of all recently started courses
|
||||
@@ -46,10 +51,10 @@ public class User
|
||||
{
|
||||
// TODO: return better results (for now only return all courses)
|
||||
List<Tuple<CourseIndex, float>> recentCourses = new List<Tuple<CourseIndex, float>>();
|
||||
foreach (Progress courseProgress in courses)
|
||||
foreach (var courseProgress in storedUserData.courses)
|
||||
{
|
||||
CourseIndex idx = courseProgress.Get<CourseIndex>("courseIndex");
|
||||
float progress = courseProgress.Get<float>("courseProgress");
|
||||
CourseIndex idx = courseProgress.courseIndex;
|
||||
float progress = courseProgress.progress;
|
||||
recentCourses.Add(Tuple.Create<CourseIndex, float>(idx, progress));
|
||||
}
|
||||
return recentCourses.Take(3).ToList();
|
||||
@@ -63,31 +68,58 @@ public class User
|
||||
public List<Tuple<CourseIndex, float>> GetRecommendedCourses()
|
||||
{
|
||||
List<Tuple<CourseIndex, float>> recommenedCourses = new List<Tuple<CourseIndex, float>>();
|
||||
if (courses.Count == 0)
|
||||
if (storedUserData.courses.Count == 0)
|
||||
{
|
||||
recommenedCourses.Add(Tuple.Create<CourseIndex, float>(CourseIndex.FINGERSPELLING, 0.0f));
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: return better results (for now only return all courses)
|
||||
foreach (Progress courseProgress in courses)
|
||||
foreach (var courseProgress in storedUserData.courses)
|
||||
{
|
||||
CourseIndex idx = courseProgress.Get<CourseIndex>("courseIndex");
|
||||
float progress = courseProgress.Get<float>("courseProgress");
|
||||
CourseIndex idx = courseProgress.courseIndex;
|
||||
float progress = courseProgress.progress;
|
||||
recommenedCourses.Add(Tuple.Create<CourseIndex, float>(idx, progress));
|
||||
}
|
||||
}
|
||||
return recommenedCourses.Take(3).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the progress of all courses the user did
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<SavedCourseProgress> GetCourses()
|
||||
{
|
||||
return storedUserData.courses;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the progress of a certain course
|
||||
/// </summary>
|
||||
/// <param name="courseIndex">Index of course</param>
|
||||
/// <returns><c>Progress</c> belonging to the <c>courseIndex</c>, <c>null</c> if course was not found</returns>
|
||||
public Progress GetCourseProgress(CourseIndex courseIndex)
|
||||
public SavedCourseProgress GetCourseProgress(CourseIndex courseIndex)
|
||||
{
|
||||
return courses.Find((p) => p.Get<CourseIndex>("courseIndex") == courseIndex);
|
||||
return storedUserData.courses.Find((p) => p.courseIndex == courseIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add new progress of a course
|
||||
/// </summary>
|
||||
/// <param name="progress">SavedCourseProgress data record</param>
|
||||
public void AddCourseProgress(SavedCourseProgress progress)
|
||||
{
|
||||
storedUserData.courses.Add(progress);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the progress of all minigames the user did
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<SavedMinigameProgress> GetMinigames()
|
||||
{
|
||||
return storedUserData.minigames;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -95,8 +127,17 @@ public class User
|
||||
/// </summary>
|
||||
/// <param name="minigameIndex">Index of the minigame</param>
|
||||
/// <returns><c>Progress</c> belonging to the <c>minigameIndex</c>, <c>null</c> if minigame was not found</returns>
|
||||
public Progress GetMinigameProgress(MinigameIndex minigameIndex)
|
||||
public SavedMinigameProgress GetMinigameProgress(MinigameIndex minigameIndex)
|
||||
{
|
||||
return minigames.Find((p) => p.Get<MinigameIndex>("minigameIndex") == minigameIndex);
|
||||
return storedUserData.minigames.Find((p) => p.minigameIndex == minigameIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add new progress of a minigame
|
||||
/// </summary>
|
||||
/// <param name="progress">SavedMinigameProgress data record</param>
|
||||
public void AddMinigameProgress(SavedMinigameProgress progress)
|
||||
{
|
||||
storedUserData.minigames.Add(progress);
|
||||
}
|
||||
}
|
||||
|
||||
19
Assets/Accounts/Scripts/UserAvatarList.cs
Normal file
19
Assets/Accounts/Scripts/UserAvatarList.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Container to hold a reference to all possible user avatar sprites
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "Create new Scriptable/User Avatar List")]
|
||||
public class UserAvatarList : ScriptableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// List of avatar sprites
|
||||
/// </summary>
|
||||
public List<Sprite> avatars = new List<Sprite>();
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
UserList.AVATARS = avatars;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d887bc641cc7a8f4abf9d4eb34d26923
|
||||
guid: 81765ea55baf15d45b01b02187b02429
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -8,11 +8,6 @@ using UnityEngine.UI;
|
||||
/// </summary>
|
||||
public class UserCard : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Reference to the userlist
|
||||
/// </summary>
|
||||
public UserList userList;
|
||||
|
||||
/// <summary>
|
||||
/// User to upload info into this card
|
||||
/// </summary>
|
||||
@@ -53,8 +48,8 @@ public class UserCard : MonoBehaviour
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
avatar.sprite = user.avatar;
|
||||
username.text = user.username;
|
||||
avatar.sprite = user.GetAvatar();
|
||||
username.text = user.GetUsername();
|
||||
button.onClick.AddListener(selectUser);
|
||||
}
|
||||
|
||||
@@ -63,10 +58,9 @@ public class UserCard : MonoBehaviour
|
||||
/// </summary>
|
||||
public void DeleteUser()
|
||||
{
|
||||
if (userList.DeleteUser(user))
|
||||
if (UserList.DeleteUser(user.GetUsername()))
|
||||
{
|
||||
// User is removed, update and save
|
||||
userList.Save();
|
||||
updateUserCardContainer();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -34,20 +34,9 @@ public class UserCreationScreen : MonoBehaviour
|
||||
/// </summary>
|
||||
public GameObject avatarPrefab;
|
||||
|
||||
/// <summary>
|
||||
/// List of all sprites that are supported as avatars
|
||||
/// </summary>
|
||||
public List<Sprite> sprites = new List<Sprite>();
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the UserList ScriptableObject
|
||||
/// </summary>
|
||||
public UserList users;
|
||||
|
||||
/// <summary>
|
||||
/// Current selected avatar
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
private int selectedAvatar = 0;
|
||||
|
||||
/// <summary>
|
||||
@@ -63,7 +52,7 @@ public class UserCreationScreen : MonoBehaviour
|
||||
{
|
||||
errorMessage.SetActive(false);
|
||||
|
||||
for (int i = 0; i < sprites.Count; i++)
|
||||
for (int i = 0; i < UserList.AVATARS.Count; i++)
|
||||
{
|
||||
// Create instance of prefab
|
||||
GameObject instance = GameObject.Instantiate(avatarPrefab, avatarsContainer);
|
||||
@@ -79,7 +68,7 @@ public class UserCreationScreen : MonoBehaviour
|
||||
// Set background color
|
||||
background.color = selectedAvatar == i ? Color.blue : Color.gray;
|
||||
// Find correct component for setting the sprite
|
||||
instance.transform.Find("Image").GetComponent<Image>().sprite = sprites[i];
|
||||
instance.transform.Find("Image").GetComponent<Image>().sprite = UserList.AVATARS[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,10 +102,10 @@ public class UserCreationScreen : MonoBehaviour
|
||||
string username = inputName.text;
|
||||
if (IsValidUsername(username))
|
||||
{
|
||||
if (users.GetUserByUsername(username) == null)
|
||||
if (UserList.GetUserByUsername(username) == null)
|
||||
{
|
||||
// Create a new entry in the UserList ScriptableObject
|
||||
users.ChangeCurrentUser(users.CreateAndAddNewUser(username, sprites[selectedAvatar]));
|
||||
UserList.AddUser(username, UserList.AVATARS[selectedAvatar]);
|
||||
SystemController.GetInstance().BackToPreviousScene();
|
||||
}
|
||||
// Warn user that username already exists
|
||||
|
||||
@@ -1,87 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Keep track of all users
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "Create new Scriptable/UserList")]
|
||||
public class UserList : ScriptableObject
|
||||
public static class UserList
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper class to enable serialization of the UserList class
|
||||
/// (<c>ScriptableObject</c>s cannot be serialized)
|
||||
/// List of possible avatar sprites
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class StoredUserList
|
||||
{
|
||||
/// <summary>
|
||||
/// The index of the current/last logged in user in the <c>storedUsers</c> list
|
||||
/// </summary>
|
||||
public int currentUserIndex = -1;
|
||||
|
||||
/// <summary>
|
||||
/// A list containing all users (which can be serialized)
|
||||
/// </summary>
|
||||
public List<User> storedUsers = new List<User>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the serializable version of <c>UserList</c>
|
||||
/// </summary>
|
||||
[SerializeField]
|
||||
private StoredUserList storedUserList = new StoredUserList();
|
||||
|
||||
/// <summary>
|
||||
/// Path of the <c>.json</c>-file to store all serialized data
|
||||
/// </summary>
|
||||
public static string PATH = null;
|
||||
|
||||
/// <summary>
|
||||
/// OnEnable will make sure the <c>PATH</c>-variable is correctly initialized
|
||||
/// </summary>
|
||||
void OnEnable()
|
||||
{
|
||||
// The PATH variable can be set by the testing framework,
|
||||
// so we don't overwrite the actual userlist with test data
|
||||
if (PATH == null)
|
||||
{
|
||||
PATH = $"{Application.persistentDataPath}/users.json";
|
||||
Load();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new user
|
||||
/// </summary>
|
||||
/// <param name="name">The username of the new user</param>
|
||||
/// <param name="avatar">Reference to the user avatar</param>
|
||||
/// <returns>A newly created user</returns>
|
||||
public User CreateNewUser(string name, Sprite avatar)
|
||||
{
|
||||
User user = new User();
|
||||
user.username = name;
|
||||
user.avatar = avatar;
|
||||
return user;
|
||||
}
|
||||
public static List<Sprite> AVATARS = new List<Sprite>();
|
||||
|
||||
/// <summary>
|
||||
/// Create a new user and save (add to list)
|
||||
/// </summary>
|
||||
/// <param name="name">The username of the new user</param>
|
||||
/// <param name="username">The username of the new user</param>
|
||||
/// <param name="avatar">Reference to the user avatar</param>
|
||||
/// <returns>A newly created user</returns>
|
||||
public User CreateAndAddNewUser(string name, Sprite avatar)
|
||||
public static User AddUser(string username, Sprite avatar)
|
||||
{
|
||||
User user = CreateNewUser(name, avatar);
|
||||
storedUserList.storedUsers.Add(user);
|
||||
if (storedUserList.storedUsers.Count == 1)
|
||||
{
|
||||
storedUserList.currentUserIndex = 0;
|
||||
}
|
||||
Save();
|
||||
return user;
|
||||
PersistentDataController pdc = PersistentDataController.GetInstance();
|
||||
PersistentDataController.SavedUserData data = new PersistentDataController.SavedUserData();
|
||||
data.username = username;
|
||||
data.playtime = 0.0;
|
||||
data.avatarIndex = AVATARS.IndexOf(avatar);
|
||||
|
||||
pdc.AddUser(data);
|
||||
return new User(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -89,43 +35,61 @@ public class UserList : ScriptableObject
|
||||
/// </summary>
|
||||
/// <param name="username">The username of the user</param>
|
||||
/// <returns><c>User</c>-object if a user with such username was found, <c>null</c> otherwise</returns>
|
||||
public User GetUserByUsername(string username)
|
||||
public static User GetUserByUsername(string username)
|
||||
{
|
||||
foreach (User user in storedUserList.storedUsers)
|
||||
if (user.username == username) return user;
|
||||
foreach (User user in GetUsers())
|
||||
if (user.GetUsername() == username) return user;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a user by index
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the user</param>
|
||||
/// <returns>User object</returns>
|
||||
/// <exception cref="IndexOutOfRangeException"></exception>
|
||||
public static User GetUserByIndex(int index)
|
||||
{
|
||||
List<User> users = GetUsers();
|
||||
if (index < 0 || users.Count <= index)
|
||||
throw new IndexOutOfRangeException();
|
||||
|
||||
return users[index];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of all users currently stored
|
||||
/// </summary>
|
||||
/// <returns>A list of all users</returns>
|
||||
public List<User> GetUsers()
|
||||
public static List<User> GetUsers()
|
||||
{
|
||||
return storedUserList.storedUsers;
|
||||
PersistentDataController pdc = PersistentDataController.GetInstance();
|
||||
return pdc.GetUsers().ConvertAll((d) => new User(d));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the current logged in user
|
||||
/// </summary>
|
||||
/// <returns>The current logged in user</returns>
|
||||
public User GetCurrentUser()
|
||||
public static User GetCurrentUser()
|
||||
{
|
||||
if (storedUserList.storedUsers.Count == 0)
|
||||
{
|
||||
List<User> users = GetUsers();
|
||||
if (users.Count == 0)
|
||||
return null;
|
||||
}
|
||||
return storedUserList.storedUsers[storedUserList.currentUserIndex];
|
||||
return users[PersistentDataController.GetInstance().GetCurrentUser()];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the index in the userlist of the current playing user
|
||||
/// Get the index in the userlist of a user
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int GetCurrentUserIndex()
|
||||
public static int IndexOf(string username)
|
||||
{
|
||||
return storedUserList.currentUserIndex;
|
||||
int idx = GetUsers().FindIndex((e) => e.GetUsername() == username);
|
||||
if (idx < 0)
|
||||
throw new KeyNotFoundException();
|
||||
return idx;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -133,89 +97,66 @@ public class UserList : ScriptableObject
|
||||
/// </summary>
|
||||
/// <param name="index">Index of the user in the userlist</param>
|
||||
/// <exception cref="IndexOutOfRangeException"></exception>
|
||||
public void ChangeCurrentUser(int index)
|
||||
public static void ChangeCurrentUser(int index)
|
||||
{
|
||||
if (0 <= index && index < storedUserList.storedUsers.Count)
|
||||
{
|
||||
storedUserList.currentUserIndex = index;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (index < 0 || GetUsers().Count <= index)
|
||||
throw new IndexOutOfRangeException();
|
||||
}
|
||||
|
||||
PersistentDataController.GetInstance().SetCurrentUser(index, true);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Change the current user
|
||||
/// </summary>
|
||||
/// <param name="user">Reference to the user in the userlist</param>
|
||||
/// <param name="index">Username of the user</param>
|
||||
/// <exception cref="KeyNotFoundException"></exception>
|
||||
public void ChangeCurrentUser(User user)
|
||||
public static void ChangeCurrentUser(string username)
|
||||
{
|
||||
int idx = storedUserList.storedUsers.IndexOf(user);
|
||||
if (idx < 0)
|
||||
{
|
||||
throw new KeyNotFoundException();
|
||||
}
|
||||
storedUserList.currentUserIndex = idx;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the user
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the user in the userlist</param>
|
||||
/// <returns>true if user was successful removed, false otherwise</returns
|
||||
public bool DeleteUser(int index)
|
||||
{
|
||||
if (0 <= index && index < storedUserList.storedUsers.Count)
|
||||
{
|
||||
return DeleteUser(storedUserList.storedUsers[index]);
|
||||
}
|
||||
return false;
|
||||
int index = GetUsers().FindIndex((e) => e.GetUsername() == username);
|
||||
try { ChangeCurrentUser(index); }
|
||||
catch (IndexOutOfRangeException) { throw new KeyNotFoundException(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// I am inevitable, *snap*
|
||||
/// </summary>
|
||||
/// <param name="user">Reference to the user to be removed</param>
|
||||
/// <param name="index">The index of the user in the userlist</param>
|
||||
/// <returns>true if the user was successful removed, false otherwise</returns>
|
||||
public bool DeleteUser(User user)
|
||||
/// <exception cref="IndexOutOfRangeException"></exception>
|
||||
public static bool DeleteUser(int index)
|
||||
{
|
||||
if (1 < storedUserList.storedUsers.Count)
|
||||
{
|
||||
if (storedUserList.currentUserIndex == storedUserList.storedUsers.Count - 1)
|
||||
{
|
||||
storedUserList.currentUserIndex--;
|
||||
}
|
||||
List<User> users = GetUsers();
|
||||
if (index < 0 || users.Count <= index)
|
||||
throw new IndexOutOfRangeException();
|
||||
|
||||
return storedUserList.storedUsers.Remove(user);
|
||||
if (1 < users.Count)
|
||||
{
|
||||
PersistentDataController.GetInstance().DeleteUser(index);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save the users
|
||||
/// Delete a user from the userliset
|
||||
/// </summary>
|
||||
public void Save()
|
||||
/// <param name="username">Username of the user</param>
|
||||
/// <returns>true if the user was successful removed, false otherwise</returns>
|
||||
/// <exception cref="KeyNotFoundException"></exception>
|
||||
public static bool DeleteUser(string username)
|
||||
{
|
||||
string json = JsonUtility.ToJson(storedUserList);
|
||||
File.CreateText(PATH).Close();
|
||||
File.WriteAllText(PATH, json);
|
||||
int index = GetUsers().FindIndex((e) => e.GetUsername() == username);
|
||||
|
||||
try { return DeleteUser(index); }
|
||||
catch (IndexOutOfRangeException) { throw new KeyNotFoundException(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override the current content of the userlist by what is stored on disk
|
||||
/// Save the current UserList
|
||||
/// </summary>
|
||||
public void Load()
|
||||
public static void Save()
|
||||
{
|
||||
storedUserList.storedUsers.Clear();
|
||||
storedUserList.currentUserIndex = -1;
|
||||
|
||||
if (!File.Exists(PATH))
|
||||
{
|
||||
Save();
|
||||
}
|
||||
string text = File.ReadAllText(PATH);
|
||||
storedUserList = JsonUtility.FromJson<StoredUserList>(text);
|
||||
PersistentDataController.GetInstance().Save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,11 +10,6 @@ using UnityEngine.UI;
|
||||
/// </summary>
|
||||
public class UserProgressScreen : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Reference to the userlist
|
||||
/// </summary>
|
||||
public UserList userList;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the current user
|
||||
/// </summary>
|
||||
@@ -112,12 +107,12 @@ public class UserProgressScreen : MonoBehaviour
|
||||
void Start()
|
||||
{
|
||||
// Assign the current user
|
||||
userList.Load();
|
||||
user = userList.GetCurrentUser();
|
||||
PersistentDataController.GetInstance().Load();
|
||||
user = UserList.GetCurrentUser();
|
||||
|
||||
// Set correct displayed items
|
||||
username.text = user.username;
|
||||
avatar.sprite = user.avatar;
|
||||
username.text = user.GetUsername();
|
||||
avatar.sprite = user.GetAvatar();
|
||||
// TODO: implement total playtime
|
||||
//playtime.text = $"Totale speeltijd: {user.playtime.ToString("0.00")}";
|
||||
|
||||
@@ -126,9 +121,10 @@ public class UserProgressScreen : MonoBehaviour
|
||||
|
||||
int i = 0;
|
||||
// Display courses
|
||||
coursesContainer.SetActive(user.courses.Count > 0);
|
||||
emptyCourses.SetActive(user.courses.Count <= 0);
|
||||
foreach (Progress courseProgress in user.courses)
|
||||
var courses = user.GetCourses();
|
||||
coursesContainer.SetActive(courses.Count > 0);
|
||||
emptyCourses.SetActive(courses.Count <= 0);
|
||||
foreach (var courseProgress in courses)
|
||||
{
|
||||
// Create instance of prefab
|
||||
GameObject instance = GameObject.Instantiate(courseCardPrefab, coursesContainer.transform.Find("Viewport").Find("Content").transform);
|
||||
@@ -142,13 +138,14 @@ public class UserProgressScreen : MonoBehaviour
|
||||
// Store reference to background so we can apply fancy coloring
|
||||
Image background = instance.GetComponent<Image>();
|
||||
background.color = Color.gray;
|
||||
activities.Add(Tuple.Create(background, (int)courseProgress.Get<CourseIndex>("courseIndex")));
|
||||
activities.Add(Tuple.Create(background, (int)courseProgress.courseIndex));
|
||||
}
|
||||
|
||||
// Display minigames
|
||||
minigamesContainer.SetActive(user.minigames.Count > 0);
|
||||
emptyMinigames.SetActive(user.minigames.Count <= 0);
|
||||
foreach (Progress minigameProgress in user.minigames)
|
||||
var minigames = user.GetMinigames();
|
||||
minigamesContainer.SetActive(minigames.Count > 0);
|
||||
emptyMinigames.SetActive(minigames.Count <= 0);
|
||||
foreach (var minigameProgress in minigames)
|
||||
{
|
||||
// Create instance of prefab
|
||||
GameObject instance = GameObject.Instantiate(minigameCardPrefab, minigamesContainer.transform.Find("Viewport").Find("Content").transform);
|
||||
@@ -162,7 +159,7 @@ public class UserProgressScreen : MonoBehaviour
|
||||
// Store reference to background so we can apply fancy coloring
|
||||
Image background = instance.GetComponent<Image>();
|
||||
background.color = Color.gray;
|
||||
activities.Add(Tuple.Create(background, (int)minigameProgress.Get<MinigameIndex>("minigameIndex")));
|
||||
activities.Add(Tuple.Create(background, (int)minigameProgress.minigameIndex));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +180,7 @@ public class UserProgressScreen : MonoBehaviour
|
||||
|
||||
selectedActivity = newActivity;
|
||||
activities[selectedActivity].Item1.color = Color.blue;
|
||||
if (selectedActivity < user.courses.Count)
|
||||
if (selectedActivity < user.GetCourses().Count)
|
||||
{
|
||||
// TODO: create a better graph
|
||||
//DisplayCourseGraph((CourseIndex)activities[selectedActivity].Item2);
|
||||
@@ -211,9 +208,9 @@ public class UserProgressScreen : MonoBehaviour
|
||||
/// <param name="minigameIndex">Index of the minigame</param>
|
||||
private void DisplayMinigameGraph(MinigameIndex minigameIndex)
|
||||
{
|
||||
Progress progress = user.GetMinigameProgress(minigameIndex);
|
||||
List<Score> latestScores = progress.Get<List<Score>>("latestScores");
|
||||
List<Score> highestScores = progress.Get<List<Score>>("highestScores");
|
||||
var progress = user.GetMinigameProgress(minigameIndex);
|
||||
List<Score> latestScores = progress.latestScores;
|
||||
List<Score> highestScores = progress.highestScores;
|
||||
if (0 < highestScores.Count)
|
||||
{
|
||||
PlotGraph(latestScores.ConvertAll<double>((s) => (double)s.scoreValue), highestScores[0].scoreValue);
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
"UnityEngine.TestRunner",
|
||||
"UnityEditor.TestRunner",
|
||||
"AccountsScripts",
|
||||
"InterfacesScripts"
|
||||
"InterfacesScripts",
|
||||
"SystemArchitecture"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
|
||||
@@ -1,213 +0,0 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Test the Progress class
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public class ProgressTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Reference to the progress object to be tested
|
||||
/// </summary>
|
||||
private Progress progress;
|
||||
|
||||
/// <summary>
|
||||
/// A dummy serializable struct to perform test operations on
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
private struct SerializableStruct
|
||||
{
|
||||
public int r, g, b;
|
||||
public float x, y, z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A dummy non-serializable struct to perform test operations on
|
||||
/// </summary>
|
||||
private struct NonSerializableStruct
|
||||
{
|
||||
public int r, g, b;
|
||||
public float x, y, z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setup the tests
|
||||
/// </summary>
|
||||
[SetUp]
|
||||
public void Setup_Progress()
|
||||
{
|
||||
progress = new Progress();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test for creation of a new progress
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_New_Progress()
|
||||
{
|
||||
Assert.IsNotNull(progress);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether invalid data will not be added
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_Progress_Add_InvalidData()
|
||||
{
|
||||
Assert.IsFalse(progress.AddOrUpdate<GameObject>("key", null));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a duplicated key will be added
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_Progress_Add_DuplicateKey()
|
||||
{
|
||||
progress.AddOrUpdate<int>("key 1", 0);
|
||||
Assert.IsTrue(progress.AddOrUpdate<int>("key 1", 1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a <c>int</c> value can be added
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_Progress_Add_Int()
|
||||
{
|
||||
Assert.IsTrue(progress.AddOrUpdate<int>("key", 1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a <c>double</c> value can be added
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_Progress_Add_Double()
|
||||
{
|
||||
Assert.IsTrue(progress.AddOrUpdate<double>("key", 1.0));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a <c>string</c> value can be added
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_Progress_Add_String()
|
||||
{
|
||||
Assert.IsTrue(progress.AddOrUpdate<string>("key", "Hello World!"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a serializable struct can be added
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_Progress_Add_SerializableStruct()
|
||||
{
|
||||
Assert.IsTrue(progress.AddOrUpdate<SerializableStruct>("key", new SerializableStruct()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a non-serializable struct will throw an error
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_Progress_Add_NonSerializableStruct()
|
||||
{
|
||||
NonSerializableStruct nss = new NonSerializableStruct();
|
||||
Assert.Throws<SerializationException>(delegate { progress.AddOrUpdate<NonSerializableStruct>("key", nss); });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a key is present
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_Progress_Has_ValidKey()
|
||||
{
|
||||
progress.AddOrUpdate<int>("key", 1);
|
||||
Assert.IsTrue(progress.Has("key"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a key is not present
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_Progress_Has_InvalidKey()
|
||||
{
|
||||
Assert.IsFalse(progress.Has("non-existing key"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether an invalid key will throw an error
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_Progress_Get_InvalidKey()
|
||||
{
|
||||
Assert.Throws<KeyNotFoundException>(delegate { progress.Get<int>("non-existing key"); });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether an invalid type will throw an error
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_Progress_Get_InvalidType()
|
||||
{
|
||||
progress.AddOrUpdate<int>("key", 123456789);
|
||||
Assert.Throws<InvalidCastException>(delegate { progress.Get<double>("key"); });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a value is correctly updated
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_Progress_Update()
|
||||
{
|
||||
progress.AddOrUpdate<int>("key", 1);
|
||||
Assert.AreEqual(progress.Get<int>("key"), 1);
|
||||
progress.AddOrUpdate<int>("key", 2);
|
||||
Assert.AreEqual(progress.Get<int>("key"), 2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a <c>int</c> value can be read
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_Progress_Get_Int()
|
||||
{
|
||||
progress.AddOrUpdate<int>("key", 1);
|
||||
Assert.AreEqual(progress.Get<int>("key"), 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a <c>double</c> value can be read
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_Progress_Get_Double()
|
||||
{
|
||||
progress.AddOrUpdate<double>("key", 1.0);
|
||||
Assert.AreEqual(progress.Get<double>("key"), 1.0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a <c>string</c> value can be read
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_Progress_Get_String()
|
||||
{
|
||||
progress.AddOrUpdate<string>("key", "Hello World!");
|
||||
Assert.AreEqual(progress.Get<string>("key"), "Hello World!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a serializable struct can be read
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_Progress_Get_Struct()
|
||||
{
|
||||
int R = 1, G = 10, B = 100;
|
||||
float X = 0.1f, Y = 0.01f, Z = 0.001f;
|
||||
SerializableStruct data = new SerializableStruct { r = R, g = G, b = B, x = X, y = Y, z = Z };
|
||||
progress.AddOrUpdate<SerializableStruct>("key", data);
|
||||
SerializableStruct result = progress.Get<SerializableStruct>("key");
|
||||
Assert.AreEqual(result, data);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
@@ -12,20 +12,10 @@ using UnityEngine;
|
||||
public class UserListTest
|
||||
{
|
||||
/// <summary>
|
||||
/// Create a new path so the existing users.json file will not be overwritten
|
||||
/// Create a new path so the existing .json file will not be overwritten
|
||||
/// </summary>
|
||||
private static string PATH = $"{Application.persistentDataPath}/unit_test_users.json";
|
||||
|
||||
/// <summary>
|
||||
/// NUnit test magic (for skipping the setup)
|
||||
/// </summary>
|
||||
public const string SKIP_SETUP = "SKIP_SETUP";
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the userlist to be tested
|
||||
/// </summary>
|
||||
private UserList userList;
|
||||
|
||||
/// <summary>
|
||||
/// Helper variable for quick user creation
|
||||
/// </summary>
|
||||
@@ -34,11 +24,7 @@ public class UserListTest
|
||||
/// <summary>
|
||||
/// Helper variable for quick user creation
|
||||
/// </summary>
|
||||
private Sprite avatar = Sprite.Create(
|
||||
Texture2D.blackTexture,
|
||||
new Rect(0, 0, Texture2D.blackTexture.width, Texture2D.blackTexture.height),
|
||||
new Vector2(0.5f, 0.5f)
|
||||
);
|
||||
private Sprite avatar = null;
|
||||
|
||||
/// <summary>
|
||||
/// Setup the tests
|
||||
@@ -46,27 +32,14 @@ public class UserListTest
|
||||
[SetUp]
|
||||
public void Setup_UserList()
|
||||
{
|
||||
// Check whether the current test needs to skip the setup
|
||||
ArrayList cat = TestContext.CurrentContext.Test.Properties["_CATEGORIES"] as ArrayList;
|
||||
bool skip = cat != null && cat.Contains(SKIP_SETUP);
|
||||
if (!skip)
|
||||
{
|
||||
// The actual setup code
|
||||
UserList.PATH = UserListTest.PATH;
|
||||
userList = ScriptableObject.CreateInstance<UserList>();
|
||||
}
|
||||
}
|
||||
PersistentDataController.PATH = UserListTest.PATH;
|
||||
|
||||
/// <summary>
|
||||
/// Test whether the UserList.PATH is correctly set
|
||||
/// </summary>
|
||||
[Test]
|
||||
[Category(SKIP_SETUP)]
|
||||
public void Test_UserList_OnEnable()
|
||||
{
|
||||
UserList.PATH = null;
|
||||
userList = ScriptableObject.CreateInstance<UserList>();
|
||||
Assert.AreEqual($"{Application.persistentDataPath}/users.json", UserList.PATH);
|
||||
if (File.Exists(PATH))
|
||||
File.Delete(PATH);
|
||||
|
||||
PersistentDataController.GetInstance().Load();
|
||||
AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
|
||||
avatar = UserList.AVATARS[0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -75,36 +48,22 @@ public class UserListTest
|
||||
[Test]
|
||||
public void Test_New_UserList()
|
||||
{
|
||||
Assert.IsNotNull(userList);
|
||||
Assert.Zero(userList.GetUsers().Count);
|
||||
Assert.Zero(UserList.GetUsers().Count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test for creation of new user (without adding the user to the list)
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_UserList_CreateNewUser()
|
||||
public void Test_UserList_AddUser()
|
||||
{
|
||||
User user = userList.CreateNewUser(username, avatar);
|
||||
Assert.Zero(UserList.GetUsers().Count);
|
||||
User user = UserList.AddUser(username, avatar);
|
||||
|
||||
Assert.IsNotNull(user);
|
||||
Assert.Zero(userList.GetUsers().Count);
|
||||
Assert.AreEqual(username, user.username);
|
||||
Assert.AreEqual(avatar, user.avatar);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test for creating a new user and adding the user to the list
|
||||
/// </summary>
|
||||
public void Test_UserList_CreateAndAddNewUser()
|
||||
{
|
||||
Assert.AreEqual(-1, userList.GetCurrentUserIndex());
|
||||
User user = userList.CreateAndAddNewUser(username, avatar);
|
||||
|
||||
Assert.IsNotNull(user);
|
||||
Assert.AreEqual(1, userList.GetUsers().Count);
|
||||
Assert.AreEqual(user, userList.GetUsers()[0]);
|
||||
Assert.Zero(userList.GetCurrentUserIndex());
|
||||
Assert.AreEqual(1, UserList.GetUsers().Count);
|
||||
Assert.AreEqual(username, user.GetUsername());
|
||||
Assert.AreEqual(avatar, user.GetAvatar());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -113,9 +72,9 @@ public class UserListTest
|
||||
[Test]
|
||||
public void Test_UserList_GetUserByUsername_Valid()
|
||||
{
|
||||
User u = userList.CreateAndAddNewUser(username, avatar);
|
||||
User v = userList.GetUserByUsername(username);
|
||||
Assert.AreEqual(u, v);
|
||||
User u = UserList.AddUser(username, avatar);
|
||||
User v = UserList.GetUserByUsername(username);
|
||||
Assert.AreEqual(u.GetUsername(), v.GetUsername());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -124,32 +83,70 @@ public class UserListTest
|
||||
[Test]
|
||||
public void Test_UserList_GetUserByUsername_Null()
|
||||
{
|
||||
User user = userList.GetUserByUsername("not-a-user");
|
||||
User user = UserList.GetUserByUsername("not-a-user");
|
||||
Assert.IsNull(user);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test whether an existing user can be found by its username
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_UserList_GetUserByIndex_Valid()
|
||||
{
|
||||
User u = UserList.AddUser(username, avatar);
|
||||
User v = UserList.GetUserByIndex(0);
|
||||
Assert.AreEqual(u.GetUsername(), v.GetUsername());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a non-existing user can not be found
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_UserList_GetUserByIndex_Exception()
|
||||
{
|
||||
Assert.Throws<IndexOutOfRangeException>(delegate { UserList.GetUserByIndex(0); });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a userlist is correctly returned
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_UserList_GetUsers()
|
||||
{
|
||||
List<User> u = new List<User>();
|
||||
for (int i = 0; i < 5; i++)
|
||||
u.Add(UserList.AddUser($"{username}_{i}", avatar));
|
||||
|
||||
List<User> v = UserList.GetUsers();
|
||||
Assert.AreEqual(v.Count, u.Count);
|
||||
for (int i = 0; i < 5; i++)
|
||||
Assert.AreEqual(u[i].GetUsername(), v[i].GetUsername());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether the correct current user is returned
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_UserList_GetCurrentUser()
|
||||
{
|
||||
User u = userList.CreateAndAddNewUser($"{username}_{'u'}", avatar);
|
||||
User v = userList.CreateAndAddNewUser($"{username}_{'v'}", avatar);
|
||||
User w = userList.CreateAndAddNewUser($"{username}_{'w'}", avatar);
|
||||
userList.ChangeCurrentUser(2);
|
||||
User u = UserList.AddUser($"{username}_{'u'}", avatar);
|
||||
User v = UserList.AddUser($"{username}_{'v'}", avatar);
|
||||
User w = UserList.AddUser($"{username}_{'w'}", avatar);
|
||||
UserList.ChangeCurrentUser(2);
|
||||
|
||||
User W = userList.GetCurrentUser();
|
||||
Assert.AreEqual(w, W);
|
||||
User W = UserList.GetCurrentUser();
|
||||
Assert.AreEqual(w.GetUsername(), W.GetUsername());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a null user is returned when the userlist is empty
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_UserList_GetCurrent_Empty()
|
||||
public void Test_UserList_GetCurrentUser_Empty()
|
||||
{
|
||||
User user = userList.GetCurrentUser();
|
||||
User user = UserList.GetCurrentUser();
|
||||
Assert.IsNull(user);
|
||||
}
|
||||
|
||||
@@ -157,24 +154,30 @@ public class UserListTest
|
||||
/// Test whether the correct index is returned for the current user
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_UserList_GetCurrentUserIndex()
|
||||
public void Test_UserList_IndexOf_Valid()
|
||||
{
|
||||
User u = userList.CreateAndAddNewUser($"{username}_{'u'}", avatar);
|
||||
User v = userList.CreateAndAddNewUser($"{username}_{'v'}", avatar);
|
||||
User w = userList.CreateAndAddNewUser($"{username}_{'w'}", avatar);
|
||||
userList.ChangeCurrentUser(2);
|
||||
User u = UserList.AddUser($"{username}_{'u'}", avatar);
|
||||
User v = UserList.AddUser($"{username}_{'v'}", avatar);
|
||||
User w = UserList.AddUser($"{username}_{'w'}", avatar);
|
||||
UserList.ChangeCurrentUser(2);
|
||||
|
||||
int idx = userList.GetCurrentUserIndex();
|
||||
Assert.AreEqual(2, idx);
|
||||
Assert.AreEqual(0, UserList.IndexOf(u.GetUsername()));
|
||||
Assert.AreEqual(1, UserList.IndexOf(v.GetUsername()));
|
||||
Assert.AreEqual(2, UserList.IndexOf(w.GetUsername()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a bad index is returned when the userlist is empty
|
||||
/// Test whether the correct index is returned for the current user
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_UserList_GetCurrentUserIndex_Empty()
|
||||
public void Test_UserList_IndexOf_Exception()
|
||||
{
|
||||
Assert.AreEqual(-1, userList.GetCurrentUserIndex());
|
||||
User u = new User(new PersistentDataController.SavedUserData()
|
||||
{
|
||||
username = username,
|
||||
avatarIndex = 0
|
||||
});
|
||||
Assert.Throws<KeyNotFoundException>(delegate { UserList.IndexOf(u.GetUsername()); });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -183,13 +186,13 @@ public class UserListTest
|
||||
[Test]
|
||||
public void Test_UserList_ChangeCurrentUser_ValidIndex()
|
||||
{
|
||||
User u = userList.CreateAndAddNewUser($"{username}_{'u'}", avatar);
|
||||
User v = userList.CreateAndAddNewUser($"{username}_{'v'}", avatar);
|
||||
User w = userList.CreateAndAddNewUser($"{username}_{'w'}", avatar);
|
||||
userList.ChangeCurrentUser(2);
|
||||
User u = UserList.AddUser($"{username}_{'u'}", avatar);
|
||||
User v = UserList.AddUser($"{username}_{'v'}", avatar);
|
||||
User w = UserList.AddUser($"{username}_{'w'}", avatar);
|
||||
UserList.ChangeCurrentUser(2);
|
||||
|
||||
User W = userList.GetCurrentUser();
|
||||
Assert.AreEqual(w, W);
|
||||
User W = UserList.GetCurrentUser();
|
||||
Assert.AreEqual(w.GetUsername(), W.GetUsername());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -198,11 +201,11 @@ public class UserListTest
|
||||
[Test]
|
||||
public void Test_UserList_ChangeCurrentUser_InvalidIndex()
|
||||
{
|
||||
User u = userList.CreateAndAddNewUser($"{username}_{'u'}", avatar);
|
||||
User v = userList.CreateAndAddNewUser($"{username}_{'v'}", avatar);
|
||||
User w = userList.CreateAndAddNewUser($"{username}_{'w'}", avatar);
|
||||
Assert.Throws<IndexOutOfRangeException>(delegate { userList.ChangeCurrentUser(-1); });
|
||||
Assert.Throws<IndexOutOfRangeException>(delegate { userList.ChangeCurrentUser(5); });
|
||||
User u = UserList.AddUser($"{username}_{'u'}", avatar);
|
||||
User v = UserList.AddUser($"{username}_{'v'}", avatar);
|
||||
User w = UserList.AddUser($"{username}_{'w'}", avatar);
|
||||
Assert.Throws<IndexOutOfRangeException>(delegate { UserList.ChangeCurrentUser(-1); });
|
||||
Assert.Throws<IndexOutOfRangeException>(delegate { UserList.ChangeCurrentUser(5); });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -211,41 +214,45 @@ public class UserListTest
|
||||
[Test]
|
||||
public void Test_UserList_ChangeCurrentUser_IndexEmpty()
|
||||
{
|
||||
Assert.Throws<IndexOutOfRangeException>(delegate { userList.ChangeCurrentUser(0); });
|
||||
Assert.Throws<IndexOutOfRangeException>(delegate { UserList.ChangeCurrentUser(0); });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether the current user is correctly changed
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_UserList_ChangeCurrentUser_ValidUser()
|
||||
public void Test_UserList_ChangeCurrentUser_ValidUsername()
|
||||
{
|
||||
User u = userList.CreateAndAddNewUser($"{username}_{'u'}", avatar);
|
||||
User v = userList.CreateAndAddNewUser($"{username}_{'v'}", avatar);
|
||||
User w = userList.CreateAndAddNewUser($"{username}_{'w'}", avatar);
|
||||
userList.ChangeCurrentUser(v);
|
||||
User V = userList.GetCurrentUser();
|
||||
Assert.AreEqual(v, V);
|
||||
User u = UserList.AddUser($"{username}_{'u'}", avatar);
|
||||
User v = UserList.AddUser($"{username}_{'v'}", avatar);
|
||||
User w = UserList.AddUser($"{username}_{'w'}", avatar);
|
||||
UserList.ChangeCurrentUser(v.GetUsername());
|
||||
User V = UserList.GetCurrentUser();
|
||||
Assert.AreEqual(v.GetUsername(), V.GetUsername());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether the current user is not changed when a non-existing user is given
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_UserList_ChangeCurrentUser_InvalidUser()
|
||||
public void Test_UserList_ChangeCurrentUser_InvalidUsername()
|
||||
{
|
||||
User u = userList.CreateAndAddNewUser($"{username}_{'u'}", avatar);
|
||||
User v = userList.CreateNewUser($"{username}_{'v'}", avatar);
|
||||
Assert.Throws<KeyNotFoundException>(delegate { userList.ChangeCurrentUser(v); });
|
||||
User u = UserList.AddUser($"{username}_{'u'}", avatar);
|
||||
User v = new User(new PersistentDataController.SavedUserData()
|
||||
{
|
||||
username = $"{username}_{'v'}",
|
||||
avatarIndex = 0
|
||||
});
|
||||
Assert.Throws<KeyNotFoundException>(delegate { UserList.ChangeCurrentUser(v.GetUsername()); });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether the current user is not changed when a null user is given
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_UserList_ChangeCurrentUser_NullUser()
|
||||
public void Test_UserList_ChangeCurrentUser_NullUsername()
|
||||
{
|
||||
Assert.Throws<KeyNotFoundException>(delegate { userList.ChangeCurrentUser(null); });
|
||||
Assert.Throws<KeyNotFoundException>(delegate { UserList.ChangeCurrentUser(null); });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -254,10 +261,10 @@ public class UserListTest
|
||||
[Test]
|
||||
public void Test_UserList_DeleteUser_ValidIndex()
|
||||
{
|
||||
User u = userList.CreateAndAddNewUser($"{username}_{'u'}", avatar);
|
||||
User v = userList.CreateAndAddNewUser($"{username}_{'v'}", avatar);
|
||||
User w = userList.CreateAndAddNewUser($"{username}_{'w'}", avatar);
|
||||
Assert.IsTrue(userList.DeleteUser(1));
|
||||
User u = UserList.AddUser($"{username}_{'u'}", avatar);
|
||||
User v = UserList.AddUser($"{username}_{'v'}", avatar);
|
||||
User w = UserList.AddUser($"{username}_{'w'}", avatar);
|
||||
Assert.IsTrue(UserList.DeleteUser(1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -266,11 +273,11 @@ public class UserListTest
|
||||
[Test]
|
||||
public void Test_UserList_DeleteUser_InValidIndex()
|
||||
{
|
||||
User u = userList.CreateAndAddNewUser($"{username}_{'u'}", avatar);
|
||||
User v = userList.CreateAndAddNewUser($"{username}_{'v'}", avatar);
|
||||
User w = userList.CreateAndAddNewUser($"{username}_{'w'}", avatar);
|
||||
Assert.IsFalse(userList.DeleteUser(-1));
|
||||
Assert.IsFalse(userList.DeleteUser(5));
|
||||
User u = UserList.AddUser($"{username}_{'u'}", avatar);
|
||||
User v = UserList.AddUser($"{username}_{'v'}", avatar);
|
||||
User w = UserList.AddUser($"{username}_{'w'}", avatar);
|
||||
Assert.Throws<IndexOutOfRangeException>(delegate { UserList.DeleteUser(-1); });
|
||||
Assert.Throws<IndexOutOfRangeException>(delegate { UserList.DeleteUser(5); });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -279,44 +286,61 @@ public class UserListTest
|
||||
[Test]
|
||||
public void Test_UserList_DeleteUser_IndexEmpty()
|
||||
{
|
||||
Assert.IsFalse(userList.DeleteUser(0));
|
||||
Assert.Throws<IndexOutOfRangeException>(delegate { UserList.DeleteUser(0); });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether deleting an existing user will correctly remove the user and set the currentUserIndex correctly
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_UserList_DeleteUser_LastValid()
|
||||
public void Test_UserList_DeleteUser_BeforeCurrentUser()
|
||||
{
|
||||
User u = userList.CreateAndAddNewUser($"{username}_{'u'}", avatar);
|
||||
User v = userList.CreateAndAddNewUser($"{username}_{'v'}", avatar);
|
||||
User w = userList.CreateAndAddNewUser($"{username}_{'w'}", avatar);
|
||||
userList.ChangeCurrentUser(2);
|
||||
User u = UserList.AddUser($"{username}_{'u'}", avatar);
|
||||
User v = UserList.AddUser($"{username}_{'v'}", avatar);
|
||||
User w = UserList.AddUser($"{username}_{'w'}", avatar);
|
||||
UserList.ChangeCurrentUser(1);
|
||||
|
||||
Assert.AreEqual(3, userList.GetUsers().Count);
|
||||
Assert.AreEqual(2, userList.GetCurrentUserIndex());
|
||||
Assert.IsTrue(userList.DeleteUser(w));
|
||||
Assert.AreEqual(2, userList.GetUsers().Count);
|
||||
Assert.AreEqual(1, userList.GetCurrentUserIndex());
|
||||
Assert.AreEqual(3, UserList.GetUsers().Count);
|
||||
Assert.AreEqual(1, UserList.IndexOf(UserList.GetCurrentUser().GetUsername()));
|
||||
Assert.IsTrue(UserList.DeleteUser(u.GetUsername()));
|
||||
Assert.AreEqual(2, UserList.GetUsers().Count);
|
||||
Assert.AreEqual(0, UserList.IndexOf(UserList.GetCurrentUser().GetUsername()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether deleting an existing user will remove the user correctly
|
||||
/// Test whether deleting an existing user will correctly remove the user and set the currentUserIndex correctly
|
||||
/// </summary>
|
||||
/// <remarks>This will change the currentUserIndex to point to another user</remarks>
|
||||
[Test]
|
||||
public void Test_UserList_DeleteUser_FirstValid()
|
||||
public void Test_UserList_DeleteUser_CurrentUser()
|
||||
{
|
||||
User u = userList.CreateAndAddNewUser($"{username}_{'u'}", avatar);
|
||||
User v = userList.CreateAndAddNewUser($"{username}_{'v'}", avatar);
|
||||
User w = userList.CreateAndAddNewUser($"{username}_{'w'}", avatar);
|
||||
userList.ChangeCurrentUser(0);
|
||||
User u = UserList.AddUser($"{username}_{'u'}", avatar);
|
||||
User v = UserList.AddUser($"{username}_{'v'}", avatar);
|
||||
User w = UserList.AddUser($"{username}_{'w'}", avatar);
|
||||
UserList.ChangeCurrentUser(1);
|
||||
|
||||
Assert.AreEqual(3, userList.GetUsers().Count);
|
||||
Assert.AreEqual(0, userList.GetCurrentUserIndex());
|
||||
Assert.IsTrue(userList.DeleteUser(u));
|
||||
Assert.AreEqual(2, userList.GetUsers().Count);
|
||||
Assert.AreEqual(0, userList.GetCurrentUserIndex());
|
||||
Assert.AreEqual(3, UserList.GetUsers().Count);
|
||||
Assert.AreEqual(1, UserList.IndexOf(UserList.GetCurrentUser().GetUsername()));
|
||||
Assert.IsTrue(UserList.DeleteUser(v.GetUsername()));
|
||||
Assert.AreEqual(2, UserList.GetUsers().Count);
|
||||
Assert.AreEqual(0, UserList.IndexOf(UserList.GetCurrentUser().GetUsername()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether deleting an existing user will correctly remove the user and set the currentUserIndex correctly
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_UserList_DeleteUser_AfterCurrentUser()
|
||||
{
|
||||
User u = UserList.AddUser($"{username}_{'u'}", avatar);
|
||||
User v = UserList.AddUser($"{username}_{'v'}", avatar);
|
||||
User w = UserList.AddUser($"{username}_{'w'}", avatar);
|
||||
UserList.ChangeCurrentUser(1);
|
||||
|
||||
Assert.AreEqual(3, UserList.GetUsers().Count);
|
||||
Assert.AreEqual(1, UserList.IndexOf(UserList.GetCurrentUser().GetUsername()));
|
||||
Assert.IsTrue(UserList.DeleteUser(w.GetUsername()));
|
||||
Assert.AreEqual(2, UserList.GetUsers().Count);
|
||||
Assert.AreEqual(1, UserList.IndexOf(UserList.GetCurrentUser().GetUsername()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -325,12 +349,16 @@ public class UserListTest
|
||||
[Test]
|
||||
public void Test_UserList_DeleteUser_Invalid()
|
||||
{
|
||||
User u = userList.CreateAndAddNewUser($"{username}_{'u'}", avatar);
|
||||
User v = userList.CreateNewUser($"{username}_{'v'}", avatar);
|
||||
User u = UserList.AddUser($"{username}_{'u'}", avatar);
|
||||
User v = new User(new PersistentDataController.SavedUserData()
|
||||
{
|
||||
username = $"{username}_{'v'}",
|
||||
avatarIndex = 0
|
||||
});
|
||||
|
||||
Assert.AreEqual(1, userList.GetUsers().Count);
|
||||
Assert.IsFalse(userList.DeleteUser(v));
|
||||
Assert.AreEqual(1, userList.GetUsers().Count);
|
||||
Assert.AreEqual(1, UserList.GetUsers().Count);
|
||||
Assert.Throws<KeyNotFoundException>(delegate { UserList.DeleteUser(v.GetUsername()); });
|
||||
Assert.AreEqual(1, UserList.GetUsers().Count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -339,10 +367,14 @@ public class UserListTest
|
||||
[Test]
|
||||
public void Test_UserList_DeleteUser_Empty()
|
||||
{
|
||||
User user = userList.CreateNewUser(username, avatar);
|
||||
Assert.Zero(userList.GetUsers().Count);
|
||||
Assert.IsFalse(userList.DeleteUser(user));
|
||||
Assert.Zero(userList.GetUsers().Count);
|
||||
User user = new User(new PersistentDataController.SavedUserData()
|
||||
{
|
||||
username = username,
|
||||
avatarIndex = 0
|
||||
});
|
||||
Assert.Zero(UserList.GetUsers().Count);
|
||||
Assert.Throws<KeyNotFoundException>(delegate { UserList.DeleteUser(user.GetUsername()); });
|
||||
Assert.Zero(UserList.GetUsers().Count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -351,23 +383,16 @@ public class UserListTest
|
||||
[Test]
|
||||
public void Test_UserList_Save_New()
|
||||
{
|
||||
if (File.Exists(PATH))
|
||||
{
|
||||
File.Delete(PATH);
|
||||
}
|
||||
|
||||
List<User> u = new List<User>();
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
u.Add(userList.CreateAndAddNewUser($"{username}_{i}", avatar));
|
||||
}
|
||||
userList.ChangeCurrentUser(3);
|
||||
userList.Save();
|
||||
u.Add(UserList.AddUser($"{username}_{i}", avatar));
|
||||
|
||||
UserList.ChangeCurrentUser(3);
|
||||
UserList.Save();
|
||||
FileAssert.Exists(PATH);
|
||||
|
||||
string content = File.ReadAllText(PATH);
|
||||
int id = avatar.GetInstanceID();
|
||||
string expected = $"{{\"currentUserIndex\":3,\"storedUsers\":[{{\"username\":\"u5erNam3_0\",\"avatar\":{{\"instanceID\":{id}}},\"playtime\":0.0,\"courses\":[],\"minigames\":[]}},{{\"username\":\"u5erNam3_1\",\"avatar\":{{\"instanceID\":{id}}},\"playtime\":0.0,\"courses\":[],\"minigames\":[]}},{{\"username\":\"u5erNam3_2\",\"avatar\":{{\"instanceID\":{id}}},\"playtime\":0.0,\"courses\":[],\"minigames\":[]}},{{\"username\":\"u5erNam3_3\",\"avatar\":{{\"instanceID\":{id}}},\"playtime\":0.0,\"courses\":[],\"minigames\":[]}},{{\"username\":\"u5erNam3_4\",\"avatar\":{{\"instanceID\":{id}}},\"playtime\":0.0,\"courses\":[],\"minigames\":[]}}]}}";
|
||||
string expected = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"u5erNam3_0\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}},{{\"entries\":[],\"username\":\"u5erNam3_1\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}},{{\"entries\":[],\"username\":\"u5erNam3_2\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}},{{\"entries\":[],\"username\":\"u5erNam3_3\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}},{{\"entries\":[],\"username\":\"u5erNam3_4\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":3,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||
Assert.AreEqual(expected, content);
|
||||
}
|
||||
|
||||
@@ -385,16 +410,14 @@ public class UserListTest
|
||||
|
||||
List<User> u = new List<User>();
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
u.Add(userList.CreateAndAddNewUser($"{username}_{i}", avatar));
|
||||
}
|
||||
userList.ChangeCurrentUser(3);
|
||||
userList.Save();
|
||||
u.Add(UserList.AddUser($"{username}_{i}", avatar));
|
||||
|
||||
UserList.ChangeCurrentUser(3);
|
||||
UserList.Save();
|
||||
FileAssert.Exists(PATH);
|
||||
|
||||
string content = File.ReadAllText(PATH);
|
||||
int id = avatar.GetInstanceID();
|
||||
string expected = $"{{\"currentUserIndex\":3,\"storedUsers\":[{{\"username\":\"u5erNam3_0\",\"avatar\":{{\"instanceID\":{id}}},\"playtime\":0.0,\"courses\":[],\"minigames\":[]}},{{\"username\":\"u5erNam3_1\",\"avatar\":{{\"instanceID\":{id}}},\"playtime\":0.0,\"courses\":[],\"minigames\":[]}},{{\"username\":\"u5erNam3_2\",\"avatar\":{{\"instanceID\":{id}}},\"playtime\":0.0,\"courses\":[],\"minigames\":[]}},{{\"username\":\"u5erNam3_3\",\"avatar\":{{\"instanceID\":{id}}},\"playtime\":0.0,\"courses\":[],\"minigames\":[]}},{{\"username\":\"u5erNam3_4\",\"avatar\":{{\"instanceID\":{id}}},\"playtime\":0.0,\"courses\":[],\"minigames\":[]}}]}}";
|
||||
string expected = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"u5erNam3_0\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}},{{\"entries\":[],\"username\":\"u5erNam3_1\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}},{{\"entries\":[],\"username\":\"u5erNam3_2\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}},{{\"entries\":[],\"username\":\"u5erNam3_3\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}},{{\"entries\":[],\"username\":\"u5erNam3_4\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":3,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||
Assert.AreEqual(expected, content);
|
||||
}
|
||||
|
||||
@@ -404,67 +427,11 @@ public class UserListTest
|
||||
[Test]
|
||||
public void Test_UserList_Save_Empty()
|
||||
{
|
||||
userList.Save();
|
||||
UserList.Save();
|
||||
FileAssert.Exists(PATH);
|
||||
|
||||
string content = File.ReadAllText(PATH);
|
||||
string expected = "{\"currentUserIndex\":-1,\"storedUsers\":[]}";
|
||||
string expected = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||
Assert.AreEqual(expected, content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether a userlist (containing some users) is correrctly loaded
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_UserList_Load()
|
||||
{
|
||||
List<User> u = new List<User>();
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
u.Add(userList.CreateAndAddNewUser($"{username}_{i}", avatar));
|
||||
}
|
||||
userList.ChangeCurrentUser(3);
|
||||
userList.Save();
|
||||
|
||||
userList.Load();
|
||||
Assert.AreEqual(userList.GetUsers().Count, u.Count);
|
||||
Assert.AreEqual(userList.GetCurrentUserIndex(), 3);
|
||||
List<User> v = userList.GetUsers();
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
Assert.AreEqual(u[i].username, v[i].username);
|
||||
Assert.AreEqual(u[i].avatar, v[i].avatar);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test whether an empty userlist is correctly loaded
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_UserList_Load_Empty()
|
||||
{
|
||||
userList.Save();
|
||||
userList.Load();
|
||||
Assert.Zero(userList.GetUsers().Count);
|
||||
Assert.AreEqual(-1, userList.GetCurrentUserIndex());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test if the user save file is not found, a new one will be created and an empty userlist will be loaded
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void Test_UserList_Load_NotFound()
|
||||
{
|
||||
List<User> u = new List<User>();
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
u.Add(userList.CreateAndAddNewUser($"{username}_{i}", avatar));
|
||||
}
|
||||
userList.ChangeCurrentUser(3);
|
||||
userList.Save();
|
||||
|
||||
File.Delete(PATH);
|
||||
userList.Load();
|
||||
Assert.Zero(userList.GetUsers().Count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,10 @@ public class UserTest
|
||||
[SetUp]
|
||||
public void Setup_User()
|
||||
{
|
||||
user = new User();
|
||||
PersistentDataController.SavedUserData data = new PersistentDataController.SavedUserData();
|
||||
data.username = "username";
|
||||
data.avatarIndex = 0;
|
||||
user = new User(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,8 +33,8 @@ public class UserTest
|
||||
public void Test_New_User()
|
||||
{
|
||||
Assert.NotNull(user);
|
||||
Assert.Zero(user.courses.Count);
|
||||
Assert.Zero(user.minigames.Count);
|
||||
Assert.Zero(user.GetCourses().Count);
|
||||
Assert.Zero(user.GetMinigames().Count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -40,10 +43,10 @@ public class UserTest
|
||||
[Test]
|
||||
public void Test_User_AddCourse()
|
||||
{
|
||||
Progress p = new Progress();
|
||||
user.courses.Add(p);
|
||||
Assert.AreEqual(user.courses.Count, 1);
|
||||
Assert.Zero(user.minigames.Count);
|
||||
var p = new PersistentDataController.SavedCourseProgress();
|
||||
user.AddCourseProgress(p);
|
||||
Assert.AreEqual(user.GetCourses().Count, 1);
|
||||
Assert.Zero(user.GetMinigames().Count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -52,10 +55,10 @@ public class UserTest
|
||||
[Test]
|
||||
public void Test_User_AddMinigame()
|
||||
{
|
||||
Progress p = new Progress();
|
||||
user.minigames.Add(p);
|
||||
Assert.Zero(user.courses.Count);
|
||||
Assert.AreEqual(user.minigames.Count, 1);
|
||||
var p = new PersistentDataController.SavedMinigameProgress();
|
||||
user.AddMinigameProgress(p);
|
||||
Assert.Zero(user.GetCourses().Count);
|
||||
Assert.AreEqual(user.GetMinigames().Count, 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -73,10 +76,10 @@ public class UserTest
|
||||
[Test]
|
||||
public void Test_User_GetRecentCourses_All()
|
||||
{
|
||||
Progress p = new Progress();
|
||||
p.AddOrUpdate<CourseIndex>("courseIndex", CourseIndex.FINGERSPELLING);
|
||||
p.AddOrUpdate<float>("courseProgress", 0.5f);
|
||||
user.courses.Add(p);
|
||||
var p = new PersistentDataController.SavedCourseProgress();
|
||||
p.courseIndex = CourseIndex.FINGERSPELLING;
|
||||
p.progress = 0.5f;
|
||||
user.AddCourseProgress(p);
|
||||
List<Tuple<CourseIndex, float>> list = user.GetRecentCourses();
|
||||
Assert.AreEqual(list.Count, 1);
|
||||
Assert.AreEqual(list[0].Item1, CourseIndex.FINGERSPELLING);
|
||||
@@ -101,10 +104,10 @@ public class UserTest
|
||||
[Test]
|
||||
public void Test_User_GetRecommendedCourses_All()
|
||||
{
|
||||
Progress p = new Progress();
|
||||
p.AddOrUpdate<CourseIndex>("courseIndex", CourseIndex.FINGERSPELLING);
|
||||
p.AddOrUpdate<float>("courseProgress", 0.5f);
|
||||
user.courses.Add(p);
|
||||
var p = new PersistentDataController.SavedCourseProgress();
|
||||
p.courseIndex = CourseIndex.FINGERSPELLING;
|
||||
p.progress = 0.5f;
|
||||
user.AddCourseProgress(p);
|
||||
List<Tuple<CourseIndex, float>> list = user.GetRecommendedCourses();
|
||||
Assert.AreEqual(list.Count, 1);
|
||||
Assert.AreEqual(list[0].Item1, CourseIndex.FINGERSPELLING);
|
||||
@@ -127,13 +130,13 @@ public class UserTest
|
||||
[Test]
|
||||
public void Test_User_GetCourseProgress_Valid()
|
||||
{
|
||||
Progress p = new Progress();
|
||||
p.AddOrUpdate<CourseIndex>("courseIndex", CourseIndex.FINGERSPELLING);
|
||||
p.AddOrUpdate<float>("courseProgress", 3.14159265f);
|
||||
user.courses.Add(p);
|
||||
Progress q = user.GetCourseProgress(CourseIndex.FINGERSPELLING);
|
||||
Assert.AreEqual(q.Get<CourseIndex>("courseIndex"), CourseIndex.FINGERSPELLING);
|
||||
Assert.AreEqual(q.Get<float>("courseProgress"), 3.14159265f);
|
||||
var p = new PersistentDataController.SavedCourseProgress();
|
||||
p.courseIndex = CourseIndex.FINGERSPELLING;
|
||||
p.progress = 3.14159265f;
|
||||
user.AddCourseProgress(p);
|
||||
var q = user.GetCourseProgress(CourseIndex.FINGERSPELLING);
|
||||
Assert.AreEqual(q.courseIndex, CourseIndex.FINGERSPELLING);
|
||||
Assert.AreEqual(q.progress, 3.14159265f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -145,9 +148,9 @@ public class UserTest
|
||||
Assert.Null(user.GetMinigameProgress(MinigameIndex.SPELLING_BEE));
|
||||
Assert.Null(user.GetMinigameProgress((MinigameIndex)100));
|
||||
|
||||
Progress p = new Progress();
|
||||
p.AddOrUpdate<MinigameIndex>("minigameIndex", MinigameIndex.SPELLING_BEE);
|
||||
user.minigames.Add(p);
|
||||
var p = new PersistentDataController.SavedMinigameProgress();
|
||||
p.minigameIndex = MinigameIndex.SPELLING_BEE;
|
||||
user.AddMinigameProgress(p);
|
||||
Assert.Null(user.GetMinigameProgress(MinigameIndex.HANGMAN));
|
||||
}
|
||||
|
||||
@@ -157,10 +160,12 @@ public class UserTest
|
||||
[Test]
|
||||
public void Test_User_GetMinigameProgress_Valid()
|
||||
{
|
||||
Progress p = new Progress();
|
||||
p.AddOrUpdate<MinigameIndex>("minigameIndex", MinigameIndex.SPELLING_BEE);
|
||||
user.minigames.Add(p);
|
||||
Progress q = user.GetMinigameProgress(MinigameIndex.SPELLING_BEE);
|
||||
Assert.AreEqual(q.Get<CourseIndex>("minigameIndex"), CourseIndex.FINGERSPELLING);
|
||||
var p = new PersistentDataController.SavedMinigameProgress();
|
||||
p.minigameIndex = MinigameIndex.SPELLING_BEE;
|
||||
user.AddMinigameProgress(p);
|
||||
var q = user.GetMinigameProgress(MinigameIndex.SPELLING_BEE);
|
||||
Assert.AreEqual(q.minigameIndex, MinigameIndex.SPELLING_BEE);
|
||||
Assert.Zero(q.latestScores.Count);
|
||||
Assert.Zero(q.highestScores.Count);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,6 +113,18 @@ TextureImporter:
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Windows Store Apps
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f3e4df0d6e02ad2f0905d1614f2e6545
|
||||
guid: 06c24ca85a8bc6b4d947cdb9b2492e99
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
|
||||
@@ -4,7 +4,7 @@ using UnityEngine;
|
||||
/// <summary>
|
||||
/// Keep track of all courses
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "Create new Scriptable/CourseList")]
|
||||
[CreateAssetMenu(menuName = "Create new Scriptable/Course List")]
|
||||
public class CourseList : ScriptableObject
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
"name": "InterfacesScripts",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:5c2b5ba89f9e74e418232e154bc5cc7a",
|
||||
"GUID:d23f64cfd3b314bb4a18a8284c99bf5e"
|
||||
"GUID:d23f64cfd3b314bb4a18a8284c99bf5e",
|
||||
"GUID:e83ddf9a537a96b4a804a16bb7872ec1"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
||||
@@ -5,7 +5,7 @@ using UnityEngine;
|
||||
/// <summary>
|
||||
/// Keep track off installed minigames
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "Create new Scriptable/MinigameList")]
|
||||
[CreateAssetMenu(menuName = "Create new Scriptable/Minigame List")]
|
||||
public class MinigameList : ScriptableObject
|
||||
{
|
||||
/// <summary>
|
||||
@@ -33,7 +33,7 @@ public class MinigameList : ScriptableObject
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
public void SetCurrentMinigame(MinigameIndex index)
|
||||
{
|
||||
{
|
||||
currentMinigameIndex = minigames.FindIndex((mi) => mi.index == index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ using UnityEngine;
|
||||
/// <summary>
|
||||
/// Keep track off defined themes
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "Create new Scriptable/ThemeList")]
|
||||
[CreateAssetMenu(menuName = "Create new Scriptable/Theme List")]
|
||||
public class ThemeList : ScriptableObject
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
|
||||
using NUnit.Framework;
|
||||
using TMPro;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
|
||||
public class BackButtonTests
|
||||
{
|
||||
@@ -15,14 +11,13 @@ public class BackButtonTests
|
||||
[UnitySetUp]
|
||||
public IEnumerator SetupFunction()
|
||||
{
|
||||
string path = $"{Application.persistentDataPath}/users.json";
|
||||
var oneUser = "{\"currentUserIndex\": 0,\"storedUsers\": [{\"username\": \"TEST\",\"avatar\": {\"instanceID\": 40848},\"playtime\": 0.0,\"courses\": [],\"minigames\": []}]}";
|
||||
string path = $"{Application.persistentDataPath}/unit_test_users.json";
|
||||
string oneUser = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||
|
||||
using (StreamWriter writer = new StreamWriter(path))
|
||||
{
|
||||
writer.Write(oneUser);
|
||||
}
|
||||
|
||||
File.WriteAllText(path, oneUser);
|
||||
PersistentDataController.PATH = path;
|
||||
PersistentDataController.GetInstance().Load();
|
||||
AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
|
||||
SystemController.GetInstance().LoadNextScene("Common/Scenes/MainMenuScreen");
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
SystemController.GetInstance().LoadNextScene("Common/Scenes/ListMinigamesScreen");
|
||||
@@ -33,11 +28,11 @@ public class BackButtonTests
|
||||
public IEnumerator BackTest()
|
||||
{
|
||||
|
||||
var backButton = (BackButton) GameObject.FindObjectOfType(typeof(BackButton));
|
||||
var backButton = (BackButton)GameObject.FindObjectOfType(typeof(BackButton));
|
||||
backButton.Back();
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
var mainMenuScreen = (MainMenuScreen) GameObject.FindObjectOfType(typeof(MainMenuScreen));
|
||||
var mainMenuScreen = (MainMenuScreen)GameObject.FindObjectOfType(typeof(MainMenuScreen));
|
||||
Assert.IsNotNull(mainMenuScreen);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
"InterfacesScripts",
|
||||
"Unity.TextMeshPro",
|
||||
"AccountsScripts",
|
||||
"SignPredictor"
|
||||
"SignPredictor",
|
||||
"SystemArchitecture"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
|
||||
using NUnit.Framework;
|
||||
using TMPro;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
|
||||
public class CourseActivityTests
|
||||
{
|
||||
@@ -15,14 +11,13 @@ public class CourseActivityTests
|
||||
[UnitySetUp]
|
||||
public IEnumerator SetupFunction()
|
||||
{
|
||||
string path = $"{Application.persistentDataPath}/users.json";
|
||||
var oneUser = "{\"currentUserIndex\": 0,\"storedUsers\": [{\"username\": \"TEST\",\"avatar\": {\"instanceID\": 40848},\"playtime\": 0.0,\"courses\": [],\"minigames\": []}]}";
|
||||
|
||||
using (StreamWriter writer = new StreamWriter(path))
|
||||
{
|
||||
writer.Write(oneUser);
|
||||
}
|
||||
string path = $"{Application.persistentDataPath}/unit_test_users.json";
|
||||
string oneUser = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||
|
||||
File.WriteAllText(path, oneUser);
|
||||
PersistentDataController.PATH = path;
|
||||
PersistentDataController.GetInstance().Load();
|
||||
AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
|
||||
SystemController.GetInstance().LoadNextScene("Common/Scenes/CourseActivityScreen");
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
}
|
||||
@@ -30,11 +25,11 @@ public class CourseActivityTests
|
||||
[UnityTest]
|
||||
public IEnumerator StartCoursesTests()
|
||||
{
|
||||
var courseActivityScreen = (CourseActivityScreen) GameObject.FindObjectOfType(typeof(CourseActivityScreen));
|
||||
var courseActivityScreen = (CourseActivityScreen)GameObject.FindObjectOfType(typeof(CourseActivityScreen));
|
||||
courseActivityScreen.StartCourse();
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
var templateCourse = (CoursesController) GameObject.FindObjectOfType(typeof(CoursesController));
|
||||
var templateCourse = (CoursesController)GameObject.FindObjectOfType(typeof(CoursesController));
|
||||
Assert.IsNotNull(templateCourse);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
|
||||
using NUnit.Framework;
|
||||
using TMPro;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
|
||||
public class CourseMenuScreenTest
|
||||
{
|
||||
@@ -15,14 +11,13 @@ public class CourseMenuScreenTest
|
||||
[UnitySetUp]
|
||||
public IEnumerator SetupFunction()
|
||||
{
|
||||
string path = $"{Application.persistentDataPath}/users.json";
|
||||
var oneUser = "{\"currentUserIndex\": 0,\"storedUsers\": [{\"username\": \"TEST\",\"avatar\": {\"instanceID\": 40848},\"playtime\": 0.0,\"courses\": [],\"minigames\": []}]}";
|
||||
|
||||
using (StreamWriter writer = new StreamWriter(path))
|
||||
{
|
||||
writer.Write(oneUser);
|
||||
}
|
||||
string path = $"{Application.persistentDataPath}/unit_test_users.json";
|
||||
string oneUser = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||
|
||||
File.WriteAllText(path, oneUser);
|
||||
PersistentDataController.PATH = path;
|
||||
PersistentDataController.GetInstance().Load();
|
||||
AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
|
||||
SystemController.GetInstance().LoadNextScene("Common/Scenes/CoursesMenuScreen");
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
}
|
||||
@@ -30,7 +25,7 @@ public class CourseMenuScreenTest
|
||||
[UnityTest]
|
||||
public IEnumerator GotoListOfCoursesTest()
|
||||
{
|
||||
var courseMenuScreen = (CourseMenuScreen) GameObject.FindObjectOfType(typeof(CourseMenuScreen));
|
||||
var courseMenuScreen = (CourseMenuScreen)GameObject.FindObjectOfType(typeof(CourseMenuScreen));
|
||||
courseMenuScreen.GotoListOfCourses();
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
|
||||
using NUnit.Framework;
|
||||
using TMPro;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
|
||||
public class ListCoursesScreenTest
|
||||
{
|
||||
@@ -15,14 +11,13 @@ public class ListCoursesScreenTest
|
||||
[UnitySetUp]
|
||||
public IEnumerator SetupFunction()
|
||||
{
|
||||
string path = $"{Application.persistentDataPath}/users.json";
|
||||
var oneUser = "{\"currentUserIndex\": 0,\"storedUsers\": [{\"username\": \"TEST\",\"avatar\": {\"instanceID\": 40848},\"playtime\": 0.0,\"courses\": [],\"minigames\": []}]}";
|
||||
|
||||
using (StreamWriter writer = new StreamWriter(path))
|
||||
{
|
||||
writer.Write(oneUser);
|
||||
}
|
||||
string path = $"{Application.persistentDataPath}/unit_test_users.json";
|
||||
string oneUser = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||
|
||||
File.WriteAllText(path, oneUser);
|
||||
PersistentDataController.PATH = path;
|
||||
PersistentDataController.GetInstance().Load();
|
||||
AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
|
||||
SystemController.GetInstance().LoadNextScene("Common/Scenes/ListCoursesScreen");
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
|
||||
using NUnit.Framework;
|
||||
using TMPro;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
|
||||
public class MainMenuScreenTests
|
||||
@@ -15,14 +13,13 @@ public class MainMenuScreenTests
|
||||
[UnitySetUp]
|
||||
public IEnumerator SetupFunction()
|
||||
{
|
||||
string path = $"{Application.persistentDataPath}/users.json";
|
||||
var oneUser = "{\"currentUserIndex\": 0,\"storedUsers\": [{\"username\": \"TEST\",\"avatar\": {\"instanceID\": 40848},\"playtime\": 0.0,\"courses\": [],\"minigames\": []}]}";
|
||||
|
||||
using (StreamWriter writer = new StreamWriter(path))
|
||||
{
|
||||
writer.Write(oneUser);
|
||||
}
|
||||
string path = $"{Application.persistentDataPath}/unit_test_users.json";
|
||||
string oneUser = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||
|
||||
File.WriteAllText(path, oneUser);
|
||||
PersistentDataController.PATH = path;
|
||||
PersistentDataController.GetInstance().Load();
|
||||
AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
|
||||
SceneManager.LoadScene("Common/Scenes/MainMenuScreen");
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
}
|
||||
@@ -42,28 +39,28 @@ public class MainMenuScreenTests
|
||||
[UnityTest]
|
||||
public IEnumerator GotoMiniGamesTest()
|
||||
{
|
||||
var mainMenuScreen = (MainMenuScreen) GameObject.FindObjectOfType(typeof(MainMenuScreen));
|
||||
var mainMenuScreen = (MainMenuScreen)GameObject.FindObjectOfType(typeof(MainMenuScreen));
|
||||
mainMenuScreen.GotoMinigames();
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
var listMinigamesScreen = (ListMinigamesScreen) GameObject.FindObjectOfType(typeof(ListMinigamesScreen));
|
||||
var listMinigamesScreen = (ListMinigamesScreen)GameObject.FindObjectOfType(typeof(ListMinigamesScreen));
|
||||
Assert.IsNotNull(listMinigamesScreen);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* [UnityTest]
|
||||
public IEnumerator GotoSettingsTest()
|
||||
{
|
||||
Arrange
|
||||
SceneManager.LoadScene("Common/Scenes/MainMenuScreen");
|
||||
/* [UnityTest]
|
||||
public IEnumerator GotoSettingsTest()
|
||||
{
|
||||
Arrange
|
||||
SceneManager.LoadScene("Common/Scenes/MainMenuScreen");
|
||||
|
||||
yield return new WaitForSeconds(1f);
|
||||
var mainMenuScreen = (MainMenuScreen)GameObject.FindObjectOfType(typeof(MainMenuScreen));
|
||||
mainMenuScreen.GotoSettings();
|
||||
yield return new WaitForSeconds(1f);
|
||||
yield return new WaitForSeconds(1f);
|
||||
var mainMenuScreen = (MainMenuScreen)GameObject.FindObjectOfType(typeof(MainMenuScreen));
|
||||
mainMenuScreen.GotoSettings();
|
||||
yield return new WaitForSeconds(1f);
|
||||
|
||||
var minigameActivityScreen = (MinigameActivityScreen)GameObject.FindObjectOfType(typeof(MinigameActivityScreen));
|
||||
Assert.IsNotNull(minigameActivityScreen);
|
||||
}*/
|
||||
var minigameActivityScreen = (MinigameActivityScreen)GameObject.FindObjectOfType(typeof(MinigameActivityScreen));
|
||||
Assert.IsNotNull(minigameActivityScreen);
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
|
||||
using NUnit.Framework;
|
||||
using TMPro;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
|
||||
public class MiniGameActivityScreenTests
|
||||
@@ -15,14 +12,13 @@ public class MiniGameActivityScreenTests
|
||||
[UnitySetUp]
|
||||
public IEnumerator SetupFunction()
|
||||
{
|
||||
string path = $"{Application.persistentDataPath}/users.json";
|
||||
var oneUser = "{\"currentUserIndex\": 0,\"storedUsers\": [{\"username\": \"TEST\",\"avatar\": {\"instanceID\": 40848},\"playtime\": 0.0,\"courses\": [],\"minigames\": []}]}";
|
||||
|
||||
using (StreamWriter writer = new StreamWriter(path))
|
||||
{
|
||||
writer.Write(oneUser);
|
||||
}
|
||||
string path = $"{Application.persistentDataPath}/unit_test_users.json";
|
||||
string oneUser = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||
|
||||
File.WriteAllText(path, oneUser);
|
||||
PersistentDataController.PATH = path;
|
||||
PersistentDataController.GetInstance().Load();
|
||||
AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
|
||||
SystemController.GetInstance().LoadNextScene("Common/Scenes/CoursesMenuScreen");
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
}
|
||||
|
||||
@@ -1,36 +1,31 @@
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
|
||||
using NUnit.Framework;
|
||||
using TMPro;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
|
||||
public class StartGamesTests
|
||||
{
|
||||
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator BootWithUsersTest()
|
||||
{
|
||||
string path = $"{Application.persistentDataPath}/users.json";
|
||||
var oneUser = "{\"currentUserIndex\": 0,\"storedUsers\": [{\"username\": \"TEST\",\"avatar\": {\"instanceID\": 40848},\"playtime\": 0.0,\"courses\": [],\"minigames\": []}]}";
|
||||
|
||||
using (StreamWriter writer = new StreamWriter(path))
|
||||
{
|
||||
writer.Write(oneUser);
|
||||
}
|
||||
string path = $"{Application.persistentDataPath}/unit_test_users.json";
|
||||
string oneUser = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||
|
||||
File.WriteAllText(path, oneUser);
|
||||
PersistentDataController.PATH = path;
|
||||
PersistentDataController.GetInstance().Load();
|
||||
AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
|
||||
SceneManager.LoadScene("Common/Scenes/Boot");
|
||||
|
||||
yield return new WaitForSeconds(1);
|
||||
|
||||
var userCreationScreen = (UserCreationScreen) GameObject.FindObjectOfType(typeof(UserCreationScreen));
|
||||
var bootScreen = (BootScreen) GameObject.FindObjectOfType(typeof(BootScreen));
|
||||
var mainMenuScreen = (MainMenuScreen) GameObject.FindObjectOfType(typeof(MainMenuScreen));
|
||||
var userCreationScreen = (UserCreationScreen)GameObject.FindObjectOfType(typeof(UserCreationScreen));
|
||||
var bootScreen = (BootScreen)GameObject.FindObjectOfType(typeof(BootScreen));
|
||||
var mainMenuScreen = (MainMenuScreen)GameObject.FindObjectOfType(typeof(MainMenuScreen));
|
||||
|
||||
// yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
|
||||
// if (Application.HasUserAuthorization(UserAuthorization.WebCam))
|
||||
@@ -42,41 +37,37 @@ public class StartGamesTests
|
||||
// Assert.AreEqual(bootScreen.errorText.text, "Zorg ervoor dat deze applicatie toegang heeft tot je webcam!");
|
||||
// }
|
||||
// else
|
||||
if(0 >= WebCamTexture.devices.Length){
|
||||
Debug.Log("no webcam");
|
||||
Assert.IsNull(userCreationScreen);
|
||||
if (0 >= WebCamTexture.devices.Length)
|
||||
{
|
||||
Assert.IsNull(mainMenuScreen);
|
||||
Assert.IsNotNull(bootScreen);
|
||||
Assert.AreEqual(bootScreen.errorText.text, "Zorg ervoor dat je webcam correct is aangesloten!");
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
Debug.Log("everything is there");
|
||||
Assert.IsNull(bootScreen);
|
||||
Assert.IsNull(userCreationScreen);
|
||||
Assert.IsNotNull(mainMenuScreen);
|
||||
}
|
||||
Assert.IsNull(userCreationScreen);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator BootWithoutUsersTest()
|
||||
{
|
||||
// Arrange
|
||||
string path = $"{Application.persistentDataPath}/users.json";
|
||||
var oneUser = "{}";
|
||||
|
||||
using (StreamWriter writer = new StreamWriter(path))
|
||||
{
|
||||
writer.Write(oneUser);
|
||||
}
|
||||
string path = $"{Application.persistentDataPath}/unit_test_users.json";
|
||||
string noUsers = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
|
||||
|
||||
File.WriteAllText(path, noUsers);
|
||||
PersistentDataController.PATH = path;
|
||||
PersistentDataController.GetInstance().Load();
|
||||
AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
|
||||
SceneManager.LoadScene("Common/Scenes/Boot");
|
||||
|
||||
yield return new WaitForSeconds(1);
|
||||
|
||||
var userCreationScreen = (UserCreationScreen) GameObject.FindObjectOfType(typeof(UserCreationScreen));
|
||||
var bootScreen = (BootScreen) GameObject.FindObjectOfType(typeof(BootScreen));
|
||||
var mainMenuScreen = (MainMenuScreen) GameObject.FindObjectOfType(typeof(MainMenuScreen));
|
||||
var userCreationScreen = (UserCreationScreen)GameObject.FindObjectOfType(typeof(UserCreationScreen));
|
||||
var bootScreen = (BootScreen)GameObject.FindObjectOfType(typeof(BootScreen));
|
||||
var mainMenuScreen = (MainMenuScreen)GameObject.FindObjectOfType(typeof(MainMenuScreen));
|
||||
|
||||
// yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
|
||||
// if (Application.HasUserAuthorization(UserAuthorization.WebCam))
|
||||
@@ -88,19 +79,18 @@ public class StartGamesTests
|
||||
// Assert.AreEqual(bootScreen.errorText.text, "Zorg ervoor dat deze applicatie toegang heeft tot je webcam!");
|
||||
// }
|
||||
// else
|
||||
if(0 >= WebCamTexture.devices.Length){
|
||||
Debug.Log("no webcam");
|
||||
if (0 >= WebCamTexture.devices.Length)
|
||||
{
|
||||
Assert.IsNull(userCreationScreen);
|
||||
Assert.IsNull(mainMenuScreen);
|
||||
Assert.IsNotNull(bootScreen);
|
||||
Assert.AreEqual(bootScreen.errorText.text, "Zorg ervoor dat je webcam correct is aangesloten!");
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("no users");
|
||||
Assert.IsNull(bootScreen);
|
||||
Assert.IsNull(mainMenuScreen);
|
||||
Assert.IsNotNull(userCreationScreen);
|
||||
}
|
||||
Assert.IsNull(mainMenuScreen);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
|
||||
using NUnit.Framework;
|
||||
using TMPro;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
|
||||
public class UserButtonTests
|
||||
@@ -15,28 +12,27 @@ public class UserButtonTests
|
||||
[UnitySetUp]
|
||||
public IEnumerator SetupFunction()
|
||||
{
|
||||
string path = $"{Application.persistentDataPath}/users.json";
|
||||
var oneUser = "{\"currentUserIndex\": 0,\"storedUsers\": [{\"username\": \"TEST\",\"avatar\": {\"instanceID\": 40848},\"playtime\": 0.0,\"courses\": [],\"minigames\": []}]}";
|
||||
|
||||
using (StreamWriter writer = new StreamWriter(path))
|
||||
{
|
||||
writer.Write(oneUser);
|
||||
}
|
||||
string path = $"{Application.persistentDataPath}/unit_test_users.json";
|
||||
string oneUser = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||
|
||||
File.WriteAllText(path, oneUser);
|
||||
PersistentDataController.PATH = path;
|
||||
PersistentDataController.GetInstance().Load();
|
||||
AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
|
||||
SystemController.GetInstance().LoadNextScene("Common/Scenes/CoursesMenuScreen");
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
}
|
||||
|
||||
/* [UnityTest]
|
||||
public IEnumerator OpenProgressCallbackTest()
|
||||
{
|
||||
var userButton = (UserButton)GameObject.FindObjectOfType(typeof(UserButton));
|
||||
userButton.OpenProgressCallback();
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
/* [UnityTest]
|
||||
public IEnumerator OpenProgressCallbackTest()
|
||||
{
|
||||
var userButton = (UserButton)GameObject.FindObjectOfType(typeof(UserButton));
|
||||
userButton.OpenProgressCallback();
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
var listCoursesScreen = (ListCoursesScreen)GameObject.FindObjectOfType(typeof(ListCoursesScreen));
|
||||
Assert.IsNotNull(listCoursesScreen);
|
||||
}*/
|
||||
var listCoursesScreen = (ListCoursesScreen)GameObject.FindObjectOfType(typeof(ListCoursesScreen));
|
||||
Assert.IsNotNull(listCoursesScreen);
|
||||
}*/
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator ChangeUserCallbackTest()
|
||||
|
||||
@@ -314,6 +314,7 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
errorText: {fileID: 1663223260}
|
||||
sprites: {fileID: 11400000, guid: 017ec1af3b6cc4d4ab2b506911a4edad, type: 2}
|
||||
--- !u!4 &1427583095
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -12,12 +12,20 @@ public class BootScreen : MonoBehaviour
|
||||
/// </summary>
|
||||
public TMP_Text errorText;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the list that holds all user avatars
|
||||
/// </summary>
|
||||
public UserAvatarList sprites;
|
||||
|
||||
/// <summary>
|
||||
/// Request authorization and check whether at least 1 webcam is available
|
||||
/// </summary>
|
||||
/// <returns>IEnumerator object</returns>
|
||||
IEnumerator Start()
|
||||
{
|
||||
UserList.AVATARS = sprites.avatars;
|
||||
PersistentDataController.GetInstance().Load();
|
||||
|
||||
yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
|
||||
if (Application.HasUserAuthorization(UserAuthorization.WebCam))
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"GUID:6055be8ebefd69e48b49212b09b47b2f",
|
||||
"GUID:63c63e721f65ebb7d871cb9ef49f4752",
|
||||
"GUID:1631ed2680c61245b8211d943c1639a8",
|
||||
"GUID:e83ddf9a537a96b4a804a16bb7872ec1",
|
||||
"GUID:7f2d0ee6dd21e1d4eb25b71b7a749d25"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
|
||||
@@ -17,15 +17,10 @@ public class CourseActivityScreen : MonoBehaviour
|
||||
/// </summary>
|
||||
public CourseList courseList;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the users
|
||||
/// </summary>
|
||||
public UserList userList;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the course progress
|
||||
/// </summary>
|
||||
private Progress progress;
|
||||
private PersistentDataController.SavedCourseProgress progress;
|
||||
|
||||
/// <summary>
|
||||
/// Title Display
|
||||
@@ -66,10 +61,10 @@ public class CourseActivityScreen : MonoBehaviour
|
||||
//slider.value = progressValue;
|
||||
|
||||
// Set progress
|
||||
userList.Load();
|
||||
progress = userList.GetCurrentUser().GetCourseProgress(course.index);
|
||||
PersistentDataController.GetInstance().Load();
|
||||
progress = UserList.GetCurrentUser().GetCourseProgress(course.index);
|
||||
if (progress != null)
|
||||
progressBar.value = progress.Get<float>("courseProgress");
|
||||
progressBar.value = progress.progress;
|
||||
else
|
||||
progressBar.value = 0.0f;
|
||||
}
|
||||
|
||||
@@ -27,11 +27,6 @@ public class CourseMenuScreen : MonoBehaviour
|
||||
/// </summary>
|
||||
public GameObject courseItem;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the users so we can get the current user;
|
||||
/// </summary>
|
||||
public UserList userList;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the courses
|
||||
/// </summary>
|
||||
@@ -42,8 +37,8 @@ public class CourseMenuScreen : MonoBehaviour
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
userList.Load();
|
||||
User user = userList.GetCurrentUser();
|
||||
PersistentDataController.GetInstance().Load();
|
||||
User user = UserList.GetCurrentUser();
|
||||
|
||||
// Recent courses
|
||||
List<Tuple<CourseIndex, float>> recentCourses = user.GetRecentCourses();
|
||||
|
||||
@@ -5,11 +5,6 @@ using UnityEngine;
|
||||
/// </summary>
|
||||
public class ListCoursesScreen : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Reference to the userlist
|
||||
/// </summary>
|
||||
public UserList userList;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the course-list container object
|
||||
/// </summary>
|
||||
@@ -30,8 +25,8 @@ public class ListCoursesScreen : MonoBehaviour
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
userList.Load();
|
||||
User user = userList.GetCurrentUser();
|
||||
PersistentDataController.GetInstance().Load();
|
||||
User user = UserList.GetCurrentUser();
|
||||
|
||||
foreach (Course course in courseList.courses)
|
||||
{
|
||||
@@ -42,8 +37,8 @@ public class ListCoursesScreen : MonoBehaviour
|
||||
CourseItem item = instance.GetComponent<CourseItem>();
|
||||
item.course = course;
|
||||
|
||||
Progress progress = user.GetCourseProgress(course.index);
|
||||
item.progress = progress != null ? progress.Get<float>("courseProgress") : 0.0f;
|
||||
var progress = user.GetCourseProgress(course.index);
|
||||
item.progress = progress != null ? progress.progress : 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,19 +6,13 @@ using UnityEngine;
|
||||
/// </summary>
|
||||
public class MainMenuScreen : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Referece to the userlist to check whether an user account is present
|
||||
/// </summary>
|
||||
public UserList userList;
|
||||
|
||||
/// <summary>
|
||||
/// Check on load whether a user is already present,
|
||||
/// if not load the UserCreationScreen scene so the user can create a new account
|
||||
/// </summary>
|
||||
void Awake()
|
||||
{
|
||||
userList.Load();
|
||||
if (!File.Exists(UserList.PATH) || userList.GetUsers().Count <= 0)
|
||||
if (!File.Exists(PersistentDataController.PATH) || UserList.GetUsers().Count <= 0)
|
||||
{
|
||||
SystemController.GetInstance().LoadNextScene("Accounts/Scenes/UserCreationScreen");
|
||||
}
|
||||
|
||||
@@ -40,15 +40,10 @@ public class MinigameActivityScreen : MonoBehaviour
|
||||
/// </summary>
|
||||
public TMP_Text controls;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the users
|
||||
/// </summary>
|
||||
public UserList userList;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the Minigame progress
|
||||
/// </summary>
|
||||
private Progress progress;
|
||||
private PersistentDataController.SavedMinigameProgress progress;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the users-high-scores container object
|
||||
@@ -65,7 +60,7 @@ public class MinigameActivityScreen : MonoBehaviour
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
userList.Load();
|
||||
PersistentDataController.GetInstance().Load();
|
||||
GenerateContent();
|
||||
GenerateHighScores();
|
||||
}
|
||||
@@ -109,17 +104,17 @@ public class MinigameActivityScreen : MonoBehaviour
|
||||
Minigame minigame = minigameList.minigames[index];
|
||||
|
||||
List<Tuple<string, Sprite, Score>> allScores = new List<Tuple<string, Sprite, Score>>();
|
||||
foreach (User user in userList.GetUsers())
|
||||
foreach (User user in UserList.GetUsers())
|
||||
{
|
||||
// Get user's progress for this minigame
|
||||
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, Sprite, Score>(user.username, user.avatar, score));
|
||||
allScores.Add(new Tuple<string, Sprite, Score>(user.GetUsername(), user.GetAvatar(), score));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,6 @@ using UnityEngine.UI;
|
||||
/// </summary>
|
||||
public class UserButton : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// Reference to the user list, so we can extract the current user
|
||||
/// </summary>
|
||||
public UserList userList;
|
||||
|
||||
/// <summary>
|
||||
/// UI reference to the avatar object
|
||||
/// </summary>
|
||||
@@ -32,10 +27,10 @@ public class UserButton : MonoBehaviour
|
||||
/// </summary>
|
||||
void Start()
|
||||
{
|
||||
userList.Load();
|
||||
User user = userList.GetCurrentUser();
|
||||
avatar.sprite = user.avatar;
|
||||
username.text = user.username;
|
||||
PersistentDataController.GetInstance().Load();
|
||||
User user = UserList.GetCurrentUser();
|
||||
avatar.sprite = user.GetAvatar();
|
||||
username.text = user.GetUsername();
|
||||
dropdownBox.SetActive(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"CommonScripts",
|
||||
"InterfacesScripts",
|
||||
"SignPredictor",
|
||||
"SystemArchitecture",
|
||||
"NatML.ML"
|
||||
],
|
||||
"includePlatforms": [
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Test the ThemeList class
|
||||
/// </summary>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using NUnit.Framework;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Test the Theme class
|
||||
/// </summary>
|
||||
|
||||
@@ -1,6 +1,22 @@
|
||||
{
|
||||
"name": "PlayModeTests",
|
||||
"optionalUnityReferences": [
|
||||
"TestAssemblies"
|
||||
]
|
||||
}
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"UnityEngine.TestRunner",
|
||||
"UnityEditor.TestRunner",
|
||||
"SystemArchitecture"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [
|
||||
"nunit.framework.dll"
|
||||
],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [
|
||||
"UNITY_INCLUDE_TESTS"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
"InterfacesScripts",
|
||||
"SignPredictor",
|
||||
"NatML.ML",
|
||||
"SystemArchitecture",
|
||||
"Tween"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
|
||||
@@ -39,11 +39,6 @@ public class CoursesController : AbstractFeedback
|
||||
/// </summary>
|
||||
public TMP_Text title;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to user list to get current user
|
||||
/// </summary>
|
||||
public UserList userList;
|
||||
|
||||
/// <summary>
|
||||
/// The current user
|
||||
/// </summary>
|
||||
@@ -52,7 +47,7 @@ public class CoursesController : AbstractFeedback
|
||||
/// <summary>
|
||||
/// Current user progress for this course
|
||||
/// </summary>
|
||||
private Progress progress = null;
|
||||
private PersistentDataController.SavedCourseProgress progress = null;
|
||||
|
||||
/// <summary>
|
||||
/// ScriptableObject with list of all courses
|
||||
@@ -169,17 +164,17 @@ public class CoursesController : AbstractFeedback
|
||||
previewMessage.SetActive(course.theme.modelIndex == ModelIndex.NONE);
|
||||
|
||||
// Create entry in current user for keeping track of progress
|
||||
userList.Load();
|
||||
user = userList.GetCurrentUser();
|
||||
//PersistentDataController pdc = PersistentDataController.GetInstance();
|
||||
//pdc.Load();
|
||||
user = UserList.GetCurrentUser();
|
||||
progress = user.GetCourseProgress(course.index);
|
||||
if (progress == null)
|
||||
{
|
||||
progress = new Progress();
|
||||
progress.AddOrUpdate<CourseIndex>("courseIndex", course.index);
|
||||
progress.AddOrUpdate<float>("courseProgress", -1.0f);
|
||||
user.courses.Add(progress);
|
||||
progress = new PersistentDataController.SavedCourseProgress();
|
||||
progress.courseIndex = course.index;
|
||||
user.AddCourseProgress(progress);
|
||||
}
|
||||
userList.Save();
|
||||
UserList.Save();
|
||||
|
||||
// Force the videoplayer to add bars to preserve aspect ratio
|
||||
player.aspectRatio = VideoAspectRatio.FitInside;
|
||||
@@ -260,8 +255,8 @@ public class CoursesController : AbstractFeedback
|
||||
|
||||
// TODO: fix correct word count
|
||||
correctWords++;
|
||||
progress.AddOrUpdate<float>("courseProgress", (float)correctWords / (float)maxWords);
|
||||
userList.Save();
|
||||
progress.progress = (float)correctWords / (float)maxWords;
|
||||
UserList.Save();
|
||||
|
||||
// Update UI if course is not finished yet
|
||||
if (currentWordIndex < maxWords)
|
||||
@@ -297,8 +292,8 @@ public class CoursesController : AbstractFeedback
|
||||
// Link button
|
||||
CoursesButton.onClick.AddListener(() => { SystemController.GetInstance().BackToPreviousScene(); });
|
||||
|
||||
progress.AddOrUpdate<float>("courseProgress", 1f);
|
||||
userList.Save();
|
||||
progress.progress = 1.0f;
|
||||
UserList.Save();
|
||||
}
|
||||
/// <summary>
|
||||
/// The updateFunction that is called when new probabilities become available
|
||||
|
||||
@@ -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:
|
||||
@@ -10,7 +10,7 @@ using UnityEngine.UI;
|
||||
/// Contains all game logic for the JustSign game
|
||||
/// </summary>
|
||||
public class JustSignController : MonoBehaviour
|
||||
{
|
||||
{
|
||||
/// <summary>
|
||||
/// All of the words that can be used in this session
|
||||
/// </summary>
|
||||
@@ -107,7 +107,7 @@ public class JustSignController : MonoBehaviour
|
||||
/// Controls movement speed of symbols (higher -> faster)
|
||||
/// </summary>
|
||||
private int moveSpeed = 200;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Starting X-coordinate of a symbol = (-1920 - symbolsize) / 2
|
||||
/// </summary>
|
||||
@@ -213,11 +213,6 @@ public class JustSignController : MonoBehaviour
|
||||
/// </summary>
|
||||
public GameObject scoreboardEntry;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the user list to access the current user
|
||||
/// </summary>
|
||||
public UserList userList;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the current user
|
||||
/// </summary>
|
||||
@@ -276,18 +271,15 @@ public class JustSignController : MonoBehaviour
|
||||
score = 0;
|
||||
gameEndedPanel.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", 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();
|
||||
PersistentDataController.GetInstance().Save();
|
||||
|
||||
scoreDisplay.text = "Score: " + score.ToString();
|
||||
currentTheme = minigame.themeList.themes[minigame.themeList.currentThemeIndex];
|
||||
@@ -314,31 +306,42 @@ public class JustSignController : MonoBehaviour
|
||||
/// Update is called once per frame
|
||||
/// </summary>
|
||||
void Update()
|
||||
{
|
||||
if (gameIsActive) {
|
||||
{
|
||||
if (gameIsActive)
|
||||
{
|
||||
int matchedSymbolIndex = -1;
|
||||
for (int i = 0; i < activeWords.Count; i++) {
|
||||
if (activeWords[i].ToLower() == answerField.text.ToLower()) {
|
||||
for (int i = 0; i < activeWords.Count; i++)
|
||||
{
|
||||
if (activeWords[i].ToLower() == answerField.text.ToLower())
|
||||
{
|
||||
matchedSymbolIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
// Destroy the oldest symbol if the current input matches it
|
||||
if (matchedSymbolIndex >= 0) {
|
||||
int difference = Math.Abs((int) (activeSymbols[matchedSymbolIndex].transform.position.x - hitZone.transform.position.x));
|
||||
if (difference < perfectBoundary) {
|
||||
if (matchedSymbolIndex >= 0)
|
||||
{
|
||||
int difference = Math.Abs((int)(activeSymbols[matchedSymbolIndex].transform.position.x - hitZone.transform.position.x));
|
||||
if (difference < perfectBoundary)
|
||||
{
|
||||
feedBack.text = "Perfect!";
|
||||
perfectSigns++;
|
||||
score += perfectScore;
|
||||
} else if (difference < goodBoundary) {
|
||||
}
|
||||
else if (difference < goodBoundary)
|
||||
{
|
||||
feedBack.text = "Good!";
|
||||
goodSigns++;
|
||||
score += goodScore;
|
||||
} else if (difference < mehBoundary) {
|
||||
}
|
||||
else if (difference < mehBoundary)
|
||||
{
|
||||
feedBack.text = "Meh...";
|
||||
mehSigns++;
|
||||
score += mehScore;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
feedBack.text = "Terrible!";
|
||||
terribleSigns++;
|
||||
score += terribleScore;
|
||||
@@ -349,8 +352,10 @@ public class JustSignController : MonoBehaviour
|
||||
}
|
||||
|
||||
// Destroy the oldest symbol if it leaves the screen
|
||||
if (activeSymbols.Count > 0) {
|
||||
if (activeSymbols[0].GetComponent<RectTransform>().localPosition.x > -trackX) {
|
||||
if (activeSymbols.Count > 0)
|
||||
{
|
||||
if (activeSymbols[0].GetComponent<RectTransform>().localPosition.x > -trackX)
|
||||
{
|
||||
DestroySymbolAt(0);
|
||||
incorrectSigns++;
|
||||
feedBack.text = "Te laat!";
|
||||
@@ -360,18 +365,21 @@ public class JustSignController : MonoBehaviour
|
||||
|
||||
// Spawn new symbol every spawn period
|
||||
float currentTime = Time.time;
|
||||
if (currentTime - lastSpawn > currentSong.spawnPeriod && lastSymbolTime > currentTime) {
|
||||
if (currentTime - lastSpawn > currentSong.spawnPeriod && lastSymbolTime > currentTime)
|
||||
{
|
||||
lastSpawn = currentTime;
|
||||
SpawnNewSymbol();
|
||||
}
|
||||
|
||||
// Check if the song has ended and activate scorescreen if it has
|
||||
if (currentTime - beginTime > currentSong.duration) {
|
||||
if (currentTime - beginTime > currentSong.duration)
|
||||
{
|
||||
ActivateEnd();
|
||||
}
|
||||
|
||||
// Move all active symbols to the right
|
||||
foreach (GameObject symbol in activeSymbols) {
|
||||
foreach (GameObject symbol in activeSymbols)
|
||||
{
|
||||
RectTransform rectTransform = symbol.GetComponent<RectTransform>();
|
||||
rectTransform.localPosition = new Vector3(rectTransform.localPosition.x + Time.deltaTime * moveSpeed, trackY, 0);
|
||||
}
|
||||
@@ -401,7 +409,8 @@ public class JustSignController : MonoBehaviour
|
||||
/// Destroy the symbol at the given index
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the symbol to destroy</param>
|
||||
void DestroySymbolAt(int index) {
|
||||
void DestroySymbolAt(int index)
|
||||
{
|
||||
activeWords.RemoveAt(index);
|
||||
GameObject symbol = activeSymbols[index];
|
||||
activeSymbols.RemoveAt(index);
|
||||
@@ -411,12 +420,15 @@ public class JustSignController : MonoBehaviour
|
||||
/// <summary>
|
||||
/// Create a new symbol at the start of the track
|
||||
/// </summary>
|
||||
void SpawnNewSymbol() {
|
||||
void SpawnNewSymbol()
|
||||
{
|
||||
// Pick a word that isn't in use yet
|
||||
List<int> unusedWordIndices = new List<int>();
|
||||
|
||||
for (int i = 0; i < words.Count; i++) {
|
||||
if (!activeWords.Contains(words[i].name)) {
|
||||
for (int i = 0; i < words.Count; i++)
|
||||
{
|
||||
if (!activeWords.Contains(words[i].name))
|
||||
{
|
||||
unusedWordIndices.Add(i);
|
||||
}
|
||||
}
|
||||
@@ -455,12 +467,11 @@ public class JustSignController : MonoBehaviour
|
||||
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);
|
||||
@@ -470,10 +481,10 @@ public class JustSignController : MonoBehaviour
|
||||
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();
|
||||
PersistentDataController.GetInstance().Save();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -520,17 +531,17 @@ public class JustSignController : 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(minigame.index);
|
||||
var 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -549,7 +560,7 @@ public class JustSignController : 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;
|
||||
|
||||
19
Assets/JustSign/Scripts/JustSignScripts.asmdef
Normal file
19
Assets/JustSign/Scripts/JustSignScripts.asmdef
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "JustSignScripts",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:e83ddf9a537a96b4a804a16bb7872ec1",
|
||||
"GUID:6055be8ebefd69e48b49212b09b47b2f",
|
||||
"GUID:1631ed2680c61245b8211d943c1639a8",
|
||||
"GUID:7f2d0ee6dd21e1d4eb25b71b7a749d25"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
7
Assets/JustSign/Scripts/JustSignScripts.asmdef.meta
Normal file
7
Assets/JustSign/Scripts/JustSignScripts.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 643048e31db889c4c8ab5a04e9a70473
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,28 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
|
||||
using NUnit.Framework;
|
||||
using TMPro;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
|
||||
public class GameEndedPanelTests
|
||||
{
|
||||
|
||||
[UnitySetUp]
|
||||
public IEnumerator SetupFunction()
|
||||
{
|
||||
string path = $"{Application.persistentDataPath}/unit_test_users.json";
|
||||
var oneUser = "{\"currentUserIndex\": 0,\"storedUsers\": [{\"username\": \"TEST\",\"avatar\": {\"instanceID\": 40848},\"playtime\": 0.0,\"courses\": [],\"minigames\": []}]}";
|
||||
|
||||
using (StreamWriter writer = new StreamWriter(path))
|
||||
{
|
||||
writer.Write(oneUser);
|
||||
}
|
||||
string oneUser = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||
|
||||
File.WriteAllText(path, oneUser);
|
||||
PersistentDataController.GetInstance().Load();
|
||||
AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
|
||||
SystemController.GetInstance().LoadNextScene("SpellingBee/Scenes/SpellingBeeGame");
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
}
|
||||
|
||||
@@ -1,28 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
|
||||
using NUnit.Framework;
|
||||
using TMPro;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
|
||||
public class SpellingBeeControllerTests
|
||||
{
|
||||
|
||||
[UnitySetUp]
|
||||
public IEnumerator SetupFunction()
|
||||
{
|
||||
string path = $"{Application.persistentDataPath}/unit_test_users.json";
|
||||
var oneUser = "{\"currentUserIndex\": 0,\"storedUsers\": [{\"username\": \"TEST\",\"avatar\": {\"instanceID\": 40848},\"playtime\": 0.0,\"courses\": [],\"minigames\": []}]}";
|
||||
|
||||
using (StreamWriter writer = new StreamWriter(path))
|
||||
{
|
||||
writer.Write(oneUser);
|
||||
}
|
||||
string oneUser = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"TEST\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||
|
||||
File.WriteAllText(path, oneUser);
|
||||
PersistentDataController.GetInstance().Load();
|
||||
AssetDatabase.LoadAssetAtPath<UserAvatarList>("Assets/Accounts/ScriptableObjects/UserAvatarList.asset").Awake();
|
||||
SystemController.GetInstance().LoadNextScene("SpellingBee/Scenes/SpellingBeeGame");
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
"Unity.TextMeshPro",
|
||||
"SpellingBeeScripts",
|
||||
"AccountsScripts",
|
||||
"SystemArchitecture",
|
||||
"SignPredictor"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
|
||||
@@ -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": [],
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
public class BasicTests
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c3f7371598add9549b5351c44a9e17b3
|
||||
guid: 00903f60e81ce95419bc0c62a11ddfd1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7992d1284c7de4b089f4155b3e4ada83
|
||||
guid: 17374f544297b194aa5517c196ca2f07
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
427
Assets/SystemArchitecture/Scripts/PersistentDataController.cs
Normal file
427
Assets/SystemArchitecture/Scripts/PersistentDataController.cs
Normal file
@@ -0,0 +1,427 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// PersistentDataController singleton
|
||||
/// </summary>
|
||||
public class PersistentDataController
|
||||
{
|
||||
/// <summary>
|
||||
/// The instance controlling the singleton
|
||||
/// </summary>
|
||||
private static PersistentDataController instance = null;
|
||||
|
||||
/// <summary>
|
||||
/// Current implementation version of the PersistentDataController
|
||||
/// </summary>
|
||||
/// <remarks>MSB represent sprint version, LSB represent subversion</remarks>
|
||||
public static readonly int VERSION = 0x04_01;
|
||||
|
||||
/// <summary>
|
||||
/// Path of the <c>.json</c>-file to store all serialized data
|
||||
/// </summary>
|
||||
public static string PATH = null;
|
||||
|
||||
/// <summary>
|
||||
/// Class to hold a list of data records
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class PersistentDataContainer
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper class for handling the stored progress
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class PersistentDataEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// The key, used to reference the data object
|
||||
/// </summary>
|
||||
public string key;
|
||||
|
||||
/// <summary>
|
||||
/// The object, representated as a list of byte (which can be serialized)
|
||||
/// </summary>
|
||||
public List<byte> data = new List<byte>();
|
||||
|
||||
public PersistentDataEntry(string key, byte[] data) : this(key, data.ToList())
|
||||
{ }
|
||||
|
||||
public PersistentDataEntry(string key, List<byte> data)
|
||||
{
|
||||
this.key = key;
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List of data records
|
||||
/// </summary>
|
||||
public List<PersistentDataEntry> entries = new List<PersistentDataEntry>();
|
||||
|
||||
/// <summary>
|
||||
/// Update the value of a certain key,
|
||||
/// or add a new value if the key was not present.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the data to be added/updated</typeparam>
|
||||
/// <param name="key">The key, used for referencing the data</param>
|
||||
/// <param name="data">The object of type <typeparamref name="T"/></param>
|
||||
/// <returns><c>true</c> if successful, <c>false</c> otherwise</returns>
|
||||
public bool Set<T>(string key, T data)
|
||||
{
|
||||
if (data == null)
|
||||
return false;
|
||||
|
||||
PersistentDataEntry entry = entries.Find(x => x.key == key);
|
||||
|
||||
// Hacky serialization stuff
|
||||
BinaryFormatter bf = new BinaryFormatter();
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
bf.Serialize(ms, data);
|
||||
if (entry != null)
|
||||
{
|
||||
entry.data.Clear();
|
||||
entry.data.AddRange(ms.ToArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
entries.Add(new PersistentDataEntry(key, ms.ToArray()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the data object of a certain key
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the data object</typeparam>
|
||||
/// <param name="key">The key referencing the data object</param>
|
||||
/// <returns>The data, cast to a type <typeparamref name="T"/></returns>
|
||||
/// <exception cref="KeyNotFoundException"></exception>
|
||||
/// <exception cref="InvalidCastException"></exception>
|
||||
public T Get<T>(string key)
|
||||
{
|
||||
BinaryFormatter bf = new BinaryFormatter();
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
// Find the correct key
|
||||
foreach (PersistentDataEntry entry in entries)
|
||||
{
|
||||
if (entry.key == key)
|
||||
{
|
||||
// Hacky serialization stuff
|
||||
byte[] data = entry.data.ToArray();
|
||||
ms.Write(data, 0, data.Length);
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
return (T)bf.Deserialize(ms);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Raise an exception when key is not found
|
||||
throw new KeyNotFoundException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a key-value from the data.
|
||||
/// </summary>
|
||||
/// <param name="key">The key referencing the data object</param>
|
||||
/// <exception cref="KeyNotFoundException"></exception>
|
||||
public void Remove(string key)
|
||||
{
|
||||
if (!Has(key))
|
||||
throw new KeyNotFoundException();
|
||||
|
||||
entries.Remove(entries.Find(x => x.key == key));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove and return value from the data.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the data object</typeparam>
|
||||
/// <param name="key">The key referencing the data object</param>
|
||||
/// <param name="save">Whether the removal of the data should also be saved to disk</param>
|
||||
/// <returns></returns>
|
||||
public T Pop<T>(string key)
|
||||
{
|
||||
T data = Get<T>(key);
|
||||
Remove(key);
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check whether a key is present
|
||||
/// </summary>
|
||||
/// <param name="key">The key to check</param>
|
||||
/// <returns>true if a item can be found with the specified key</returns>
|
||||
public bool Has(string key)
|
||||
{
|
||||
return entries.Find(x => x.key == key) != null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stored user data record
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class SavedUserData : PersistentDataContainer
|
||||
{
|
||||
public string username = null;
|
||||
public int avatarIndex = -1;
|
||||
public double playtime = 0.0;
|
||||
public List<SavedMinigameProgress> minigames = new List<SavedMinigameProgress>();
|
||||
public List<SavedCourseProgress> courses = new List<SavedCourseProgress>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stored course progress data record
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class SavedCourseProgress : PersistentDataContainer
|
||||
{
|
||||
public CourseIndex courseIndex;
|
||||
public float progress = -1.0f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stored minigame progress data record
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class SavedMinigameProgress : PersistentDataContainer
|
||||
{
|
||||
public MinigameIndex minigameIndex;
|
||||
public List<Score> latestScores = new List<Score>();
|
||||
public List<Score> highestScores = new List<Score>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stored WeSign data record
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
private class SavedDataStructure
|
||||
{
|
||||
public int version = VERSION;
|
||||
public List<SavedUserData> users = new List<SavedUserData>();
|
||||
public int currentUser = -1;
|
||||
public MinigameIndex currentMinigame;
|
||||
public CourseIndex currentCourse;
|
||||
public ThemeIndex currentTheme;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The object holding the data references
|
||||
/// </summary>
|
||||
private SavedDataStructure json = new SavedDataStructure();
|
||||
|
||||
/// <summary>
|
||||
/// Get the instance loaded by the singleton
|
||||
/// </summary>
|
||||
/// <returns><c>PersistentDataController</c> instance</returns>
|
||||
public static PersistentDataController GetInstance()
|
||||
{
|
||||
// Create a new instance if non exists
|
||||
if (instance == null)
|
||||
{
|
||||
if (PATH == null)
|
||||
PersistentDataController.PATH = $"{Application.persistentDataPath}/wesign_saved_data.json";
|
||||
instance = new PersistentDataController();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// PersistentDataController contructor
|
||||
/// </summary>
|
||||
private PersistentDataController()
|
||||
{
|
||||
Load();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clear everything stored in the PersistentDataController, won't save to disk
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
json.users.Clear();
|
||||
json.currentUser = -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save all data to disk
|
||||
/// </summary>
|
||||
public void Save()
|
||||
{
|
||||
string text = JsonUtility.ToJson(json);
|
||||
File.CreateText(PATH).Close();
|
||||
File.WriteAllText(PATH, text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override current data with the data from disk, will just clear if no data was found.
|
||||
/// </summary>
|
||||
/// <param name="overrideOnFail"><c>true</c> if you want to override the existing file if it exists and the loading failed.</param>
|
||||
/// <remarks>If the data on disk is outdated (version number is lower than the current version), the loading will also fail</remarks>
|
||||
/// <returns><c>true</c> if successful, <c>false</c> otherwise</returns>
|
||||
public bool Load(bool overrideOnFail = true)
|
||||
{
|
||||
Clear();
|
||||
if (!File.Exists(PATH))
|
||||
goto failed;
|
||||
|
||||
try
|
||||
{
|
||||
string text = File.ReadAllText(PATH);
|
||||
SavedDataStructure newJson = JsonUtility.FromJson<SavedDataStructure>(text);
|
||||
if (newJson == null || newJson.version < VERSION)
|
||||
goto failed;
|
||||
|
||||
json = newJson;
|
||||
return true;
|
||||
}
|
||||
catch (Exception) { goto failed; }
|
||||
|
||||
failed:
|
||||
if (overrideOnFail)
|
||||
Save();
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a user to the WeSign data record
|
||||
/// </summary>
|
||||
/// <param name="user">User data record</param>
|
||||
/// <param name="save">Whether to save the addition immediately to disk</param>
|
||||
public void AddUser(SavedUserData user, bool save = true)
|
||||
{
|
||||
if (json.users.Count == 0)
|
||||
json.currentUser = 0;
|
||||
json.users.Add(user);
|
||||
|
||||
if (save)
|
||||
Save();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a list of all user data records
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<SavedUserData> GetUsers()
|
||||
{
|
||||
return json.users;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the index of the current user
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int GetCurrentUser()
|
||||
{
|
||||
return json.currentUser;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the index of the current record
|
||||
/// </summary>
|
||||
/// <param name="index">New index</param>
|
||||
/// <param name="save">Whether to save the change immediately to disk</param>
|
||||
/// <exception cref="IndexOutOfRangeException"></exception>
|
||||
public void SetCurrentUser(int index, bool save = true)
|
||||
{
|
||||
if (index < 0 || json.users.Count <= index)
|
||||
throw new IndexOutOfRangeException();
|
||||
json.currentUser = index;
|
||||
|
||||
if (save)
|
||||
Save();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove a user data record
|
||||
/// </summary>
|
||||
/// <param name="index">Index of the user</param>
|
||||
/// <param name="save">Whether to save the deletion immediately to disk</param>
|
||||
/// <exception cref="IndexOutOfRangeException"></exception>
|
||||
public void DeleteUser(int index, bool save = true)
|
||||
{
|
||||
if (index < 0 || json.users.Count <= index)
|
||||
throw new IndexOutOfRangeException();
|
||||
|
||||
if (0 < json.currentUser && index <= json.currentUser)
|
||||
json.currentUser--;
|
||||
json.users.RemoveAt(index);
|
||||
|
||||
if (save)
|
||||
Save();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the current course
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public CourseIndex GetCurrentCourse()
|
||||
{
|
||||
return json.currentCourse;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the current course
|
||||
/// </summary>
|
||||
/// <param name="course">New course index</param>
|
||||
/// <param name="save">Whether to save the change immediately to disk</param>
|
||||
public void SetCurrentCourse(CourseIndex course, bool save = true)
|
||||
{
|
||||
json.currentCourse = course;
|
||||
|
||||
if (save)
|
||||
Save();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the current minigame
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public MinigameIndex GetCurrentMinigame()
|
||||
{
|
||||
return json.currentMinigame;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the current minigame
|
||||
/// </summary>
|
||||
/// <param name="minigame">New minigame index</param>
|
||||
/// <param name="save">Whether to save the change immediately to disk</param>
|
||||
public void SetCurrentMinigame(MinigameIndex minigame, bool save = true)
|
||||
{
|
||||
json.currentMinigame = minigame;
|
||||
|
||||
if (save)
|
||||
Save();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the current theme
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ThemeIndex GetCurrentTheme()
|
||||
{
|
||||
return json.currentTheme;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the current theme
|
||||
/// </summary>
|
||||
/// <param name="theme">New theme index</param>
|
||||
/// <param name="save">Whether to save the change immediately to disk</param>
|
||||
public void SetCurrentTheme(ThemeIndex theme, bool save = true)
|
||||
{
|
||||
json.currentTheme = theme;
|
||||
|
||||
if (save)
|
||||
Save();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 30234b937b9c84460ad4846ae1941484
|
||||
guid: 164b1accbeff688429a4311f1e40bd59
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "SystemArchitecture",
|
||||
"rootNamespace": "",
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e83ddf9a537a96b4a804a16bb7872ec1
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/SystemArchitecture/Tests.meta
Normal file
8
Assets/SystemArchitecture/Tests.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8559f509b8f924f44bc10e2d20ac3eed
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
606
Assets/SystemArchitecture/Tests/PersistentDataControllerTest.cs
Normal file
606
Assets/SystemArchitecture/Tests/PersistentDataControllerTest.cs
Normal file
@@ -0,0 +1,606 @@
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
[TestFixture]
|
||||
public class PersistentDataTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Create a new path so the existing .json file will not be overwritten
|
||||
/// </summary>
|
||||
private static string PATH = $"{Application.persistentDataPath}/wesign_unit_test.json";
|
||||
|
||||
/// <summary>
|
||||
/// Reference to the pdc to perform tests on
|
||||
/// </summary>
|
||||
private PersistentDataController pdc = null;
|
||||
|
||||
/// <summary>
|
||||
/// A dummy serializable struct to perform test operations on
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
private struct Struct
|
||||
{
|
||||
public int r, g, b;
|
||||
public float x, y, z;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A dummy serializable enum to perform test operations on
|
||||
/// </summary>
|
||||
private enum Enum
|
||||
{
|
||||
SQUARE,
|
||||
TRIANBLE,
|
||||
CIRCLE
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void Setup_PersistentDataController()
|
||||
{
|
||||
PersistentDataController.PATH = PersistentDataTests.PATH;
|
||||
//PersistentDataController.PATH = null;
|
||||
pdc = PersistentDataController.GetInstance();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_GetInstance()
|
||||
{
|
||||
Assert.IsNotNull(pdc);
|
||||
//Assert.AreEqual($"{Application.persistentDataPath}/wesign_saved_data.json", PersistentDataController.PATH);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_Clear()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
Assert.Zero(pdc.GetUsers().Count);
|
||||
Assert.AreEqual(-1, pdc.GetCurrentUser());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_Save_Empty()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
|
||||
pdc.Save();
|
||||
FileAssert.Exists(PATH);
|
||||
|
||||
string content = File.ReadAllText(PATH);
|
||||
string expected = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||
Assert.AreEqual(expected, content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_Save_New()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
|
||||
if (File.Exists(PATH))
|
||||
File.Delete(PATH);
|
||||
pdc.Save();
|
||||
FileAssert.Exists(PATH);
|
||||
|
||||
string content = File.ReadAllText(PATH);
|
||||
string expected = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||
Assert.AreEqual(expected, content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_Load_Existing()
|
||||
{
|
||||
string content = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||
File.WriteAllText(PATH, content);
|
||||
Assert.IsTrue(pdc.Load(false));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_Load_OlderVersion()
|
||||
{
|
||||
string content = $"{{\"version\":{PersistentDataController.VERSION - 1},\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||
File.WriteAllText(PATH, content);
|
||||
Assert.IsFalse(pdc.Load(false));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_Load_New()
|
||||
{
|
||||
if (File.Exists(PATH))
|
||||
File.Delete(PATH);
|
||||
Assert.IsFalse(pdc.Load(false));
|
||||
FileAssert.DoesNotExist(PATH);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_Load_Exception()
|
||||
{
|
||||
File.WriteAllText(PATH, "https://www.youtube.com/watch?v=dQw4w9WgXcQ");
|
||||
Assert.IsFalse(pdc.Load(false));
|
||||
Assert.AreEqual("https://www.youtube.com/watch?v=dQw4w9WgXcQ", File.ReadAllText(PATH));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_Load_Override()
|
||||
{
|
||||
File.WriteAllText(PATH, "https://www.youtube.com/watch?v=dQw4w9WgXcQ");
|
||||
Assert.IsFalse(pdc.Load(true));
|
||||
string content = File.ReadAllText(PATH);
|
||||
string expected = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[],\"currentUser\":-1,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||
Assert.AreEqual(expected, content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_Version()
|
||||
{
|
||||
const int VERSION = 0x04_01;
|
||||
Assert.AreEqual(VERSION, PersistentDataController.VERSION);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_AddUser()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
var d = new PersistentDataController.SavedUserData()
|
||||
{
|
||||
username = "username",
|
||||
avatarIndex = 0
|
||||
};
|
||||
|
||||
pdc.AddUser(d);
|
||||
string content = File.ReadAllText(PATH);
|
||||
string expected = $"{{\"version\":{PersistentDataController.VERSION},\"users\":[{{\"entries\":[],\"username\":\"username\",\"avatarIndex\":0,\"playtime\":0.0,\"minigames\":[],\"courses\":[]}}],\"currentUser\":0,\"currentMinigame\":0,\"currentCourse\":0,\"currentTheme\":0}}";
|
||||
Assert.AreEqual(expected, content);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_GetUsers()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
var d = new PersistentDataController.SavedUserData()
|
||||
{
|
||||
username = "username",
|
||||
avatarIndex = 0
|
||||
};
|
||||
|
||||
pdc.AddUser(d);
|
||||
var users = pdc.GetUsers();
|
||||
Assert.AreEqual(1, users.Count);
|
||||
Assert.AreEqual("username", users[0].username);
|
||||
Assert.AreEqual(0, users[0].avatarIndex);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_GetCurrentUser()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
|
||||
Assert.AreEqual(-1, pdc.GetCurrentUser());
|
||||
pdc.AddUser(new PersistentDataController.SavedUserData()
|
||||
{
|
||||
username = "username",
|
||||
avatarIndex = 0
|
||||
});
|
||||
Assert.AreEqual(0, pdc.GetCurrentUser());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_SetCurrentUser()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
pdc.AddUser(new PersistentDataController.SavedUserData()
|
||||
{
|
||||
username = $"username_{i}",
|
||||
avatarIndex = i
|
||||
});
|
||||
pdc.SetCurrentUser(3);
|
||||
Assert.AreEqual(3, pdc.GetCurrentUser());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_SetCurrentUser_Invalid()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
|
||||
pdc.AddUser(new PersistentDataController.SavedUserData()
|
||||
{
|
||||
username = $"username",
|
||||
avatarIndex = 0
|
||||
});
|
||||
Assert.Throws<IndexOutOfRangeException>(delegate { pdc.SetCurrentUser(3); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_SetCurrentUser_Empty()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
Assert.Throws<IndexOutOfRangeException>(delegate { pdc.SetCurrentUser(0); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_DeleteUser_BeforeCurrent()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
|
||||
var users = new List<PersistentDataController.SavedUserData>();
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
var d = new PersistentDataController.SavedUserData()
|
||||
{
|
||||
username = $"username_{i}",
|
||||
avatarIndex = i
|
||||
};
|
||||
pdc.AddUser(d);
|
||||
users.Add(d);
|
||||
}
|
||||
pdc.SetCurrentUser(0);
|
||||
users.RemoveAt(2);
|
||||
pdc.DeleteUser(2);
|
||||
|
||||
var vsers = pdc.GetUsers();
|
||||
Assert.AreEqual(0, pdc.GetCurrentUser());
|
||||
Assert.AreEqual(users.Count, vsers.Count);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Assert.AreEqual(users[i].username, vsers[i].username);
|
||||
Assert.AreEqual(users[i].avatarIndex, vsers[i].avatarIndex);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_DeleteUser_Current()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
|
||||
var users = new List<PersistentDataController.SavedUserData>();
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
var d = new PersistentDataController.SavedUserData()
|
||||
{
|
||||
username = $"username_{i}",
|
||||
avatarIndex = i
|
||||
};
|
||||
pdc.AddUser(d);
|
||||
users.Add(d);
|
||||
}
|
||||
pdc.SetCurrentUser(2);
|
||||
users.RemoveAt(2);
|
||||
pdc.DeleteUser(2);
|
||||
|
||||
var vsers = pdc.GetUsers();
|
||||
Assert.AreEqual(1, pdc.GetCurrentUser());
|
||||
Assert.AreEqual(users.Count, vsers.Count);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Assert.AreEqual(users[i].username, vsers[i].username);
|
||||
Assert.AreEqual(users[i].avatarIndex, vsers[i].avatarIndex);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_DeleteUser_AfterCurrent()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
|
||||
var users = new List<PersistentDataController.SavedUserData>();
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
var d = new PersistentDataController.SavedUserData()
|
||||
{
|
||||
username = $"username_{i}",
|
||||
avatarIndex = i
|
||||
};
|
||||
pdc.AddUser(d);
|
||||
users.Add(d);
|
||||
|
||||
}
|
||||
pdc.SetCurrentUser(4);
|
||||
users.RemoveAt(2);
|
||||
pdc.DeleteUser(2);
|
||||
|
||||
var vsers = pdc.GetUsers();
|
||||
Assert.AreEqual(3, pdc.GetCurrentUser());
|
||||
Assert.AreEqual(users.Count, vsers.Count);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Assert.AreEqual(users[i].username, vsers[i].username);
|
||||
Assert.AreEqual(users[i].avatarIndex, vsers[i].avatarIndex);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_DeleteUser_Invalid()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
|
||||
pdc.AddUser(new PersistentDataController.SavedUserData()
|
||||
{
|
||||
username = $"username",
|
||||
avatarIndex = 0
|
||||
});
|
||||
Assert.Throws<IndexOutOfRangeException>(delegate { pdc.SetCurrentUser(3); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_DeleteUser_Empty()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
Assert.Throws<IndexOutOfRangeException>(delegate { pdc.DeleteUser(0); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_CurrentCourse()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
pdc.SetCurrentCourse(CourseIndex.FINGERSPELLING);
|
||||
Assert.AreEqual(CourseIndex.FINGERSPELLING, pdc.GetCurrentCourse());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_CurrentMinigame()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
pdc.SetCurrentMinigame(MinigameIndex.SPELLING_BEE);
|
||||
Assert.AreEqual(MinigameIndex.SPELLING_BEE, pdc.GetCurrentMinigame());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataController_CurrentTheme()
|
||||
{
|
||||
pdc.Load();
|
||||
pdc.Clear();
|
||||
pdc.SetCurrentTheme(ThemeIndex.SIGN_ALPHABET);
|
||||
Assert.AreEqual(ThemeIndex.SIGN_ALPHABET, pdc.GetCurrentTheme());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_New_PersistentDataContainer()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.IsNotNull(c);
|
||||
Assert.Zero(c.entries.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Set_Invalid()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.IsFalse(c.Set<object>("key", null));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Set_DuplicateKey()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.IsTrue(c.Set<int>("key", 123));
|
||||
Assert.IsTrue(c.Set<int>("key", 321));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Set_Int()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.IsTrue(c.Set<int>("key", 123));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Set_String()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.IsTrue(c.Set<string>("key", "abc"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Set_Struct()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.IsTrue(c.Set<Struct>("key", new Struct()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Set_Enum()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.IsTrue(c.Set<Enum>("key", new Enum()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Get_InvalidType()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<Struct>("key", new Struct() { r = 255, g = 127, b = 63, x = 31, y = 15, z = 7 });
|
||||
Assert.Throws<InvalidCastException>(delegate { c.Get<int>("key"); });
|
||||
c.Set<int>("key", 123);
|
||||
Assert.Throws<InvalidCastException>(delegate { c.Get<Struct>("key"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Get_KeyNotFound()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<int>("key", 123);
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Get<int>("KEY"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Get_Empty()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Get<int>("key"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Get_Int()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<int>("key", 123);
|
||||
Assert.AreEqual(123, c.Get<int>("key"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Get_String()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<string>("key", "value");
|
||||
Assert.AreEqual("value", c.Get<string>("key"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Get_Struct()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
var s = new Struct() { r = 255, g = 127, b = 63, x = 31, y = 15, z = 7 };
|
||||
c.Set<Struct>("key", s);
|
||||
Assert.AreEqual(s, c.Get<Struct>("key"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Get_Enum()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
var e = Enum.CIRCLE;
|
||||
c.Set<Enum>("key", e);
|
||||
Assert.AreEqual(e, c.Get<Enum>("key"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Remove_Invalid()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<int>("key", 123);
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Remove("KEY"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Remove_Empty()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Remove("key"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Remove_Int()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<int>("key", 123);
|
||||
c.Remove("key");
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Get<int>("key"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Remove_String()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<string>("key", "value");
|
||||
c.Remove("key");
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Get<string>("key"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Remove_Struct()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
var s = new Struct() { r = 255, g = 127, b = 63, x = 31, y = 15, z = 7 };
|
||||
c.Set<Struct>("key", s);
|
||||
c.Remove("key");
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Get<Struct>("key"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Remove_Enum()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<Enum>("key", Enum.CIRCLE);
|
||||
c.Remove("key");
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Get<Enum>("key"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Pop_Invalid()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<int>("key", 123);
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Remove("KEY"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Pop_Empty()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Remove("KEY"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Pop_Int()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<int>("key", 123);
|
||||
Assert.AreEqual(123, c.Pop<int>("key"));
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Get<int>("key"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Pop_String()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<string>("key", "value");
|
||||
Assert.AreEqual("value", c.Pop<string>("key"));
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Get<string>("key"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Pop_Struct()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
var s = new Struct() { r = 255, g = 127, b = 63, x = 31, y = 15, z = 7 };
|
||||
c.Set<Struct>("key", s);
|
||||
Assert.AreEqual(s, c.Pop<Struct>("key"));
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Get<Struct>("key"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Pop_Enum()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
c.Set<Enum>("key", Enum.CIRCLE);
|
||||
Assert.AreEqual(Enum.CIRCLE, c.Pop<Enum>("key"));
|
||||
Assert.Throws<KeyNotFoundException>(delegate { c.Get<Enum>("key"); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Has_ValidKey()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.IsFalse(c.Has("key"));
|
||||
c.Set<int>("key", 123);
|
||||
Assert.IsTrue(c.Has("key"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_PersistentDataContainer_Has_InvalidKey()
|
||||
{
|
||||
var c = new PersistentDataController.PersistentDataContainer();
|
||||
Assert.IsFalse(c.Has("KEY"));
|
||||
c.Set<int>("key", 123);
|
||||
Assert.IsFalse(c.Has("KEY"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56873c5649b881846a54e2a2aa5ce499
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "SystemArchitectureTests",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"UnityEditor.TestRunner",
|
||||
"UnityEngine.TestRunner",
|
||||
"SystemArchitecture"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [
|
||||
"nunit.framework.dll"
|
||||
],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [
|
||||
"UNITY_INCLUDE_TESTS"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1a4ef95cbacdca459433eb2ddc05755
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user