Browse Source

Moved ExecuteBlocks to SaveManager class. Save Point command can now optionally fire Save Point Loaded events.

master
Christopher 8 years ago
parent
commit
6c18c17bd9
  1. 8
      Assets/Fungus/Scripts/Commands/SavePoint.cs
  2. 47
      Assets/Fungus/Scripts/Components/SaveManager.cs
  3. 2
      Assets/Fungus/Scripts/Components/SaveMenu.cs
  4. 47
      Assets/Fungus/Scripts/Utils/SavePointData.cs

8
Assets/Fungus/Scripts/Commands/SavePoint.cs

@ -16,6 +16,9 @@ namespace Fungus
[Tooltip("A short description of this save point.")]
[SerializeField] protected StringData savePointDescription;
[Tooltip("Fire an event that will be handled by any Save Point Loaded event handler with matching key.")]
[SerializeField] protected bool fireEvent = true;
[Tooltip("Resume execution from this command after loading a save point.")]
[SerializeField] protected bool resumeFromHere = true;
@ -43,6 +46,11 @@ namespace Fungus
saveManager.AddSavePoint(savePointKey, savePointDescription.Value);
if (fireEvent)
{
SavePointLoaded.NotifyEventHandlers(savePointKey);
}
Continue();
}

47
Assets/Fungus/Scripts/Components/SaveManager.cs

@ -137,7 +137,52 @@ namespace Fungus
{
saveHistory.Clear();
}
/// <summary>
/// Starts Block execution based on a Save Point Key
/// The execution order is:
/// 1. Save Point Loaded event handlers with a matching key.
/// 2. First Save Point command (in any Block) with matching key. Execution starts at following command.
/// 3. Any label in any block with name matching the key. Execution starts at following command.
/// </summary>
public static void ExecuteBlocks(string savePointKey)
{
// Execute Save Point Loaded event handlers with matching key.
SavePointLoaded.NotifyEventHandlers(savePointKey);
// Execute any block containing a SavePoint command matching the save key, with Resume From Here enabled
var savePoints = Object.FindObjectsOfType<SavePoint>();
for (int i = 0; i < savePoints.Length; i++)
{
var savePoint = savePoints[i];
if (savePoint.ResumeFromHere &&
string.Compare(savePoint.SavePointKey, savePointKey, true) == 0)
{
int index = savePoint.CommandIndex;
var block = savePoint.ParentBlock;
var flowchart = savePoint.GetFlowchart();
flowchart.ExecuteBlock(block, index + 1);
// Assume there's only one SavePoint using this key
break;
}
}
// Execute any block containing a Label matching the save key
var labels = Object.FindObjectsOfType<Label>();
for (int i = 0; i < labels.Length; i++)
{
var label = labels[i];
if (string.Compare(label.Key, savePointKey, true) == 0)
{
int index = label.CommandIndex;
var block = label.ParentBlock;
var flowchart = label.GetFlowchart();
flowchart.ExecuteBlock(block, index + 1);
}
}
}
#endregion
}
}

2
Assets/Fungus/Scripts/Components/SaveMenu.cs

@ -97,7 +97,7 @@ namespace Fungus
saveManager.AddSavePoint(NewGameSavePointKey, "");
// Start game execution
SavePointData.ExecuteBlocks(NewGameSavePointKey);
SaveManager.ExecuteBlocks(NewGameSavePointKey);
}
protected virtual void Update()

47
Assets/Fungus/Scripts/Utils/SavePointData.cs

@ -33,7 +33,7 @@ namespace Fungus
FlowchartData.Decode(flowchartData);
}
ExecuteBlocks(savePointData.savePointKey);
SaveManager.ExecuteBlocks(savePointData.savePointKey);
}
protected static SavePointData Create(string _savePointKey, string _savePointDescription, string _sceneName)
@ -100,51 +100,6 @@ namespace Fungus
SceneManager.LoadScene(tempSavePointData.SceneName);
}
/// <summary>
/// Starts Block execution based on a Save Point Key
/// The execution order is:
/// 1. Save Point Loaded event handlers with a matching key.
/// 2. First Save Point command (in any Block) with matching key. Execution starts at following command.
/// 3. Any label in any block with name matching the key. Execution starts at following command.
/// </summary>
public static void ExecuteBlocks(string savePointKey)
{
// Execute Save Point Loaded event handlers with matching key.
SavePointLoaded.NotifyEventHandlers(savePointKey);
// Execute any block containing a SavePoint command matching the save key, with Resume From Here enabled
var savePoints = Object.FindObjectsOfType<SavePoint>();
for (int i = 0; i < savePoints.Length; i++)
{
var savePoint = savePoints[i];
if (savePoint.ResumeFromHere &&
string.Compare(savePoint.SavePointKey, savePointKey, true) == 0)
{
int index = savePoint.CommandIndex;
var block = savePoint.ParentBlock;
var flowchart = savePoint.GetFlowchart();
flowchart.ExecuteBlock(block, index + 1);
// Assume there's only one SavePoint using this key
break;
}
}
// Execute any block containing a Label matching the save key
var labels = Object.FindObjectsOfType<Label>();
for (int i = 0; i < labels.Length; i++)
{
var label = labels[i];
if (string.Compare(label.Key, savePointKey, true) == 0)
{
int index = label.CommandIndex;
var block = label.ParentBlock;
var flowchart = label.GetFlowchart();
flowchart.ExecuteBlock(block, index + 1);
}
}
}
#endregion
}
}
Loading…
Cancel
Save