diff --git a/Assets/Data/Puzzles/Ass1.asset b/Assets/Data/Puzzles/Ass1.asset index b595f4f2..076b42b7 100644 --- a/Assets/Data/Puzzles/Ass1.asset +++ b/Assets/Data/Puzzles/Ass1.asset @@ -14,7 +14,7 @@ MonoBehaviour: m_EditorClassIdentifier: stepId: ass1 displayName: Pickup Ass 1 - description: + description: Some description of the quest icon: {fileID: 0} unlocks: - {fileID: 11400000, guid: 9de0c57af6191384e96e2ba7c04a3d0d, type: 2} diff --git a/Assets/Data/Puzzles/Ass2.asset b/Assets/Data/Puzzles/Ass2.asset index ffe8b867..c42813f8 100644 --- a/Assets/Data/Puzzles/Ass2.asset +++ b/Assets/Data/Puzzles/Ass2.asset @@ -14,7 +14,7 @@ MonoBehaviour: m_EditorClassIdentifier: stepId: ass2 displayName: Pickup Ass 2 - description: + description: Some other description of the quest icon: {fileID: 0} unlocks: - {fileID: 11400000, guid: 13b0c411066f85a41ba40c3bbbc281ed, type: 2} diff --git a/Assets/Data/Puzzles/Ass3.asset b/Assets/Data/Puzzles/Ass3.asset index c44e349f..f8be0bba 100644 --- a/Assets/Data/Puzzles/Ass3.asset +++ b/Assets/Data/Puzzles/Ass3.asset @@ -14,7 +14,7 @@ MonoBehaviour: m_EditorClassIdentifier: stepId: ass3 displayName: Pickup Ass 3 - description: + description: Designers were too lazy to write this one icon: {fileID: 0} unlocks: - {fileID: 11400000, guid: 9de0c57af6191384e96e2ba7c04a3d0d, type: 2} diff --git a/Assets/Data/Puzzles/Head.asset b/Assets/Data/Puzzles/Head.asset index 1351bcde..cb539884 100644 --- a/Assets/Data/Puzzles/Head.asset +++ b/Assets/Data/Puzzles/Head.asset @@ -14,10 +14,6 @@ MonoBehaviour: m_EditorClassIdentifier: stepId: head displayName: Pickup Head - description: + description: Skeet icon: {fileID: 0} - dependencies: - - {fileID: 11400000, guid: 0b13ff4f31443b74281b13e0eef865c2, type: 2} - - {fileID: 11400000, guid: a84cbe9804e13f74e857c55d90cc10d1, type: 2} - - {fileID: 11400000, guid: 13b0c411066f85a41ba40c3bbbc281ed, type: 2} unlocks: [] diff --git a/Assets/Editor/PuzzleChainEditorWindow.cs b/Assets/Editor/PuzzleChainEditorWindow.cs new file mode 100644 index 00000000..cfbe5467 --- /dev/null +++ b/Assets/Editor/PuzzleChainEditorWindow.cs @@ -0,0 +1,88 @@ +using UnityEditor; +using UnityEngine; +using System.Collections.Generic; + +public class PuzzleChainEditorWindow : EditorWindow +{ + private List puzzleSteps = new List(); + private Dictionary> dependencyGraph; + private Vector2 scrollPos; + private const int INDENT_SIZE = 24; + + [MenuItem("Tools/Puzzle Chain Editor")] + public static void ShowWindow() + { + var window = GetWindow("Puzzle Chain Editor"); + window.minSize = new Vector2(600, 400); + window.maxSize = new Vector2(1200, 800); + window.position = new Rect(100, 100, 700, 500); // Reasonable default size and position + } + + private void OnEnable() + { + LoadPuzzleSteps(); + ProcessPuzzleChains(); + } + + private void LoadPuzzleSteps() + { + puzzleSteps.Clear(); + string[] guids = AssetDatabase.FindAssets("t:PuzzleStepSO", new[] { "Assets/Data/Puzzles" }); + foreach (var guid in guids) + { + var path = AssetDatabase.GUIDToAssetPath(guid); + var step = AssetDatabase.LoadAssetAtPath(path); + if (step != null) + puzzleSteps.Add(step); + } + } + + private void ProcessPuzzleChains() + { + dependencyGraph = PuzzleGraphUtility.BuildDependencyGraph(puzzleSteps); + } + + private void OnGUI() + { + EditorGUILayout.LabelField("Puzzle Chain Visualization", EditorStyles.boldLabel); + if (puzzleSteps.Count == 0) + { + EditorGUILayout.HelpBox("No PuzzleStepSO assets found in Assets/Data/Puzzles.", MessageType.Warning); + return; + } + scrollPos = EditorGUILayout.BeginScrollView(scrollPos); + var initialSteps = PuzzleGraphUtility.FindInitialSteps(dependencyGraph); + foreach (var step in initialSteps) + { + EditorGUILayout.BeginVertical("box"); + EditorGUILayout.LabelField($"Step Path: {step.displayName} ({step.stepId})", EditorStyles.largeLabel); + GUILayout.Space(6); + DrawStepTree(step, 0); + EditorGUILayout.EndVertical(); + GUILayout.Space(12); // Space between step paths + } + EditorGUILayout.EndScrollView(); + } + + private void DrawStepTree(PuzzleStepSO step, int indent) + { + EditorGUILayout.BeginHorizontal(); + GUILayout.Space(indent * INDENT_SIZE); + EditorGUILayout.BeginVertical("box"); + EditorGUILayout.LabelField($"{step.displayName} ({step.stepId})", EditorStyles.boldLabel); + EditorGUILayout.LabelField(step.description ?? "", EditorStyles.wordWrappedLabel); + GUILayout.Space(4); + if (GUILayout.Button("Open in Inspector", GUILayout.Width(150))) + { + Selection.activeObject = step; // Opens in Inspector + EditorGUIUtility.PingObject(step); // Highlights in Project + } + EditorGUILayout.EndVertical(); + EditorGUILayout.EndHorizontal(); + GUILayout.Space(6); // Spacer between steps + foreach (var unlock in step.unlocks) + { + DrawStepTree(unlock, indent + 1); + } + } +} diff --git a/Assets/Editor/PuzzleChainEditorWindow.cs.meta b/Assets/Editor/PuzzleChainEditorWindow.cs.meta new file mode 100644 index 00000000..26053c53 --- /dev/null +++ b/Assets/Editor/PuzzleChainEditorWindow.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f7bfaa69d42e45adaa4a44dd143efc2f +timeCreated: 1756991142 \ No newline at end of file diff --git a/Assets/Scripts/Editor.meta b/Assets/Scripts/Editor.meta new file mode 100644 index 00000000..04deb595 --- /dev/null +++ b/Assets/Scripts/Editor.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 7c8178e4dbe545d691ce5f513299adcb +timeCreated: 1756991127 \ No newline at end of file diff --git a/Assets/Scripts/PuzzleGraphUtility.cs b/Assets/Scripts/PuzzleGraphUtility.cs new file mode 100644 index 00000000..f7811721 --- /dev/null +++ b/Assets/Scripts/PuzzleGraphUtility.cs @@ -0,0 +1,50 @@ +using System.Collections.Generic; +using UnityEngine; + +public static class PuzzleGraphUtility +{ + // Builds a dependency graph: for each step, lists the steps it depends on + public static Dictionary> BuildDependencyGraph(IEnumerable steps) + { + var graph = new Dictionary>(); + foreach (var step in steps) + { + graph[step] = new List(); + } + foreach (var step in steps) + { + foreach (var unlocked in step.unlocks) + { + if (!graph.ContainsKey(unlocked)) + graph[unlocked] = new List(); + graph[unlocked].Add(step); + } + } + return graph; + } + + // Finds initial steps (no dependencies) + public static List FindInitialSteps(Dictionary> graph) + { + var initial = new List(); + foreach (var kvp in graph) + { + if (kvp.Value.Count == 0) + initial.Add(kvp.Key); + } + return initial; + } + + // Finds all steps unlocked by a given step + public static List FindUnlocks(PuzzleStepSO step, IEnumerable allSteps) + { + var unlocks = new List(); + foreach (var s in allSteps) + { + if (s.unlocks.Contains(step)) + unlocks.Add(s); + } + return unlocks; + } +} + diff --git a/Assets/Scripts/PuzzleGraphUtility.cs.meta b/Assets/Scripts/PuzzleGraphUtility.cs.meta new file mode 100644 index 00000000..4a827697 --- /dev/null +++ b/Assets/Scripts/PuzzleGraphUtility.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9f484cf99777457a8bc38430a0d67416 +timeCreated: 1756991444 \ No newline at end of file diff --git a/Assets/Scripts/PuzzleManager.cs b/Assets/Scripts/PuzzleManager.cs index 2d183128..1bdba079 100644 --- a/Assets/Scripts/PuzzleManager.cs +++ b/Assets/Scripts/PuzzleManager.cs @@ -1,5 +1,6 @@ using UnityEngine; using System.Collections.Generic; +using System.Linq; public class PuzzleManager : MonoBehaviour { @@ -62,19 +63,12 @@ public class PuzzleManager : MonoBehaviour private void BuildRuntimeDependencies() { - runtimeDependencies.Clear(); - foreach (var step in stepBehaviours.Keys) + runtimeDependencies = PuzzleGraphUtility.BuildDependencyGraph(stepBehaviours.Keys); + foreach (var step in runtimeDependencies.Keys) { - runtimeDependencies[step] = new List(); - } - foreach (var step in stepBehaviours.Keys) - { - foreach (var unlocked in step.unlocks) + foreach (var dep in runtimeDependencies[step]) { - if (!runtimeDependencies.ContainsKey(unlocked)) - runtimeDependencies[unlocked] = new List(); - runtimeDependencies[unlocked].Add(step); - Debug.Log($"[Puzzles] Step {unlocked.stepId} depends on {step.stepId}"); + Debug.Log($"[Puzzles] Step {step.stepId} depends on {dep.stepId}"); } } Debug.Log($"[Puzzles] Runtime dependencies built. Total steps: {stepBehaviours.Count}"); @@ -82,13 +76,11 @@ public class PuzzleManager : MonoBehaviour private void UnlockInitialSteps() { - foreach (var step in stepBehaviours.Keys) + var initialSteps = PuzzleGraphUtility.FindInitialSteps(runtimeDependencies); + foreach (var step in initialSteps) { - if (runtimeDependencies[step].Count == 0) - { - Debug.Log($"[Puzzles] Initial step unlocked: {step.stepId}"); - UnlockStep(step); - } + Debug.Log($"[Puzzles] Initial step unlocked: {step.stepId}"); + UnlockStep(step); } }