|
|
|
@ -6,29 +6,85 @@ using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Fungus |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
[System.Serializable] |
|
|
|
|
public class conditionExpression |
|
|
|
|
{ |
|
|
|
|
[SerializeField] protected CompareOperator compareOperator; |
|
|
|
|
[SerializeField] protected AnyVariableAndDataPair anyVar; |
|
|
|
|
|
|
|
|
|
public virtual AnyVariableAndDataPair AnyVar { get { return anyVar; } } |
|
|
|
|
public virtual CompareOperator CompareOperator { get { return compareOperator; } } |
|
|
|
|
|
|
|
|
|
public conditionExpression(){} |
|
|
|
|
public conditionExpression(CompareOperator op, AnyVariableAndDataPair variablePair) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
compareOperator = op; |
|
|
|
|
anyVar = variablePair; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// anyone with a better name for this can update it |
|
|
|
|
public enum AnyOrAllConditions |
|
|
|
|
{ |
|
|
|
|
AnyOneTrue, |
|
|
|
|
AllTrue |
|
|
|
|
} |
|
|
|
|
public abstract class VariableCondition : Condition, ISerializationCallbackReceiver |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
[Tooltip("The type of comparison to be performed")] |
|
|
|
|
[SerializeField] protected CompareOperator compareOperator; |
|
|
|
|
|
|
|
|
|
[SerializeField] protected AnyVariableAndDataPair anyVar = new AnyVariableAndDataPair(); |
|
|
|
|
[SerializeField] protected AnyOrAllConditions anyOrAllConditions; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] protected List<conditionExpression> conditions = new List<conditionExpression>(); |
|
|
|
|
|
|
|
|
|
protected override bool EvaluateCondition() |
|
|
|
|
{ |
|
|
|
|
if (anyVar.variable == null) |
|
|
|
|
if (conditions == null || conditions.Count == 0) |
|
|
|
|
{ |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool condition = false; |
|
|
|
|
anyVar.Compare(compareOperator, ref condition); |
|
|
|
|
bool resultAny = false, resultAll = true; |
|
|
|
|
foreach (conditionExpression condition in conditions) |
|
|
|
|
{ |
|
|
|
|
bool curResult = false; |
|
|
|
|
if (condition.AnyVar == null) |
|
|
|
|
{ |
|
|
|
|
resultAll &= curResult; |
|
|
|
|
resultAny |= curResult; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
condition.AnyVar.Compare(condition.CompareOperator, ref curResult); |
|
|
|
|
Debug.Log("res : " + curResult.ToString()); |
|
|
|
|
resultAll &= curResult; |
|
|
|
|
resultAny |= curResult; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return condition; |
|
|
|
|
if (anyOrAllConditions == AnyOrAllConditions.AnyOneTrue) return resultAny; |
|
|
|
|
|
|
|
|
|
return resultAll; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected override bool HasNeededProperties() |
|
|
|
|
{ |
|
|
|
|
return (anyVar.variable != null); |
|
|
|
|
if( conditions == null || conditions.Count == 0){ |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foreach (conditionExpression condition in conditions) |
|
|
|
|
{ |
|
|
|
|
if(condition.AnyVar == null || condition.AnyVar.variable == null){ |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#region Public members |
|
|
|
@ -36,18 +92,40 @@ namespace Fungus
|
|
|
|
|
/// <summary> |
|
|
|
|
/// The type of comparison operation to be performed. |
|
|
|
|
/// </summary> |
|
|
|
|
public virtual CompareOperator CompareOperator { get { return compareOperator; } } |
|
|
|
|
public virtual CompareOperator CompareOperator { get { return conditions[0].CompareOperator; } } |
|
|
|
|
|
|
|
|
|
public virtual List<conditionExpression> Conditions { get { return conditions; } } |
|
|
|
|
|
|
|
|
|
public override string GetSummary() |
|
|
|
|
{ |
|
|
|
|
if (anyVar.variable == null) |
|
|
|
|
if (!this.HasNeededProperties()) |
|
|
|
|
{ |
|
|
|
|
return "Error: No variable selected"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
string summary = anyVar.variable.Key + " "; |
|
|
|
|
summary += VariableUtil.GetCompareOperatorDescription(compareOperator) + " "; |
|
|
|
|
summary += anyVar.GetDataDescription(); |
|
|
|
|
string summary = ""; |
|
|
|
|
string connector = ""; |
|
|
|
|
if(anyOrAllConditions == AnyOrAllConditions.AnyOneTrue){ |
|
|
|
|
connector = " Or "; |
|
|
|
|
} |
|
|
|
|
else{ |
|
|
|
|
connector = " And "; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for(int i = 0 ; i < conditions.Count; i++) |
|
|
|
|
{ |
|
|
|
|
summary += conditions[i].AnyVar.variable.Key + " "; |
|
|
|
|
summary += VariableUtil.GetCompareOperatorDescription(conditions[i].CompareOperator) + " "; |
|
|
|
|
summary += conditions[i].AnyVar.GetDataDescription(); |
|
|
|
|
|
|
|
|
|
if(i<conditions.Count-1){ |
|
|
|
|
summary += connector; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return summary; |
|
|
|
|
} |
|
|
|
@ -61,6 +139,10 @@ namespace Fungus
|
|
|
|
|
|
|
|
|
|
#region backwards compat |
|
|
|
|
|
|
|
|
|
[SerializeField] protected CompareOperator compareOperator; |
|
|
|
|
|
|
|
|
|
[SerializeField] protected AnyVariableAndDataPair anyVar; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Tooltip("Variable to use in expression")] |
|
|
|
|
[VariableProperty(AllVariableTypes.VariableAny.Any)] |
|
|
|
@ -120,11 +202,10 @@ namespace Fungus
|
|
|
|
|
|
|
|
|
|
void ISerializationCallbackReceiver.OnAfterDeserialize() |
|
|
|
|
{ |
|
|
|
|
if (variable == null) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( variable != null) |
|
|
|
|
{ |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
anyVar.variable = variable; |
|
|
|
|
} |
|
|
|
@ -214,6 +295,23 @@ namespace Fungus
|
|
|
|
|
//moved to new anyvar storage, clear legacy. |
|
|
|
|
variable = null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// just checking for anyVar != null fails here. is any var beig reintilaized somewhere? |
|
|
|
|
|
|
|
|
|
if(anyVar != null && anyVar.variable != null){ |
|
|
|
|
conditionExpression c = new conditionExpression(compareOperator,anyVar); |
|
|
|
|
if(!conditions.Contains(c)){ |
|
|
|
|
conditions.Add(c); |
|
|
|
|
} |
|
|
|
|
//added to list |
|
|
|
|
anyVar = null; |
|
|
|
|
|
|
|
|
|
//this is not nullabale? |
|
|
|
|
//compareOperator = null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|