From b650b80cf5383c58cd44eb020a7bb023b604876e Mon Sep 17 00:00:00 2001 From: Christopher Date: Tue, 10 Jan 2017 15:58:03 +0000 Subject: [PATCH] If Save Point Key is empty use the parent Block Name. If Save Point Description is empty use the current date and time. --- Assets/Fungus/Scripts/Commands/SavePoint.cs | 53 ++++++++---- .../FungusExamples/SaveGame/SaveExample.unity | 84 ++++++++----------- 2 files changed, 70 insertions(+), 67 deletions(-) diff --git a/Assets/Fungus/Scripts/Commands/SavePoint.cs b/Assets/Fungus/Scripts/Commands/SavePoint.cs index cd2f8162..c7793e65 100644 --- a/Assets/Fungus/Scripts/Commands/SavePoint.cs +++ b/Assets/Fungus/Scripts/Commands/SavePoint.cs @@ -7,14 +7,14 @@ namespace Fungus { [CommandInfo("Flow", "Save Point", - "Creates a save point which can be saved to persistant storage and loaded again later.")] + "Creates a Save Point and adds it to the Save History. The player can save the Save History to peristent storage and load it again later.")] public class SavePoint : Command { - [Tooltip("A string key which identifies this save point. Must be unique in this scene.")] - [SerializeField] protected string savePointKey; + [Tooltip("A string key which uniquely identifies this save point. If empty then the parent Block's name will be used.")] + [SerializeField] protected string savePointKey = ""; - [Tooltip("A short description of this save point.")] - [SerializeField] protected StringData savePointDescription; + [Tooltip("A short description of this save point. If empty then the current time and date will be used.")] + [SerializeField] protected string savePointDescription; [Tooltip("Fire an event that will be handled by any Save Point Loaded event handler with matching key.")] [SerializeField] protected bool fireEvent = true; @@ -25,9 +25,36 @@ namespace Fungus #region Public members /// - /// A string key which identifies this save point. Must be unique in this scene. + /// A string key which uniquely identifies this Save Point. + /// If the save point key is empty then the parent Block's name is returned. /// - public string SavePointKey { get { return savePointKey; } } + public string SavePointKey + { + get + { + if (string.IsNullOrEmpty(savePointKey)) + { + return ParentBlock.BlockName; + } + return savePointKey; + } + } + + /// + /// Gets the save point description. + /// If the description is empty then the current time and date will be returned. + /// + public string SavePointDescription + { + get + { + if (string.IsNullOrEmpty(savePointDescription)) + { + return System.DateTime.UtcNow.ToString("HH:mm dd MMMM, yyyy"); + } + return savePointDescription; + } + } /// /// Resume execution from this command after loading a save point. @@ -36,15 +63,9 @@ namespace Fungus public override void OnEnter() { - if (string.IsNullOrEmpty(savePointKey)) - { - Continue(); - return; - } - var saveManager = FungusManager.Instance.SaveManager; - saveManager.AddSavePoint(savePointKey, savePointDescription.Value); + saveManager.AddSavePoint(SavePointKey, SavePointDescription); if (fireEvent) { @@ -58,10 +79,10 @@ namespace Fungus { if (string.IsNullOrEmpty(savePointKey)) { - return "Error: Save Point Key not specified"; + return ""; } - return savePointKey + " : " + savePointDescription.Value; + return savePointKey; } public override Color GetButtonColor() diff --git a/Assets/FungusExamples/SaveGame/SaveExample.unity b/Assets/FungusExamples/SaveGame/SaveExample.unity index 8b4360ac..7d38358f 100644 --- a/Assets/FungusExamples/SaveGame/SaveExample.unity +++ b/Assets/FungusExamples/SaveGame/SaveExample.unity @@ -697,7 +697,7 @@ Prefab: - target: {fileID: 224000012150207008, guid: bd2b99773f3e0489aae9f9b5053ad360, type: 2} propertyPath: m_AnchoredPosition.y - value: 0 + value: -10.5 objectReference: {fileID: 0} - target: {fileID: 224000012150207008, guid: bd2b99773f3e0489aae9f9b5053ad360, type: 2} @@ -707,7 +707,7 @@ Prefab: - target: {fileID: 224000012150207008, guid: bd2b99773f3e0489aae9f9b5053ad360, type: 2} propertyPath: m_SizeDelta.y - value: 0 + value: 21 objectReference: {fileID: 0} - target: {fileID: 224000013898185038, guid: bd2b99773f3e0489aae9f9b5053ad360, type: 2} @@ -727,7 +727,7 @@ Prefab: - target: {fileID: 224000013898185038, guid: bd2b99773f3e0489aae9f9b5053ad360, type: 2} propertyPath: m_AnchoredPosition.y - value: 0 + value: -10.5 objectReference: {fileID: 0} - target: {fileID: 224000013898185038, guid: bd2b99773f3e0489aae9f9b5053ad360, type: 2} @@ -737,7 +737,7 @@ Prefab: - target: {fileID: 224000013898185038, guid: bd2b99773f3e0489aae9f9b5053ad360, type: 2} propertyPath: m_SizeDelta.y - value: 0 + value: 21 objectReference: {fileID: 0} - target: {fileID: 224000012687811630, guid: bd2b99773f3e0489aae9f9b5053ad360, type: 2} @@ -757,7 +757,7 @@ Prefab: - target: {fileID: 224000012687811630, guid: bd2b99773f3e0489aae9f9b5053ad360, type: 2} propertyPath: m_AnchoredPosition.y - value: 0 + value: -10.5 objectReference: {fileID: 0} - target: {fileID: 224000012687811630, guid: bd2b99773f3e0489aae9f9b5053ad360, type: 2} @@ -767,7 +767,7 @@ Prefab: - target: {fileID: 224000012687811630, guid: bd2b99773f3e0489aae9f9b5053ad360, type: 2} propertyPath: m_SizeDelta.y - value: 0 + value: 21 objectReference: {fileID: 0} - target: {fileID: 224000012590701094, guid: bd2b99773f3e0489aae9f9b5053ad360, type: 2} @@ -787,7 +787,7 @@ Prefab: - target: {fileID: 224000012590701094, guid: bd2b99773f3e0489aae9f9b5053ad360, type: 2} propertyPath: m_AnchoredPosition.y - value: 0 + value: -10.5 objectReference: {fileID: 0} - target: {fileID: 224000012590701094, guid: bd2b99773f3e0489aae9f9b5053ad360, type: 2} @@ -797,7 +797,7 @@ Prefab: - target: {fileID: 224000012590701094, guid: bd2b99773f3e0489aae9f9b5053ad360, type: 2} propertyPath: m_SizeDelta.y - value: 0 + value: 21 objectReference: {fileID: 0} - target: {fileID: 224000013149320576, guid: bd2b99773f3e0489aae9f9b5053ad360, type: 2} @@ -817,7 +817,7 @@ Prefab: - target: {fileID: 224000013149320576, guid: bd2b99773f3e0489aae9f9b5053ad360, type: 2} propertyPath: m_AnchoredPosition.y - value: 0 + value: -10.5 objectReference: {fileID: 0} - target: {fileID: 224000013149320576, guid: bd2b99773f3e0489aae9f9b5053ad360, type: 2} @@ -827,7 +827,7 @@ Prefab: - target: {fileID: 224000013149320576, guid: bd2b99773f3e0489aae9f9b5053ad360, type: 2} propertyPath: m_SizeDelta.y - value: 0 + value: 21 objectReference: {fileID: 0} m_RemovedComponents: [] m_ParentPrefab: {fileID: 100100000, guid: bd2b99773f3e0489aae9f9b5053ad360, type: 2} @@ -1293,7 +1293,6 @@ GameObject: - component: {fileID: 1889213480} - component: {fileID: 1889213479} - component: {fileID: 1889213475} - - component: {fileID: 1889213472} m_Layer: 0 m_Name: Flowchart m_TagString: Untagged @@ -1314,8 +1313,8 @@ MonoBehaviour: m_EditorClassIdentifier: nodeRect: serializedVersion: 2 - x: 64.99671 - y: 268.1121 + x: 76.99671 + y: 228.11209 width: 120 height: 40 tint: {r: 1, g: 1, b: 1, a: 1} @@ -1340,27 +1339,7 @@ MonoBehaviour: parentBlock: {fileID: 1889213470} savePointKeys: - new_game - - queens_chamber ---- !u!114 &1889213472 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1889213469} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 050fb9e6e72f442b3b883da8a965bdeb, type: 3} - m_Name: - m_EditorClassIdentifier: - itemId: 60 - indentLevel: 0 - targetFlowchart: {fileID: 0} - targetBlock: {fileID: 1889213481} - startLabel: - stringRef: {fileID: 0} - stringVal: - startIndex: 0 - callMode: 0 + - Queens Chamber --- !u!114 &1889213473 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1443,7 +1422,7 @@ MonoBehaviour: width: 1502.7736 height: 1138.5048 selectedBlocks: - - {fileID: 1889213496} + - {fileID: 1889213481} selectedCommands: [] variables: - {fileID: 1889213489} @@ -1484,9 +1463,9 @@ MonoBehaviour: m_EditorClassIdentifier: parentBlock: {fileID: 1889213481} savePointKeys: - - use_umbrella - - duck_down - - queen_fight + - Use Umbrella + - Duck Down + - The Queen --- !u!114 &1889213480 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1517,8 +1496,8 @@ MonoBehaviour: m_EditorClassIdentifier: nodeRect: serializedVersion: 2 - x: 63.28943 - y: 337.5421 + x: 81.28943 + y: 288.5421 width: 120 height: 40 tint: {r: 1, g: 1, b: 1, a: 1} @@ -1621,14 +1600,14 @@ MonoBehaviour: m_EditorClassIdentifier: nodeRect: serializedVersion: 2 - x: 232.40749 + x: 233.40749 y: 144.44666 - width: 140 + width: 143 height: 40 tint: {r: 1, g: 1, b: 1, a: 1} useCustomTint: 0 itemId: 20 - blockName: QueensChamber + blockName: Queens Chamber description: eventHandler: {fileID: 0} commandList: @@ -1638,7 +1617,6 @@ MonoBehaviour: - {fileID: 1889213495} - {fileID: 1889213494} - {fileID: 1889213491} - - {fileID: 1889213472} --- !u!114 &1889213487 MonoBehaviour: m_ObjectHideFlags: 2 @@ -1652,10 +1630,11 @@ MonoBehaviour: m_EditorClassIdentifier: itemId: 21 indentLevel: 0 - savePointKey: queens_chamber + savePointKey: savePointDescription: stringRef: {fileID: 0} stringVal: + fireEvent: 1 resumeFromHere: 1 --- !u!114 &1889213488 MonoBehaviour: @@ -1747,7 +1726,7 @@ MonoBehaviour: nodeRect: serializedVersion: 2 x: 394.38702 - y: 183.56548 + y: 184.56548 width: 120 height: 40 tint: {r: 1, g: 1, b: 1, a: 1} @@ -1836,7 +1815,7 @@ MonoBehaviour: m_EditorClassIdentifier: nodeRect: serializedVersion: 2 - x: 392.23532 + x: 391.23532 y: 97.65081 width: 121 height: 40 @@ -1943,7 +1922,7 @@ MonoBehaviour: m_EditorClassIdentifier: nodeRect: serializedVersion: 2 - x: 541.1676 + x: 542.1676 y: 144.44673 width: 120 height: 40 @@ -1973,10 +1952,11 @@ MonoBehaviour: m_EditorClassIdentifier: itemId: 35 indentLevel: 0 - savePointKey: duck_down + savePointKey: savePointDescription: stringRef: {fileID: 0} stringVal: + fireEvent: 1 resumeFromHere: 1 --- !u!114 &1889213502 MonoBehaviour: @@ -1991,10 +1971,11 @@ MonoBehaviour: m_EditorClassIdentifier: itemId: 34 indentLevel: 0 - savePointKey: use_umbrella + savePointKey: savePointDescription: stringRef: {fileID: 0} stringVal: + fireEvent: 1 resumeFromHere: 1 --- !u!114 &1889213503 MonoBehaviour: @@ -2257,10 +2238,11 @@ MonoBehaviour: m_EditorClassIdentifier: itemId: 43 indentLevel: 0 - savePointKey: queen_fight + savePointKey: savePointDescription: stringRef: {fileID: 0} stringVal: + fireEvent: 1 resumeFromHere: 1 --- !u!1 &2025975869 GameObject: