From f7fe75fd16829d1944cc365998dfe8a84470928a Mon Sep 17 00:00:00 2001 From: Ash Blue Date: Tue, 16 Apr 2024 13:03:28 -0700 Subject: [PATCH] refactor(conditions): definition data is now exposed to implement custom runtime choice displays --- .../com.fluid.dialogue/Runtime/Conditions/ConditionRuntime.cs | 1 + Assets/com.fluid.dialogue/Runtime/Conditions/ICondition.cs | 2 ++ .../com.fluid.dialogue/Runtime/Nodes/ChoiceHub/NodeChoiceHub.cs | 1 + Assets/com.fluid.dialogue/Runtime/Nodes/INode.cs | 2 ++ Assets/com.fluid.dialogue/Runtime/Nodes/NodeBase.cs | 1 + 5 files changed, 7 insertions(+) diff --git a/Assets/com.fluid.dialogue/Runtime/Conditions/ConditionRuntime.cs b/Assets/com.fluid.dialogue/Runtime/Conditions/ConditionRuntime.cs index 5ca44cb..dacf013 100644 --- a/Assets/com.fluid.dialogue/Runtime/Conditions/ConditionRuntime.cs +++ b/Assets/com.fluid.dialogue/Runtime/Conditions/ConditionRuntime.cs @@ -13,6 +13,7 @@ public class ConditionRuntime : ICondition { private bool _initTriggered; public string UniqueId { get; } + public IConditionData Data => _data; public ConditionRuntime (IDialogueController dialogueController, string uniqueId, IConditionData data) { _data = data; diff --git a/Assets/com.fluid.dialogue/Runtime/Conditions/ICondition.cs b/Assets/com.fluid.dialogue/Runtime/Conditions/ICondition.cs index 23b8b27..30034b8 100644 --- a/Assets/com.fluid.dialogue/Runtime/Conditions/ICondition.cs +++ b/Assets/com.fluid.dialogue/Runtime/Conditions/ICondition.cs @@ -2,6 +2,8 @@ namespace CleverCrow.Fluid.Dialogues.Conditions { public interface ICondition : IUniqueId { + IConditionData Data { get; } + bool GetIsValid (INode parent); } } diff --git a/Assets/com.fluid.dialogue/Runtime/Nodes/ChoiceHub/NodeChoiceHub.cs b/Assets/com.fluid.dialogue/Runtime/Nodes/ChoiceHub/NodeChoiceHub.cs index d106a33..ddd1d69 100644 --- a/Assets/com.fluid.dialogue/Runtime/Nodes/ChoiceHub/NodeChoiceHub.cs +++ b/Assets/com.fluid.dialogue/Runtime/Nodes/ChoiceHub/NodeChoiceHub.cs @@ -12,6 +12,7 @@ public class NodeChoiceHub : INode { public string UniqueId { get; } public List EnterActions { get; } public List ExitActions { get; } + public IReadOnlyList Conditions => _conditions; public virtual bool IsValid => _conditions.Find(c => !c.GetIsValid(this)) == null; diff --git a/Assets/com.fluid.dialogue/Runtime/Nodes/INode.cs b/Assets/com.fluid.dialogue/Runtime/Nodes/INode.cs index 2974cf3..a0af434 100644 --- a/Assets/com.fluid.dialogue/Runtime/Nodes/INode.cs +++ b/Assets/com.fluid.dialogue/Runtime/Nodes/INode.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using CleverCrow.Fluid.Dialogues.Actions; using CleverCrow.Fluid.Dialogues.Choices; +using CleverCrow.Fluid.Dialogues.Conditions; namespace CleverCrow.Fluid.Dialogues.Nodes { public interface INode : IUniqueId { @@ -8,6 +9,7 @@ public interface INode : IUniqueId { List ExitActions { get; } bool IsValid { get; } List HubChoices { get; } + IReadOnlyList Conditions { get; } /// /// Returns the first valid child node diff --git a/Assets/com.fluid.dialogue/Runtime/Nodes/NodeBase.cs b/Assets/com.fluid.dialogue/Runtime/Nodes/NodeBase.cs index 8378acf..d4a5434 100644 --- a/Assets/com.fluid.dialogue/Runtime/Nodes/NodeBase.cs +++ b/Assets/com.fluid.dialogue/Runtime/Nodes/NodeBase.cs @@ -18,6 +18,7 @@ public abstract class NodeBase : INode { _conditions.Find(c => !c.GetIsValid(this)) == null; public List HubChoices { get; } public string UniqueId { get; } + public IReadOnlyList Conditions => _conditions; protected List Children => _childrenRuntimeCache ??