1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

Improve use of Ref.is_null/valid

Use `is_null` over `!is_valid` and vice versa.
This commit is contained in:
A Thousand Ships
2024-08-25 14:15:10 +02:00
committed by AThousandShips
parent 0f95e9f8e6
commit a1846b27ea
177 changed files with 517 additions and 519 deletions

View File

@@ -86,11 +86,11 @@ void EditorResourcePicker::_update_resource() {
assign_button->set_tooltip_text(resource_path + TTR("Type:") + " " + edited_resource->get_class());
}
assign_button->set_disabled(!editable && !edited_resource.is_valid());
assign_button->set_disabled(!editable && edited_resource.is_null());
}
void EditorResourcePicker::_update_resource_preview(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, ObjectID p_obj) {
if (!edited_resource.is_valid() || edited_resource->get_instance_id() != p_obj) {
if (edited_resource.is_null() || edited_resource->get_instance_id() != p_obj) {
return;
}
@@ -711,7 +711,7 @@ void EditorResourcePicker::drop_data_fw(const Point2 &p_point, const Variant &p_
dropped_resource = drag_data["resource"];
}
if (!dropped_resource.is_valid() && drag_data.has("type") && String(drag_data["type"]) == "files") {
if (dropped_resource.is_null() && drag_data.has("type") && String(drag_data["type"]) == "files") {
Vector<String> files = drag_data["files"];
if (files.size() == 1) {
@@ -733,7 +733,7 @@ void EditorResourcePicker::drop_data_fw(const Point2 &p_point, const Variant &p_
if (at == "BaseMaterial3D" && Ref<Texture2D>(dropped_resource).is_valid()) {
// Use existing resource if possible and only replace its data.
Ref<StandardMaterial3D> mat = edited_resource;
if (!mat.is_valid()) {
if (mat.is_null()) {
mat.instantiate();
}
mat->set_texture(StandardMaterial3D::TextureParam::TEXTURE_ALBEDO, dropped_resource);
@@ -743,7 +743,7 @@ void EditorResourcePicker::drop_data_fw(const Point2 &p_point, const Variant &p_
if (at == "ShaderMaterial" && Ref<Shader>(dropped_resource).is_valid()) {
Ref<ShaderMaterial> mat = edited_resource;
if (!mat.is_valid()) {
if (mat.is_null()) {
mat.instantiate();
}
mat->set_shader(dropped_resource);
@@ -753,7 +753,7 @@ void EditorResourcePicker::drop_data_fw(const Point2 &p_point, const Variant &p_
if (at == "ImageTexture" && Ref<Image>(dropped_resource).is_valid()) {
Ref<ImageTexture> texture = edited_resource;
if (!texture.is_valid()) {
if (texture.is_null()) {
texture.instantiate();
}
texture->set_image(dropped_resource);
@@ -888,7 +888,7 @@ Vector<String> EditorResourcePicker::get_allowed_types() const {
}
void EditorResourcePicker::set_edited_resource(Ref<Resource> p_resource) {
if (!p_resource.is_valid()) {
if (p_resource.is_null()) {
edited_resource = Ref<Resource>();
_update_resource();
return;
@@ -948,7 +948,7 @@ void EditorResourcePicker::set_resource_owner(Object *p_object) {
void EditorResourcePicker::set_editable(bool p_editable) {
editable = p_editable;
assign_button->set_disabled(!editable && !edited_resource.is_valid());
assign_button->set_disabled(!editable && edited_resource.is_null());
load_button->set_visible(editable);
edit_button->set_visible(editable);
}
@@ -1269,7 +1269,7 @@ void EditorAudioStreamPicker::_update_resource() {
void EditorAudioStreamPicker::_preview_draw() {
Ref<AudioStream> audio_stream = get_edited_resource();
if (!audio_stream.is_valid()) {
if (audio_stream.is_null()) {
get_assign_button()->set_text(TTR("<empty>"));
return;
}