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,6 +5,8 @@ using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using static Unity.VisualScripting.Member;
using UnityEditor;
public class GameController : MonoBehaviour
{
@@ -60,10 +62,24 @@ public class GameController : MonoBehaviour
// Counter that keeps track of how many letters have been spelled correctly
private int spelledWords;
[Header("User")]
// Reference to the user list to access the current user
public UserList userList;
// Reference to the current user
private User user;
// Reference to the minigame progress of the current user
private Progress progress = null;
[Header("Minigame")]
// Reference to the minigame ScriptableObject
public Minigame minigame;
[Header("Letter prefab")]
// Letter prefab
public GameObject letterPrefab;
[Header("UI References")]
// Reference to letter prefab
public Transform letterContainer;
@@ -72,7 +88,7 @@ public class GameController : MonoBehaviour
// Timer display
public TMP_Text timerText;
[Header("private variables")]
[Header("Private Variables")]
// The GameObjects representing the letters
private List<GameObject> letters = new List<GameObject>();
@@ -90,6 +106,20 @@ public class GameController : MonoBehaviour
gameEndedPanel.SetActive(false);
replayButton.onClick.AddListener(Start);
// Create entry in current user for keeping track of progress
user = userList.users[userList.currentUserIndex];
progress = user.minigames.Find((p) => p != null && p.Get<MinigameIndex>("minigameIndex") == minigame.index);
if (progress == null)
{
progress = new Progress();
progress.AddOrUpdate<MinigameIndex>("minigameIndex", MinigameIndex.SPELLING_BEE);
// TODO: add progress we want to keep track off
// (for example 'highscore')
progress.AddOrUpdate<int>("highscore", 0);
user.minigames.Add(progress);
}
EditorUtility.SetDirty(user);
// TODO: change to ScriptableObject
themeList = ThemeLoader.LoadJson();
currentTheme = FindThemeByName(PlayerPrefs.GetString("themeName"));
@@ -153,6 +183,18 @@ public class GameController : MonoBehaviour
// Display win screen
private void ActivateWin()
{
int score = words.Length;
// Update progress
// TODO: update all tracked progress
int highscore = progress.Get<int>("highscore");
if (score < highscore)
{
progress.AddOrUpdate<int>("highsscore", score);
EditorUtility.SetDirty(user);
}
// @lukas stuff
DeleteWord();
endText.text = "YOU WIN!";
correctLettersText.text = "Your time: " + spelledLetters.ToString();
@@ -208,7 +250,7 @@ public class GameController : MonoBehaviour
// Delete all letter objects
private void DeleteWord()
{
for (int i = 0; i < currentWord.Length; i++)
for (int i = 0; i < letters.Count; i++)
{
Destroy(letters[i]);
}