From 7fa82ce8ec11096d477f15999180eb0c69a2b936 Mon Sep 17 00:00:00 2001 From: WillJeynes Date: Mon, 24 Aug 2026 17:15:52 +0100 Subject: [PATCH] stop silly recursion. Implement init vers of question answering --- Assets/LevelData/old_classic.json | 8 +-- Assets/Scripts/DialogManager.cs | 72 ++++++++++++++++--- Assets/Scripts/DoorManager.cs | 28 ++++++++ Assets/Scripts/GuardManager.cs | 68 ++++++++++++++++++ Assets/Scripts/QuestionAnswer.cs | 9 +++ Assets/Scripts/QuestionAnswer.cs.meta | 3 + Assets/Scripts/Utils/StringExtensions.cs | 15 ++++ Assets/Scripts/Utils/StringExtensions.cs.meta | 3 + 8 files changed, 193 insertions(+), 13 deletions(-) create mode 100644 Assets/Scripts/QuestionAnswer.cs create mode 100644 Assets/Scripts/QuestionAnswer.cs.meta create mode 100644 Assets/Scripts/Utils/StringExtensions.cs create mode 100644 Assets/Scripts/Utils/StringExtensions.cs.meta diff --git a/Assets/LevelData/old_classic.json b/Assets/LevelData/old_classic.json index 1e64c44..f3f6870 100644 --- a/Assets/LevelData/old_classic.json +++ b/Assets/LevelData/old_classic.json @@ -26,14 +26,14 @@ "dialog": { "is": { "DOORS": { - "safe": "SDOOR#safe", - "unsafe": "SDOOR#safe!" + "safe": "DS#safe", + "unsafe": "DS#safe!" } }, - "what would": { + "NOREC_what would": { "GUARDS": { "answer to:": { - "QUESTION": "SGUARD#ask" + "QUESTION": "GS%" } } } diff --git a/Assets/Scripts/DialogManager.cs b/Assets/Scripts/DialogManager.cs index 0999698..4601ccd 100644 --- a/Assets/Scripts/DialogManager.cs +++ b/Assets/Scripts/DialogManager.cs @@ -10,7 +10,7 @@ using Utils; public class DialogManager : Singleton { - private int currentGuard = 0; + private GuardManager currentGuard; private JObject dialogTree; @@ -24,7 +24,11 @@ public class DialogManager : Singleton private Transform QuestionOptionArea; private Transform QuestionInfillArea; + private Stack FullQuestionPrefixes = new Stack(); private string FullQuestion; + + private int recursiveDepth = 0; + public int MaxRecursiveDepth = 1; private Stack<(string key, JObject parent, GameObject infil)> questionStack = new(); @@ -42,13 +46,15 @@ public class DialogManager : Singleton } - [ContextMenu("Debug Something")] + //start from right click + [ContextMenu("Debug Questioning")] private void DebugSpeech() { - StartDialog(0); + StartDialog(LevelLoader.Instance.Guards[0]); } - public void StartDialog(int guardId) + //public interface to start interaction + public void StartDialog(GuardManager guardId) { dialogTree = LevelLoader.Instance.SpeechTree; @@ -90,21 +96,22 @@ public class DialogManager : Singleton } else if (kvp.Key == "QUESTION") { + recursiveDepth++; + FullQuestionPrefixes.Push((kvp.Value as JValue).ToString()); currentItem = dialogTree; PopulateQuestionOptions(); } - else + else if (!kvp.Key.StartsWith("NOREC_") || recursiveDepth < MaxRecursiveDepth) { PopulateSingleQuestionOption(kvp); } - } } private void PopulateSingleQuestionOption(KeyValuePair kvp) { var option = Instantiate(QuestionOptionPrefab, QuestionOptionArea); - option.GetComponentInChildren().text = kvp.Key; + option.GetComponentInChildren().text = kvp.Key.Replace("NOREC_", ""); option.GetComponent