Browse Source

Flowcharts use a localisation id property when exporting strings #8

master
chrisgregan 10 years ago
parent
commit
f5e1c89936
  1. 3
      Assets/Fungus/Flowchart/Editor/FlowchartEditor.cs
  2. 6
      Assets/Fungus/Flowchart/Scripts/Flowchart.cs
  3. 14
      Assets/Fungus/Flowchart/Scripts/Language.cs

3
Assets/Fungus/Flowchart/Editor/FlowchartEditor.cs

@ -23,6 +23,7 @@ namespace Fungus
protected SerializedProperty hideComponentsProp; protected SerializedProperty hideComponentsProp;
protected SerializedProperty runSlowDurationProp; protected SerializedProperty runSlowDurationProp;
protected SerializedProperty saveSelectionProp; protected SerializedProperty saveSelectionProp;
protected SerializedProperty localizationIdProp;
protected SerializedProperty variablesProp; protected SerializedProperty variablesProp;
protected virtual void OnEnable() protected virtual void OnEnable()
@ -32,6 +33,7 @@ namespace Fungus
hideComponentsProp = serializedObject.FindProperty("hideComponents"); hideComponentsProp = serializedObject.FindProperty("hideComponents");
runSlowDurationProp = serializedObject.FindProperty("runSlowDuration"); runSlowDurationProp = serializedObject.FindProperty("runSlowDuration");
saveSelectionProp = serializedObject.FindProperty("saveSelection"); saveSelectionProp = serializedObject.FindProperty("saveSelection");
localizationIdProp = serializedObject.FindProperty("localizationId");
variablesProp = serializedObject.FindProperty("variables"); variablesProp = serializedObject.FindProperty("variables");
} }
@ -48,6 +50,7 @@ namespace Fungus
EditorGUILayout.PropertyField(hideComponentsProp); EditorGUILayout.PropertyField(hideComponentsProp);
EditorGUILayout.PropertyField(runSlowDurationProp); EditorGUILayout.PropertyField(runSlowDurationProp);
EditorGUILayout.PropertyField(saveSelectionProp); EditorGUILayout.PropertyField(saveSelectionProp);
EditorGUILayout.PropertyField(localizationIdProp);
GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();

6
Assets/Fungus/Flowchart/Scripts/Flowchart.cs

@ -109,6 +109,12 @@ namespace Fungus
[Tooltip("Saves the selected block and commands when saving the scene.")] [Tooltip("Saves the selected block and commands when saving the scene.")]
public bool saveSelection = true; public bool saveSelection = true;
/**
* Unique identifier for identifying this flowchart in localized string keys.
*/
[Tooltip("Unique identifier for this flowchart in localized string keys. An id must be provided for Language string export to work.")]
public string localizationId = "";
/** /**
* Unique id to assign to the next created item. * Unique id to assign to the next created item.
* Increases monotonically every time a new item is added to the Flowchart. * Increases monotonically every time a new item is added to the Flowchart.

14
Assets/Fungus/Flowchart/Scripts/Language.cs

@ -112,6 +112,12 @@ namespace Fungus
Flowchart[] flowcharts = GameObject.FindObjectsOfType<Flowchart>(); Flowchart[] flowcharts = GameObject.FindObjectsOfType<Flowchart>();
foreach (Flowchart flowchart in flowcharts) foreach (Flowchart flowchart in flowcharts)
{ {
// Have to set a unique localization id to export strings
if (flowchart.localizationId.Length == 0)
{
continue;
}
Block[] blocks = flowchart.GetComponentsInChildren<Block>(); Block[] blocks = flowchart.GetComponentsInChildren<Block>();
foreach (Block block in blocks) foreach (Block block in blocks)
{ {
@ -124,14 +130,14 @@ namespace Fungus
System.Type type = command.GetType(); System.Type type = command.GetType();
if (type == typeof(Say)) if (type == typeof(Say))
{ {
stringID = "SAY." + flowchart.name + "." + command.itemId; stringID = "SAY." + flowchart.localizationId + "." + command.itemId;
Say sayCommand = command as Say; Say sayCommand = command as Say;
standardText = sayCommand.storyText; standardText = sayCommand.storyText;
description = sayCommand.description; description = sayCommand.description;
} }
else if (type == typeof(Menu)) else if (type == typeof(Menu))
{ {
stringID = "MENU." + flowchart.name + "." + command.itemId; stringID = "MENU." + flowchart.localizationId + "." + command.itemId;
Menu menuCommand = command as Menu; Menu menuCommand = command as Menu;
standardText = menuCommand.text; standardText = menuCommand.text;
description = menuCommand.description; description = menuCommand.description;
@ -233,7 +239,7 @@ namespace Fungus
// Parse header row // Parse header row
string[] columnNames = csvTable[0]; string[] columnNames = csvTable[0];
if (columnNames.Length < 5) if (columnNames.Length < 4)
{ {
// No languages defined in CSV file // No languages defined in CSV file
return; return;
@ -259,7 +265,7 @@ namespace Fungus
Dictionary<string, Flowchart> flowchartDict = new Dictionary<string, Flowchart>(); Dictionary<string, Flowchart> flowchartDict = new Dictionary<string, Flowchart>();
foreach (Flowchart flowChart in GameObject.FindObjectsOfType<Flowchart>()) foreach (Flowchart flowChart in GameObject.FindObjectsOfType<Flowchart>())
{ {
flowchartDict[flowChart.name] = flowChart; flowchartDict[flowChart.localizationId] = flowChart;
} }
for (int i = 1; i < csvTable.Length; ++i) for (int i = 1; i < csvTable.Length; ++i)

Loading…
Cancel
Save