Dries Van Schuylenbergh 26f3322e4e Add formatting rules
2023-03-10 09:21:11 +00:00

103 lines
3.6 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// A class holding all information of a user
/// </summary>
[Serializable]
public class User
{
/// <summary>
/// User nickname
/// </summary>
public string username;
/// <summary>
/// The avatar of the user
/// </summary>
public Sprite avatar;
/// <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]
public List<Progress> courses = new List<Progress>();
/// <summary>
/// List of minigames a user played
/// </summary>
[SerializeField]
public List<Progress> minigames = new List<Progress>();
/// <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)
List<Tuple<CourseIndex, float>> recentCourses = new List<Tuple<CourseIndex, float>>();
foreach (Progress courseProgress in courses)
{
CourseIndex idx = courseProgress.Get<CourseIndex>("courseIndex");
float progress = courseProgress.Get<float>("courseProgress");
recentCourses.Add(Tuple.Create<CourseIndex, float>(idx, progress));
}
return recentCourses;
}
/// <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>>();
if (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)
{
CourseIndex idx = courseProgress.Get<CourseIndex>("courseIndex");
float progress = courseProgress.Get<float>("courseProgress");
recommenedCourses.Add(Tuple.Create<CourseIndex, float>(idx, progress));
}
}
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);
}
}