Browse Source

validation for empty conditions and improved UI

master
vjs22334 5 years ago
parent
commit
1736ff1393
  1. 66
      Assets/Fungus/Scripts/Commands/VariableCondition.cs
  2. 13
      Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs
  3. 8
      Assets/FungusExamples/Conditions.meta
  4. 1436
      Assets/FungusExamples/Conditions/MultipleConditionsExample.unity
  5. 7
      Assets/FungusExamples/Conditions/MultipleConditionsExample.unity.meta

66
Assets/Fungus/Scripts/Commands/VariableCondition.cs

@ -27,6 +27,7 @@ namespace Fungus
}
// anyone with a better name for this can update it
public enum AnyOrAllConditions
{
@ -43,6 +44,26 @@ namespace Fungus
[SerializeField] protected List<conditionExpression> conditions = new List<conditionExpression>();
/// <summary>
/// Called when the script is loaded or a value is changed in the
/// inspector (Called in the editor only).
/// </summary>
public override void OnValidate()
{
base.OnValidate();
if (conditions == null)
{
conditions = new List<conditionExpression>();
}
if (conditions.Count == 0)
{
conditions.Add(new conditionExpression());
}
}
protected override bool EvaluateCondition()
{
if (conditions == null || conditions.Count == 0)
@ -61,7 +82,6 @@ namespace Fungus
continue;
}
condition.AnyVar.Compare(condition.CompareOperator, ref curResult);
Debug.Log("res : " + curResult.ToString());
resultAll &= curResult;
resultAny |= curResult;
}
@ -73,13 +93,15 @@ namespace Fungus
protected override bool HasNeededProperties()
{
if( conditions == null || conditions.Count == 0){
if (conditions == null || conditions.Count == 0)
{
return false;
}
foreach (conditionExpression condition in conditions)
{
if(condition.AnyVar == null || condition.AnyVar.variable == null){
if (condition.AnyVar == null || condition.AnyVar.variable == null)
{
return false;
}
@ -105,10 +127,12 @@ namespace Fungus
string summary = "";
string connector = "";
if(anyOrAllConditions == AnyOrAllConditions.AnyOneTrue){
if (anyOrAllConditions == AnyOrAllConditions.AnyOneTrue)
{
connector = " Or ";
}
else{
else
{
connector = " And ";
}
@ -118,15 +142,11 @@ namespace Fungus
summary += VariableUtil.GetCompareOperatorDescription(conditions[i].CompareOperator) + " ";
summary += conditions[i].AnyVar.GetDataDescription();
if(i<conditions.Count-1){
if (i < conditions.Count - 1)
{
summary += connector;
}
}
return summary;
}
@ -139,8 +159,10 @@ namespace Fungus
#region backwards compat
[HideInInspector]
[SerializeField] protected CompareOperator compareOperator;
[HideInInspector]
[SerializeField] protected AnyVariableAndDataPair anyVar;
@ -202,13 +224,9 @@ namespace Fungus
void ISerializationCallbackReceiver.OnAfterDeserialize()
{
if (variable != null)
{
{
anyVar.variable = variable;
}
if (variable.GetType() == typeof(BooleanVariable) && !booleanData.Equals(new BooleanData()))
{
@ -296,22 +314,22 @@ namespace Fungus
variable = null;
}
// just checking for anyVar != null fails here. is any var beig reintilaized somewhere?
// just checking for anyVar != null fails here. is any var being reintilaized somewhere?
if(anyVar != null && anyVar.variable != null){
if (anyVar != null && anyVar.variable != null)
{
conditionExpression c = new conditionExpression(compareOperator,anyVar);
if(!conditions.Contains(c)){
if (!conditions.Contains(c))
{
conditions.Add(c);
}
//added to list
anyVar = null;
}
//this is not nullabale?
//compareOperator = null;
if (anyVar != null && anyVar.variable == null)
{
anyVar = null;
}
}
#endregion
}
}

13
Assets/Fungus/Scripts/Editor/VariableConditionEditor.cs

@ -49,6 +49,7 @@ namespace Fungus.EditorUtils
conditions = serializedObject.FindProperty("conditions");
}
public override void DrawCommandGUI()
@ -62,6 +63,12 @@ namespace Fungus.EditorUtils
for (int i = 0; i < conditions.arraySize; i++)
{
GUILayout.Label("Condition "+(i+1).ToString(),EditorStyles.boldLabel);
//uncomment this for indentation
// EditorGUI.indentLevel++;
VariableCondition t = target as VariableCondition;
var flowchart = (Flowchart)t.GetFlowchart();
@ -103,11 +110,13 @@ namespace Fungus.EditorUtils
conditionCompare.enumValueIndex = selectedIndex;
}
//uncomment this for indentation
// EditorGUI.indentLevel--;
GUILayout.Space(10f);
}
}
serializedObject.ApplyModifiedProperties();
}
}

8
Assets/FungusExamples/Conditions.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ab073c9a6f825fe4b82cbe37c37addb0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1436
Assets/FungusExamples/Conditions/MultipleConditionsExample.unity

File diff suppressed because it is too large Load Diff

7
Assets/FungusExamples/Conditions/MultipleConditionsExample.unity.meta

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 0d9b345eec71ebc46bfb14d1a3b8af20
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save