Integrate minigame and courses

This commit is contained in:
Dries Van Schuylenbergh
2023-03-08 19:07:57 +00:00
parent 7e98fea538
commit 852a17b0b4
56 changed files with 1431 additions and 1300 deletions

View File

@@ -5,8 +5,8 @@ using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine;
[Serializable]
// Can not be created from Editor
public class Progress
{
[Serializable]
@@ -23,39 +23,34 @@ public class Progress
}
}
// TODO: use inheritance to create seperate MinigameProgress and CourseProgress
[Header("Course or Minigame")]
// TODO: change to course/minigame ScriptableObject reference
// Index of item in courses/minigame list object
public int index;
[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
public bool Add<T>(string key, T data)
public bool AddOrUpdate<T>(string key, T data)
{
if (data == null)
return false;
// Search for already existing key
foreach (DataEntry entry in entries)
{
if (entry.key == key)
{
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);
entries.Add(new DataEntry(key, ms.ToArray()));
if (entry != null)
{
entry.bytes.Clear();
entry.bytes.AddRange(ms.ToArray());
}
else
{
entries.Add(new DataEntry(key, ms.ToArray()));
}
return true;
}
}