Add formatting rules

This commit is contained in:
Dries Van Schuylenbergh
2023-03-10 09:21:11 +00:00
parent 6d762a63f7
commit 26f3322e4e
30 changed files with 975 additions and 160 deletions

View File

@@ -4,15 +4,26 @@ using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine;
/// <summary>
/// A class for holding all progress belonging to a user
/// </summary>
[Serializable]
// Can not be created from Editor
public class Progress
{
/// <summary>
/// A helper class for handling the stored progress
/// </summary>
[Serializable]
// Helper class to serialize into byte[]
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)
@@ -22,13 +33,21 @@ public class Progress
}
}
[Header("Course or Minigame")]
/// <summary>
/// Entries in the <c>Progress</c> object
/// </summary>
[SerializeField]
// values belonging to a certain key, in List (which can be serialized)
private List<DataEntry> entries = new List<DataEntry>();
// Add new `key` := `value`, returns `true` if successful
/// <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)
@@ -55,6 +74,13 @@ public class Progress
}
// Get the value of type `T` belonging to `key`
/// <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();

View File

@@ -2,29 +2,45 @@ using System;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// A class holding all information of a user
/// </summary>
[Serializable]
public class User
{
[Header("Personal data")]
// User nickname
/// <summary>
/// User nickname
/// </summary>
public string username;
// User avatar
/// <summary>
/// The avatar of the user
/// </summary>
public Sprite avatar;
[Header("Personal settings")]
// TODO: set personal settings and preferences
[Header("Progress")]
// Total playtime
/// <summary>
/// The total playtime of the user
/// </summary>
/// <remarks>TODO: needs to be implemented</remarks>
public double playtime;
/// <summary>
/// List of courses a user started/completed
/// </summary>
[SerializeField]
// List of courses a user started/completed
public List<Progress> courses = new List<Progress>();
/// <summary>
/// List of minigames a user played
/// </summary>
[SerializeField]
// List of minigames a user played
public List<Progress> minigames = new List<Progress>();
// Get a list of all recently started courses, returns a list of tuples of `<CourseIndex idx, float courseProgress>`
/// <summary>
/// Get a list of all recently started courses
/// </summary>
/// <returns>A <c>List</c> of <c>Tuples</c>, containing the <c>CourseIndex</c>
/// and a <c>float</c> holding the progress (value between 0 and 1) of the user in this course</returns>
public List<Tuple<CourseIndex, float>> GetRecentCourses()
{
// TODO: return better results (for now only return all courses)
@@ -38,7 +54,11 @@ public class User
return recentCourses;
}
// Get a list of all recommended courses, returns a list of tuples of `<CourseIndex idx, float courseProgress>`
/// <summary>
/// Get a list of all recommended courses
/// </summary>
/// <returns>A <c>List</c> of <c>Tuples</c>, containing the <c>CourseIndex</c>
/// and a <c>float</c> holding the progress (value between 0 and 1) of the user in this course</returns>
public List<Tuple<CourseIndex, float>> GetRecommendedCourses()
{
List<Tuple<CourseIndex, float>> recommenedCourses = new List<Tuple<CourseIndex, float>>();
@@ -59,4 +79,24 @@ public class User
return recommenedCourses;
}
/// <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)
{
return courses.Find((p) => p.Get<CourseIndex>("courseIndex") == courseIndex);
}
/// <summary>
/// Get the progress of certain minigame
/// </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)
{
return minigames.Find((p) => p.Get<MinigameIndex>("minigameIndex") == minigameIndex);
}
}

View File

