game(scripts): update references

This commit is contained in:
Mark Joshwel 2025-02-14 22:25:01 +08:00
parent 587e6a1c6e
commit 8bc9aa4686
4 changed files with 52 additions and 49 deletions

View file

@ -36,7 +36,7 @@ public class BroomSweeping : MonoBehaviour
if (dirtSweepCount < dirtRequired || _taskCompleted) return; if (dirtSweepCount < dirtRequired || _taskCompleted) return;
_taskCompleted = true; _taskCompleted = true;
GameManager.Instance.FloorSweepedTaskComplete(); GameManager.Instance.FloorSweptTaskComplete();
storyPanelUI.SetActive(true); storyPanelUI.SetActive(true);
storyText.text = "I hope the house is clean enough now so I don't get scolded later..."; 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) if (GameManager.Instance != null)
{ {
var dayNumber = GameManager.Instance.currentDay; var dayNumber = GameManager.Instance.CurrentDay;
dayText.text = "Day " + dayNumber; dayText.text = "Day " + dayNumber;
} }

View file

@ -32,11 +32,11 @@ public class DayIncrementPlaygroundScript : MonoBehaviour
Debug.Log("initialisation wait..."); Debug.Log("initialisation wait...");
yield return new WaitForSeconds(3); 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 // get game manager and then increment the day
GameManager.Instance.IncrementDay(); 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 // change to the next scene
// ReSharper disable once Unity.LoadSceneDisabledSceneName // ReSharper disable once Unity.LoadSceneDisabledSceneName
@ -48,7 +48,7 @@ public class DayIncrementPlaygroundScript : MonoBehaviour
Debug.Log("initialisation wait..."); Debug.Log("initialisation wait...");
yield return new WaitForSeconds(3); 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; yield return 0;

View file

