chore: cleaned up order_activate_object_under_cursor with guard clause

This commit is contained in:
Sara 2024-08-29 18:33:14 +02:00
parent 78baddfdfb
commit 1599f3aaad

View file

@ -99,16 +99,14 @@ void RTSPlayer::order_activate_object_under_cursor() {
return;
// fetch whatever's under the cursor in the "objects" layer
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;
if(!this->order_activate_object(gd::Object::cast_to<Node3D>(dict["collider"]))) {
GoalMarker *marker = gd::Object::cast_to<GoalMarker>(this->ground_marker_scene->instantiate());
// setup position before planning to achieve goal
this->add_child(marker);
marker->set_as_top_level(true);
marker->set_global_position(dict["position"]);
this->selected_unit->begin_marker_temporary(marker);
}
GoalMarker *marker = gd::Object::cast_to<GoalMarker>(this->ground_marker_scene->instantiate());
// setup position before planning to achieve goal
this->add_child(marker);
marker->set_as_top_level(true);
marker->set_global_position(dict["position"]);
this->selected_unit->begin_marker_temporary(marker);
}
bool RTSPlayer::order_activate_object(gd::Node3D *node) {
// get the hit object as a marker