diff --git a/Assets/Accounts/ScriptableObjects/UserAvatarList.asset b/Assets/Accounts/ScriptableObjects/UserAvatarList.asset
new file mode 100644
index 0000000..dd6dba2
--- /dev/null
+++ b/Assets/Accounts/ScriptableObjects/UserAvatarList.asset
@@ -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}
diff --git a/Assets/Accounts/ScriptableObjects/UserAvatarList.asset.meta b/Assets/Accounts/ScriptableObjects/UserAvatarList.asset.meta
new file mode 100644
index 0000000..aa1812e
--- /dev/null
+++ b/Assets/Accounts/ScriptableObjects/UserAvatarList.asset.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 017ec1af3b6cc4d4ab2b506911a4edad
+NativeFormatImporter:
+ externalObjects: {}
+ mainObjectFileID: 11400000
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Accounts/Scripts/AccountsScripts.asmdef b/Assets/Accounts/Scripts/AccountsScripts.asmdef
index 9238363..8a40a7f 100644
--- a/Assets/Accounts/Scripts/AccountsScripts.asmdef
+++ b/Assets/Accounts/Scripts/AccountsScripts.asmdef
@@ -3,6 +3,7 @@
"rootNamespace": "",
"references": [
"GUID:6055be8ebefd69e48b49212b09b47b2f",
+ "GUID:e83ddf9a537a96b4a804a16bb7872ec1",
"GUID:7f2d0ee6dd21e1d4eb25b71b7a749d25"
],
"includePlatforms": [],
diff --git a/Assets/Accounts/Scripts/ChangeUserScreen.cs b/Assets/Accounts/Scripts/ChangeUserScreen.cs
index e5e0041..fbf7175 100644
--- a/Assets/Accounts/Scripts/ChangeUserScreen.cs
+++ b/Assets/Accounts/Scripts/ChangeUserScreen.cs
@@ -22,11 +22,6 @@ public class ChangeUserScreen : MonoBehaviour
///
public GameObject error;
- ///
- /// Reference to the user list
- ///
- public UserList userList;
-
///
/// Index of the current selected user in the UserList
///
@@ -42,7 +37,7 @@ public class ChangeUserScreen : MonoBehaviour
///
void Start()
{
- userList.Load();
+ PersistentDataController.GetInstance().Load();
error.SetActive(false);
DisplayUsers();
}
@@ -57,8 +52,8 @@ public class ChangeUserScreen : MonoBehaviour
Destroy(child.gameObject);
}
- List users = userList.GetUsers();
- currentUserIndex = userList.GetCurrentUserIndex();
+ List 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
///
public void IChooseYou()
{
- userList.ChangeCurrentUser(currentUserIndex);
- userList.Save();
+ UserList.ChangeCurrentUser(currentUserIndex);
SystemController.GetInstance().BackToPreviousScene();
}
diff --git a/Assets/Accounts/Scripts/CourseProgressCard.cs b/Assets/Accounts/Scripts/CourseProgressCard.cs
index 76b7550..2c6522b 100644
--- a/Assets/Accounts/Scripts/CourseProgressCard.cs
+++ b/Assets/Accounts/Scripts/CourseProgressCard.cs
@@ -21,7 +21,7 @@ public class CourseProgressCard : MonoBehaviour
///
/// Reference to the progress so we can display a progress bar
///
- public Progress courseProgress;
+ public PersistentDataController.SavedCourseProgress courseProgress;
///
/// Reference to the list of courses so we can query the correct course
@@ -48,11 +48,11 @@ public class CourseProgressCard : MonoBehaviour
///
void Start()
{
- Course course = courseList.GetCourseByIndex(courseProgress.Get("courseIndex"));
+ Course course = courseList.GetCourseByIndex(courseProgress.courseIndex);
thumbnail.sprite = course.thumbnail;
title.text = course.title;
- progressBar.value = courseProgress.Get("courseProgress");
+ progressBar.value = courseProgress.progress;
button.onClick.AddListener(selectActivity);
}
}
diff --git a/Assets/Accounts/Scripts/MinigameProgressCard.cs b/Assets/Accounts/Scripts/MinigameProgressCard.cs
index 6e4b2f5..aca0b4b 100644
--- a/Assets/Accounts/Scripts/MinigameProgressCard.cs
+++ b/Assets/Accounts/Scripts/MinigameProgressCard.cs
@@ -22,7 +22,7 @@ public class MinigameProgressCard : MonoBehaviour
///
/// Reference to the minigame progress
///
- public Progress minigameProgress;
+ public PersistentDataController.SavedMinigameProgress minigameProgress;
///
/// Reference to the minigame list
@@ -49,11 +49,11 @@ public class MinigameProgressCard : MonoBehaviour
///
void Start()
{
- Minigame minigame = minigameList.GetMinigameByIndex(minigameProgress.Get("minigameIndex"));
+ Minigame minigame = minigameList.GetMinigameByIndex(minigameProgress.minigameIndex);
thumbnail.sprite = minigame.thumbnail;
title.text = minigame.title;
- List highscores = minigameProgress.Get>("highestScores");
+ List highscores = minigameProgress.highestScores;
int score = highscores.Count > 0 ? highscores[0].scoreValue : 0;
highscore.text = $"Topscore: {score}";
button.onClick.AddListener(selectActivity);
diff --git a/Assets/Accounts/Scripts/Progress.cs b/Assets/Accounts/Scripts/Progress.cs
deleted file mode 100644
index e6adf98..0000000
--- a/Assets/Accounts/Scripts/Progress.cs
+++ /dev/null
@@ -1,114 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Runtime.Serialization.Formatters.Binary;
-using UnityEngine;
-
-///
-/// A class for holding all progress belonging to a user
-///
-[Serializable]
-public class Progress
-{
- ///
- /// A helper class for handling the stored progress
- ///
- [Serializable]
- protected class DataEntry
- {
- ///
- /// The key, used to reference the data object
- ///
- public string key;
-
- ///
- /// The object, representated as a list of byte (which can be serialized)
- ///
- public List bytes = new List();
-
- public DataEntry(string key, byte[] data)
- {
- this.key = key;
- this.bytes = new List(data);
- }
- }
-
- ///
- /// Entries in the Progress object
- ///
- [SerializeField]
- private List entries = new List();
-
-
- ///
- /// Update the value of a certain key,
- /// or add a new value if the key was not present
- ///
- /// The type of the data to be added/updated
- /// The key, used for referencing the data
- /// The object of type
- /// true if successful, false otherwise
- public bool AddOrUpdate(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;
- }
- }
-
- ///
- /// Get the data object of a certain key
- ///
- /// The type of the data object
- /// The key referencing the data object
- /// The data, cast to a type
- ///
- public T Get(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();
- }
-
- ///
- /// Check whether a key is present
- ///
- /// The key to check
- /// true if a item can be found with the specified key
- public bool Has(string key)
- {
- return entries.Find(x => x.key == key) != null;
- }
-}
diff --git a/Assets/Accounts/Scripts/User.cs b/Assets/Accounts/Scripts/User.cs
index 74aa614..bd6aa93 100644
--- a/Assets/Accounts/Scripts/User.cs
+++ b/Assets/Accounts/Scripts/User.cs
@@ -2,40 +2,45 @@ using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
+using static PersistentDataController;
///
/// A class holding all information of a user
///
-[Serializable]
public class User
{
///
- /// User nickname
+ /// Reference to the user stored data record
///
- public string username;
+ private SavedUserData storedUserData;
///
- /// The avatar of the user
+ /// Constructor
///
- public Sprite avatar;
+ /// Reference to the user stored data record
+ public User(SavedUserData data)
+ {
+ this.storedUserData = data;
+ }
///
- /// The total playtime of the user
+ /// Get the username
///
- /// TODO: needs to be implemented
- public double playtime;
+ ///
+ public string GetUsername() { return storedUserData.username; }
///
- /// List of courses a user started/completed
+ /// Get the total playtime
///
- [SerializeField]
- public List