@@ -5,34 +5,56 @@ using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
/// <summary>
/// UserCreationScreen scene manager
/// </summary>
public class UserCreationScreen : MonoBehaviour
{
// Max length of a username
/// <summary>
/// Maximum lenght of a username
/// </summary>
private const int MAX_USERNAME_LENGTH = 12;
[Header("UI References")]
// Reference to the input text field for username
/// <summary>
/// Reference to the input text field for username
/// </summary>
public TMP_InputField inputName;
// Reference to the avatar-list container
/// <summary>
/// Reference to the avatar-list container
/// </summary>
public Transform avatarsContainer;
[Header("Prefab")]
// Avatar prefab
/// <summary>
/// Avatar prefab
/// </summary>
public GameObject avatarPrefab;
// List of all sprites that are supported as avatars
/// <summary>
/// List of all sprites that are supported as avatars
/// </summary>
public List<Sprite> sprites = new List<Sprite>();
[Header("Users List")]
// Reference to the UserList ScriptableObject
/// <summary>
/// Reference to the UserList ScriptableObject
/// </summary>
public UserList users;
/// <summary>
/// Current selected avatar
/// </summary>
[SerializeField]
// Current selected avatar
private int selectedAvatar = 0;
// List of references to avatar background sprites (so we can color them nicely)
/// <summary>
/// List of references to avatar background sprites (so we can color them nicely)
/// </summary>
private List<Image> avatars = new List<Image>();
/// <summary>
/// Start is called before the first frame update
/// </summary>
void Start()
{
for (int i = 0; i < sprites.Count; i++)
@@ -60,7 +82,10 @@ public class UserCreationScreen : MonoBehaviour
}
}
// Update the current selected avatar
/// <summary>
/// Update the current selected avatar
/// </summary>
/// <param name="newAvatar">Index to the new avatar in the <c>this.avatars</c> list</param>
private void UpdateAvatar(int newAvatar)
{
avatars[selectedAvatar].color = Color.gray;
@@ -68,13 +93,20 @@ public class UserCreationScreen : MonoBehaviour
avatars[selectedAvatar].color = Color.blue;
}
// Check if a given string is a correct username (using Regex)
/// <summary>
/// Check if a given string is a correct username (using Regex)
/// </summary>
/// <param name="username">The username to be checked</param>
/// <returns><c>true</c> if the username was valid, <c>false</c> otherwise</returns>
static public bool IsValidUsername(string username)
{
return new Regex($@"^[abcdefghijklmnopqrstuvwxyz]{{1,{MAX_USERNAME_LENGTH}}}$").IsMatch(username);
}
// Create a new user (will be called by button)
/// <summary>
/// Create a new user
/// (this method will be called by a button callback)
/// </summary>
public void CreateUser()
{
string username = inputName.text;

View File

@@ -3,31 +3,55 @@ 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
{
// Serializable UserList content
/// <summary>
/// Helper class to enable serialization of the UserList class
/// (<c>ScriptableObkect</c>s cannot be serialized)
/// </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;
/// <summary>
/// A list containing all users (which can be serialized)
/// </summary>
public List<User> storedUsers = new List<User>();
}
[Header("Users")]
/// <summary>
/// Reference to the serializable version of <c>UserList</c>
/// </summary>
[SerializeField]
// Reference to serializable version of UserList
private StoredUserList storedUserList = new StoredUserList();
// Path to .json file
/// <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()
{
PATH = $"{Application.dataPath}/users.json";
Load();
}
// Create a new User
/// <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();
@@ -36,7 +60,12 @@ public class UserList : ScriptableObject
return user;
}
// Create a new User and add to list
/// <summary>
/// Create a new user and save (add to list)
/// </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 CreateAndAddNewUser(string name, Sprite avatar)
{
User user = CreateNewUser(name, avatar);
@@ -45,7 +74,11 @@ public class UserList : ScriptableObject
return user;
}
// Get user by username, returns `null` if no user can be found with such name
/// <summary>
/// Get a user by username
/// </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)
{
foreach (User user in storedUserList.storedUsers)
@@ -54,19 +87,27 @@ public class UserList : ScriptableObject
return null;
}
// Get a list of all users
/// <summary>
/// Get a list of all users currently stored
/// </summary>
/// <returns>A list of all users</returns>
public List<User> GetUsers()
{
return storedUserList.storedUsers;
}
// Get the current active user
/// <summary>
/// Get the current logged in user
/// </summary>
/// <returns>The current logged in user</returns>
public User GetCurrentUser()
{
return storedUserList.storedUsers[storedUserList.currentUserIndex];
}
// Save the userList
/// <summary>
/// Save the users
/// </summary>
public void Save()
{
string json = JsonUtility.ToJson(storedUserList);
@@ -74,7 +115,9 @@ public class UserList : ScriptableObject
File.WriteAllText(PATH, json);
}
// Load the userList into this object
/// <summary>
/// Override the current content of the userlist by what is stored on disk
/// </summary>
public void Load()
{
try

View File

@@ -3,24 +3,34 @@ using System.Collections.Generic;
using System.Runtime.Serialization;
using UnityEngine;
/// <summary>
/// Test the Progress class
/// </summary>
public class TestProgress : MonoBehaviour
{
/// <summary>
/// A dummy serializable struct to perform test operations on
/// </summary>
[Serializable]
// Dummy struct
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;
}
// Helper method, returns true if `Progress.Get(...)` throws a `KeyNotFoundException`
/// <summary>
/// Helper method
/// </summary>
/// <returns><c>true</c> if <c>Progress.AddOrUpdate(...)</c> throws a <c>SerializationException</c></returns>
private bool AddNonSerializableStruct()
{
Progress progress = new Progress();
@@ -30,7 +40,10 @@ public class TestProgress : MonoBehaviour
return false;
}
// Helper method, returns true if `Progress.Get(...)` throws a `KeyNotFoundException`
/// <summary>
/// Helper method
/// </summary>
/// <returns><c>true</c> if <c>Progress.Get(...)</c> throws a <c>KeyNotFoundException</c></returns>
private bool AccessInvalidKey()
{
Progress progress = new Progress();
@@ -39,7 +52,10 @@ public class TestProgress : MonoBehaviour
return false;
}
// Helper method, returns true if `Progress.Get(...)` throws a `InvalidCastException`
/// <summary>
/// Helper method
/// </summary>
/// <returns><c>true</c> if <c>Progress.Get(...)</c> throws a <c>InvalidCastException</c></returns>
private bool AccessInvalidType()
{
Progress progress = new Progress();
@@ -49,6 +65,9 @@ public class TestProgress : MonoBehaviour
return false;
}
/// <summary>
/// Start is called before the first frame update
/// </summary>
void Start()
{
TestNewProgress();
@@ -68,18 +87,27 @@ public class TestProgress : MonoBehaviour
TestProgressGetStruct();
}
/// <summary>
/// Test for creation of a new progress
/// </summary>
public void TestNewProgress()
{
Progress progress = new Progress();
Debug.Assert(progress != null);
}
/// <summary>
/// Test whether invalid data will not be added
/// </summary>
public void TestProgressAddInvalidData()
{
Progress progress = new Progress();
Debug.Assert(!progress.AddOrUpdate<GameObject>("key", null));
}
/// <summary>
/// Test whether a duplicated key will be added
/// </summary>
public void TestProgressAddDuplicateKey()
{
Progress progress = new Progress();
@@ -87,45 +115,69 @@ public class TestProgress : MonoBehaviour
Debug.Assert(progress.AddOrUpdate<int>("key 1", 1));
}
/// <summary>
/// Test whether a <c>int</c> value can be added
/// </summary>
public void TestProgressAddInt()
{
Progress progress = new Progress();
Debug.Assert(progress.AddOrUpdate<int>("key", 1));
}
/// <summary>
/// Test whether a <c>double</c> value can be added
/// </summary>
public void TestProgressAddDouble()
{
Progress progress = new Progress();
Debug.Assert(progress.AddOrUpdate<double>("key", 1.0));
}
/// <summary>
/// Test whether a <c>string</c> value can be added
/// </summary>
public void TestProgressAddString()
{
Progress progress = new Progress();
Debug.Assert(progress.AddOrUpdate<string>("key", "Hello World!"));
}
/// <summary>
/// Test whether a serializable struct can be added
/// </summary>
public void TestProgressAddSerializableStruct()
{
Progress progress = new Progress();
Debug.Assert(progress.AddOrUpdate<SerializableStruct>("key", new SerializableStruct()));
}
/// <summary>
/// Test whether a non-serializable struct will throw an error
/// </summary>
public void TestProgressAddNonSerializableStruct()
{
Debug.Assert(AddNonSerializableStruct());
}
/// <summary>
/// Test whether an invalid key will throw an error
/// </summary>
public void TestProgressGetInvalidKey()
{
Debug.Assert(AccessInvalidKey());
}
/// <summary>
/// Test whether an invalid type will throw an error
/// </summary>
public void TestProgressGetInvalidType()
{
Debug.Assert(AccessInvalidType());
}
/// <summary>
/// Test whether a value is correctly updated
/// </summary>
public void TestProgressUpdate()
{
Progress progress = new Progress();
@@ -135,6 +187,9 @@ public class TestProgress : MonoBehaviour
Debug.Assert(progress.Get<int>("key") == 2);
}
/// <summary>
/// Test whether a <c>int</c> value can be read
/// </summary>
public void TestProgressGetInt()
{
Progress progress = new Progress();
@@ -142,6 +197,9 @@ public class TestProgress : MonoBehaviour
Debug.Assert(progress.Get<int>("key") == 1);
}
/// <summary>
/// Test whether a <c>double</c> value can be read
/// </summary>
public void TestProgressGetDouble()
{
Progress progress = new Progress();
@@ -149,6 +207,9 @@ public class TestProgress : MonoBehaviour
Debug.Assert(progress.Get<double>("key") == 1.0);
}
/// <summary>
/// Test whether a <c>string</c> value can be read
/// </summary>
public void TestProgressGetString()
{
Progress progress = new Progress();
@@ -156,6 +217,9 @@ public class TestProgress : MonoBehaviour
Debug.Assert(progress.Get<string>("key") == "Hello World!");
}
/// <summary>
/// Test whether a serializable struct can be read
/// </summary>
public void TestProgressGetStruct()
{
Progress progress = new Progress();

View File

@@ -0,0 +1,168 @@
using System;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Test the User class
/// </summary>
public class TestUser : MonoBehaviour
{
/// <summary>
/// Start is called before the first frame update
/// </summary>
void Start()
{
TestNewUser();
TestUserAddCourse();
TestUserAddMinigame();
TestGetRecentCoursesEmpty();
TestGetRecentCoursesAll();
TestGetRecommendedCoursesEmpty();
TestGetRecommendedCoursesAll();
TestGetCourseProgressNull();
TestGetCourseProgressValid();
TestGetMinigameProgressNull();
TestGetMinigameProgressValid();
}
/// <summary>
/// Test for the creation of a new user
/// </summary>
public void TestNewUser()
{
User user = new User();
Debug.Assert(user != null);
Debug.Assert(user.courses.Count == 0);
Debug.Assert(user.minigames.Count == 0);
}
/// <summary>
/// Test whether progress on a new course can be added
/// </summary>
public void TestUserAddCourse()
{
User user = new User();
Progress p = new Progress();
user.courses.Add(p);
Debug.Assert(user.courses.Count == 1);
Debug.Assert(user.minigames.Count == 0);
}
/// <summary>
/// Test whether progress on a new minigame can be added
/// </summary>
public void TestUserAddMinigame()
{
User user = new User();
Progress p = new Progress();
user.minigames.Add(p);
Debug.Assert(user.courses.Count == 0);
Debug.Assert(user.minigames.Count == 1);
}
/// <summary>
/// Test GetRecentCourses will return empty when no progress is stored
/// </summary>
public void TestGetRecentCoursesEmpty()
{
User user = new User();
Debug.Assert(user.GetRecentCourses().Count == 0);
}
/// <summary>
/// Temporary test for GetRecentCourses will return all progress that is stored
/// </summary>
public void TestGetRecentCoursesAll()
{
User user = new User();
Progress p = new Progress();
p.AddOrUpdate<CourseIndex>("courseIndex", CourseIndex.FINGERSPELLING);
p.AddOrUpdate<float>("courseProgress", 0.5f);
user.courses.Add(p);
List<Tuple<CourseIndex, float>> list = user.GetRecentCourses();
Debug.Assert(list.Count == 1);
Debug.Assert(list[0].Item1 == CourseIndex.FINGERSPELLING);
Debug.Assert(list[0].Item2 == 0.5f);
}
/// <summary>
/// Test GetRecommendedCourses will return <c>Tuple<CourseIndex.FINGERSPELLING, 0.0></c> when no progress is stored
/// </summary>
public void TestGetRecommendedCoursesEmpty()
{
User user = new User();
List<Tuple<CourseIndex, float>> list = user.GetRecommendedCourses();
Debug.Assert(list.Count == 1);
Debug.Assert(list[0].Item1 == CourseIndex.FINGERSPELLING);
Debug.Assert(list[0].Item2 == 0.0f);
}
/// <summary>
/// Temporary test for GetRecommenedCourses will return all progress that is stored
/// </summary>
public void TestGetRecommendedCoursesAll()
{
User user = new User();
Progress p = new Progress();
p.AddOrUpdate<CourseIndex>("courseIndex", CourseIndex.FINGERSPELLING);
p.AddOrUpdate<float>("courseProgress", 0.5f);
user.courses.Add(p);
List<Tuple<CourseIndex, float>> list = user.GetRecommendedCourses();
Debug.Assert(list.Count == 1);
Debug.Assert(list[0].Item1 == CourseIndex.FINGERSPELLING);
Debug.Assert(list[0].Item2 == 0.5f);
}
/// <summary>
/// Test GetCourseProgress returns null when course cannot be found
/// </summary>
public void TestGetCourseProgressNull()
{
User user = new User();
Debug.Assert(user.GetCourseProgress(CourseIndex.FINGERSPELLING) == null);
Debug.Assert(user.GetCourseProgress((CourseIndex)100) == null);
}
/// <summary>
/// Test GetCourseProgress returns correct progress object
/// </summary>
public void TestGetCourseProgressValid()
{
User user = new User();
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);
Debug.Assert(q.Get<CourseIndex>("courseIndex") == CourseIndex.FINGERSPELLING);
Debug.Assert(q.Get<float>("courseProgress") == 3.14159265f);
}
/// <summary>
/// Test GetMinigameProgress returns null when minigame cannot be found
/// </summary>
public void TestGetMinigameProgressNull()
{
User user = new User();
Debug.Assert(user.GetMinigameProgress(MinigameIndex.SPELLING_BEE) == null);
Debug.Assert(user.GetMinigameProgress((MinigameIndex)100) == null);
Progress p = new Progress();
p.AddOrUpdate<MinigameIndex>("minigameIndex", MinigameIndex.SPELLING_BEE);
user.minigames.Add(p);
Debug.Assert(user.GetMinigameProgress(MinigameIndex.HANGMAN) == null);
}
/// <summary>
/// Test GetMinigameProgress returns correct progress object
/// </summary>
public void TestGetMinigameProgressValid()
{
User user = new User();
Progress p = new Progress();
p.AddOrUpdate<MinigameIndex>("minigameIndex", MinigameIndex.SPELLING_BEE);
user.minigames.Add(p);
Progress q = user.GetMinigameProgress(MinigameIndex.SPELLING_BEE);
Debug.Assert(q.Get<CourseIndex>("minigameIndex") == CourseIndex.FINGERSPELLING);
}
}

View File

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

View File

@@ -1,13 +1,22 @@
using UnityEngine;
/// <summary>
/// Test the UserCreationScreen class
/// </summary>
public class TestUserCreationScreen : MonoBehaviour
{
/// <summary>
/// Start is called before the first frame update
/// </summary>
void Start()
{
TestIsValidUsernameTrue();
TestIsValidUsernameFalse();
}
/// <summary>
/// Tets IsValidUsername will return <c>true</c> for an valid username
/// </summary>
public void TestIsValidUsernameTrue()
{
foreach (char c in "abcdefghijklmnopqrstuvwxyz")
@@ -16,6 +25,9 @@ public class TestUserCreationScreen : MonoBehaviour
Debug.Assert(UserCreationScreen.IsValidUsername("abcdefghijkl"));
}
/// <summary>
/// Tets IsValidUsername will return <c>false</c> for an invalid username
/// </summary>
public void TestIsValidUsernameFalse()
{
Debug.Assert(!UserCreationScreen.IsValidUsername(string.Empty));

View File

@@ -1,21 +1,33 @@
using UnityEngine;
using UnityEngine.SceneManagement;
/// <summary>
/// Class to handle scene loading callbacks
/// </summary>
public class ChangeSceneOnClick : MonoBehaviour
{
// Load scene from path name
/// <summary>
/// Method used as callback for gameobject onClick events
/// </summary>
/// <param name="sceneName">The path to the new scene (<c>path == $"Assets/{sceneName}"</c>)</param>
public void LoadScene(string sceneName)
{
SceneManager.LoadScene(sceneName);
}
// Load scene from reference
/// <summary>
/// Method used as callback for gameobject onClick events
/// </summary>
/// <param name="scene">Reference to a scene</param>
public void LoadScene(Scene scene)
{
SceneManager.LoadScene(scene.buildIndex);
}
// Load scene from build index
/// <summary>
/// Method used as callback from gameobject onClick events
/// </summary>
/// <param name="buildIndex">Build index of the scene to be loaded</param>
public void LoadScene(int buildIndex)
{
SceneManager.LoadScene(buildIndex);

View File

@@ -3,33 +3,58 @@ using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
/// <summary>
/// Handles the display of courses in the ListCourseScreen and CourseScreenManager scene
/// </summary>
public class CourseItem : MonoBehaviour
{
[Header("Course")]
// Reference to the course
/// <summary>
/// Reference to the course object
/// </summary>
public Course course;
// Progress of the current user on this course
/// <summary>
/// Progress of the current user on this specific course
/// </summary>
public float progress;
[Header("UI references")]
// Reference to thumbnail object
/// <summary>
/// UI Reference to the image for displaying the course thumbnail
/// </summary>
public Image thumbnail;
// Reference to title object
/// <summary>
/// UI Reference to the gameobject for displaying the course title
/// </summary>
public TMP_Text title;
// Refetence to object so correct callback can be trigger on click
/// <summary>
/// UI Reference to the button so the correct callback can be trigger on click
/// </summary>
public Button button;
// Reference to progress bar
/// <summary>
/// Reference to the slider that displays the progress of the user
/// </summary>
public GameObject slider;
// Reference to `COMPLETED`
/// <summary>
/// Reference to the gameobject that holds the text 'COMPLETED'
/// </summary>
public GameObject completed;
/// <summary>
/// Start is called before the first frame update
/// </summary>
void Start()
{
// Use public function so that this component can get Instantiated
GenerateContent();
}
/// <summary>
/// (Re)generate the CourseItem object and update its appearance
/// </summary>
public void GenerateContent()
{
// Set appearance

View File

@@ -1,20 +1,29 @@
using UnityEngine;
using UnityEngine.SceneManagement;
/// <summary>
/// ListCourseScreen scene manager
/// </summary>
public class CourseListManager : MonoBehaviour
{
[Header("Course list UI components")]
// Reference to course-list holder object
/// <summary>
/// Reference to the course-list container object
/// </summary>
public Transform courseContainer;
[Header("Prefabs")]
// Prefab of item
/// <summary>
/// Prefab of the course item object
/// </summary>
public GameObject courseItemPrefab;
[Header("Courses")]
// Reference to the list of all courses
/// <summary>
/// Reference to the list of all courses
/// </summary>
public CourseList courseList;
/// <summary>
/// Start is called before the first frame update
/// </summary>
void Start()
{
foreach (Course course in courseList.courses)
@@ -28,7 +37,10 @@ public class CourseListManager : MonoBehaviour
}
}
// Method used as callback for on click events
/// <summary>
/// Method used as callback for course item onClick events
/// </summary>
/// <param name="sceneName">The path to the new scene (<c>path == $"Assets/{sceneName}"</c>)</param>
public void LoadScene(string sceneName)
{
SceneManager.LoadScene(sceneName);

View File

@@ -3,26 +3,44 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
/// <summary>
/// CourseScreen scene manager
/// </summary>
public class CourseScreenManager : MonoBehaviour
{
[Header("Course Screen Components")]
// Reference to text that displays when there are no recent courses
/// <summary>
/// Reference to text that displays when there are no recent courses
/// </summary>
public GameObject noRecentCourses;
// Reference to recent-courses-list holder object
/// <summary>
/// Reference to recent-courses-list container object
/// </summary>
public Transform recentCoursesContainer;
// Reference to recommended-courses-list holder object
/// <summary>
/// Reference to recommended-courses-list container object
/// </summary>
public Transform recommendedCoursesContainer;
[Header("Prefabs")]
// CourseItem prefab
/// <summary>
/// Prefab of the course item object
/// </summary>
public GameObject courseItem;
[Header("User")]
// Reference to the users so we can get the current user;
/// <summary>
/// Reference to the users so we can get the current user;
/// </summary>
public UserList userList;
// Reference to the courses
/// <summary>
/// Reference to the courses
/// </summary>
public CourseList courseList;
/// <summary>
/// Start is called before the first frame update
/// </summary>
void Start()
{
User user = userList.GetCurrentUser();
@@ -55,7 +73,10 @@ public class CourseScreenManager : MonoBehaviour
}
}
// Method used as callback for on click events
/// <summary>
/// Method used as callback for course item onClick events
/// </summary>
/// <param name="sceneName">The path to the new scene (<c>path == $"Assets/{sceneName}"</c>)</param>
public void LoadScene(string sceneName)
{
SceneManager.LoadScene(sceneName);

View File

@@ -1,19 +1,33 @@
using UnityEngine;
/// <summary>
/// Class for holding all (static) data about a certain minigame
/// </summary>
[CreateAssetMenu(menuName = "Create new Scriptable/Minigame")]
public class Minigame : ScriptableObject
{
[Header("Minigame info")]
// Minigame index
/// <summary>
/// Index of the minigame
/// </summary>
public MinigameIndex index;
// Minigame title
/// <summary>
/// The minigame title
/// </summary>
public string title;
// Short desciption of the course
/// <summary>
/// A short description of the minigame
/// </summary>
public string description;
// Thumbnail of the course
/// <summary>
/// Reference to the minigame thumbnail
/// </summary>
public Sprite thumbnail;
[Header("Scene")]
// Reference to the minigame starting scene
/// <summary>
/// The path to the minigame starting scene (<c>path == $"Assets/{minigameEntryPoint}"</c>)
/// </summary>
public string minigameEntryPoint;
}

View File

@@ -1,5 +1,7 @@
// TODO: add other courses
/// <summary>
/// Enum for easy indexing and checking if a minigame is of a certain kind
/// </summary>
public enum MinigameIndex
{
SPELLING_BEE,

View File

@@ -3,27 +3,43 @@ using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
/// <summary>
/// Handles the display of minigames in the ListMinigameScreen scene
/// </summary>
public class MinigameItem : MonoBehaviour
{
// TODO: change to ScriptableObject Minigame;
[Header("ScriptableObject Course")]
/// <summary>
/// Reference to the minigame object
/// </summary>
public Minigame minigame;
[Header("UI references")]
// Reference to thumbnail object
/// <summary>
/// UI Reference to the image for displaying the minigame thumbnail
/// </summary>
public Image thumbnail;
// Reference to title object
/// <summary>
/// UI Reference to the gameobject for displaying the minigame title
/// </summary>
public TMP_Text title;
// Refetence to object so correct callback can be trigger on click
/// <summary>
/// UI Reference to the button so the correct callback can be trigger on click
/// </summary>
public Button button;
/// <summary>
/// Start is called before the first frame update
/// </summary>
void Start()
{
// Use public function so that this component can get Instantiated
GenerateContent();
}
/// <summary>
/// (Re)generate the MinigameItem object and update its appearance
/// </summary>
public void GenerateContent()
{
// Set appearance

View File

@@ -1,14 +1,20 @@
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Keep track off installed minigames
/// </summary>
[CreateAssetMenu(menuName = "Create new Scriptable/MinigameList")]
public class MinigameList : ScriptableObject
{
[Header("Current Minigame")]
// Index of the current course
/// <summary>
/// Index of the active/to be loaded/current minigame
/// </summary>
public int currentMinigameIndex = 0;
[Header("Minigames")]
// List of minigames
/// <summary>
/// List of all installed minigames
/// </summary>
public List<Minigame> minigames = new List<Minigame>();
}

View File

@@ -1,20 +1,29 @@
using UnityEngine;
using UnityEngine.SceneManagement;
/// <summary>
/// ListMinigameScreen scene manager
/// </summary>
public class MinigameListManager : MonoBehaviour
{
[Header("Minigame list UI components")]
// Reference to minigame-list holder object
/// <summary>
/// Reference to minigame-list container object
/// </summary>
public Transform minigameContainer;
[Header("Prefabs")]
// Prefab of item
/// <summary>
/// Prefab of the minigame item object
/// </summary>
public GameObject minigameItemPrefab;
[Header("Minigames")]
// Reference to the list of all minigames
/// <summary>
/// Reference to the list of all minigames
/// </summary>
public MinigameList minigameList;
/// <summary>
/// Start is called before the first frame update
/// </summary>
void Start()
{
foreach (Minigame minigame in minigameList.minigames)
@@ -28,7 +37,10 @@ public class MinigameListManager : MonoBehaviour
}
}
// Method used as callback for on click events
/// <summary>
/// Method used as callback for minigame item onClick events
/// </summary>
/// <param name="sceneName">The path to the new scene (<c>path == $"Assets/{sceneName}"</c>)</param>
public void LoadScene(string sceneName)
{
SceneManager.LoadScene(sceneName);

View File

@@ -1,14 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.SceneManagement;
/// <summary>
/// StartScreen scene manager
/// </summary>
public class StartScreenManager : 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()
{
if (!File.Exists(UserList.PATH) || userList.GetUsers().Count <= 0)

View File

@@ -2,18 +2,29 @@ using TMPro;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// Handles actions when a user presses the account button (upper left corner)
/// </summary>
public class UserButton : MonoBehaviour
{
[Header("User")]
// Reference to the user list, so we can extract the current user
/// <summary>
/// Reference to the user list, so we can extract the current user
/// </summary>
public UserList userList;
[Header("UI References")]
// Reference to the avatar object
/// <summary>
/// UI Reference to the avatar object
/// </summary>
public Image avatar;
// Reference to the username object
/// <summary>
/// UI Reference to the username object
/// </summary>
public TMP_Text username;
/// <summary>
/// Start is called before the first frame update
/// </summary>
void Start()
{
User user = userList.GetCurrentUser();

View File

@@ -3,32 +3,56 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
/// <summary>
/// Class for holding all (static) data about a certain course
/// </summary>
[CreateAssetMenu(menuName = "Create new Scriptable/Course")]
public class Course : ScriptableObject
{
/// <summary>
/// Small class to hold information about a single learnable (e.g., a word or a letter)
/// </summary>
[Serializable]
// Small class to hold information about a single learnable (e.g., a word or a letter)
public class Learnable
{
// Name of the word/letter to learn
/// <summary>
/// Name of the word/letter to learn
/// </summary>
public string name;
// Sprite of this word/letter
/// <summary>
/// Sprite of this word/letter
/// </summary>
public Sprite image;
// Example video clip
/// <summary>
/// Example video clip
/// </summary>
public VideoClip clip;
}
[Header("Course info")]
// Course index
/// <summary>
/// Index of the course
/// </summary>
public CourseIndex index;
// Course title
/// <summary>
/// The course title
/// </summary>
public string title;
// Short desciption of the course
/// <summary>
/// A short description of the course
/// </summary>
public string description;
// Thumbnail of the course
/// <summary>
/// Reference to the course thumbnail
/// </summary>
public Sprite thumbnail;
[Header("Learnable words")]
// List of learnable words/letters
/// <summary>
/// List of all learnable words/letters
/// </summary>
public List<Learnable> learnables = new List<Learnable>();
}

View File

@@ -1,5 +1,7 @@
// TODO: add other courses
/// <summary>
/// Enum for easy indexing and checking if a course is of a certain kind
/// </summary>
public enum CourseIndex
{
FINGERSPELLING

View File

@@ -1,14 +1,19 @@
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Keep track of all courses
/// </summary>
[CreateAssetMenu(menuName = "Create new Scriptable/CourseList")]
public class CourseList : ScriptableObject
{
[Header("Current Course")]
// Index of the current course
/// <summary>
/// Index of the active/to be loaded/current course
/// </summary>
public int currentCourseIndex = 0;
[Header("Courses")]
// List of courses
/// <summary>
/// List of all installed courses
/// </summary>
public List<Course> courses = new List<Course>();
}

View File

@@ -1,7 +1,7 @@
using UnityEngine;
using UnityEngine.Video;
using UnityEngine.UI;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
public class StartPause : MonoBehaviour
{

View File

@@ -1,7 +1,7 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Webcam : MonoBehaviour
{
@@ -13,7 +13,8 @@ public class Webcam : MonoBehaviour
public GameObject popup;
public TextMeshProUGUI dynamic;
void Awake(){
void Awake()
{
popup.SetActive(false);
WebCamDevice device = WebCamTexture.devices[camdex];
@@ -55,20 +56,25 @@ public class Webcam : MonoBehaviour
SceneManager.LoadScene(sceneName);
}
public void Show_feedback(){
if(popup.activeSelf){
public void Show_feedback()
{
if (popup.activeSelf)
{
dynamic.text = "";
popup.SetActive(false);
return;
}
double index = UnityEngine.Random.value;
if(index < 0.5){
if (index < 0.5)
{
dynamic.text = "Poor";
}
else if(index > 0.8){
else if (index > 0.8)
{
dynamic.text = "Excellent";
}
else{
else
{
dynamic.text = "Good";
}
popup.SetActive(true);

View File

@@ -1,8 +1,4 @@
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
public class BasicTest
{

View File

@@ -1,8 +1,4 @@
using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
public class BasicTest
{

View File

@@ -1,6 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

View File

@@ -1,9 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class SpellingBeeWebcam : MonoBehaviour
{
@@ -13,7 +11,8 @@ public class SpellingBeeWebcam : MonoBehaviour
public RawImage display;
public TextMeshProUGUI dynamic;
void Awake(){
void Awake()
{
//popup.SetActive(false);
WebCamDevice device = WebCamTexture.devices[camdex];

View File

@@ -3,29 +3,54 @@ using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
/// <summary>
/// Handles the display of themes in the ThemeSelectionController scene
/// </summary>
public class ThemeItem : MonoBehaviour
{
// TODO: change to ScriptableObject Theme;
[Header("ScriptableObject Theme")]
/// <summary>
/// The theme title
/// </summary>
public string themeTitle;
/// <summary>
/// A short description of the theme
/// </summary>
public string themeDescription;
/// <summary>
/// The callback function to start the game with the correct theme loaded
/// </summary>
public UnityAction startGameCallback;
[Header("UI references")]
// Reference to thumbnail object
/// <summary>
/// UI reference to the gameobject for displaying the theme title
/// </summary>
public TMP_Text title;
// Reference to description object
/// <summary>
/// UI reference to the gameobject for displaying the description
/// </summary>
public TMP_Text description;
// Refetence to object so correct callback can be trigger on click
/// <summary>
/// UI reference to the button so the correct callback can be trigger on click
/// </summary>
public Button button;
/// <summary>
/// Start is called before the first frame update
/// </summary>
void Start()
{
// Use public function so that this component can get Instantiated
GenerateContent();
}
/// <summary>
/// (Re)generate the ThemeItem object and update its appearance
/// </summary>
public void GenerateContent()
{
// Set appearance