summaryrefslogtreecommitdiffstats
path: root/scene
diff options
context:
space:
mode:
authorNinni Pipping <over999ships@gmail.com>2023-06-05 14:56:54 +0200
committerNinni Pipping <over999ships@gmail.com>2023-06-10 13:22:56 +0200
commit0c16082e1e2030379039e0831cb26497d20b3720 (patch)
treea769795b86fe0af9f156533d707ffde6e93e62f2 /scene
parent37d1dfef9d81aade27ab0c56fc6b6f12f6a08045 (diff)
downloadredot-engine-0c16082e1e2030379039e0831cb26497d20b3720.tar.gz
Use `get_node_or_null` when null checks are present
Avoids duplicate or unnecessary errors
Diffstat (limited to 'scene')
-rw-r--r--scene/3d/area_3d.cpp8
-rw-r--r--scene/animation/animation_player.cpp2
-rw-r--r--scene/gui/control.cpp36
-rw-r--r--scene/gui/graph_edit.cpp2
-rw-r--r--scene/gui/menu_bar.cpp6
-rw-r--r--scene/gui/popup_menu.cpp6
-rw-r--r--scene/main/viewport.cpp8
7 files changed, 28 insertions, 40 deletions
diff --git a/scene/3d/area_3d.cpp b/scene/3d/area_3d.cpp
index fbf928f3f4..29d151b726 100644
--- a/scene/3d/area_3d.cpp
+++ b/scene/3d/area_3d.cpp
@@ -172,9 +172,11 @@ void Area3D::_initialize_wind() {
// Overwrite with area-specified info if available
if (!wind_source_path.is_empty()) {
- Node3D *p_wind_source = Object::cast_to<Node3D>(get_node(wind_source_path));
- ERR_FAIL_NULL(p_wind_source);
- Transform3D global_transform = p_wind_source->get_transform();
+ Node *wind_source_node = get_node_or_null(wind_source_path);
+ ERR_FAIL_NULL_MSG(wind_source_node, "Path to wind source is invalid: '" + wind_source_path + "'.");
+ Node3D *wind_source_node3d = Object::cast_to<Node3D>(wind_source_node);
+ ERR_FAIL_NULL_MSG(wind_source_node3d, "Path to wind source does not point to a Node3D: '" + wind_source_path + "'.");
+ Transform3D global_transform = wind_source_node3d->get_transform();
wind_direction = -global_transform.basis.get_column(Vector3::AXIS_Z).normalized();
wind_source = global_transform.origin;
temp_magnitude = wind_force_magnitude;
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp
index f95a7f98bb..0eb832a2dd 100644
--- a/scene/animation/animation_player.cpp
+++ b/scene/animation/animation_player.cpp
@@ -271,7 +271,7 @@ void AnimationPlayer::_ensure_node_caches(AnimationData *p_anim, Node *p_root_ov
return;
}
- Node *parent = p_root_override ? p_root_override : get_node(root);
+ Node *parent = p_root_override ? p_root_override : get_node_or_null(root);
ERR_FAIL_NULL(parent);
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 160d55bf9b..108d8dd09e 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -2063,14 +2063,10 @@ Control *Control::find_next_valid_focus() const {
// If the focus property is manually overwritten, attempt to use it.
if (!data.focus_next.is_empty()) {
- Node *n = get_node(data.focus_next);
- Control *c;
- if (n) {
- c = Object::cast_to<Control>(n);
- ERR_FAIL_COND_V_MSG(!c, nullptr, "Next focus node is not a control: " + n->get_name() + ".");
- } else {
- return nullptr;
- }
+ Node *n = get_node_or_null(data.focus_next);
+ ERR_FAIL_NULL_V_MSG(n, nullptr, "Next focus node path is invalid: '" + data.focus_next + "'.");
+ Control *c = Object::cast_to<Control>(n);
+ ERR_FAIL_NULL_V_MSG(c, nullptr, "Next focus node is not a control: '" + n->get_name() + "'.");
if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE) {
return c;
}
@@ -2154,14 +2150,10 @@ Control *Control::find_prev_valid_focus() const {
// If the focus property is manually overwritten, attempt to use it.
if (!data.focus_prev.is_empty()) {
- Node *n = get_node(data.focus_prev);
- Control *c;
- if (n) {
- c = Object::cast_to<Control>(n);
- ERR_FAIL_COND_V_MSG(!c, nullptr, "Previous focus node is not a control: " + n->get_name() + ".");
- } else {
- return nullptr;
- }
+ Node *n = get_node_or_null(data.focus_prev);
+ ERR_FAIL_NULL_V_MSG(n, nullptr, "Previous focus node path is invalid: '" + data.focus_prev + "'.");
+ Control *c = Object::cast_to<Control>(n);
+ ERR_FAIL_NULL_V_MSG(c, nullptr, "Previous focus node is not a control: '" + n->get_name() + "'.");
if (c->is_visible() && c->get_focus_mode() != FOCUS_NONE) {
return c;
}
@@ -2250,14 +2242,10 @@ Control *Control::_get_focus_neighbor(Side p_side, int p_count) {
return nullptr;
}
if (!data.focus_neighbor[p_side].is_empty()) {
- Control *c = nullptr;
- Node *n = get_node(data.focus_neighbor[p_side]);
- if (n) {
- c = Object::cast_to<Control>(n);
- ERR_FAIL_COND_V_MSG(!c, nullptr, "Neighbor focus node is not a control: " + n->get_name() + ".");
- } else {
- return nullptr;
- }
+ Node *n = get_node_or_null(data.focus_neighbor[p_side]);
+ ERR_FAIL_NULL_V_MSG(n, nullptr, "Neighbor focus node path is invalid: '" + data.focus_neighbor[p_side] + "'.");
+ Control *c = Object::cast_to<Control>(n);
+ ERR_FAIL_NULL_V_MSG(c, nullptr, "Neighbor focus node is not a control: '" + n->get_name() + "'.");
bool valid = true;
if (!c->is_visible()) {
valid = false;
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index be9195e9dc..5a004c122f 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -989,7 +989,7 @@ void GraphEdit::_top_layer_draw() {
_update_scroll();
if (connecting) {
- Node *fromn = get_node(NodePath(connecting_from));
+ Node *fromn = get_node_or_null(NodePath(connecting_from));
ERR_FAIL_NULL(fromn);
GraphNode *from = Object::cast_to<GraphNode>(fromn);
ERR_FAIL_NULL(from);
diff --git a/scene/gui/menu_bar.cpp b/scene/gui/menu_bar.cpp
index c61e10b6fd..2a3956dd22 100644
--- a/scene/gui/menu_bar.cpp
+++ b/scene/gui/menu_bar.cpp
@@ -209,10 +209,10 @@ void MenuBar::_update_submenu(const String &p_menu_name, PopupMenu *p_child) {
if (p_child->is_item_separator(i)) {
DisplayServer::get_singleton()->global_menu_add_separator(p_menu_name);
} else if (!p_child->get_item_submenu(i).is_empty()) {
- Node *n = p_child->get_node(p_child->get_item_submenu(i));
- ERR_FAIL_COND_MSG(!n, "Item subnode does not exist: " + p_child->get_item_submenu(i) + ".");
+ Node *n = p_child->get_node_or_null(p_child->get_item_submenu(i));
+ ERR_FAIL_NULL_MSG(n, "Item subnode does not exist: '" + p_child->get_item_submenu(i) + "'.");
PopupMenu *pm = Object::cast_to<PopupMenu>(n);
- ERR_FAIL_COND_MSG(!pm, "Item subnode is not a PopupMenu: " + p_child->get_item_submenu(i) + ".");
+ ERR_FAIL_NULL_MSG(pm, "Item subnode is not a PopupMenu: '" + p_child->get_item_submenu(i) + "'.");
DisplayServer::get_singleton()->global_menu_add_submenu_item(p_menu_name, atr(p_child->get_item_text(i)), p_menu_name + "/" + itos(i));
_update_submenu(p_menu_name + "/" + itos(i), pm);
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index f6797b7f64..445edc1ef9 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -185,10 +185,10 @@ int PopupMenu::_get_mouse_over(const Point2 &p_over) const {
}
void PopupMenu::_activate_submenu(int p_over, bool p_by_keyboard) {
- Node *n = get_node(items[p_over].submenu);
- ERR_FAIL_COND_MSG(!n, "Item subnode does not exist: " + items[p_over].submenu + ".");
+ Node *n = get_node_or_null(items[p_over].submenu);
+ ERR_FAIL_NULL_MSG(n, "Item subnode does not exist: '" + items[p_over].submenu + "'.");
Popup *submenu_popup = Object::cast_to<Popup>(n);
- ERR_FAIL_COND_MSG(!submenu_popup, "Item subnode is not a Popup: " + items[p_over].submenu + ".");
+ ERR_FAIL_NULL_MSG(submenu_popup, "Item subnode is not a Popup: '" + items[p_over].submenu + "'.");
if (submenu_popup->is_visible()) {
return; // Already visible.
}
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 66bd60cc67..c0d6b6f325 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -170,12 +170,10 @@ Ref<Image> ViewportTexture::get_image() const {
}
void ViewportTexture::_setup_local_to_scene(const Node *p_loc_scene) {
- Node *vpn = p_loc_scene->get_node(path);
- ERR_FAIL_COND_MSG(!vpn, "ViewportTexture: Path to node is invalid.");
-
+ Node *vpn = p_loc_scene->get_node_or_null(path);
+ ERR_FAIL_NULL_MSG(vpn, "Path to node is invalid: '" + path + "'.");
vp = Object::cast_to<Viewport>(vpn);
-
- ERR_FAIL_COND_MSG(!vp, "ViewportTexture: Path to node does not point to a viewport.");
+ ERR_FAIL_NULL_MSG(vp, "Path to node does not point to a viewport: '" + path + "'.");
vp->viewport_textures.insert(this);