Jamie Greunbaum 43bed62c7e - Added a briefing to the beginning of round 2, with intention to add more.
- Cleaned up a lot of code to help make development smoother in the future.
2025-06-17 04:50:05 -04:00

118 lines
2.8 KiB
C#

using UdonSharp;
using UnityEngine;
using VRC.SDK3.Data;
using VRC.SDK3.StringLoading;
using VRC.SDK3.UdonNetworkCalling;
using VRC.SDKBase;
using VRC.Udon;
using VRC.Udon.Common.Interfaces;
[UdonBehaviourSyncMode(BehaviourSyncMode.Manual)]
public class CaseManager : UdonSharpBehaviour
{
[SerializeField] protected VRCUrl _QuestionURL;
[SerializeField] private GameManagerRound1 _Round1Manager;
[SerializeField] private GameManagerRound2 _Round2Manager;
//[SerializeField] private GameManagerRound3 _Round3Manager;
[SerializeField] private HostCardManager _HostCard;
private DataDictionary _CaseFile;
void Start()
{
// Download our test question.
VRCStringDownloader.LoadUrl(_QuestionURL, (IUdonEventReceiver)this);
}
public override void OnStringLoadSuccess(IVRCStringDownload DownloadedString)
{
string ErrorString = "";
string JSONString = DownloadedString.Result;
if (VRCJson.TryDeserializeFromJson(JSONString, out DataToken JSONResult))
{
if (JSONResult.TokenType == TokenType.DataDictionary)
{
_CaseFile = JSONResult.DataDictionary;
if (_CaseFile.ContainsKey("Round 1") && _CaseFile.ContainsKey("Round 2") && _CaseFile.ContainsKey("Round 3"))
{
// Attempt to load Round 1 data
if (_CaseFile["Round 1"].TokenType == TokenType.DataList)
{
_Round1Manager.LoadQuestionData(_CaseFile["Round 1"]);
}
else
{
ErrorString = "Ensure the 'Round 1' entry is an array of dictionaries.";
}
// Attempt to load Round 2 data
if (_CaseFile["Round 2"].TokenType == TokenType.DataDictionary)
{
_Round2Manager.LoadQuestionData(_CaseFile["Round 2"]);
}
else
{
ErrorString = "Ensure the 'Round 2' entry is a dictionary with a location name and a list of landmarks.";
}
//// Attempt to load Round 3 data
//if (_CaseFile["Round 3"].TokenType == TokenType.DataList)
//{
// _Round3Manager.LoadQuestionData(_CaseFile["Round 3"].DataList);
//}
//else
//{
// ErrorString = "Ensure the 'Round 3' dictionary entry is whatever it's meant to be once it's done being decided.";
//}
ContinueToRound1();
}
else
{
ErrorString = "Could not find all the necessary keys for game rounds.";
}
}
else
{
ErrorString = "Ensure the first element is a dictionary";
}
}
if (ErrorString != "")
{
Debug.LogError("Malformed case file. " + ErrorString);
}
}
public string ContinueToRound1()
{
_HostCard.SetGameManager(_Round1Manager);
_Round1Manager.InitialiseGameMode();
return "";
}
public string ContinueToRound2()
{
_HostCard.SetGameManager(_Round2Manager);
_Round2Manager.InitialiseGameMode();
return "";
}
public string ContinueToRound3()
{
//_HostCard.SetGameManager(_Round3Manager);
//_Round3Manager.InitialiseGameMode();
return "";
}
}