@ -1,5 +1,5 @@
/* /*
* Author: Reza and Wai Lam * Author: Reza, Wai Lam, Mark
* Date: 3/2/25 * Date: 3/2/25
* Description: To keep track of tasks, which level the player is at, and game mechanics * Description: To keep track of tasks, which level the player is at, and game mechanics
*/ */
@ -22,23 +22,23 @@ public class GameManager : MonoBehaviour
public TMP_Text storyText; public TMP_Text storyText;
// Queue for managing messages // Queue for managing messages
private readonly Queue<string> messageQueue = new(); private readonly Queue<string> _messageQueue = new();
private bool bedroomCleaned; private bool _bedroomCleaned;
private bool floorSweeped; private bool _floorSwept;
// Tracks GoToSchool task status // Tracks GoToSchool task status
private bool goToSchool; private bool _goToSchool;
private bool hasIncrementedToday; private bool _hasIncrementedToday;
private bool isMessageActive; private bool _isMessageActive;
private string lastSceneName; private string _lastSceneName;
private bool teethBrushed; private bool _teethBrushed;
// current day, publicly readable, privately settable // current day, publicly readable, privately settable
// for public access, setting is a no-op // for public access, setting is a no-op
public int currentDay { get; private set; } = 1; public int CurrentDay { get; private set; } = 1;
/// <summary> /// <summary>
/// Enforces singleton behavior; sets doesn't destroy on load and checks for multiple instances /// Enforces singleton behavior; sets doesn't destroy on load and checks for multiple instances
@ -62,7 +62,7 @@ public class GameManager : MonoBehaviour
} }
Debug.Log($"game manager ({GetInstanceID()}) is initialising itself!"); Debug.Log($"game manager ({GetInstanceID()}) is initialising itself!");
currentDay = 1; CurrentDay = 1;
// Try to find UI elements if not set // Try to find UI elements if not set
if (storyPanelUI == null) storyPanelUI = GameObject.Find("StoryPanelUI"); if (storyPanelUI == null) storyPanelUI = GameObject.Find("StoryPanelUI");
@ -76,9 +76,9 @@ public class GameManager : MonoBehaviour
private void Update() private void Update()
{ {
// Continuously check and display queued messages // Continuously check and display queued messages
if (!isMessageActive && messageQueue.Count > 0) if (!_isMessageActive && _messageQueue.Count > 0)
{ {
var nextMessage = messageQueue.Dequeue(); var nextMessage = _messageQueue.Dequeue();
StartCoroutine(DisplayMessage(nextMessage)); StartCoroutine(DisplayMessage(nextMessage));
} }
} }
@ -88,30 +88,31 @@ public class GameManager : MonoBehaviour
/// </summary> /// </summary>
public bool IsBedroomCleaned() public bool IsBedroomCleaned()
{ {
return bedroomCleaned; return _bedroomCleaned;
} }
public bool IsTeethBrushed() public bool IsTeethBrushed()
{ {
return teethBrushed; return _teethBrushed;
} }
public bool IsFloorSweeped() public bool IsFloorSwept()
{ {
return floorSweeped; return _floorSwept;
} }
public bool IsGoToSchool() public bool IsGoToSchool()
{ {
return goToSchool; return _goToSchool;
} }
/// <summary> /// <summary>
/// Queues a message to be displayed /// Queues a message to be displayed
/// </summary> /// </summary>
// ReSharper disable once MemberCanBePrivate.Global
public void QueueMessage(string message) public void QueueMessage(string message)
{ {
messageQueue.Enqueue(message); _messageQueue.Enqueue(message);
} }
/// <summary> /// <summary>
@ -119,80 +120,82 @@ public class GameManager : MonoBehaviour
/// </summary> /// </summary>
private IEnumerator DisplayMessage(string message) private IEnumerator DisplayMessage(string message)
{ {
isMessageActive = true; _isMessageActive = true;
storyPanelUI.SetActive(true); storyPanelUI.SetActive(true);
storyText.text = message; storyText.text = message;
yield return new WaitForSeconds(7f); // Wait for 7 seconds before hiding yield return new WaitForSeconds(7f); // Wait for 7 seconds before hiding
storyPanelUI.SetActive(false); 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() public void LogPlayerChoices()
{ {
Debug.Log("Player is trying to leave the house. Task Completion Status:"); Debug.Log("Player is trying to leave the house. Task Completion Status:");
Debug.Log("Bedroom Cleaned: " + bedroomCleaned); Debug.Log("Bedroom Cleaned: " + _bedroomCleaned);
Debug.Log("Teeth Brushed: " + teethBrushed); Debug.Log("Teeth Brushed: " + _teethBrushed);
Debug.Log("Floor Sweeped: " + floorSweeped); Debug.Log("Floor Swept: " + _floorSwept);
Debug.Log("Go To School: " + goToSchool); Debug.Log("Go To School: " + _goToSchool);
} }
// Checks if all tasks are done before player can go to school // Checks if all tasks are done before player can go to school
// ReSharper disable once MemberCanBePrivate.Global
public void AreTasksDone() 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"); 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 // 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 didnt do the task // do the tasks in game, then we can ask them irl why they didn't do the task
// Tracks if bedroom is cleaned or not // Tracks if the bedroom is cleaned or not
public void BedroomTaskComplete() public void BedroomTaskComplete()
{ {
bedroomCleaned = true; _bedroomCleaned = true;
AreTasksDone(); AreTasksDone();
} }
// Tracks if teeth is brushed or not // Tracks if teeth are brushed or not
public void BrushTeethTaskComplete() public void BrushTeethTaskComplete()
{ {
teethBrushed = true; _teethBrushed = true;
AreTasksDone(); AreTasksDone();
} }
// Tracks if floor is sweeped or not // Tracks if the floor has been swept or not
public void FloorSweepedTaskComplete() public void FloorSweptTaskComplete()
{ {
floorSweeped = true; _floorSwept = true;
AreTasksDone(); AreTasksDone();
} }
public void GoToSchoolTaskComplete() public void GoToSchoolTaskComplete()
{ {
goToSchool = true; _goToSchool = true;
} }
// Increments the current day by 1 // Increments the current day by 1
public void IncrementDay() public void IncrementDay()
{ {
if (hasIncrementedToday) return; // Prevents multiple increments if (_hasIncrementedToday) return; // Prevents multiple increments
hasIncrementedToday = true; _hasIncrementedToday = true;
currentDay++; CurrentDay++;
Debug.Log("Day incremented to: " + currentDay); Debug.Log("Day incremented to: " + CurrentDay);
if (currentDay > 3) LoadCallingScene(); if (CurrentDay > 3) LoadCallingScene();
} }
private 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 // Loads the callingChoice scene when Day 3 is completed
private void LoadCallingScene() private void LoadCallingScene()
{ {
Debug.Log("Loading Calling Scene: callingChoice"); Debug.Log("Loading Calling Scene: callingChoice");
SceneManager.LoadScene("CallingChoice"); Debug.LogError("not ready yet");
// FIXME: SceneManager.LoadScene("CallingChoice");
} }
} }