Browse Source

Renamed commandId to itemId #86

Other types of Flowchart objects should be able to have ids besides
commands (e.g Blocks)
master
chrisgregan 10 years ago
parent
commit
1a77429756
  1. 2
      Assets/Fungus/Flowchart/Editor/CommandEditor.cs
  2. 4
      Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs
  3. 2
      Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs
  4. 20
      Assets/Fungus/Flowchart/Editor/FountainExporter.cs
  5. 4
      Assets/Fungus/Flowchart/Editor/SequenceEditor.cs
  6. 4
      Assets/Fungus/Flowchart/Scripts/Command.cs
  7. 21
      Assets/Fungus/Flowchart/Scripts/Flowchart.cs

2
Assets/Fungus/Flowchart/Editor/CommandEditor.cs

@ -71,7 +71,7 @@ namespace Fungus
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
GUILayout.Label(new GUIContent("(" + t.commandId + ")")); GUILayout.Label(new GUIContent("(" + t.itemId + ")"));
GUILayout.Space(10); GUILayout.Space(10);

4
Assets/Fungus/Flowchart/Editor/CommandListAdaptor.cs

@ -94,7 +94,7 @@ namespace Fungus
} }
Command newCommand = Undo.AddComponent<Comment>(block.gameObject) as Command; Command newCommand = Undo.AddComponent<Comment>(block.gameObject) as Command;
newCommand.commandId = flowchart.NextCommandId(); newCommand.itemId = flowchart.NextItemId();
flowchart.ClearSelectedCommands(); flowchart.ClearSelectedCommands();
flowchart.AddSelectedCommand(newCommand); flowchart.AddSelectedCommand(newCommand);
@ -110,7 +110,7 @@ namespace Fungus
System.Type type = command.GetType(); System.Type type = command.GetType();
Command newCommand = Undo.AddComponent(parentBlock.gameObject, type) as Command; 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(); System.Reflection.FieldInfo[] fields = type.GetFields();
foreach (System.Reflection.FieldInfo field in fields) foreach (System.Reflection.FieldInfo field in fields)
{ {

2
Assets/Fungus/Flowchart/Editor/FlowchartWindow.cs

@ -689,7 +689,7 @@ namespace Fungus
{ {
field.SetValue(newCommand, field.GetValue(command)); field.SetValue(newCommand, field.GetValue(command));
} }
newCommand.commandId = flowchart.NextCommandId(); newCommand.itemId = flowchart.NextItemId();
newBlock.commandList.Add(newCommand); newBlock.commandList.Add(newCommand);
} }

20
Assets/Fungus/Flowchart/Editor/FountainExporter.cs

