An easy to use Unity 3D library for creating illustrated Interactive Fiction games and more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
3.3 KiB

using UnityEngine;
using System.Collections.Generic;
using Fungus;
using UnityEngine.SceneManagement;
namespace Fungus
{
/// <summary>
/// The Save History is a list of previously created Save Points, sorted chronologically.
/// </summary>
[System.Serializable]
public class SaveHistory
{
/// <summary>
/// Version number of current save data format.
/// </summary>
protected const int SaveDataVersion = 1;
[SerializeField] protected int version = SaveDataVersion;
[SerializeField] protected List<string> savePoints = new List<string>();
[SerializeField] protected List<string> rewoundSavePoints = new List<string>();
#region Public methods
/// <summary>
/// Returns the number of Save Points in the Save History.
/// </summary>
public int NumSavePoints { get { return savePoints.Count; } }
/// <summary>
/// Returns the current number of rewound Save Points in the Save History.
/// </summary>
public int NumRewoundSavePoints { get { return rewoundSavePoints.Count; } }
/// <summary>
/// Creates a new Save Point using a key and description, and adds it to the Save History.
/// </summary>
public void AddSavePoint(string savePointKey, string savePointDescription)
{
string sceneName = SceneManager.GetActiveScene().name;
var savePointData = SavePointData.Encode(savePointKey, savePointDescription, sceneName);
savePoints.Add(savePointData);
}
/// <summary>
/// Rewinds to the previous Save Point in the Save History.
/// The latest Save Point is moved to a seperate list of rewound save points.
/// </summary>
public void Rewind()
{
if (savePoints.Count > 0)
{
rewoundSavePoints.Add(savePoints[savePoints.Count - 1]);
savePoints.RemoveAt(savePoints.Count - 1);
}
}
/// <summary>
/// Fast forwards to the next Save Point in the Save History.
/// The most recently rewound Save Point is moved back to the main list of save points.
/// </summary>
public void FastForward()
{
if (rewoundSavePoints.Count > 0)
{
savePoints.Add(rewoundSavePoints[rewoundSavePoints.Count - 1]);
rewoundSavePoints.RemoveAt(rewoundSavePoints.Count - 1);
}
}
/// <summary>
/// Loads the latest Save Point.
/// </summary>
public void LoadLatestSavePoint()
{
if (savePoints.Count > 0)
{
var savePointData = savePoints[savePoints.Count - 1];
SavePointData.Decode(savePointData);
}
}
/// <summary>
/// Clears all Save Points.
/// </summary>
public void Clear()
{
savePoints.Clear();
rewoundSavePoints.Clear();
}
/// <summary>
/// Clears rewound Save Points only. The main Save Point list is not changed.
/// </summary>
public void ClearRewoundSavePoints()
{
rewoundSavePoints.Clear();
}
#endregion
}
}