Add level selection system. Add levels upto jester
This commit is contained in:
@@ -189,6 +189,9 @@ public class DialogManager : Singleton<DialogManager>
|
||||
public void SubmitButtonPress()
|
||||
{
|
||||
AudioManager.Instance.PlaySound("Select");
|
||||
|
||||
var FullQuestionCopt = FullQuestion + "";
|
||||
|
||||
//formulate query string in format PERPSECTIVE%ITEM#PROPERTY
|
||||
//slightly wack way of doing it, hoping it is future proof
|
||||
while (FullQuestionPrefixes.Count > 0)
|
||||
@@ -228,19 +231,32 @@ public class DialogManager : Singleton<DialogManager>
|
||||
|
||||
Debug.Log(FullQuestion);
|
||||
|
||||
//now get a response from the guard being questioned
|
||||
var response = currentGuard.Answer(FullQuestion);
|
||||
|
||||
|
||||
|
||||
r = r.Replace("NOREC_", "");
|
||||
|
||||
r = Regex.Replace(
|
||||
r,
|
||||
@"^is\s+(?:\S+\s+)*guard\s+\(you\)",
|
||||
"are you",
|
||||
RegexOptions.IgnoreCase
|
||||
);
|
||||
|
||||
if (!r.Contains(":"))
|
||||
{
|
||||
r = Regex.Replace(
|
||||
r,
|
||||
@"is.*\(you\)",
|
||||
"are you",
|
||||
RegexOptions.IgnoreCase
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
var response = FullQuestionCopt;
|
||||
if (!FullQuestion.Contains("$"))
|
||||
{
|
||||
//now get a response from the guard being questioned
|
||||
response = currentGuard.Answer(FullQuestion).ToRandomString();
|
||||
|
||||
}
|
||||
|
||||
response = response.Replace("$", "");
|
||||
|
||||
string responsePrefix = "";
|
||||
if (FullQuestion.Contains("%"))
|
||||
{
|
||||
@@ -250,7 +266,7 @@ public class DialogManager : Singleton<DialogManager>
|
||||
SpeechManager.Instance.StartText(new[]
|
||||
{
|
||||
new KeyValuePair<string, string>(r, "PLAYER"),
|
||||
new KeyValuePair<string, string>(responsePrefix + response.ToRandomString(), "GUARD")
|
||||
new KeyValuePair<string, string>(responsePrefix + response, "GUARD")
|
||||
});
|
||||
|
||||
reset();
|
||||
|
||||
@@ -84,6 +84,7 @@ public class DoorManager : MonoBehaviour, IDescribable
|
||||
{
|
||||
return $"the {mod} door";
|
||||
} // add more modification here
|
||||
throw new NotImplementedException();
|
||||
|
||||
return "the door";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Utils;
|
||||
|
||||
public class GlobalStateManager : Singleton<GlobalStateManager>
|
||||
{
|
||||
public int MenuIntended = 0;
|
||||
public int LevelIntended;
|
||||
|
||||
|
||||
public int HighestLevel;
|
||||
|
||||
public List<TextAsset> levels;
|
||||
|
||||
//aaaaa theres nicer syntax for this i think
|
||||
protected override bool dontDestroyOnLoad()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
HighestLevel = PlayerPrefs.GetInt("HighestLevel", 0);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void SetLevelCompleted(int level)
|
||||
{
|
||||
if (level > HighestLevel)
|
||||
{
|
||||
PlayerPrefs.SetInt("HighestLevel", level);
|
||||
PlayerPrefs.Save();
|
||||
|
||||
LevelIntended = level + 1;
|
||||
//Reload game scene to start next level??
|
||||
SceneManager.LoadScene(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
//playing old level so load level select
|
||||
MenuIntended = 1;
|
||||
SceneManager.LoadScene(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void PlayNewestLevel()
|
||||
{
|
||||
LevelIntended = HighestLevel;
|
||||
//load game scene
|
||||
SceneManager.LoadScene(1);
|
||||
}
|
||||
|
||||
public void LoadSpecificLevel(int level)
|
||||
{
|
||||
LevelIntended = level;
|
||||
//load game scene
|
||||
SceneManager.LoadScene(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ae2faa8094378b90bfa2d47351f2b2c
|
||||
@@ -133,6 +133,14 @@ public class GuardManager : MonoBehaviour, IDescribable
|
||||
{
|
||||
return "the guard with the hat";
|
||||
}
|
||||
else if (mod == "#LEFTHORSE")
|
||||
{
|
||||
return "the left horse";
|
||||
}
|
||||
else if (mod == "#RIGHTHORSE")
|
||||
{
|
||||
return "the right horse";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "the plain guard";
|
||||
@@ -152,6 +160,16 @@ public class GuardManager : MonoBehaviour, IDescribable
|
||||
{
|
||||
answer = mod == "SHORT" ? QuestionAnswer.YES : QuestionAnswer.NO;
|
||||
}
|
||||
|
||||
if (property.StartsWith("truth"))
|
||||
{
|
||||
answer = type == "TRUTHER" ? QuestionAnswer.YES : QuestionAnswer.NO;
|
||||
}
|
||||
|
||||
if (property.StartsWith("horse"))
|
||||
{
|
||||
answer = QuestionAnswer.YES;
|
||||
}
|
||||
|
||||
if (property.EndsWith("!"))
|
||||
{
|
||||
|
||||
@@ -12,8 +12,6 @@ public class LevelLoader : Singleton<LevelLoader>
|
||||
[SerializeField]
|
||||
private List<GameEntry<GameObject>> GuardPrefabs;
|
||||
|
||||
[SerializeField]
|
||||
private List<TextAsset> levels;
|
||||
|
||||
[SerializeField]
|
||||
private float widthAvail = 50;
|
||||
@@ -23,10 +21,13 @@ public class LevelLoader : Singleton<LevelLoader>
|
||||
|
||||
public JObject SpeechTree { private set; get; }
|
||||
|
||||
public string GlobalModifier { private set; get; }
|
||||
|
||||
void Start()
|
||||
{
|
||||
var text = GlobalStateManager.Instance.levels[GlobalStateManager.Instance.LevelIntended].ToString();
|
||||
//load level data
|
||||
var data = JsonUtility.FromJson<LevelData>(levels[0].text);
|
||||
var data = JsonUtility.FromJson<LevelData>(text);
|
||||
|
||||
//shuffle for randomness
|
||||
data.doors.Shuffle();
|
||||
@@ -55,16 +56,35 @@ public class LevelLoader : Singleton<LevelLoader>
|
||||
|
||||
var manager = guardinstance.GetComponent<GuardManager>();
|
||||
manager.type = data.guards[i].action;
|
||||
manager.mod = data.guardsmods.GetRandomAndRemove();
|
||||
|
||||
if (data.guardsmods[0].StartsWith("#"))
|
||||
{
|
||||
manager.mod = data.guardsmods.GetTopAndRemove();
|
||||
}
|
||||
else
|
||||
{
|
||||
manager.mod = data.guardsmods.GetRandomAndRemove();
|
||||
}
|
||||
|
||||
Guards.Add(manager);
|
||||
}
|
||||
|
||||
|
||||
//dynamic dialog tree
|
||||
SpeechTree = JObject.Parse(levels[0].text)["dialog"] as JObject;
|
||||
SpeechTree = JObject.Parse(text)["dialog"] as JObject;
|
||||
|
||||
StatusManager.Instance.PopulatePanels();
|
||||
|
||||
if (data.introdialog != null)
|
||||
{
|
||||
SpeechManager.Instance.StartText(new[]
|
||||
{
|
||||
new KeyValuePair<string, string>(data.introdialog, "GUARD")
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
GlobalModifier = data.globalmod;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Utils;
|
||||
|
||||
public class MainMenuController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject InitMenu;
|
||||
[SerializeField] private GameObject LevelSelectMenu;
|
||||
|
||||
[SerializeField] private GameObject LevelItemPrefab;
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
if (GlobalStateManager.Instance.MenuIntended == 1)
|
||||
{
|
||||
InstantiateLevelButtons();
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OpenExternalLink(string url)
|
||||
{
|
||||
Application.OpenURL(url);
|
||||
}
|
||||
|
||||
public void Cheat(int highestLevel)
|
||||
{
|
||||
GlobalStateManager.Instance.HighestLevel = highestLevel;
|
||||
}
|
||||
|
||||
public void PlaySelect()
|
||||
{
|
||||
if (GlobalStateManager.Instance.HighestLevel >= GlobalStateManager.Instance.levels.Count)
|
||||
{
|
||||
//handle edge case of completing all the levels
|
||||
LevelSelect();
|
||||
return;
|
||||
}
|
||||
GlobalStateManager.Instance.PlayNewestLevel();
|
||||
}
|
||||
|
||||
public void LevelSelect()
|
||||
{
|
||||
InstantiateLevelButtons();
|
||||
}
|
||||
|
||||
public void BackSelect()
|
||||
{
|
||||
InitMenu.SetActive(true);
|
||||
LevelSelectMenu.SetActive(false);
|
||||
}
|
||||
|
||||
private void InstantiateLevelButtons()
|
||||
{
|
||||
InitMenu.SetActive(false);
|
||||
LevelSelectMenu.SetActive(true);
|
||||
|
||||
var parent = transform.FindChildRecursive("ADDLEVELSHERE");
|
||||
|
||||
foreach (Transform child in parent)
|
||||
{
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
|
||||
for (int i = 0; i < GlobalStateManager.Instance.levels.Count; i++)
|
||||
{
|
||||
int levelIndex = i;
|
||||
|
||||
GameObject levelButton = Instantiate(LevelItemPrefab, parent);
|
||||
|
||||
if (i <= GlobalStateManager.Instance.HighestLevel)
|
||||
{
|
||||
levelButton.GetComponentInChildren<Button>().onClick.AddListener(() => {
|
||||
|
||||
GlobalStateManager.Instance.LoadSpecificLevel(levelIndex);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
levelButton.GetComponent<Image>().color = Color.red;
|
||||
}
|
||||
levelButton.GetComponentInChildren<TextMeshProUGUI>().text = (i + 1).ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26b0d5e5fdf7d6f8096ff6f6801c65ba
|
||||
@@ -0,0 +1,20 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class PauseController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject pauseMenu;
|
||||
|
||||
public void TogglePause(bool on)
|
||||
{
|
||||
pauseMenu.SetActive(on);
|
||||
Time.timeScale = on ? 0 : 1;
|
||||
}
|
||||
|
||||
public void GoBackToMenu(int intended)
|
||||
{
|
||||
GlobalStateManager.Instance.MenuIntended = intended;
|
||||
|
||||
SceneManager.LoadScene(0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b13a7ab538f05c756a8915e5bb9002fa
|
||||
@@ -13,6 +13,15 @@ namespace DefaultNamespace
|
||||
{
|
||||
public static string ToRandomString(this QuestionAnswer answer)
|
||||
{
|
||||
if (LevelLoader.Instance.GlobalModifier == "HORSE")
|
||||
{
|
||||
return answer switch
|
||||
{
|
||||
QuestionAnswer.YES => "Neigh",
|
||||
QuestionAnswer.NO => "Heigh",
|
||||
QuestionAnswer.NO_YES => "Hmph"
|
||||
};
|
||||
}
|
||||
string[] options = answer switch
|
||||
{
|
||||
QuestionAnswer.YES => new[]
|
||||
|
||||
@@ -69,12 +69,24 @@ public class SpeechManager : Singleton<SpeechManager>
|
||||
|
||||
private void NextText()
|
||||
{
|
||||
var item = textBuffer.Dequeue();
|
||||
speaker = item.Value;
|
||||
if (LevelLoader.Instance.GlobalModifier == "HORSE" && speaker == "GUARD")
|
||||
{
|
||||
Debug.LogError("HORSE");
|
||||
mainText.text = item.Key;
|
||||
playerPanel.SetActive(false);
|
||||
otherPanel.SetActive(false);
|
||||
AudioManager.Instance.PlaySound("Horse");
|
||||
return;
|
||||
}
|
||||
|
||||
Status = "TALKING";
|
||||
AudioManager.Instance.PlaySound("Select");
|
||||
var item = textBuffer.Dequeue();
|
||||
|
||||
ccoroutine = StartCoroutine(TypeTextUncapped(item.Key));
|
||||
|
||||
speaker = item.Value;
|
||||
|
||||
|
||||
if (speaker == "PLAYER")
|
||||
{
|
||||
|
||||
@@ -9,6 +9,9 @@ namespace Utils
|
||||
public List<GuardData> guards;
|
||||
public List<string> guardsmods;
|
||||
public List<string> doorsmods;
|
||||
|
||||
public string introdialog;
|
||||
public string globalmod;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
@@ -23,16 +26,5 @@ namespace Utils
|
||||
{
|
||||
public string type;
|
||||
public string action;
|
||||
|
||||
|
||||
public string GetName()
|
||||
{
|
||||
return action;
|
||||
}
|
||||
|
||||
public string GetDescription()
|
||||
{
|
||||
return "Describe " + action;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,5 +27,17 @@ namespace Utils
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
public static T GetTopAndRemove<T>(this List<T> list)
|
||||
{
|
||||
if (list.Count == 0)
|
||||
return default;
|
||||
|
||||
T item = list[0];
|
||||
|
||||
list.RemoveAt(0);
|
||||
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,14 +8,24 @@ namespace Utils
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
if (Instance != null && Instance != this)
|
||||
if (dontDestroyOnLoad() && Instance != null && Instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
Instance = this as T;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
if (dontDestroyOnLoad())
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected virtual bool dontDestroyOnLoad()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user