Add `LimboHSM.has_transition(from, event)`

This commit is contained in:
Serhii Snitsaruk 2024-07-21 13:35:16 +02:00
parent a7881a0eea
commit f7eb374c1e
No known key found for this signature in database
GPG Key ID: A965EF8799FFEC2D
4 changed files with 24 additions and 0 deletions

View File

@ -56,6 +56,8 @@ Methods
+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`LimboState<class_LimboState>` | :ref:`get_previous_active_state<class_LimboHSM_method_get_previous_active_state>`\ (\ ) |const| |
+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ``bool`` | :ref:`has_transition<class_LimboHSM_method_has_transition>`\ (\ from_state\: :ref:`LimboState<class_LimboState>`, event\: ``StringName``\ ) |const| |
+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`initialize<class_LimboHSM_method_initialize>`\ (\ agent\: ``Node``, parent_scope\: :ref:`Blackboard<class_Blackboard>` = null\ ) |
+-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |void| | :ref:`remove_transition<class_LimboHSM_method_remove_transition>`\ (\ from_state\: :ref:`LimboState<class_LimboState>`, event\: ``StringName``\ ) |
@ -247,6 +249,18 @@ Returns the previously active substate.
----
.. _class_LimboHSM_method_has_transition:
.. rst-class:: classref-method
``bool`` **has_transition**\ (\ from_state\: :ref:`LimboState<class_LimboState>`, event\: ``StringName``\ ) |const| :ref:`🔗<class_LimboHSM_method_has_transition>`
Returns ``true`` if there is a transition from ``from_state`` for a given ``event``.
.. rst-class:: classref-item-separator
----
.. _class_LimboHSM_method_initialize:
.. rst-class:: classref-method

View File

@ -44,6 +44,14 @@
Returns the previously active substate.
</description>
</method>
<method name="has_transition" qualifiers="const">
<return type="bool" />
<param index="0" name="from_state" type="LimboState" />
<param index="1" name="event" type="StringName" />
<description>
Returns [code]true[/code] if there is a transition from [param from_state] for a given [param event].
</description>
</method>
<method name="initialize">
<return type="void" />
<param index="0" name="agent" type="Node" />

View File

@ -278,6 +278,7 @@ void LimboHSM::_bind_methods() {
ClassDB::bind_method(D_METHOD("update", "delta"), &LimboHSM::update);
ClassDB::bind_method(D_METHOD("add_transition", "from_state", "to_state", "event"), &LimboHSM::add_transition);
ClassDB::bind_method(D_METHOD("remove_transition", "from_state", "event"), &LimboHSM::remove_transition);
ClassDB::bind_method(D_METHOD("has_transition", "from_state", "event"), &LimboHSM::has_transition);
ClassDB::bind_method(D_METHOD("anystate"), &LimboHSM::anystate);
ClassDB::bind_method(D_METHOD("initialize", "agent", "parent_scope"), &LimboHSM::initialize, Variant());
ClassDB::bind_method(D_METHOD("change_active_state", "state"), &LimboHSM::change_active_state);

View File

@ -91,6 +91,7 @@ public:
void add_transition(LimboState *p_from_state, LimboState *p_to_state, const StringName &p_event);
void remove_transition(LimboState *p_from_state, const StringName &p_event);
bool has_transition(LimboState *p_from_state, const StringName &p_event) const { return transitions.has(Transition::make_key(p_from_state, p_event)); }
void get_transition(LimboState *p_from_state, const StringName &p_event, Transition &r_transition) const;
LimboState *anystate() const { return nullptr; }