Compare commits

...

2 commits

Author SHA1 Message Date
8bc9aa4686 game(scripts): update references 2025-02-14 22:25:01 +08:00
587e6a1c6e game(scripts): standardise GameManager 2025-02-14 22:24:45 +08:00
4 changed files with 84 additions and 89 deletions

View file

@ -36,7 +36,7 @@ public class BroomSweeping : MonoBehaviour
if (dirtSweepCount < dirtRequired || _taskCompleted) return;
_taskCompleted = true;
GameManager.Instance.FloorSweepedTaskComplete();
GameManager.Instance.FloorSweptTaskComplete();
storyPanelUI.SetActive(true);
storyText.text = "I hope the house is clean enough now so I don't get scolded later...";

View file

@ -18,7 +18,7 @@ public class CanvasFade : MonoBehaviour
{
if (GameManager.Instance != null)
{
var dayNumber = GameManager.Instance.currentDay;
var dayNumber = GameManager.Instance.CurrentDay;
dayText.text = "Day " + dayNumber;
}

View file

@ -32,11 +32,11 @@ public class DayIncrementPlaygroundScript : MonoBehaviour
Debug.Log("initialisation wait...");
yield return new WaitForSeconds(3);
Debug.Log($"hello vro, day is {GameManager.Instance.currentDay}");
Debug.Log($"hello vro, day is {GameManager.Instance.CurrentDay}");
// get game manager and then increment the day
GameManager.Instance.IncrementDay();
Debug.Log($"post-increment day is {GameManager.Instance.currentDay}");
Debug.Log($"post-increment day is {GameManager.Instance.CurrentDay}");
// change to the next scene
// ReSharper disable once Unity.LoadSceneDisabledSceneName
@ -48,7 +48,7 @@ public class DayIncrementPlaygroundScript : MonoBehaviour
Debug.Log("initialisation wait...");
yield return new WaitForSeconds(3);
Debug.Log($"hello vro, day is {GameManager.Instance.currentDay}");
Debug.Log($"hello vro, day is {GameManager.Instance.CurrentDay}");
}
yield return 0;

View file

