feat: state machine exposes switch_to_state

This commit is contained in:
Sara Gerretsen 2026-01-29 15:19:15 +01:00
parent 7d7c61e8f7
commit ca49ee81d7

View file

@ -2,7 +2,9 @@
#include "core/config/engine.h" #include "core/config/engine.h"
#include "state.h" #include "state.h"
void StateMachine::_bind_methods() {} void StateMachine::_bind_methods() {
ClassDB::bind_method(D_METHOD("switch_to_state", "state"), &self_type::switch_to_state);
}
void StateMachine::switch_to_state(State *state) { void StateMachine::switch_to_state(State *state) {
if (this->current_state != nullptr) { if (this->current_state != nullptr) {
@ -13,8 +15,6 @@ void StateMachine::switch_to_state(State *state) {
if (this->current_state != nullptr) { if (this->current_state != nullptr) {
this->current_state_is_active = true; this->current_state_is_active = true;
this->current_state->enter_state(); this->current_state->enter_state();
} else {
print_error("StateMachine::switch_to_state: New state is nullptr, StateMachine will now stop working");
} }
} }