using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using static PersistentDataController;
///
/// A class holding all information of a user
///
public class User
{
///
/// Reference to the user stored data record
///
private SavedUserData storedUserData;
///
/// Constructor
///
/// Reference to the user stored data record
public User(SavedUserData data)
{
this.storedUserData = data;
}
///
/// Get the username
///
public string GetUsername() { return storedUserData.username; }
///
/// Get the total playtime
///
public double GetPlaytime() { return storedUserData.playtime; }
///
/// Get the avatar
///
public Sprite GetAvatar() { return UserList.AVATARS[storedUserData.avatarIndex]; }
///
/// Get a list of all recently started minigameCards
///
/// A List of Tuples, containing the CourseIndex
/// and a float holding the progress (value between 0 and 1) of the user in this course
public List> GetRecentCourses()
{
// TODO: return better results (for now only return all minigameCards)
List> recentCourses = new List>();
foreach (var courseProgress in storedUserData.courses)
{
CourseIndex idx = courseProgress.courseIndex;
float progress = courseProgress.progress;
recentCourses.Add(Tuple.Create(idx, progress));
}
return recentCourses.Take(3).ToList();
}
///
/// Get a list of all recommended minigameCards
///
/// A List of Tuples, containing the CourseIndex
/// and a float holding the progress (value between 0 and 1) of the user in this course
public List> GetRecommendedCourses()
{
List> recommenedCourses = new List>();
if (storedUserData.courses.Count == 0)
{
recommenedCourses.Add(Tuple.Create(CourseIndex.FINGERSPELLING, 0.0f));
}
else
{
// TODO: return better results (for now only return all minigameCards)
foreach (var courseProgress in storedUserData.courses)
{
CourseIndex idx = courseProgress.courseIndex;
float progress = courseProgress.progress;
recommenedCourses.Add(Tuple.Create(idx, progress));
}
}
return recommenedCourses.Take(3).ToList();
}
///
/// Get the progress of all minigameCards the user did
///
///
public List GetCourses()
{
return storedUserData.courses;
}
///
/// Get the progress of a certain course
///
/// Index of course
/// Progress belonging to the courseIndex, null if course was not found
public SavedCourseProgress GetCourseProgress(CourseIndex courseIndex)
{
return storedUserData.courses.Find((p) => p.courseIndex == courseIndex);
}
///
/// Add new progress of a course
///
/// SavedCourseProgress data record
public void AddCourseProgress(SavedCourseProgress progress)
{
storedUserData.courses.Add(progress);
}
///
/// Reset progress of a course
///
/// Index of course
public void ResetCourseProgress(CourseIndex courseIndex)
{
storedUserData.courses.RemoveAll((p) => p.courseIndex == courseIndex);
}
///
/// Get the progress of all minigames the user did
///
///
public List GetMinigames()
{
return storedUserData.minigames;
}
///
/// Get the progress of certain minigame
///
/// Index of the minigame
/// Progress belonging to the minigameIndex, null if minigame was not found
public SavedMinigameProgress GetMinigameProgress(MinigameIndex minigameIndex)
{
return storedUserData.minigames.Find((p) => p.minigameIndex == minigameIndex);
}
///
/// Add new progress of a minigame
///
/// SavedMinigameProgress data record
public void AddMinigameProgress(SavedMinigameProgress progress)
{
storedUserData.minigames.Add(progress);
}
///
/// Reset progress of a minigame
///
/// Index of the minigame
public void ResetMinigameProgress(MinigameIndex minigameIndex)
{
storedUserData.minigames.RemoveAll((p) => p.minigameIndex == minigameIndex);
}
}