Browse Source

Updated slot picking

master
Christopher 8 years ago
parent
commit
b230acf506
  1. 46
      Assets/Fungus/Scripts/Components/SaveManager.cs
  2. 26
      Assets/Fungus/Scripts/SavePoints/SavePointData.cs
  3. 12
      Assets/FungusExamples/SaveGame/SavePicker.cs
  4. 2
      ProjectSettings/ProjectVersion.txt

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

@ -16,22 +16,6 @@ namespace Fungus
return string.Format(SlotKeyFormat, slot);
}
protected virtual bool LoadNewGame(string key)
{
if (PlayerPrefs.HasKey(key) &&
PlayerPrefs.GetString(key) != "")
{
return false;
}
// Create a new save entry
PlayerPrefs.SetString(key, "");
SavePointLoaded.NotifyEventHandlers("new_game");
return true;
}
protected virtual void StoreJSONData(string key, string jsonData)
{
if (key.Length > 0)
@ -79,20 +63,42 @@ namespace Fungus
saveBuffer = "";
}
public virtual bool SlotExists(int slot)
{
var key = FormatSaveKey(slot);
if (PlayerPrefs.HasKey(key) &&
PlayerPrefs.GetString(key) != "")
{
return false;
}
return true;
}
public virtual void Load(int slot)
{
ActiveSlot = slot;
var key = FormatSaveKey(slot);
if (LoadNewGame(key))
var saveDataJSON = LoadJSONData(key);
if (saveDataJSON != "")
{
return;
SavePointData.Decode(saveDataJSON);
}
}
var saveDataJSON = LoadJSONData(key);
public virtual void LoadNewGame(int slot, string saveDescription)
{
var key = FormatSaveKey(slot);
SavePointData.Decode(saveDataJSON);
var saveDataJSON = SavePointData.EncodeNewGame(saveDescription, SceneManager.GetActiveScene().name);
// Create a new save entry
PlayerPrefs.SetString(key, saveDataJSON);
SavePointLoaded.NotifyEventHandlers("new_game");
}
public virtual void Delete(int slot)

26
Assets/Fungus/Scripts/SavePoints/SavePointData.cs

@ -58,6 +58,18 @@ namespace Fungus
}
}
protected static SavePointData Create(string _saveKey, string _description, string _sceneName)
{
var savePointData = new SavePointData();
savePointData.version = 1;
savePointData.saveKey = _saveKey;
savePointData.description = _description;
savePointData.sceneName = _sceneName;
return savePointData;
}
#region Public methods
public string SaveKey { get { return saveKey; } set { saveKey = value; } }
@ -65,14 +77,16 @@ namespace Fungus
public string SceneName { get { return sceneName; } set { sceneName = value; } }
public List<FlowchartData> FlowchartDatas { get { return flowchartDatas; } set { flowchartDatas = value; } }
public static string Encode(string _saveKey, string _description, string _sceneName)
public static string EncodeNewGame(string _description, string _sceneName)
{
var savePointData = new SavePointData();
var savePointData = Create("new_game", _description, _sceneName);
savePointData.version = 1;
savePointData.saveKey = _saveKey;
savePointData.description = _description;
savePointData.sceneName = _sceneName;
return JsonUtility.ToJson(savePointData, true);
}
public static string Encode(string _saveKey, string _description, string _sceneName)
{
var savePointData = Create(_saveKey, _description, _sceneName);
var gameSaver = GameObject.FindObjectOfType<GameSaver>();
if (gameSaver == null)

12
Assets/FungusExamples/SaveGame/SavePicker.cs

@ -5,12 +5,22 @@ namespace Fungus
{
public class SavePicker : MonoBehaviour
{
[SerializeField] protected string newGameDescription = "Playing";
#region Public methods
public virtual void Select(int slot)
{
var saveManager = FungusManager.Instance.SaveManager;
saveManager.Load(slot);
if (saveManager.SlotExists(slot))
{
saveManager.Load(slot);
}
else
{
saveManager.LoadNewGame(slot, newGameDescription);
}
}
public virtual void Delete(int slot)

2
ProjectSettings/ProjectVersion.txt

@ -1,2 +1,2 @@
m_EditorVersion: 5.4.2f2
m_EditorVersion: 5.4.3f1
m_StandardAssetsVersion: 0

Loading…
Cancel
Save