Skip to content

Commit

Permalink
Merge branch 'hotfix/841'
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehalliwell committed Jun 13, 2020
2 parents 3fcaee1 + 8971ab1 commit 870256b
Show file tree
Hide file tree
Showing 6 changed files with 1,280 additions and 2 deletions.
14 changes: 14 additions & 0 deletions Assets/Fungus/Scripts/Commands/SetVariable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ public override Color GetButtonColor()

#endregion



#region Editor caches
#if UNITY_EDITOR
protected override void RefreshVariableCache()
{
base.RefreshVariableCache();

if(anyVar != null)
anyVar.RefreshVariableCacheHelper(GetFlowchart(), ref referencedVariables);
}
#endif
#endregion Editor caches

#region backwards compat


Expand Down
18 changes: 18 additions & 0 deletions Assets/Fungus/Scripts/Commands/VariableCondition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,24 @@ public override bool HasReference(Variable variable)
}



#region Editor caches
#if UNITY_EDITOR
protected override void RefreshVariableCache()
{
base.RefreshVariableCache();

if (conditions != null)
{
foreach (var item in conditions)
{
item.AnyVar.RefreshVariableCacheHelper(GetFlowchart(), ref referencedVariables);
}
}
}
#endif
#endregion Editor caches

#region backwards compat

[HideInInspector]
Expand Down
6 changes: 6 additions & 0 deletions Assets/Fungus/Scripts/Components/Variable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ public abstract class Variable : MonoBehaviour
/// Not recommended for direct use, primarily intended for use in editor code.
/// </summary>
public abstract object GetValue();

//we are required to be on a flowchart so we provide this as a helper
public virtual Flowchart GetFlowchart()
{
return GetComponent<Flowchart>();
}
#endregion
}

Expand Down
29 changes: 27 additions & 2 deletions Assets/Fungus/Scripts/Utils/AllVariableTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public enum VariableAny
///
/// New types created need to be added to the list below and also to AllVariableTypes and
/// AnyVaraibleAndDataPair
///
/// Note; when using this in a command ensure that RefreshVariableCache is also handled for
/// string var substitution.
/// </summary>
[System.Serializable]
public partial struct AnyVariableData
Expand Down Expand Up @@ -121,6 +124,9 @@ public bool HasReference(Variable var)
///
/// New types created need to be added to the list below and also to AllVariableTypes and
/// AnyVariableData
///
/// Note to ensure use of RefreshVariableCacheHelper in commands, see SetVariable for
/// example.
/// </summary>
[System.Serializable]
public class AnyVariableAndDataPair
Expand Down Expand Up @@ -243,9 +249,17 @@ public TypeActions(string dataPropName,
(anyVar, setOperator) => anyVar.variable.Apply(setOperator, anyVar.data.spriteData.Value)) },
{ typeof(StringVariable),
new TypeActions( "stringData",
(anyVar, compareOperator) => {return anyVar.variable.Evaluate(compareOperator, anyVar.data.stringData.Value); },
(anyVar, compareOperator) =>
{
var subbedRHS = anyVar.variable.GetFlowchart().SubstituteVariables(anyVar.data.stringData.Value);
return anyVar.variable.Evaluate(compareOperator, subbedRHS);
},
(anyVar) => anyVar.data.stringData.GetDescription(),
(anyVar, setOperator) => anyVar.variable.Apply(setOperator, anyVar.data.stringData.Value)) },
(anyVar, setOperator) =>
{
var subbedRHS = anyVar.variable.GetFlowchart().SubstituteVariables(anyVar.data.stringData.Value);
anyVar.variable.Apply(setOperator, subbedRHS);
})},
{ typeof(TextureVariable),
new TypeActions( "textureData",
(anyVar, compareOperator) => {return anyVar.variable.Evaluate(compareOperator, anyVar.data.textureData.Value); },
Expand Down Expand Up @@ -278,6 +292,17 @@ public bool HasReference(Variable variable)
return variable == this.variable || data.HasReference(variable);
}

#if UNITY_EDITOR
public void RefreshVariableCacheHelper(Flowchart f, ref List<Variable> referencedVariables)
{
if (variable is StringVariable asStringVar && asStringVar != null && !string.IsNullOrEmpty(asStringVar.Value))
f.DetermineSubstituteVariables(asStringVar.Value, referencedVariables);

if (!string.IsNullOrEmpty(data.stringData.Value))
f.DetermineSubstituteVariables(data.stringData.Value, referencedVariables);
}
#endif

public string GetDataDescription()
{
TypeActions ta = null;
Expand Down
Loading

0 comments on commit 870256b

Please sign in to comment.