chore: cleaned up order_activate_object_under_cursor with guard clause
This commit is contained in:
parent
78baddfdfb
commit
1599f3aaad
|
@ -99,16 +99,14 @@ void RTSPlayer::order_activate_object_under_cursor() {
|
||||||
return;
|
return;
|
||||||
// fetch whatever's under the cursor in the "objects" layer
|
// fetch whatever's under the cursor in the "objects" layer
|
||||||
gd::Dictionary const dict = this->raycast_from_cursor(0x4);
|
gd::Dictionary const dict = this->raycast_from_cursor(0x4);
|
||||||
if(dict.is_empty())
|
if(dict.is_empty() || this->order_activate_object(gd::Object::cast_to<Node3D>(dict["collider"])))
|
||||||
return;
|
return;
|
||||||
if(!this->order_activate_object(gd::Object::cast_to<Node3D>(dict["collider"]))) {
|
|
||||||
GoalMarker *marker = gd::Object::cast_to<GoalMarker>(this->ground_marker_scene->instantiate());
|
GoalMarker *marker = gd::Object::cast_to<GoalMarker>(this->ground_marker_scene->instantiate());
|
||||||
// setup position before planning to achieve goal
|
// setup position before planning to achieve goal
|
||||||
this->add_child(marker);
|
this->add_child(marker);
|
||||||
marker->set_as_top_level(true);
|
marker->set_as_top_level(true);
|
||||||
marker->set_global_position(dict["position"]);
|
marker->set_global_position(dict["position"]);
|
||||||
this->selected_unit->begin_marker_temporary(marker);
|
this->selected_unit->begin_marker_temporary(marker);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
bool RTSPlayer::order_activate_object(gd::Node3D *node) {
|
bool RTSPlayer::order_activate_object(gd::Node3D *node) {
|
||||||
// get the hit object as a marker
|
// get the hit object as a marker
|
||||||
|
|
Loading…
Reference in a new issue