diff --git a/doc/source/classes/class_limbohsm.rst b/doc/source/classes/class_limbohsm.rst index f3b30fc..70ca18c 100644 --- a/doc/source/classes/class_limbohsm.rst +++ b/doc/source/classes/class_limbohsm.rst @@ -56,6 +56,8 @@ Methods +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`LimboState` | :ref:`get_previous_active_state`\ (\ ) |const| | +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ + | ``bool`` | :ref:`has_transition`\ (\ from_state\: :ref:`LimboState`, event\: ``StringName``\ ) |const| | + +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`initialize`\ (\ agent\: ``Node``, parent_scope\: :ref:`Blackboard` = null\ ) | +-------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |void| | :ref:`remove_transition`\ (\ from_state\: :ref:`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`, event\: ``StringName``\ ) |const| :ref:`🔗` + +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 diff --git a/doc_classes/LimboHSM.xml b/doc_classes/LimboHSM.xml index d038fe6..fc6652f 100644 --- a/doc_classes/LimboHSM.xml +++ b/doc_classes/LimboHSM.xml @@ -44,6 +44,14 @@ Returns the previously active substate. + + + + + + Returns [code]true[/code] if there is a transition from [param from_state] for a given [param event]. + + diff --git a/hsm/limbo_hsm.cpp b/hsm/limbo_hsm.cpp index 76a806f..07ff329 100644 --- a/hsm/limbo_hsm.cpp +++ b/hsm/limbo_hsm.cpp @@ -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); diff --git a/hsm/limbo_hsm.h b/hsm/limbo_hsm.h index cfad779..dc8cfe7 100644 --- a/hsm/limbo_hsm.h +++ b/hsm/limbo_hsm.h @@ -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; }