Browse Source

Command can now cache a list of referenced variables that are checked by the variablelistadapter for highlighting

- Flowchart can identify add variables found via the substitute regex
- Commands that use SubstituteVariables on their string data use the new caching method so they can highlight variables that will be used during substitution
master
desktop-maesty/steve 6 years ago
parent
commit
e73121ea5c
  1. 14
      Assets/Fungus/Scripts/Commands/Conversation.cs
  2. 13
      Assets/Fungus/Scripts/Commands/DebugLog.cs
  3. 13
      Assets/Fungus/Scripts/Commands/DeleteSaveKey.cs
  4. 12
      Assets/Fungus/Scripts/Commands/LoadVariable.cs
  5. 13
      Assets/Fungus/Scripts/Commands/Menu.cs
  6. 12
      Assets/Fungus/Scripts/Commands/SaveVariable.cs
  7. 14
      Assets/Fungus/Scripts/Commands/SetText.cs
  8. 13
      Assets/Fungus/Scripts/Commands/SetVariable.cs
  9. 34
      Assets/Fungus/Scripts/Components/Command.cs
  10. 17
      Assets/Fungus/Scripts/Components/Flowchart.cs
  11. 4
      Assets/Fungus/Scripts/Editor/VariableListAdaptor.cs

14
Assets/Fungus/Scripts/Commands/Conversation.cs

@ -64,5 +64,19 @@ namespace Fungus
}
#endregion
#region Editor caches
#if UNITY_EDITOR
protected override void RefreshVariableCache()
{
base.RefreshVariableCache();
var f = GetFlowchart();
f.DetermineSubstituteVariables(conversationText, referencedVariables);
}
#endif
#endregion Editor caches
}
}

13
Assets/Fungus/Scripts/Commands/DebugLog.cs

@ -67,5 +67,18 @@ namespace Fungus
}
#endregion
#region Editor caches
#if UNITY_EDITOR
protected override void RefreshVariableCache()
{
base.RefreshVariableCache();
var f = GetFlowchart();
f.DetermineSubstituteVariables(logMessage.Value, referencedVariables);
}
#endif
#endregion Editor caches
}
}

13
Assets/Fungus/Scripts/Commands/DeleteSaveKey.cs

@ -53,5 +53,18 @@ namespace Fungus
}
#endregion
#region Editor caches
#if UNITY_EDITOR
protected override void RefreshVariableCache()
{
base.RefreshVariableCache();
var f = GetFlowchart();
f.DetermineSubstituteVariables(key, referencedVariables);
}
#endif
#endregion Editor caches
}
}

12
Assets/Fungus/Scripts/Commands/LoadVariable.cs

@ -100,5 +100,17 @@ namespace Fungus
}
#endregion
#region Editor caches
#if UNITY_EDITOR
protected override void RefreshVariableCache()
{
base.RefreshVariableCache();
var f = GetFlowchart();
f.DetermineSubstituteVariables(key, referencedVariables);
}
#endif
#endregion Editor caches
}
}

13
Assets/Fungus/Scripts/Commands/Menu.cs

@ -121,5 +121,18 @@ namespace Fungus
}
#endregion
#region Editor caches
#if UNITY_EDITOR
protected override void RefreshVariableCache()
{
base.RefreshVariableCache();
var f = GetFlowchart();
f.DetermineSubstituteVariables(text, referencedVariables);
}
#endif
#endregion Editor caches
}
}

12
Assets/Fungus/Scripts/Commands/SaveVariable.cs

@ -104,5 +104,17 @@ namespace Fungus
}
#endregion
#region Editor caches
#if UNITY_EDITOR
protected override void RefreshVariableCache()
{
base.RefreshVariableCache();
var f = GetFlowchart();
f.DetermineSubstituteVariables(key, referencedVariables);
}
#endif
#endregion Editor caches
}
}

14
Assets/Fungus/Scripts/Commands/SetText.cs

@ -82,6 +82,20 @@ namespace Fungus
#endregion
#region Editor caches
#if UNITY_EDITOR
protected override void RefreshVariableCache()
{
base.RefreshVariableCache();
var f = GetFlowchart();
f.DetermineSubstituteVariables(text, referencedVariables);
}
#endif
#endregion Editor caches
#region ILocalizable implementation
public virtual string GetStandardText()

13
Assets/Fungus/Scripts/Commands/SetVariable.cs

@ -319,5 +319,18 @@ namespace Fungus
}
#endregion
#region Editor caches
#if UNITY_EDITOR
protected override void RefreshVariableCache()
{
base.RefreshVariableCache();
var f = GetFlowchart();
f.DetermineSubstituteVariables(stringData.Value, referencedVariables);
}
#endif
#endregion Editor caches
}
}

34
Assets/Fungus/Scripts/Components/Command.cs

@ -50,6 +50,30 @@ namespace Fungus
protected string errorMessage = "";
#region Editor caches
#if UNITY_EDITOR
//
protected List<Variable> referencedVariables = new List<Variable>();
//used by var list adapter to highlight variables
public bool IsVariableReferenced(Variable variable)
{
return referencedVariables.Contains(variable) || HasReference(variable);
}
/// <summary>
/// Called by OnValidate
///
/// Child classes to specialise to add variable references to referencedVariables, either directly or
/// via the use of Flowchart.DetermineSubstituteVariables
/// </summary>
protected virtual void RefreshVariableCache()
{
referencedVariables.Clear();
}
#endif
#endregion Editor caches
#region Public members
/// <summary>
@ -204,6 +228,16 @@ namespace Fungus
return false;
}
/// <summary>
/// Called by unity when script is loaded or its data changed by editor
/// </summary>
public virtual void OnValidate()
{
#if UNITY_EDITOR
RefreshVariableCache();
#endif
}
/// <summary>
/// Returns the summary text to display in the command inspector.
/// </summary>

17
Assets/Fungus/Scripts/Components/Flowchart.cs

@ -1264,6 +1264,23 @@ namespace Fungus
}
}
public virtual void DetermineSubstituteVariables(string str, List<Variable> vars)
{
Regex r = new Regex(Flowchart.SubstituteVariableRegexString);
// Match the regular expression pattern against a text string.
var results = r.Matches(str);
for (int i = 0; i < results.Count; i++)
{
var match = results[i];
var v = GetVariable(match.Value.Substring(2, match.Value.Length - 3));
if (v != null)
{
vars.Add(v);
}
}
}
#endregion
#region IStringSubstituter implementation

4
Assets/Fungus/Scripts/Editor/VariableListAdaptor.cs

@ -178,7 +178,7 @@ namespace Fungus.EditorUtils
{
if (Application.isPlaying && flowchart.SelectedBlock.IsExecuting())
{
highlight = flowchart.SelectedBlock.ActiveCommand.HasReference(variable);
highlight = flowchart.SelectedBlock.ActiveCommand.IsVariableReferenced(variable);
}
else if (!Application.isPlaying && flowchart.SelectedCommands.Count > 0)
{
@ -189,7 +189,7 @@ namespace Fungus.EditorUtils
continue;
}
if (selectedCommand.HasReference(variable))
if (selectedCommand.IsVariableReferenced(variable))
{
highlight = true;
break;

Loading…
Cancel
Save