From cb95ccc760a20c6a732a09cd3fc31f17c18111b6 Mon Sep 17 00:00:00 2001 From: Christopher Date: Tue, 15 Nov 2016 14:53:32 +0000 Subject: [PATCH] Refactored SavePointData to support multiple flowcharts --- Assets/Fungus/Scripts/Commands/SavePoint.cs | 2 +- .../Fungus/Scripts/Components/SaveHelper.cs | 9 ++ .../Fungus/Scripts/Components/SaveManager.cs | 89 ++----------------- .../Scripts/SavePoints/SavePointData.cs | 89 ++++++++++++++++++- 4 files changed, 102 insertions(+), 87 deletions(-) diff --git a/Assets/Fungus/Scripts/Commands/SavePoint.cs b/Assets/Fungus/Scripts/Commands/SavePoint.cs index ef2c355d..085a7684 100644 --- a/Assets/Fungus/Scripts/Commands/SavePoint.cs +++ b/Assets/Fungus/Scripts/Commands/SavePoint.cs @@ -24,7 +24,7 @@ namespace Fungus { var saveManager = FungusManager.Instance.SaveManager; - saveManager.PopulateSaveBuffer(GetFlowchart(), saveKey, description); + saveManager.PopulateSaveBuffer(saveKey, description); if (saveNow) { diff --git a/Assets/Fungus/Scripts/Components/SaveHelper.cs b/Assets/Fungus/Scripts/Components/SaveHelper.cs index 5a249684..324879a9 100644 --- a/Assets/Fungus/Scripts/Components/SaveHelper.cs +++ b/Assets/Fungus/Scripts/Components/SaveHelper.cs @@ -1,5 +1,6 @@ using UnityEngine; using System.Collections; +using System.Collections.Generic; using UnityEngine.SceneManagement; namespace Fungus @@ -8,6 +9,12 @@ namespace Fungus { [SerializeField] protected string startScene = ""; + [SerializeField] protected List flowcharts = new List(); + + #region Public methods + + public List Flowcharts { get { return flowcharts; } } + public virtual void Load(int slot) { var saveManager = FungusManager.Instance.SaveManager; @@ -30,5 +37,7 @@ namespace Fungus { SceneManager.LoadScene(sceneName); } + + #endregion } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Components/SaveManager.cs b/Assets/Fungus/Scripts/Components/SaveManager.cs index 3067afcb..11b4bf7b 100644 --- a/Assets/Fungus/Scripts/Components/SaveManager.cs +++ b/Assets/Fungus/Scripts/Components/SaveManager.cs @@ -9,30 +9,8 @@ namespace Fungus const string SlotKeyFormat = "slot{0}"; - // Make serialize data extensible (subclassing?) - // Save key, use save profile and variable substitution - // Store scene name, flowchart name and block name to execute after load - // Show link to Block to be executed - // Handle New Save Slot case: Scene to load? - // Save command stores data in SaveManager for writing later - // If SaveImmediately is selected then save it straight away (SaveGame command) - // If not selected, then Save when a Save button is pressed - // Select / Load button - set active slot (in playerprefs) and load the state - // Get list of saved games - // Delete Save Game - // Rename SaveFlowchart to SaveGame - protected string saveBuffer = ""; - protected static SaveManager instance; - - protected SavePointData tempSaveData; - - protected virtual void Awake() - { - instance = this; - } - protected virtual string FormatSaveKey(int slot) { return string.Format(SlotKeyFormat, slot); @@ -55,50 +33,6 @@ namespace Fungus return true; } - protected virtual string CreateSaveData(Flowchart flowchart, string saveKey, string description) - { - var saveData = new SavePointData(); - - // Store the scene, flowchart and block to execute on resume - saveData.SceneName = SceneManager.GetActiveScene().name; - saveData.SaveKey = saveKey; - saveData.Description = description; - - var flowchartData = FlowchartData.Encode(flowchart); - saveData.FlowchartData.Add(flowchartData); - - return JsonUtility.ToJson(saveData, true); - } - - protected virtual void RestoreSavedGame(SavePointData saveData) - { - var flowchartData = saveData.FlowchartData[0]; - - FlowchartData.Decode(flowchartData); - - // Fire any matching SavePointLoaded event handler with matching save key. - var eventHandlers = Object.FindObjectsOfType(); - for (int i = 0; i < eventHandlers.Length; i++) - { - var eventHandler = eventHandlers[i]; - eventHandler.OnSavePointLoaded(saveData.SaveKey); - } - - // Execute any block with a Label matching the save key - var labels = Object.FindObjectsOfType