OctoCore 0.0.1
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
using UnityEngine;
|
||||
using OctoCore.Save.Data;
|
||||
|
||||
namespace OctoCore.Dialogue
|
||||
{
|
||||
/// <summary>
|
||||
/// Condition for dialogue choices.
|
||||
/// Supports OctoDataBool, OctoDataInt, and OctoDataFloat.
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public class OctoDialogueCondition
|
||||
{
|
||||
/// <summary>
|
||||
/// Source data to evaluate (OctoDataBool, OctoDataInt, or OctoDataFloat).
|
||||
/// </summary>
|
||||
[Tooltip("Source data to evaluate")]
|
||||
public OctoData Source;
|
||||
|
||||
/// <summary>
|
||||
/// Operation to perform.
|
||||
/// </summary>
|
||||
[Tooltip("Operation to perform")]
|
||||
public OctoDialogueOperation Operation = OctoDialogueOperation.Equal;
|
||||
|
||||
/// <summary>
|
||||
/// Value to compare against.
|
||||
/// For bool: 0 = false, 1 = true
|
||||
/// For int/float: direct comparison
|
||||
/// </summary>
|
||||
[Tooltip("Value to compare against (bool: 0=false, 1=true)")]
|
||||
public float Value;
|
||||
|
||||
/// <summary>
|
||||
/// Evaluate if the condition is met.
|
||||
/// </summary>
|
||||
public bool Evaluate()
|
||||
{
|
||||
if (Source == null)
|
||||
return true; // No condition = always true
|
||||
|
||||
float sourceValue = GetSourceValue();
|
||||
|
||||
switch (Operation)
|
||||
{
|
||||
case OctoDialogueOperation.Equal:
|
||||
return Mathf.Approximately(sourceValue, Value);
|
||||
|
||||
case OctoDialogueOperation.NotEqual:
|
||||
return !Mathf.Approximately(sourceValue, Value);
|
||||
|
||||
case OctoDialogueOperation.GreaterThan:
|
||||
return sourceValue > Value;
|
||||
|
||||
case OctoDialogueOperation.GreaterOrEqual:
|
||||
return sourceValue >= Value;
|
||||
|
||||
case OctoDialogueOperation.LessThan:
|
||||
return sourceValue < Value;
|
||||
|
||||
case OctoDialogueOperation.LessOrEqual:
|
||||
return sourceValue <= Value;
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private float GetSourceValue()
|
||||
{
|
||||
if (!OctoCore.Instance)
|
||||
return 0f;
|
||||
|
||||
if (Source is OctoDataBool dataBool)
|
||||
{
|
||||
return OctoCore.Instance.Save.Get(dataBool) ? 1f : 0f;
|
||||
}
|
||||
else if (Source is OctoDataInt dataInt)
|
||||
{
|
||||
return OctoCore.Instance.Save.Get(dataInt);
|
||||
}
|
||||
else if (Source is OctoDataFloat dataFloat)
|
||||
{
|
||||
return OctoCore.Instance.Save.Get(dataFloat);
|
||||
}
|
||||
|
||||
Debug.LogWarning("[OctoDialogueCondition] Unsupported data type: " + Source.GetType().Name);
|
||||
return 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user