Resolve WES-133 "Multiple choice"
This commit is contained in:
committed by
Jelle De Geest
parent
04d9a4bf2b
commit
4e9d801e61
@@ -19,7 +19,7 @@ public class PersistentDataController
|
||||
/// Current implementation version of the PersistentDataController
|
||||
/// </summary>
|
||||
/// <remarks>MSB represent sprint version, LSB represent subversion</remarks>
|
||||
public static readonly int VERSION = 0x04_01;
|
||||
public static readonly int VERSION = 0x04_03;
|
||||
|
||||
/// <summary>
|
||||
/// Path of the <c>.json</c>-file to store all serialized data
|
||||
@@ -184,8 +184,139 @@ public class PersistentDataController
|
||||
[Serializable]
|
||||
public class SavedCourseProgress : PersistentDataContainer
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Update the progress value of the SavedLearnableProgress with the given learnableName.
|
||||
/// </summary>
|
||||
/// <param name="learnableName"></param>
|
||||
/// <param name="addValue"></param>
|
||||
public void UpdateLearnable(string learnableName, float addValue)
|
||||
{
|
||||
SavedLearnableProgress learnable = learnables.Find(l => l.name == learnableName);
|
||||
if (learnable == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the progress value of the SavedLearnableProgress
|
||||
learnable.progress += addValue;
|
||||
// crop the learnable progress around -5 and 5
|
||||
if (learnable.progress > 5.0f)
|
||||
{
|
||||
learnable.progress = 5.0f;
|
||||
}
|
||||
else if (learnable.progress < -5.0f)
|
||||
{
|
||||
learnable.progress = -5.0f;
|
||||
}
|
||||
|
||||
// if learnable progress is big enough it is "completed"
|
||||
|
||||
if (learnable.progress > 3)
|
||||
{
|
||||
completedLearnables++;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns> bool which indicates if there are enough inUseLearnables </returns>
|
||||
private bool EnoughLearnables()
|
||||
{
|
||||
// There need to be more then 5 non completed learnables
|
||||
return inUseLearnables - completedLearnables > 5 || totalLearnables == inUseLearnables;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find a SavedLearnableProgress with the given name
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns> SavedLearnableProgress with the given name </returns>
|
||||
public SavedLearnableProgress FindLearnable(string name)
|
||||
{
|
||||
return learnables.Find(l => l.name == name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// find learnable in learnables which is not yet in use, and set it active
|
||||
/// </summary>
|
||||
/// <returns> bool which indicates the success of the function </returns>
|
||||
public SavedLearnableProgress AddNewLearnable()
|
||||
{
|
||||
SavedLearnableProgress learnable = learnables.Find(l => !l.inUse);
|
||||
if (learnable == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
learnable.inUse = true;
|
||||
inUseLearnables++;
|
||||
return learnable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a random inUse learnable
|
||||
/// </summary>
|
||||
/// <returns> a randomly selected inUse SavedLearnable which is not yet completed</returns>
|
||||
public SavedLearnableProgress GetRandomLearnable()
|
||||
{
|
||||
if (!EnoughLearnables())
|
||||
{
|
||||
return AddNewLearnable();
|
||||
}
|
||||
else
|
||||
{
|
||||
// only select inUse learnables which are not yet completed (progress < 3.5f)
|
||||
List<SavedLearnableProgress> inUseLearnables = learnables.FindAll(l => l.inUse && l.progress <= 3.5f);
|
||||
|
||||
if (inUseLearnables.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Select a random index from the in-use learnables list
|
||||
int randomIndex = UnityEngine.Random.Range(0, inUseLearnables.Count);
|
||||
return inUseLearnables[randomIndex];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create new SavedLearnableProgress object and assigns the index and name values
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="index"></param>
|
||||
/// <returns> bool which indicates the success of the function</returns>
|
||||
public bool AddLearnable(string name, int index)
|
||||
{
|
||||
if (learnables.Any(learnable => learnable.name == name || learnable.index == index))
|
||||
return false;
|
||||
|
||||
SavedLearnableProgress savedLearnableProgress = new SavedLearnableProgress();
|
||||
savedLearnableProgress.index = index;
|
||||
savedLearnableProgress.name = name;
|
||||
learnables.Add(savedLearnableProgress);
|
||||
totalLearnables++;
|
||||
return true;
|
||||
}
|
||||
|
||||
public CourseIndex courseIndex;
|
||||
public float progress = -1.0f;
|
||||
public int completedLearnables = 0;
|
||||
public int inUseLearnables = 0;
|
||||
public int totalLearnables = 0;
|
||||
public List<SavedLearnableProgress> learnables = new List<SavedLearnableProgress>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stored individual learnable progress
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class SavedLearnableProgress : PersistentDataContainer
|
||||
{
|
||||
public int index;
|
||||
public bool inUse = false;
|
||||
public string name;
|
||||
public float progress = 0.0f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user