@ -77,7 +77,7 @@ namespace Fungus
exportText += say.character.nameText.ToUpper() + "\n"; exportText += say.character.nameText.ToUpper() + "\n";
} }
idText += "[[Say," + c.commandId + "]]\n"; idText += "[[Say," + c.itemId + "]]\n";
exportText += idText; exportText += idText;
@ -106,7 +106,7 @@ namespace Fungus
string idText = ""; string idText = "";
Menu menu = c as Menu; Menu menu = c as Menu;
idText += "[[Menu," + c.commandId + "]]\n"; idText += "[[Menu," + c.itemId + "]]\n";
exportText += idText + menu.text.Trim() + "\n\n"; exportText += idText + menu.text.Trim() + "\n\n";
} }
@ -114,7 +114,7 @@ namespace Fungus
{ {
string idText = ""; string idText = "";
Comment comment = c as Comment; Comment comment = c as Comment;
idText += "[[Comment," + c.commandId + "]]\n"; idText += "[[Comment," + c.itemId + "]]\n";
exportText += idText + comment.commentText.Trim() + "\n\n"; exportText += idText + comment.commentText.Trim() + "\n\n";
} }
@ -142,7 +142,7 @@ namespace Fungus
Dictionary<int, Command> commandDict = new Dictionary<int, Command>(); Dictionary<int, Command> commandDict = new Dictionary<int, Command>();
foreach (Command c in flowchart.gameObject.GetComponentsInChildren<Command>()) foreach (Command c in flowchart.gameObject.GetComponentsInChildren<Command>())
{ {
commandDict.Add (c.commandId, c); commandDict.Add (c.itemId, c);
} }
foreach (StringsParser.StringItem item in items) foreach (StringsParser.StringItem item in items)
@ -155,8 +155,8 @@ namespace Fungus
string stringType = item.parameters[0]; string stringType = item.parameters[0];
if (stringType == "Say") if (stringType == "Say")
{ {
int commandId = int.Parse(item.parameters[1]); int itemId = int.Parse(item.parameters[1]);
Say sayCommand = commandDict[commandId] as Say; Say sayCommand = commandDict[itemId] as Say;
if (sayCommand != null) if (sayCommand != null)
{ {
sayCommand.storyText = item.bodyText; sayCommand.storyText = item.bodyText;
@ -164,8 +164,8 @@ namespace Fungus
} }
else if (stringType == "Menu") else if (stringType == "Menu")
{ {
int commandId = int.Parse(item.parameters[1]); int itemId = int.Parse(item.parameters[1]);
Menu menuCommand = commandDict[commandId] as Menu; Menu menuCommand = commandDict[itemId] as Menu;
if (menuCommand != null) if (menuCommand != null)
{ {
menuCommand.text = item.bodyText; menuCommand.text = item.bodyText;
@ -173,8 +173,8 @@ namespace Fungus
} }
else if (stringType == "Comment") else if (stringType == "Comment")
{ {
int commandId = int.Parse(item.parameters[1]); int itemId = int.Parse(item.parameters[1]);
Comment commentCommand = commandDict[commandId] as Comment; Comment commentCommand = commandDict[itemId] as Comment;
if (commentCommand != null) if (commentCommand != null)
{ {
commentCommand.commentText = item.bodyText; commentCommand.commentText = item.bodyText;

4
Assets/Fungus/Flowchart/Editor/SequenceEditor.cs

@ -605,7 +605,7 @@ namespace Fungus
Command newCommand = Undo.AddComponent(block.gameObject, commandOperation.commandType) as Command; Command newCommand = Undo.AddComponent(block.gameObject, commandOperation.commandType) as Command;
block.GetFlowchart().AddSelectedCommand(newCommand); block.GetFlowchart().AddSelectedCommand(newCommand);
newCommand.parentBlock = block; newCommand.parentBlock = block;
newCommand.commandId = flowchart.NextCommandId(); newCommand.itemId = flowchart.NextItemId();
// Let command know it has just been added to the block // Let command know it has just been added to the block
newCommand.OnCommandAdded(block); newCommand.OnCommandAdded(block);
@ -813,7 +813,7 @@ namespace Fungus
Command pastedCommand = commands.Last<Command>(); Command pastedCommand = commands.Last<Command>();
if (pastedCommand != null) if (pastedCommand != null)
{ {
pastedCommand.commandId = flowchart.NextCommandId(); pastedCommand.itemId = flowchart.NextItemId();
flowchart.selectedBlock.commandList.Insert(pasteIndex++, pastedCommand); flowchart.selectedBlock.commandList.Insert(pasteIndex++, pastedCommand);
} }
} }

4
Assets/Fungus/Flowchart/Scripts/Command.cs

@ -1,4 +1,5 @@
using UnityEngine; using UnityEngine;
using UnityEngine.Serialization;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
@ -31,8 +32,9 @@ namespace Fungus
public class Command : MonoBehaviour public class Command : MonoBehaviour
{ {
[FormerlySerializedAs("commandId")]
[HideInInspector] [HideInInspector]
public int commandId = -1; // Invalid command id public int itemId = -1; // Invalid flowchart item id
[HideInInspector] [HideInInspector]
public string errorMessage = ""; public string errorMessage = "";

21
Assets/Fungus/Flowchart/Scripts/Flowchart.cs

@ -110,32 +110,33 @@ namespace Fungus
public bool saveSelection = true; public bool saveSelection = true;
/** /**
* Unique id to assign to the next created command. * Unique id to assign to the next created item.
* Increases monotonically every time a new command is added to the block. * Increases monotonically every time a new item is added to the Flowchart.
*/ */
[FormerlySerializedAs("nextCommandId")]
[SerializeField] [SerializeField]
protected int nextCommandId = 0; protected int nextItemId = 0;
/** /**
* Returns the next command id to assign to a new command. * Returns the next id to assign to a new flowchart item.
* Command ids increase monotically so they are guaranteed to * Item ids increase monotically so they are guaranteed to
* be unique within a Flowchart. * be unique within a Flowchart.
*/ */
public int NextCommandId() public int NextItemId()
{ {
return nextCommandId++; return nextItemId++;
} }
public virtual void OnEnable() 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 // This should only happen after loading a legacy Flowchart
Command[] commands = GetComponentsInChildren<Command>(); Command[] commands = GetComponentsInChildren<Command>();
foreach (Command command in commands) foreach (Command command in commands)
{ {
if (command.commandId == -1) if (command.itemId == -1)
{ {
command.commandId = NextCommandId(); command.itemId = NextItemId();
} }
} }
} }

Loading…
Cancel
Save