@ -1,13 +1,13 @@
/*
Author: Reza and Wai Lam
Date: 3/2/25
Description: To keep track of tasks, which level the player is at, and game mechanics
*/
* Author: Reza, Wai Lam, Mark
* Date: 3/2/25
* Description: To keep track of tasks, which level the player is at, and game mechanics
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
@ -17,51 +17,28 @@ public class GameManager : MonoBehaviour
/// </summary>
public static GameManager Instance;
// current day, publicly readable, privately settable
// for public access, setting is a no-op
public int currentDay { get; private set; } = 1;
// Tracks GoToSchool task status
private bool goToSchool = false;
private bool bedroomCleaned = false;
private bool teethBrushed = false;
private bool floorSweeped = false;
private string lastSceneName;
private bool hasIncrementedToday = false;
// Defines UI references
[Header("UI References")] public GameObject storyPanelUI;
public TMP_Text storyText;
// Queue for managing messages
private Queue<string> messageQueue = new Queue<string>();
private bool isMessageActive = false;
private readonly Queue<string> _messageQueue = new();
private bool _bedroomCleaned;
private bool _floorSwept;
/// <summary>
/// Checks if tasks are completed
/// </summary>
public bool IsBedroomCleaned()
{
return bedroomCleaned;
}
// Tracks GoToSchool task status
private bool _goToSchool;
public bool IsTeethBrushed()
{
return teethBrushed;
}
private bool _hasIncrementedToday;
private bool _isMessageActive;
public bool IsFloorSweeped()
{
return floorSweeped;
}
private string _lastSceneName;
private bool _teethBrushed;
public bool IsGoToSchool()
{
return goToSchool;
}
// current day, publicly readable, privately settable
// for public access, setting is a no-op
public int CurrentDay { get; private set; } = 1;
/// <summary>
/// Enforces singleton behavior; sets doesn't destroy on load and checks for multiple instances
@ -85,39 +62,57 @@ public class GameManager : MonoBehaviour
}
Debug.Log($"game manager ({GetInstanceID()}) is initialising itself!");
currentDay = 1;
CurrentDay = 1;
// Try to find UI elements if not set
if (storyPanelUI == null)
{
storyPanelUI = GameObject.Find("StoryPanelUI");
}
if (storyPanelUI == null) storyPanelUI = GameObject.Find("StoryPanelUI");
if (storyText == null)
{
storyText = GameObject.Find("StoryText").GetComponent<TMP_Text>();
}
if (storyText == null) storyText = GameObject.Find("StoryText").GetComponent<TMP_Text>();
SceneManager.sceneLoaded += OnSceneLoaded;
}
// Update is called once per frame
void Update()
private void Update()
{
// Continuously check and display queued messages
if (!isMessageActive && messageQueue.Count > 0)
if (!_isMessageActive && _messageQueue.Count > 0)
{
string nextMessage = messageQueue.Dequeue();
var nextMessage = _messageQueue.Dequeue();
StartCoroutine(DisplayMessage(nextMessage));
}
}
/// <summary>
/// Checks if tasks are completed
/// </summary>
public bool IsBedroomCleaned()
{
return _bedroomCleaned;
}
public bool IsTeethBrushed()
{
return _teethBrushed;
}
public bool IsFloorSwept()
{
return _floorSwept;
}
public bool IsGoToSchool()
{
return _goToSchool;
}
/// <summary>
/// Queues a message to be displayed
/// </summary>
// ReSharper disable once MemberCanBePrivate.Global
public void QueueMessage(string message)
{
messageQueue.Enqueue(message);
_messageQueue.Enqueue(message);
}
/// <summary>
@ -125,82 +120,82 @@ public class GameManager : MonoBehaviour
/// </summary>
private IEnumerator DisplayMessage(string message)
{
isMessageActive = true;
_isMessageActive = true;
storyPanelUI.SetActive(true);
storyText.text = message;
yield return new WaitForSeconds(7f); // Wait for 7 seconds before hiding
storyPanelUI.SetActive(false);
isMessageActive = false;
_isMessageActive = false;
}
// Logs player's choices before leaving the house (for future Firebase tracking)
// log the players choices before leaving the house (for future Firebase tracking)
public void LogPlayerChoices()
{
Debug.Log("Player is trying to leave the house. Task Completion Status:");
Debug.Log("Bedroom Cleaned: " + bedroomCleaned);
Debug.Log("Teeth Brushed: " + teethBrushed);
Debug.Log("Floor Sweeped: " + floorSweeped);
Debug.Log("Go To School: " + goToSchool);
Debug.Log("Bedroom Cleaned: " + _bedroomCleaned);
Debug.Log("Teeth Brushed: " + _teethBrushed);
Debug.Log("Floor Swept: " + _floorSwept);
Debug.Log("Go To School: " + _goToSchool);
}
// Checks if all tasks are done before player can go to school
// ReSharper disable once MemberCanBePrivate.Global
public void AreTasksDone()
{
if (bedroomCleaned && teethBrushed && floorSweeped)
{
if (_bedroomCleaned && _teethBrushed && _floorSwept)
QueueMessage("I think I did everything... I think I can leave for school now");
}
}
// mark : u can track whether they want to do their tasks, some people may be unmoticvated to
// do the tasks in game, then we can ask them irl why they didnt do the task
// Tracks if bedroom is cleaned or not
// mark: u can track whether they want to do their tasks, some people may be unmotivated to
// do the tasks in game, then we can ask them irl why they didn't do the task
// Tracks if the bedroom is cleaned or not
public void BedroomTaskComplete()
{
bedroomCleaned = true;
_bedroomCleaned = true;
AreTasksDone();
}
// Tracks if teeth is brushed or not
// Tracks if teeth are brushed or not
public void BrushTeethTaskComplete()
{
teethBrushed = true;
_teethBrushed = true;
AreTasksDone();
}
// Tracks if floor is sweeped or not
public void FloorSweepedTaskComplete()
// Tracks if the floor has been swept or not
public void FloorSweptTaskComplete()
{
floorSweeped = true;
_floorSwept = true;
AreTasksDone();
}
public void GoToSchoolTaskComplete()
{
goToSchool = true;
_goToSchool = true;
}
// Increments the current day by 1
public void IncrementDay()
{
if (hasIncrementedToday) return; // Prevents multiple increments
hasIncrementedToday = true;
currentDay++;
Debug.Log("Day incremented to: " + currentDay);
if (currentDay > 3) LoadCallingScene();
if (_hasIncrementedToday) return; // Prevents multiple increments
_hasIncrementedToday = true;
CurrentDay++;
Debug.Log("Day incremented to: " + CurrentDay);
if (CurrentDay > 3) LoadCallingScene();
}
void OnSceneLoaded(Scene scene, LoadSceneMode mode)
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
hasIncrementedToday = false; // Allows the day to be incremented again in the next transition
_hasIncrementedToday = false; // Allows the day to be incremented again in the next transition
}
// Loads the callingChoice scene when Day 3 is completed
private void LoadCallingScene()
{
Debug.Log("Loading Calling Scene: callingChoice");
SceneManager.LoadScene("CallingChoice");
Debug.LogError("not ready yet");
// FIXME: SceneManager.LoadScene("CallingChoice");
}
}