From 1a774297569dcae9a9438b0eac173d371adf781e Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Tue, 31 Mar 2015 17:30:16 +0100 Subject: [PATCH] Renamed commandId to itemId #86 Other types of Flowchart objects should be able to have ids besides commands (e.g Blocks) --- .../Fungus/Flowchart/Editor/CommandEditor.cs | 2 +- .../Flowchart/Editor/CommandListAdaptor.cs | 4 ++-- .../Flowchart/Editor/FlowchartWindow.cs | 2 +- .../Flowchart/Editor/FountainExporter.cs | 20 +++++++++--------- .../Fungus/Flowchart/Editor/SequenceEditor.cs | 4 ++-- Assets/Fungus/Flowchart/Scripts/Command.cs | 4 +++- Assets/Fungus/Flowchart/Scripts/Flowchart.cs | 21 ++++++++++--------- 7 files changed, 30 insertions(+), 27 deletions(-) diff --git a/Assets/Fungus/Flowchart/Editor/CommandEditor.cs b/Assets/Fungus/Flowchart/Editor/CommandEditor.cs index 877e97b2..7a469c81 100644 --- a/Assets/Fungus/Flowchart/Editor/CommandEditor.cs +++ b/Assets/Fungus/Flowchart/Editor/CommandEditor.cs @@ -71,7 +71,7 @@ namespace Fungus GUILayout.FlexibleSpace(); - GUILayout.Label(new GUIContent("(" + t.commandId + ")")); + GUILayout.Label(new GUIContent("(" + t.itemId + ")")); GUILayout.Space(10); diff --git a/Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs b/Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs index 692db510..4c07dbc3 100644 --- a/Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs +++ b/Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs @@ -94,7 +94,7 @@ namespace Fungus } Command newCommand = Undo.AddComponent(block.gameObject) as Command; - newCommand.commandId = flowchart.NextCommandId(); + newCommand.itemId = flowchart.NextItemId(); flowchart.ClearSelectedCommands(); flowchart.AddSelectedCommand(newCommand); @@ -110,7 +110,7 @@ namespace Fungus System.Type type = command.GetType(); Command newCommand = Undo.AddComponent(parentBlock.gameObject, type) as Command; - newCommand.commandId = newCommand.GetFlowchart().NextCommandId(); + newCommand.itemId = newCommand.GetFlowchart().NextItemId(); System.Reflection.FieldInfo[] fields = type.GetFields(); foreach (System.Reflection.FieldInfo field in fields) { diff --git a/Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs b/Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs index f6e4670f..db0d0c44 100755 --- a/Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs +++ b/Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs @@ -689,7 +689,7 @@ namespace Fungus { field.SetValue(newCommand, field.GetValue(command)); } - newCommand.commandId = flowchart.NextCommandId(); + newCommand.itemId = flowchart.NextItemId(); newBlock.commandList.Add(newCommand); } diff --git a/Assets/Fungus/Flowchart/Editor/FountainExporter.cs b/Assets/Fungus/Flowchart/Editor/FountainExporter.cs index 7af75535..e45fd6b7 100644 --- a/Assets/Fungus/Flowchart/Editor/FountainExporter.cs +++ b/Assets/Fungus/Flowchart/Editor/FountainExporter.cs @@ -77,7 +77,7 @@ namespace Fungus exportText += say.character.nameText.ToUpper() + "\n"; } - idText += "[[Say," + c.commandId + "]]\n"; + idText += "[[Say," + c.itemId + "]]\n"; exportText += idText; @@ -106,7 +106,7 @@ namespace Fungus string idText = ""; Menu menu = c as Menu; - idText += "[[Menu," + c.commandId + "]]\n"; + idText += "[[Menu," + c.itemId + "]]\n"; exportText += idText + menu.text.Trim() + "\n\n"; } @@ -114,7 +114,7 @@ namespace Fungus { string idText = ""; Comment comment = c as Comment; - idText += "[[Comment," + c.commandId + "]]\n"; + idText += "[[Comment," + c.itemId + "]]\n"; exportText += idText + comment.commentText.Trim() + "\n\n"; } @@ -142,7 +142,7 @@ namespace Fungus Dictionary commandDict = new Dictionary(); foreach (Command c in flowchart.gameObject.GetComponentsInChildren()) { - commandDict.Add (c.commandId, c); + commandDict.Add (c.itemId, c); } foreach (StringsParser.StringItem item in items) @@ -155,8 +155,8 @@ namespace Fungus string stringType = item.parameters[0]; if (stringType == "Say") { - int commandId = int.Parse(item.parameters[1]); - Say sayCommand = commandDict[commandId] as Say; + int itemId = int.Parse(item.parameters[1]); + Say sayCommand = commandDict[itemId] as Say; if (sayCommand != null) { sayCommand.storyText = item.bodyText; @@ -164,8 +164,8 @@ namespace Fungus } else if (stringType == "Menu") { - int commandId = int.Parse(item.parameters[1]); - Menu menuCommand = commandDict[commandId] as Menu; + int itemId = int.Parse(item.parameters[1]); + Menu menuCommand = commandDict[itemId] as Menu; if (menuCommand != null) { menuCommand.text = item.bodyText; @@ -173,8 +173,8 @@ namespace Fungus } else if (stringType == "Comment") { - int commandId = int.Parse(item.parameters[1]); - Comment commentCommand = commandDict[commandId] as Comment; + int itemId = int.Parse(item.parameters[1]); + Comment commentCommand = commandDict[itemId] as Comment; if (commentCommand != null) { commentCommand.commentText = item.bodyText; diff --git a/Assets/Fungus/Flowchart/Editor/SequenceEditor.cs b/Assets/Fungus/Flowchart/Editor/SequenceEditor.cs index 0b5e0779..32d39002 100644 --- a/Assets/Fungus/Flowchart/Editor/SequenceEditor.cs +++ b/Assets/Fungus/Flowchart/Editor/SequenceEditor.cs @@ -605,7 +605,7 @@ namespace Fungus Command newCommand = Undo.AddComponent(block.gameObject, commandOperation.commandType) as Command; block.GetFlowchart().AddSelectedCommand(newCommand); newCommand.parentBlock = block; - newCommand.commandId = flowchart.NextCommandId(); + newCommand.itemId = flowchart.NextItemId(); // Let command know it has just been added to the block newCommand.OnCommandAdded(block); @@ -813,7 +813,7 @@ namespace Fungus Command pastedCommand = commands.Last(); if (pastedCommand != null) { - pastedCommand.commandId = flowchart.NextCommandId(); + pastedCommand.itemId = flowchart.NextItemId(); flowchart.selectedBlock.commandList.Insert(pasteIndex++, pastedCommand); } } diff --git a/Assets/Fungus/Flowchart/Scripts/Command.cs b/Assets/Fungus/Flowchart/Scripts/Command.cs index 65c7a0c3..13515e1a 100644 --- a/Assets/Fungus/Flowchart/Scripts/Command.cs +++ b/Assets/Fungus/Flowchart/Scripts/Command.cs @@ -1,4 +1,5 @@ using UnityEngine; +using UnityEngine.Serialization; using System; using System.Collections; using System.Collections.Generic; @@ -31,8 +32,9 @@ namespace Fungus public class Command : MonoBehaviour { + [FormerlySerializedAs("commandId")] [HideInInspector] - public int commandId = -1; // Invalid command id + public int itemId = -1; // Invalid flowchart item id [HideInInspector] public string errorMessage = ""; diff --git a/Assets/Fungus/Flowchart/Scripts/Flowchart.cs b/Assets/Fungus/Flowchart/Scripts/Flowchart.cs index 415f3303..e441484a 100644 --- a/Assets/Fungus/Flowchart/Scripts/Flowchart.cs +++ b/Assets/Fungus/Flowchart/Scripts/Flowchart.cs @@ -110,32 +110,33 @@ namespace Fungus public bool saveSelection = true; /** - * Unique id to assign to the next created command. - * Increases monotonically every time a new command is added to the block. + * Unique id to assign to the next created item. + * Increases monotonically every time a new item is added to the Flowchart. */ + [FormerlySerializedAs("nextCommandId")] [SerializeField] - protected int nextCommandId = 0; + protected int nextItemId = 0; /** - * Returns the next command id to assign to a new command. - * Command ids increase monotically so they are guaranteed to + * Returns the next id to assign to a new flowchart item. + * Item ids increase monotically so they are guaranteed to * be unique within a Flowchart. */ - public int NextCommandId() + public int NextItemId() { - return nextCommandId++; + return nextItemId++; } public virtual void OnEnable() { - // Assign a command id to any command that doesn't have one yet. + // Assign an item id to any command that doesn't have one yet. // This should only happen after loading a legacy Flowchart Command[] commands = GetComponentsInChildren(); foreach (Command command in commands) { - if (command.commandId == -1) + if (command.itemId == -1) { - command.commandId = NextCommandId(); + command.itemId = NextItemId(); } } }