From e81236abdc150f709c7a33492be44aef44f8957e Mon Sep 17 00:00:00 2001 From: Christopher Date: Thu, 12 Jan 2017 11:25:09 +0000 Subject: [PATCH] Added KeyMode and DescriptionMode enums --- Assets/Fungus/Scripts/Commands/SavePoint.cs | 79 +++++++++++++++++---- 1 file changed, 64 insertions(+), 15 deletions(-) diff --git a/Assets/Fungus/Scripts/Commands/SavePoint.cs b/Assets/Fungus/Scripts/Commands/SavePoint.cs index c30ebbac..80363726 100644 --- a/Assets/Fungus/Scripts/Commands/SavePoint.cs +++ b/Assets/Fungus/Scripts/Commands/SavePoint.cs @@ -8,14 +8,42 @@ namespace Fungus { [CommandInfo("Flow", "Save Point", - "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.")] + "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 using the Save Menu.")] public class SavePoint : Command { - [Tooltip("A string key which uniquely identifies this save point. If you leave this empty then the parent Block's name will be used.")] - [SerializeField] protected string savePointKey = ""; + /// + /// Supported modes for specifying a Save Point Key. + /// + public enum KeyMode + { + /// Use the parent Block's name as the Save Point Key. N.B. If you change the Block name later it will break the save file! + UseBlockName, + /// Use a custom string for the key. This allows you to use multiple Save Points in the same block and save files will still work if the Block is renamed later. + Custom + } - [Tooltip("A short description of this save point. If you leave this empty then the current time and date will be used.")] - [SerializeField] protected string savePointDescription; + /// + /// Supported modes for specifying a Save Point Description. + /// + public enum DescriptionMode + { + /// Uses the current date and time as the save point description. + Timestamp, + /// Use a custom string for the save point description. + Custom + } + + [Tooltip("How the Save Point Key for this Save Point is defined.")] + [SerializeField] protected KeyMode keyMode = KeyMode.UseBlockName; + + [Tooltip("A string key which uniquely identifies this save point.")] + [SerializeField] protected string customKey = ""; + + [Tooltip("How the description for this Save Point is defined.")] + [SerializeField] protected DescriptionMode descriptionMode = DescriptionMode.Timestamp; + + [Tooltip("A short description of this save point.")] + [SerializeField] protected string customDescription; [Tooltip("Fire a Save Point Loaded event when this command executes.")] [SerializeField] protected bool fireEvent = true; @@ -39,34 +67,38 @@ namespace Fungus #region Public members /// - /// A string key which uniquely identifies this Save Point. - /// If the save point key is empty then the parent Block's name is returned. + /// Gets a string key which uniquely identifies this Save Point. /// public string SavePointKey { get { - if (string.IsNullOrEmpty(savePointKey)) + if (keyMode == KeyMode.UseBlockName) { return ParentBlock.BlockName; } - return savePointKey; + else + { + return customKey; + } } } /// /// 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)) + if (descriptionMode == DescriptionMode.Timestamp) { return System.DateTime.UtcNow.ToString("HH:mm dd MMMM, yyyy"); } - return savePointDescription; + else + { + return customDescription; + } } } @@ -91,12 +123,12 @@ namespace Fungus public override string GetSummary() { - if (string.IsNullOrEmpty(savePointKey)) + if (keyMode == KeyMode.UseBlockName) { - return ""; + return "key: "; } - return savePointKey; + return "key: " + customKey; } public override Color GetButtonColor() @@ -104,6 +136,23 @@ namespace Fungus return new Color32(235, 191, 217, 255); } + public override bool IsPropertyVisible(string propertyName) + { + if (propertyName == "customKey" && + keyMode != KeyMode.Custom) + { + return false; + } + + if (propertyName == "customDescription" && + descriptionMode != DescriptionMode.Custom) + { + return false; + } + + return true; + } + #endregion } } \ No newline at end of file