limboai/blackboard/bb_param/bb_node.cpp

46 lines
1.4 KiB
C++
Raw Normal View History

/**
* bb_node.cpp
* =============================================================================
2024-03-21 20:38:57 +00:00
* Copyright 2021-2024 Serhii Snitsaruk
*
* Use of this source code is governed by an MIT-style
* license that can be found in the LICENSE file or at
* https://opensource.org/licenses/MIT.
* =============================================================================
*/
2022-10-20 16:26:46 +00:00
#include "bb_node.h"
2024-01-06 20:05:08 +00:00
#ifdef LIMBOAI_MODULE
#include "core/error/error_macros.h"
2022-10-20 16:26:46 +00:00
#include "scene/main/node.h"
2024-01-06 20:05:08 +00:00
#endif // LIMBOAI_MODULE
2024-01-13 16:10:42 +00:00
2024-01-06 20:05:08 +00:00
#ifdef LIMBOAI_GDEXTENSION
#include <godot_cpp/classes/node.hpp>
#endif // LIMBOAI_GDEXTENSION
2022-10-20 16:26:46 +00:00
2024-05-01 21:32:44 +00:00
Variant BBNode::get_value(Node *p_scene_root, const Ref<Blackboard> &p_blackboard, const Variant &p_default) {
ERR_FAIL_NULL_V_MSG(p_scene_root, Variant(), "BBNode: get_value() failed - scene_root is null.");
ERR_FAIL_NULL_V_MSG(p_blackboard, Variant(), "BBNode: get_value() failed - blackboard is null.");
2022-10-20 16:26:46 +00:00
Variant val;
if (get_value_source() == SAVED_VALUE) {
val = get_saved_value();
} else {
val = p_blackboard->get_var(get_variable(), p_default);
}
if (val.get_type() == Variant::NODE_PATH) {
2024-05-01 21:32:44 +00:00
return p_scene_root->get_node_or_null(val);
2022-10-20 16:26:46 +00:00
} else {
2023-09-05 08:55:17 +00:00
Object *obj = val;
if (unlikely(obj == nullptr && val.get_type() != Variant::NIL)) {
2022-10-20 16:26:46 +00:00
WARN_PRINT("BBNode: Unexpected variant type of a blackboard variable.");
return p_default;
} else {
2023-09-05 08:55:17 +00:00
return obj;
2022-10-20 16:26:46 +00:00
}
}
}