diff options
author | Nathan Franke <natfra@pm.me> | 2021-12-09 03:42:46 -0600 |
---|---|---|
committer | Nathan Franke <natfra@pm.me> | 2021-12-09 04:48:38 -0600 |
commit | 49403cbfa0399bb4284ea5c36cc90216a0bda6ff (patch) | |
tree | caa6c7249d35d83b288a180a4f5d7e4fd959704f /scene | |
parent | 31ded7e126b9d71ed8dddab9ffc1ce813f1a8ec2 (diff) |
Replace String comparisons with "", String() to is_empty()
Also:
- Adds two stress tests to test_string.h
- Changes to .empty() on std::strings
Diffstat (limited to 'scene')
42 files changed, 174 insertions, 174 deletions
diff --git a/scene/2d/animated_sprite_2d.cpp b/scene/2d/animated_sprite_2d.cpp index 98aa2ad4cc..4fc5c4c21f 100644 --- a/scene/2d/animated_sprite_2d.cpp +++ b/scene/2d/animated_sprite_2d.cpp @@ -128,7 +128,7 @@ void AnimatedSprite2D::_validate_property(PropertyInfo &property) const { } if (!current_found) { - if (property.hint_string == String()) { + if (property.hint_string.is_empty()) { property.hint_string = String(animation); } else { property.hint_string = String(animation) + "," + property.hint_string; diff --git a/scene/3d/lightmap_gi.cpp b/scene/3d/lightmap_gi.cpp index 1b5d4ad243..910cf3a37d 100644 --- a/scene/3d/lightmap_gi.cpp +++ b/scene/3d/lightmap_gi.cpp @@ -614,7 +614,7 @@ void LightmapGI::_gen_new_positions_from_octree(const GenProbesOctree *p_cell, f } LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_path, Lightmapper::BakeStepFunc p_bake_step, void *p_bake_userdata) { - if (p_image_data_path == "") { + if (p_image_data_path.is_empty()) { if (get_light_data().is_null()) { return BAKE_ERROR_NO_SAVE_PATH; } diff --git a/scene/3d/occluder_instance_3d.cpp b/scene/3d/occluder_instance_3d.cpp index aeac430cd9..ac22239d70 100644 --- a/scene/3d/occluder_instance_3d.cpp +++ b/scene/3d/occluder_instance_3d.cpp @@ -291,7 +291,7 @@ void OccluderInstance3D::_bake_node(Node *p_node, PackedVector3Array &r_vertices } OccluderInstance3D::BakeError OccluderInstance3D::bake(Node *p_from_node, String p_occluder_path) { - if (p_occluder_path == "") { + if (p_occluder_path.is_empty()) { if (get_occluder().is_null()) { return BAKE_ERROR_NO_SAVE_PATH; } diff --git a/scene/3d/skeleton_3d.cpp b/scene/3d/skeleton_3d.cpp index 04b5b88ef8..85ef532459 100644 --- a/scene/3d/skeleton_3d.cpp +++ b/scene/3d/skeleton_3d.cpp @@ -506,7 +506,7 @@ int Skeleton3D::get_bone_axis_forward_enum(int p_bone) { // Skeleton creation api void Skeleton3D::add_bone(const String &p_name) { - ERR_FAIL_COND(p_name == "" || p_name.find(":") != -1 || p_name.find("/") != -1); + ERR_FAIL_COND(p_name.is_empty() || p_name.find(":") != -1 || p_name.find("/") != -1); for (int i = 0; i < bones.size(); i++) { ERR_FAIL_COND(bones[i].name == p_name); diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp index 3eabc6b562..09f0187147 100644 --- a/scene/3d/sprite_3d.cpp +++ b/scene/3d/sprite_3d.cpp @@ -1004,7 +1004,7 @@ void AnimatedSprite3D::_validate_property(PropertyInfo &property) const { } if (!current_found) { - if (property.hint_string == String()) { + if (property.hint_string.is_empty()) { property.hint_string = String(animation); } else { property.hint_string = String(animation) + "," + property.hint_string; diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp index d6c5d0b51c..8f644face5 100644 --- a/scene/animation/animation_blend_tree.cpp +++ b/scene/animation/animation_blend_tree.cpp @@ -57,7 +57,7 @@ void AnimationNodeAnimation::_validate_property(PropertyInfo &property) const { } anims += String(names[i]); } - if (anims != String()) { + if (!anims.is_empty()) { property.hint = PROPERTY_HINT_ENUM; property.hint_string = anims; } diff --git a/scene/animation/animation_node_state_machine.cpp b/scene/animation/animation_node_state_machine.cpp index c8fa8bf395..31a1d4d64c 100644 --- a/scene/animation/animation_node_state_machine.cpp +++ b/scene/animation/animation_node_state_machine.cpp @@ -52,7 +52,7 @@ void AnimationNodeStateMachineTransition::set_advance_condition(const StringName String cs = p_condition; ERR_FAIL_COND(cs.find("/") != -1 || cs.find(":") != -1); advance_condition = p_condition; - if (cs != String()) { + if (!cs.is_empty()) { advance_condition_name = "conditions/" + cs; } else { advance_condition_name = StringName(); diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index b9435b6692..d603106696 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -1416,7 +1416,7 @@ bool AnimationPlayer::is_playing() const { } void AnimationPlayer::set_current_animation(const String &p_anim) { - if (p_anim == "[stop]" || p_anim == "") { + if (p_anim == "[stop]" || p_anim.is_empty()) { stop(); } else if (!is_playing() || playback.assigned != p_anim) { play(p_anim); diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index 57c615a6ab..527946b9de 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -138,7 +138,7 @@ real_t AnimationNode::_pre_process(const StringName &p_base_path, AnimationNode void AnimationNode::make_invalid(const String &p_reason) { ERR_FAIL_COND(!state); state->valid = false; - if (state->invalid_reasons != String()) { + if (!state->invalid_reasons.is_empty()) { state->invalid_reasons += "\n"; } state->invalid_reasons += String::utf8("• ") + p_reason; diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp index 56c04b32e3..e1594384d5 100644 --- a/scene/debugger/scene_debugger.cpp +++ b/scene/debugger/scene_debugger.cpp @@ -226,7 +226,7 @@ void SceneDebugger::add_to_cache(const String &p_filename, Node *p_node) { return; } - if (EngineDebugger::get_script_debugger() && p_filename != String()) { + if (EngineDebugger::get_script_debugger() && !p_filename.is_empty()) { debugger->live_scene_edit_cache[p_filename].insert(p_node); } } diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 9f712ed478..f4de48689e 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -355,7 +355,7 @@ String BaseButton::get_tooltip(const Point2 &p_pos) const { String tooltip = Control::get_tooltip(p_pos); if (shortcut_in_tooltip && shortcut.is_valid() && shortcut->has_valid_event()) { String text = shortcut->get_name() + " (" + shortcut->get_as_text() + ")"; - if (tooltip != String() && shortcut->get_name().nocasecmp_to(tooltip) != 0) { + if (!tooltip.is_empty() && shortcut->get_name().nocasecmp_to(tooltip) != 0) { text += "\n" + tooltip; } tooltip = text; diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index 655fc783d7..8bb41e7abf 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -52,7 +52,7 @@ Size2 Button::get_minimum_size() const { if (icon_alignment != HORIZONTAL_ALIGNMENT_CENTER) { minsize.width += _icon->get_width(); - if (xl_text != "") { + if (!xl_text.is_empty()) { minsize.width += get_theme_constant(SNAME("hseparation")); } } else { @@ -359,7 +359,7 @@ void Button::_shape() { } else { text_buf->set_direction((TextServer::Direction)text_direction); } - text_buf->add_string(xl_text, font, font_size, opentype_features, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale()); + text_buf->add_string(xl_text, font, font_size, opentype_features, (!language.is_empty()) ? language : TranslationServer::get_singleton()->get_tool_locale()); } void Button::set_text(const String &p_text) { diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index 23ac36c5eb..ba37d51e24 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -189,7 +189,7 @@ void CodeEdit::_notification(int p_what) { } /* Code hint */ - if (caret_visible && code_hint != "" && (!code_completion_active || (code_completion_below != code_hint_draw_below))) { + if (caret_visible && !code_hint.is_empty() && (!code_completion_active || (code_completion_below != code_hint_draw_below))) { const int font_height = font->get_height(font_size); Ref<StyleBox> sb = get_theme_stylebox(SNAME("panel"), SNAME("TooltipPanel")); Color font_color = get_theme_color(SNAME("font_color"), SNAME("TooltipLabel")); @@ -315,7 +315,7 @@ void CodeEdit::gui_input(const Ref<InputEvent> &p_gui_input) { } } else { if (mb->get_button_index() == MouseButton::LEFT) { - if (mb->is_command_pressed() && symbol_lookup_word != String()) { + if (mb->is_command_pressed() && !symbol_lookup_word.is_empty()) { Vector2i mpos = mb->get_position(); if (is_layout_rtl()) { mpos.x = get_size().x - mpos.x; @@ -530,7 +530,7 @@ void CodeEdit::gui_input(const Ref<InputEvent> &p_gui_input) { /* General overrides */ Control::CursorShape CodeEdit::get_cursor_shape(const Point2 &p_pos) const { - if (symbol_lookup_word != String()) { + if (!symbol_lookup_word.is_empty()) { return CURSOR_POINTING_HAND; } @@ -2597,7 +2597,7 @@ void CodeEdit::_add_delimiter(const String &p_start_key, const String &p_end_key delimiter.type = p_type; delimiter.start_key = p_start_key; delimiter.end_key = p_end_key; - delimiter.line_only = p_line_only || p_end_key == ""; + delimiter.line_only = p_line_only || p_end_key.is_empty(); delimiters.insert(at, delimiter); if (!setting_delimiters) { delimiter_cache.clear(); @@ -2647,7 +2647,7 @@ void CodeEdit::_set_delimiters(const TypedArray<String> &p_delimiters, Delimiter const String start_key = key.get_slice(" ", 0); const String end_key = key.get_slice_count(" ") > 1 ? key.get_slice(" ", 1) : String(); - _add_delimiter(start_key, end_key, end_key == "", p_type); + _add_delimiter(start_key, end_key, end_key.is_empty(), p_type); } setting_delimiters = false; _update_delimiter_cache(); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 3a926b3fb5..249eb95ed8 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -2791,7 +2791,7 @@ void Control::get_argument_options(const StringName &p_function, int p_idx, List TypedArray<String> Control::get_configuration_warnings() const { TypedArray<String> warnings = Node::get_configuration_warnings(); - if (data.mouse_filter == MOUSE_FILTER_IGNORE && data.tooltip != "") { + if (data.mouse_filter == MOUSE_FILTER_IGNORE && !data.tooltip.is_empty()) { warnings.push_back(TTR("The Hint Tooltip won't be displayed as the control's Mouse Filter is set to \"Ignore\". To solve this, set the Mouse Filter to \"Stop\" or \"Pass\".")); } diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index f66d3f6835..f1725e57ea 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -242,7 +242,7 @@ Button *AcceptDialog::add_button(const String &p_text, bool p_right, const Strin hbc->add_spacer(true); } - if (p_action != "") { + if (!p_action.is_empty()) { button->connect("pressed", callable_mp(this, &AcceptDialog::_custom_action), varray(p_action)); } @@ -251,7 +251,7 @@ Button *AcceptDialog::add_button(const String &p_text, bool p_right, const Strin Button *AcceptDialog::add_cancel_button(const String &p_cancel) { String c = p_cancel; - if (p_cancel == "") { + if (p_cancel.is_empty()) { c = TTRC("Cancel"); } Button *b = swap_cancel_ok ? add_button(c, true) : add_button(c); diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index 3177911a70..7a7b35585e 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -458,7 +458,7 @@ void GraphNode::_shape() { } else { title_buf->set_direction((TextServer::Direction)text_direction); } - title_buf->add_string(title, font, font_size, opentype_features, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale()); + title_buf->add_string(title, font, font_size, opentype_features, (!language.is_empty()) ? language : TranslationServer::get_singleton()->get_tool_locale()); } #ifdef TOOLS_ENABLED diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index a3235dd382..6deb39b9e2 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -43,7 +43,7 @@ void ItemList::_shape(int p_idx) { } else { item.text_buf->set_direction((TextServer::Direction)item.text_direction); } - item.text_buf->add_string(item.text, get_theme_font(SNAME("font")), get_theme_font_size(SNAME("font_size")), item.opentype_features, (item.language != "") ? item.language : TranslationServer::get_singleton()->get_tool_locale()); + item.text_buf->add_string(item.text, get_theme_font(SNAME("font")), get_theme_font_size(SNAME("font_size")), item.opentype_features, (!item.language.is_empty()) ? item.language : TranslationServer::get_singleton()->get_tool_locale()); if (icon_mode == ICON_MODE_TOP && max_text_lines > 0) { item.text_buf->set_flags(TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND | TextServer::BREAK_GRAPHEME_BOUND); } else { @@ -653,7 +653,7 @@ void ItemList::gui_input(const Ref<InputEvent> &p_event) { if (p_event->is_pressed() && items.size() > 0) { if (p_event->is_action("ui_up")) { - if (search_string != "") { + if (!search_string.is_empty()) { uint64_t now = OS::get_singleton()->get_ticks_msec(); uint64_t diff = now - search_time_msec; @@ -683,7 +683,7 @@ void ItemList::gui_input(const Ref<InputEvent> &p_event) { accept_event(); } } else if (p_event->is_action("ui_down")) { - if (search_string != "") { + if (!search_string.is_empty()) { uint64_t now = OS::get_singleton()->get_ticks_msec(); uint64_t diff = now - search_time_msec; @@ -920,7 +920,7 @@ void ItemList::_notification(int p_what) { minsize = items[i].get_icon_size() * icon_scale; } - if (items[i].text != "") { + if (!items[i].text.is_empty()) { if (icon_mode == ICON_MODE_TOP) { minsize.y += icon_margin; } else { @@ -929,7 +929,7 @@ void ItemList::_notification(int p_what) { } } - if (items[i].text != "") { + if (!items[i].text.is_empty()) { int max_width = -1; if (fixed_column_width) { max_width = fixed_column_width; @@ -1188,7 +1188,7 @@ void ItemList::_notification(int p_what) { draw_texture(items[i].tag_icon, draw_pos + base_ofs); } - if (items[i].text != "") { + if (!items[i].text.is_empty()) { int max_len = -1; Vector2 size2 = items[i].text_buf->get_size(); @@ -1360,10 +1360,10 @@ String ItemList::get_tooltip(const Point2 &p_pos) const { if (!items[closest].tooltip_enabled) { return ""; } - if (items[closest].tooltip != "") { + if (!items[closest].tooltip.is_empty()) { return items[closest].tooltip; } - if (items[closest].text != "") { + if (!items[closest].text.is_empty()) { return items[closest].text; } } diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index bd3a2c2e53..0a09d87509 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -96,7 +96,7 @@ void Label::_shape() { if (visible_chars >= 0) { text = text.substr(0, visible_chars); } - TS->shaped_text_add_string(text_rid, text, font->get_rids(), font_size, opentype_features, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale()); + TS->shaped_text_add_string(text_rid, text, font->get_rids(), font_size, opentype_features, (!language.is_empty()) ? language : TranslationServer::get_singleton()->get_tool_locale()); TS->shaped_text_set_bidi_override(text_rid, structured_text_parser(st_parser, st_args, text)); dirty = false; lines_dirty = true; diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 9df2f7309c..810781995e 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -1017,7 +1017,7 @@ void LineEdit::paste_text() { // Strip escape characters like \n and \t as they can't be displayed on LineEdit. String paste_buffer = DisplayServer::get_singleton()->clipboard_get().strip_escapes(); - if (paste_buffer != "") { + if (!paste_buffer.is_empty()) { int prev_len = text.length(); if (selection.enabled) { selection_delete(); @@ -2078,7 +2078,7 @@ void LineEdit::_shape() { const Ref<Font> &font = get_theme_font(SNAME("font")); int font_size = get_theme_font_size(SNAME("font_size")); ERR_FAIL_COND(font.is_null()); - TS->shaped_text_add_string(text_rid, t, font->get_rids(), font_size, opentype_features, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale()); + TS->shaped_text_add_string(text_rid, t, font->get_rids(), font_size, opentype_features, (!language.is_empty()) ? language : TranslationServer::get_singleton()->get_tool_locale()); TS->shaped_text_set_bidi_override(text_rid, structured_text_parser(st_parser, st_args, t)); full_width = TS->shaped_text_get_size(text_rid).x; diff --git a/scene/gui/link_button.cpp b/scene/gui/link_button.cpp index 9856247b7c..b59f4fb7d4 100644 --- a/scene/gui/link_button.cpp +++ b/scene/gui/link_button.cpp @@ -42,7 +42,7 @@ void LinkButton::_shape() { text_buf->set_direction((TextServer::Direction)text_direction); } TS->shaped_text_set_bidi_override(text_buf->get_rid(), structured_text_parser(st_parser, st_args, xl_text)); - text_buf->add_string(xl_text, font, font_size, opentype_features, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale()); + text_buf->add_string(xl_text, font, font_size, opentype_features, (!language.is_empty()) ? language : TranslationServer::get_singleton()->get_tool_locale()); } void LinkButton::set_text(const String &p_text) { diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 4e16111f99..c2f912fc96 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -80,7 +80,7 @@ Size2 PopupMenu::_get_contents_minimum_size() const { accel_max_w = MAX(accel_w, accel_max_w); } - if (items[i].submenu != "") { + if (!items[i].submenu.is_empty()) { size.width += get_theme_icon(SNAME("submenu"))->get_width(); } @@ -326,13 +326,13 @@ void PopupMenu::gui_input(const Ref<InputEvent> &p_event) { set_input_as_handled(); } } else if (p_event->is_action("ui_right") && p_event->is_pressed()) { - if (mouse_over >= 0 && mouse_over < items.size() && !items[mouse_over].separator && items[mouse_over].submenu != "" && submenu_over != mouse_over) { + if (mouse_over >= 0 && mouse_over < items.size() && !!items[mouse_over].separator && items[mouse_over].submenu.is_empty() && submenu_over != mouse_over) { _activate_submenu(mouse_over); set_input_as_handled(); } } else if (p_event->is_action("ui_accept") && p_event->is_pressed()) { if (mouse_over >= 0 && mouse_over < items.size() && !items[mouse_over].separator) { - if (items[mouse_over].submenu != "" && submenu_over != mouse_over) { + if (!items[mouse_over].submenu.is_empty() && submenu_over != mouse_over) { _activate_submenu(mouse_over); } else { activate_item(mouse_over); @@ -387,7 +387,7 @@ void PopupMenu::gui_input(const Ref<InputEvent> &p_event) { return; } - if (items[over].submenu != "") { + if (!items[over].submenu.is_empty()) { _activate_submenu(over); return; } @@ -419,7 +419,7 @@ void PopupMenu::gui_input(const Ref<InputEvent> &p_event) { return; } - if (items[over].submenu != "" && submenu_over != over) { + if (!items[over].submenu.is_empty() && submenu_over != over) { submenu_over = over; submenu_timer->start(); } @@ -558,7 +558,7 @@ void PopupMenu::_draw_items() { if (items[i].separator) { int sep_h = separator->get_center_size().height + separator->get_minimum_size().height; int sep_ofs = Math::floor((h - sep_h) / 2.0); - if (text != String()) { + if (!text.is_empty()) { int text_size = items[i].text_buf->get_size().width; int text_center = display_width / 2; int text_left = text_center - text_size / 2; @@ -599,7 +599,7 @@ void PopupMenu::_draw_items() { } // Submenu arrow on right hand side - if (items[i].submenu != "") { + if (!items[i].submenu.is_empty()) { if (rtl) { submenu->draw(ci, Point2(scroll_width + style->get_margin(SIDE_LEFT) + item_end_padding, item_ofs.y + Math::floor(h - submenu->get_height()) / 2), icon_color); } else { @@ -611,7 +611,7 @@ void PopupMenu::_draw_items() { Color font_outline_color = get_theme_color(SNAME("font_outline_color")); int outline_size = get_theme_constant(SNAME("outline_size")); if (items[i].separator) { - if (text != String()) { + if (!text.is_empty()) { int center = (display_width - items[i].text_buf->get_size().width) / 2; Vector2 text_pos = Point2(center, item_ofs.y + Math::floor((h - items[i].text_buf->get_size().y) / 2.0)); if (outline_size > 0 && font_outline_color.a > 0) { @@ -701,7 +701,7 @@ void PopupMenu::_shape_item(int p_item) { } else { items.write[p_item].text_buf->set_direction((TextServer::Direction)items[p_item].text_direction); } - items.write[p_item].text_buf->add_string(items.write[p_item].xl_text, font, font_size, items[p_item].opentype_features, (items[p_item].language != "") ? items[p_item].language : TranslationServer::get_singleton()->get_tool_locale()); + items.write[p_item].text_buf->add_string(items.write[p_item].xl_text, font, font_size, items[p_item].opentype_features, !items[p_item].language.is_empty() ? items[p_item].language : TranslationServer::get_singleton()->get_tool_locale()); items.write[p_item].accel_text_buf->clear(); items.write[p_item].accel_text_buf->set_direction(is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR); @@ -736,7 +736,7 @@ void PopupMenu::_notification(int p_what) { grab_focus(); } break; case NOTIFICATION_WM_MOUSE_EXIT: { - if (mouse_over >= 0 && (items[mouse_over].submenu == "" || submenu_over != -1)) { + if (mouse_over >= 0 && (items[mouse_over].submenu.is_empty() || submenu_over != -1)) { mouse_over = -1; control->update(); } @@ -769,7 +769,7 @@ void PopupMenu::_notification(int p_what) { } for (int i = 0; i < items.size(); i++) { - if (items[i].submenu == "") { + if (items[i].submenu.is_empty()) { continue; } @@ -1323,7 +1323,7 @@ bool PopupMenu::activate_item_by_event(const Ref<InputEvent> &p_event, bool p_fo return true; } - if (items[i].submenu != "") { + if (!items[i].submenu.is_empty()) { Node *n = get_node(items[i].submenu); if (!n) { continue; @@ -1412,7 +1412,7 @@ void PopupMenu::add_separator(const String &p_text, int p_id) { Item sep; sep.separator = true; sep.id = p_id; - if (p_text != String()) { + if (!p_text.is_empty()) { sep.text = p_text; sep.xl_text = atr(p_text); } @@ -1510,7 +1510,7 @@ void PopupMenu::set_parent_rect(const Rect2 &p_rect) { void PopupMenu::get_translatable_strings(List<String> *p_strings) const { for (int i = 0; i < items.size(); i++) { - if (items[i].xl_text != "") { + if (!items[i].xl_text.is_empty()) { p_strings->push_back(items[i].xl_text); } } diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index c69565c2f7..7ed8056826 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -670,7 +670,7 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o prefix = segment + prefix; } } - if (prefix != "") { + if (!prefix.is_empty()) { Ref<Font> font = _find_font(l.from); if (font.is_null()) { font = get_theme_font(SNAME("normal_font")); @@ -1423,7 +1423,7 @@ void RichTextLabel::_notification(int p_what) { } break; case NOTIFICATION_THEME_CHANGED: case NOTIFICATION_ENTER_TREE: { - if (text != "") { + if (!text.is_empty()) { set_text(text); } @@ -3853,7 +3853,7 @@ String RichTextLabel::get_selected_text() const { void RichTextLabel::selection_copy() { String text = get_selected_text(); - if (text != "") { + if (!text.is_empty()) { DisplayServer::get_singleton()->clipboard_set(text); } } @@ -4005,7 +4005,7 @@ float RichTextLabel::get_percent_visible() const { void RichTextLabel::set_effects(Array p_effects) { custom_effects = p_effects; - if ((text != "") && use_bbcode) { + if ((!text.is_empty()) && use_bbcode) { parse_bbcode(text); } } @@ -4020,7 +4020,7 @@ void RichTextLabel::install_effect(const Variant effect) { if (rteffect.is_valid()) { custom_effects.push_back(effect); - if ((text != "") && use_bbcode) { + if ((!text.is_empty()) && use_bbcode) { parse_bbcode(text); } } diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index c4a1d8e5a6..8d6315d085 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -41,10 +41,10 @@ Size2 SpinBox::get_minimum_size() const { void SpinBox::_value_changed(double) { String value = TS->format_number(String::num(get_value(), Math::range_step_decimals(get_step()))); - if (prefix != "") { + if (!prefix.is_empty()) { value = prefix + " " + value; } - if (suffix != "") { + if (!suffix.is_empty()) { value += " " + suffix; } line_edit->set_text(value); diff --git a/scene/gui/tab_bar.cpp b/scene/gui/tab_bar.cpp index dd410e2472..3d88c117e7 100644 --- a/scene/gui/tab_bar.cpp +++ b/scene/gui/tab_bar.cpp @@ -50,7 +50,7 @@ Size2 TabBar::get_minimum_size() const { Ref<Texture2D> tex = tabs[i].icon; if (tex.is_valid()) { ms.height = MAX(ms.height, tex->get_size().height); - if (tabs[i].text != "") { + if (!tabs[i].text.is_empty()) { ms.width += get_theme_constant(SNAME("hseparation")); } } @@ -270,7 +270,7 @@ void TabBar::_shape(int p_tab) { tabs.write[p_tab].text_buf->set_direction((TextServer::Direction)tabs[p_tab].text_direction); } - tabs.write[p_tab].text_buf->add_string(tabs.write[p_tab].xl_text, font, font_size, tabs[p_tab].opentype_features, (tabs[p_tab].language != "") ? tabs[p_tab].language : TranslationServer::get_singleton()->get_tool_locale()); + tabs.write[p_tab].text_buf->add_string(tabs.write[p_tab].xl_text, font, font_size, tabs[p_tab].opentype_features, !tabs[p_tab].language.is_empty() ? tabs[p_tab].language : TranslationServer::get_singleton()->get_tool_locale()); } void TabBar::_notification(int p_what) { @@ -385,7 +385,7 @@ void TabBar::_notification(int p_what) { } else { icon->draw(ci, Point2i(w, sb->get_margin(SIDE_TOP) + ((sb_rect.size.y - sb_ms.y) - icon->get_height()) / 2)); } - if (tabs[i].text != "") { + if (!tabs[i].text.is_empty()) { w += icon->get_width() + get_theme_constant(SNAME("hseparation")); } } @@ -980,7 +980,7 @@ int TabBar::get_tab_width(int p_idx) const { Ref<Texture2D> tex = tabs[p_idx].icon; if (tex.is_valid()) { x += tex->get_width(); - if (tabs[p_idx].text != "") { + if (!tabs[p_idx].text.is_empty()) { x += get_theme_constant(SNAME("hseparation")); } } diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 23e8f2bce8..fd5df5c93b 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -561,7 +561,7 @@ void TabContainer::_draw_tab(Ref<StyleBox> &p_tab_style, Color &p_font_color, in if (icon.is_valid()) { int y = y_center - (icon->get_height() / 2); icon->draw(canvas, Point2i(x_content, y)); - if (text != "") { + if (!text.is_empty()) { x_content += icon->get_width() + icon_text_distance; } } @@ -656,7 +656,7 @@ int TabContainer::_get_tab_width(int p_index) const { Ref<Texture2D> icon = control->get_meta("_tab_icon"); if (icon.is_valid()) { width += icon->get_width(); - if (text != "") { + if (!text.is_empty()) { width += get_theme_constant(SNAME("icon_separation")); } } @@ -1108,7 +1108,7 @@ void TabContainer::get_translatable_strings(List<String> *p_strings) const { String name = c->get_meta("_tab_name"); - if (name != "") { + if (!name.is_empty()) { p_strings->push_back(name); } } diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index c54b4dda00..2986be28c2 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -601,7 +601,7 @@ void TextEdit::_notification(int p_what) { String highlighted_text = get_selected_text(); // Check if highlighted words contain only whitespaces (tabs or spaces). - bool only_whitespaces_highlighted = highlighted_text.strip_edges() == String(); + bool only_whitespaces_highlighted = highlighted_text.strip_edges().is_empty(); const int caret_wrap_index = get_caret_wrap_index(); @@ -916,7 +916,7 @@ void TextEdit::_notification(int p_what) { switch (gutter.type) { case GUTTER_TYPE_STRING: { const String &text = get_line_gutter_text(line, g); - if (text == "") { + if (text.is_empty()) { break; } @@ -2428,7 +2428,7 @@ void TextEdit::_update_caches() { } else { dir = (TextServer::Direction)text_direction; } - text.set_direction_and_language(dir, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale()); + text.set_direction_and_language(dir, (!language.is_empty()) ? language : TranslationServer::get_singleton()->get_tool_locale()); text.set_font_features(opentype_features); text.set_draw_control_chars(draw_control_chars); text.set_font(font); @@ -2611,7 +2611,7 @@ void TextEdit::set_text_direction(Control::TextDirection p_text_direction) { } else { dir = (TextServer::Direction)text_direction; } - text.set_direction_and_language(dir, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale()); + text.set_direction_and_language(dir, (!language.is_empty()) ? language : TranslationServer::get_singleton()->get_tool_locale()); text.invalidate_all(); if (menu_dir) { @@ -2662,7 +2662,7 @@ void TextEdit::set_language(const String &p_language) { } else { dir = (TextServer::Direction)text_direction; } - text.set_direction_and_language(dir, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale()); + text.set_direction_and_language(dir, (!language.is_empty()) ? language : TranslationServer::get_singleton()->get_tool_locale()); text.invalidate_all(); update(); } diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index d2d4167a25..5a6ac7c0d2 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -1536,7 +1536,7 @@ void Tree::update_column(int p_col) { columns.write[p_col].text_buf->set_direction((TextServer::Direction)columns[p_col].text_direction); } - columns.write[p_col].text_buf->add_string(columns[p_col].title, cache.font, cache.font_size, columns[p_col].opentype_features, (columns[p_col].language != "") ? columns[p_col].language : TranslationServer::get_singleton()->get_tool_locale()); + columns.write[p_col].text_buf->add_string(columns[p_col].title, cache.font, cache.font_size, columns[p_col].opentype_features, !columns[p_col].language.is_empty() ? columns[p_col].language : TranslationServer::get_singleton()->get_tool_locale()); } void Tree::update_item_cell(TreeItem *p_item, int p_col) { @@ -1544,7 +1544,7 @@ void Tree::update_item_cell(TreeItem *p_item, int p_col) { p_item->cells.write[p_col].text_buf->clear(); if (p_item->cells[p_col].mode == TreeItem::CELL_MODE_RANGE) { - if (p_item->cells[p_col].text != "") { + if (!p_item->cells[p_col].text.is_empty()) { if (!p_item->cells[p_col].editable) { return; } @@ -1571,7 +1571,7 @@ void Tree::update_item_cell(TreeItem *p_item, int p_col) { valtext = p_item->cells[p_col].text; } - if (p_item->cells[p_col].suffix != String()) { + if (!p_item->cells[p_col].suffix.is_empty()) { valtext += " " + p_item->cells[p_col].suffix; } @@ -1594,7 +1594,7 @@ void Tree::update_item_cell(TreeItem *p_item, int p_col) { } else { font_size = cache.font_size; } - p_item->cells.write[p_col].text_buf->add_string(valtext, font, font_size, p_item->cells[p_col].opentype_features, (p_item->cells[p_col].language != "") ? p_item->cells[p_col].language : TranslationServer::get_singleton()->get_tool_locale()); + p_item->cells.write[p_col].text_buf->add_string(valtext, font, font_size, p_item->cells[p_col].opentype_features, !p_item->cells[p_col].language.is_empty() ? p_item->cells[p_col].language : TranslationServer::get_singleton()->get_tool_locale()); TS->shaped_text_set_bidi_override(p_item->cells[p_col].text_buf->get_rid(), structured_text_parser(p_item->cells[p_col].st_parser, p_item->cells[p_col].st_args, valtext)); p_item->cells.write[p_col].dirty = false; } @@ -1660,7 +1660,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 if (p_item->cells[i].expand_right) { int plus = 1; - while (i + plus < columns.size() && !p_item->cells[i + plus].editable && p_item->cells[i + plus].mode == TreeItem::CELL_MODE_STRING && p_item->cells[i + plus].text == "" && p_item->cells[i + plus].icon.is_null()) { + while (i + plus < columns.size() && !p_item->cells[i + plus].editable && p_item->cells[i + plus].mode == TreeItem::CELL_MODE_STRING && p_item->cells[i + plus].text.is_empty() && p_item->cells[i + plus].icon.is_null()) { w += get_column_width(i + plus); plus++; skip2++; @@ -1857,7 +1857,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 } break; case TreeItem::CELL_MODE_RANGE: { - if (p_item->cells[i].text != "") { + if (!p_item->cells[i].text.is_empty()) { if (!p_item->cells[i].editable) { break; } @@ -2337,7 +2337,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int if (p_item->cells[i].expand_right) { int plus = 1; - while (i + plus < columns.size() && !p_item->cells[i + plus].editable && p_item->cells[i + plus].mode == TreeItem::CELL_MODE_STRING && p_item->cells[i + plus].text == "" && p_item->cells[i + plus].icon.is_null()) { + while (i + plus < columns.size() && !p_item->cells[i + plus].editable && p_item->cells[i + plus].mode == TreeItem::CELL_MODE_STRING && p_item->cells[i + plus].text.is_empty() && p_item->cells[i + plus].icon.is_null()) { col_width += cache.hseparation; col_width += get_column_width(i + plus); plus++; @@ -2520,7 +2520,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int } break; case TreeItem::CELL_MODE_RANGE: { - if (c.text != "") { + if (!c.text.is_empty()) { //if (x >= (get_column_width(col)-item_h/2)) { popup_menu->clear(); for (int i = 0; i < c.text.get_slice_count(","); i++) { @@ -3430,7 +3430,7 @@ bool Tree::edit_selected() { item_edited(col, s); return true; - } else if (c.mode == TreeItem::CELL_MODE_RANGE && c.text != "") { + } else if (c.mode == TreeItem::CELL_MODE_RANGE && !c.text.is_empty()) { popup_menu->clear(); for (int i = 0; i < c.text.get_slice_count(","); i++) { String s2 = c.text.get_slicec(',', i); @@ -4679,7 +4679,7 @@ String Tree::get_tooltip(const Point2 &p_pos) const { Size2 size = b->get_size() + cache.button_pressed->get_minimum_size(); if (pos.x > col_width - size.width) { String tooltip = c.buttons[j].tooltip; - if (tooltip != "") { + if (!tooltip.is_empty()) { return tooltip; } } diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp index a4fcc04e20..4797729871 100644 --- a/scene/main/http_request.cpp +++ b/scene/main/http_request.cpp @@ -243,7 +243,7 @@ bool HTTPRequest::_handle_response(bool *ret_value) { } } - if (new_request != "") { + if (!new_request.is_empty()) { // Process redirect client->close(); int new_redirs = redirections + 1; // Because _request() will clear it @@ -363,7 +363,7 @@ bool HTTPRequest::_update_connection() { return true; } - if (download_to_file != String()) { + if (!download_to_file.is_empty()) { file = FileAccess::open(download_to_file, FileAccess::WRITE); if (!file) { call_deferred(SNAME("_request_done"), RESULT_DOWNLOAD_FILE_CANT_OPEN, response_code, response_headers, PackedByteArray()); diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 0d646ff2a9..87f77ed4bd 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -892,7 +892,7 @@ void Node::_set_name_nocheck(const StringName &p_name) { void Node::set_name(const String &p_name) { String name = p_name.validate_node_name(); - ERR_FAIL_COND(name == ""); + ERR_FAIL_COND(name.is_empty()); data.name = name; if (data.parent) { @@ -1990,7 +1990,7 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const nip->set_instance_path(ip->get_instance_path()); node = nip; - } else if ((p_flags & DUPLICATE_USE_INSTANCING) && get_scene_file_path() != String()) { + } else if ((p_flags & DUPLICATE_USE_INSTANCING) && !get_scene_file_path().is_empty()) { Ref<PackedScene> res = ResourceLoader::load(get_scene_file_path()); ERR_FAIL_COND_V(res.is_null(), nullptr); PackedScene::GenEditState ges = PackedScene::GEN_EDIT_STATE_DISABLED; @@ -2014,7 +2014,7 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const ERR_FAIL_COND_V(!node, nullptr); } - if (get_scene_file_path() != "") { //an instance + if (!get_scene_file_path().is_empty()) { //an instance node->set_scene_file_path(get_scene_file_path()); node->data.editable_instance = data.editable_instance; } @@ -2046,7 +2046,7 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const node_tree.push_back(descendant); - if (descendant->get_scene_file_path() != "" && instance_roots.has(descendant->get_owner())) { + if (!descendant->get_scene_file_path().is_empty() && instance_roots.has(descendant->get_owner())) { instance_roots.push_back(descendant); } } diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index a122241cd0..2af8024fe4 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -510,7 +510,7 @@ bool SceneTree::process(double p_time) { cpath = fallback->get_path(); } if (cpath != env_path) { - if (env_path != String()) { + if (!env_path.is_empty()) { fallback = ResourceLoader::load(env_path); if (fallback.is_null()) { //could not load fallback, set as empty @@ -1290,7 +1290,7 @@ void SceneTree::get_argument_options(const StringName &p_function, int p_idx, Li dir_access->list_dir_begin(); String filename = dir_access->get_next(); - while (filename != "") { + while (!filename.is_empty()) { if (filename == "." || filename == "..") { filename = dir_access->get_next(); continue; @@ -1400,7 +1400,7 @@ SceneTree::SceneTree() { ResourceLoader::get_recognized_extensions_for_type("Environment", &exts); String ext_hint; for (const String &E : exts) { - if (ext_hint != String()) { + if (!ext_hint.is_empty()) { ext_hint += ","; } ext_hint += "*." + E; @@ -1410,7 +1410,7 @@ SceneTree::SceneTree() { // Setup property. ProjectSettings::get_singleton()->set_custom_property_info("rendering/environment/defaults/default_environment", PropertyInfo(Variant::STRING, "rendering/viewport/default_environment", PROPERTY_HINT_FILE, ext_hint)); env_path = env_path.strip_edges(); - if (env_path != String()) { + if (!env_path.is_empty()) { Ref<Environment> env = ResourceLoader::load(env_path); if (env.is_valid()) { root->get_world_3d()->set_fallback_environment(env); diff --git a/scene/property_utils.cpp b/scene/property_utils.cpp index 7df601492b..e3c65bbc6e 100644 --- a/scene/property_utils.cpp +++ b/scene/property_utils.cpp @@ -164,7 +164,7 @@ Vector<SceneState::PackState> PropertyUtils::get_node_states_stack(const Node *p } } break; - } else if (n->get_scene_file_path() != String()) { + } else if (!n->get_scene_file_path().is_empty()) { const Ref<SceneState> &state = n->get_scene_instance_state(); _collect_inheritance_chain(state, n->get_path_to(p_node), states_stack); } diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index b56cd18930..9023b758b6 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -1046,7 +1046,7 @@ void initialize_theme() { ProjectSettings::get_singleton()->set_custom_property_info("gui/theme/custom_font", PropertyInfo(Variant::STRING, "gui/theme/custom_font", PROPERTY_HINT_FILE, "*.tres,*.res,*.font", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED)); Ref<Font> font; - if (font_path != String()) { + if (!font_path.is_empty()) { font = ResourceLoader::load(font_path); if (!font.is_valid()) { ERR_PRINT("Error loading custom font '" + font_path + "'"); @@ -1058,7 +1058,7 @@ void initialize_theme() { make_default_theme(default_theme_hidpi, font); } - if (theme_path != String()) { + if (!theme_path.is_empty()) { Ref<Theme> theme = ResourceLoader::load(theme_path); if (theme.is_valid()) { Theme::set_project_default(theme); diff --git a/scene/resources/importer_mesh.cpp b/scene/resources/importer_mesh.cpp index 7afa4c91f0..604b9e359f 100644 --- a/scene/resources/importer_mesh.cpp +++ b/scene/resources/importer_mesh.cpp @@ -653,7 +653,7 @@ Ref<ArrayMesh> ImporterMesh::get_mesh(const Ref<ArrayMesh> &p_base) { if (surfaces[i].material.is_valid()) { mesh->surface_set_material(mesh->get_surface_count() - 1, surfaces[i].material); } - if (surfaces[i].name != String()) { + if (!surfaces[i].name.is_empty()) { mesh->surface_set_name(mesh->get_surface_count() - 1, surfaces[i].name); } } @@ -839,7 +839,7 @@ Dictionary ImporterMesh::_get_data() const { d["material"] = surfaces[i].material; } - if (surfaces[i].name != String()) { + if (!surfaces[i].name.is_empty()) { d["name"] = surfaces[i].name; } diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index e14d6be235..bd63d17424 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -1104,7 +1104,7 @@ Array ArrayMesh::_get_surfaces() const { data["material"] = surfaces[i].material; } - if (surfaces[i].name != String()) { + if (!surfaces[i].name.is_empty()) { data["name"] = surfaces[i].name; } diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index c39f59d535..e6b499d4f1 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -417,7 +417,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map // save the child instantiated scenes that are chosen as editable, so they can be restored // upon load back - if (p_node != p_owner && p_node->get_scene_file_path() != String() && p_owner->is_editable_instance(p_node)) { + if (p_node != p_owner && !p_node->get_scene_file_path().is_empty() && p_owner->is_editable_instance(p_node)) { editable_instances.push_back(p_owner->get_path_to(p_node)); // Node is the root of an editable instance. is_editable_instance = true; @@ -451,7 +451,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map bool instantiated_by_owner = false; Vector<SceneState::PackState> states_stack = PropertyUtils::get_node_states_stack(p_node, p_owner, &instantiated_by_owner); - if (p_node->get_scene_file_path() != String() && p_node->get_owner() == p_owner && instantiated_by_owner) { + if (!p_node->get_scene_file_path().is_empty() && p_node->get_owner() == p_owner && instantiated_by_owner) { if (p_node->get_scene_instance_load_placeholder()) { //it's a placeholder, use the placeholder path nd.instance = _vm_get_variant(p_node->get_scene_file_path(), variant_map); @@ -656,7 +656,7 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName ERR_CONTINUE(!common_parent); - if (common_parent != p_owner && common_parent->get_scene_file_path() == String()) { + if (common_parent != p_owner && common_parent->get_scene_file_path().is_empty()) { common_parent = common_parent->get_owner(); } @@ -716,7 +716,7 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map<StringName nl = nullptr; } else { - if (nl->get_scene_file_path() != String()) { + if (!nl->get_scene_file_path().is_empty()) { //is an instance Ref<SceneState> state = nl->get_scene_instance_state(); if (state.is_valid()) { diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp index cead42b4e2..0e354ebff4 100644 --- a/scene/resources/resource_format_text.cpp +++ b/scene/resources/resource_format_text.cpp @@ -274,12 +274,12 @@ Ref<PackedScene> ResourceLoaderText::_parse_node_tag(VariantParser::ResourcePars } } - if (assign != String()) { + if (!assign.is_empty()) { int nameidx = packed_scene->get_state()->add_name(assign); int valueidx = packed_scene->get_state()->add_value(value); packed_scene->get_state()->add_node_property(node_id, nameidx, valueidx); //it's assignment - } else if (next_tag.name != String()) { + } else if (!next_tag.name.is_empty()) { break; } } @@ -575,12 +575,12 @@ Error ResourceLoaderText::load() { return error; } - if (assign != String()) { + if (!assign.is_empty()) { if (do_assign) { res->set(assign, value); } //it's assignment - } else if (next_tag.name != String()) { + } else if (!next_tag.name.is_empty()) { error = OK; break; } else { @@ -659,10 +659,10 @@ Error ResourceLoaderText::load() { return error; } - if (assign != String()) { + if (!assign.is_empty()) { resource->set(assign, value); //it's assignment - } else if (next_tag.name != String()) { + } else if (!next_tag.name.is_empty()) { error = ERR_FILE_CORRUPT; error_text = "Extra tag found when parsing main resource file"; _printerr(); @@ -1166,13 +1166,13 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path) return error; } - if (assign != String()) { + if (!assign.is_empty()) { Map<StringName, int> empty_string_map; //unused bs_save_unicode_string(wf2, assign, true); ResourceFormatSaverBinaryInstance::write_variant(wf2, value, dummy_read.resource_index_map, dummy_read.external_resources, empty_string_map); prop_count++; - } else if (next_tag.name != String()) { + } else if (!next_tag.name.is_empty()) { error = OK; break; } else { @@ -1350,7 +1350,7 @@ RES ResourceFormatLoaderText::load(const String &p_path, const String &p_origina ERR_FAIL_COND_V_MSG(err != OK, RES(), "Cannot open file '" + p_path + "'."); ResourceLoaderText loader; - String path = p_original_path != "" ? p_original_path : p_path; + String path = !p_original_path.is_empty() ? p_original_path : p_path; loader.cache_mode = p_cache_mode; loader.use_sub_threads = p_use_sub_threads; loader.local_path = ProjectSettings::get_singleton()->localize_path(path); @@ -1369,7 +1369,7 @@ RES ResourceFormatLoaderText::load(const String &p_path, const String &p_origina } void ResourceFormatLoaderText::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const { - if (p_type == "") { + if (p_type.is_empty()) { get_recognized_extensions(p_extensions); return; } @@ -1655,7 +1655,7 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r Set<String> cached_ids_found; for (KeyValue<RES, String> &E : external_resources) { String cached_id = E.key->get_id_for_path(local_path); - if (cached_id == "" || cached_ids_found.has(cached_id)) { + if (cached_id.is_empty() || cached_ids_found.has(cached_id)) { int sep_pos = E.value.find("_"); if (sep_pos != -1) { E.value = E.value.substr(0, sep_pos + 1); // Keep the order found, for improved thread loading performance. @@ -1729,7 +1729,7 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r for (List<RES>::Element *E = saved_resources.front(); E; E = E->next()) { RES res = E->get(); if (E->next() && res->is_built_in()) { - if (res->get_scene_unique_id() != "") { + if (!res->get_scene_unique_id().is_empty()) { if (used_unique_ids.has(res->get_scene_unique_id())) { res->set_scene_unique_id(""); // Repeated. } else { @@ -1752,7 +1752,7 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r f->store_line("[resource]"); } else { String line = "[sub_resource "; - if (res->get_scene_unique_id() == "") { + if (res->get_scene_unique_id().is_empty()) { String new_id; while (true) { new_id = res->get_class() + "_" + Resource::generate_scene_unique_id(); @@ -1866,7 +1866,7 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r f->store_string(header); - if (instance_placeholder != String()) { + if (!instance_placeholder.is_empty()) { String vars; f->store_string(" instance_placeholder="); VariantWriter::write_to_string(instance_placeholder, vars, _write_resources, this); diff --git a/scene/resources/syntax_highlighter.cpp b/scene/resources/syntax_highlighter.cpp index cfb5ac2ca6..800752d597 100644 --- a/scene/resources/syntax_highlighter.cpp +++ b/scene/resources/syntax_highlighter.cpp @@ -493,7 +493,7 @@ void CodeHighlighter::add_color_region(const String &p_start_key, const String & color_region.color = p_color; color_region.start_key = p_start_key; color_region.end_key = p_end_key; - color_region.line_only = p_line_only || p_end_key == ""; + color_region.line_only = p_line_only || p_end_key.is_empty(); color_regions.insert(at, color_region); clear_highlighting_cache(); } @@ -529,7 +529,7 @@ void CodeHighlighter::set_color_regions(const Dictionary &p_color_regions) { String start_key = key.get_slice(" ", 0); String end_key = key.get_slice_count(" ") > 1 ? key.get_slice(" ", 1) : String(); - add_color_region(start_key, end_key, p_color_regions[key], end_key == ""); + add_color_region(start_key, end_key, p_color_regions[key], end_key.is_empty()); } clear_highlighting_cache(); } diff --git a/scene/resources/text_file.cpp b/scene/resources/text_file.cpp index 33bb0a83e9..1dc46711f8 100644 --- a/scene/resources/text_file.cpp +++ b/scene/resources/text_file.cpp @@ -33,7 +33,7 @@ #include "core/io/file_access.h" bool TextFile::has_text() const { - return text != ""; + return !text.is_empty(); } String TextFile::get_text() const { diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 311bd9524b..13c3f6ea1d 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -553,7 +553,7 @@ Error StreamTexture2D::load(const String &p_path) { path_to_file = p_path; format = image->get_format(); - if (get_path() == String()) { + if (get_path().is_empty()) { //temporarily set path if no path set for resource, helps find errors RenderingServer::get_singleton()->texture_set_path(texture, p_path); } @@ -927,7 +927,7 @@ Error StreamTexture3D::load(const String &p_path) { path_to_file = p_path; - if (get_path() == String()) { + if (get_path().is_empty()) { //temporarily set path if no path set for resource, helps find errors RenderingServer::get_singleton()->texture_set_path(texture, p_path); } @@ -2680,7 +2680,7 @@ Error StreamTextureLayered::load(const String &p_path) { path_to_file = p_path; - if (get_path() == String()) { + if (get_path().is_empty()) { //temporarily set path if no path set for resource, helps find errors RenderingServer::get_singleton()->texture_set_path(texture, p_path); } diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index 41e78e0bc8..10e75fb023 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -979,7 +979,7 @@ String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port String VisualShader::validate_port_name(const String &p_port_name, VisualShaderNode *p_node, int p_port_id, bool p_output) const { String name = p_port_name; - if (name == String()) { + if (name.is_empty()) { return String(); } @@ -987,7 +987,7 @@ String VisualShader::validate_port_name(const String &p_port_name, VisualShaderN name = name.substr(1, name.length() - 1); } - if (name != String()) { + if (!name.is_empty()) { String valid_name; for (int i = 0; i < name.length(); i++) { @@ -1031,7 +1031,7 @@ String VisualShader::validate_uniform_name(const String &p_name, const Ref<Visua while (name.length() && !IS_INITIAL_CHAR(name[0])) { name = name.substr(1, name.length() - 1); } - if (name != String()) { + if (!name.is_empty()) { String valid_name; for (int i = 0; i < name.length(); i++) { @@ -1045,7 +1045,7 @@ String VisualShader::validate_uniform_name(const String &p_name, const Ref<Visua name = valid_name; } - if (name == String()) { + if (name.is_empty()) { name = p_uniform->get_caption(); } @@ -1075,7 +1075,7 @@ String VisualShader::validate_uniform_name(const String &p_name, const Ref<Visua while (name.length() && name[name.length() - 1] >= '0' && name[name.length() - 1] <= '9') { name = name.substr(0, name.length() - 1); } - ERR_FAIL_COND_V(name == String(), String()); + ERR_FAIL_COND_V(name.is_empty(), String()); name += itos(attempt); } else { break; @@ -1568,7 +1568,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui } node_code += vsnode->generate_code(get_mode(), type, node, inputs, outputs, for_preview); - if (node_code != String()) { + if (!node_code.is_empty()) { code += node_name; code += node_code; code += "\n"; @@ -1664,7 +1664,7 @@ void VisualShader::_update_shader() const { String mode = ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader_mode))[i]; if (mode.begins_with(render_mode_enums[idx].string)) { if (count == which) { - if (render_mode != String()) { + if (!render_mode.is_empty()) { render_mode += ", "; } render_mode += mode; @@ -1682,7 +1682,7 @@ void VisualShader::_update_shader() const { for (int i = 0; i < ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader_mode)).size(); i++) { String mode = ShaderTypes::get_singleton()->get_modes(RenderingServer::ShaderMode(shader_mode))[i]; if (flags.has(mode)) { - if (render_mode != String()) { + if (!render_mode.is_empty()) { render_mode += ", "; } render_mode += mode; @@ -1690,7 +1690,7 @@ void VisualShader::_update_shader() const { } } - if (render_mode != String()) { + if (!render_mode.is_empty()) { global_code += "render_mode " + render_mode + ";\n\n"; } @@ -2468,7 +2468,7 @@ String VisualShaderNodeInput::generate_code(Shader::Mode p_mode, VisualShader::T idx++; } - if (code == String()) { + if (code.is_empty()) { switch (get_output_port_type(0)) { case PORT_TYPE_SCALAR: { code = " " + p_output_vars[0] + " = 0.0;\n"; @@ -2502,7 +2502,7 @@ String VisualShaderNodeInput::generate_code(Shader::Mode p_mode, VisualShader::T idx++; } - if (code == String()) { + if (code.is_empty()) { code = " " + p_output_vars[0] + " = 0.0;\n"; //default (none found) is scalar } @@ -2605,7 +2605,7 @@ void VisualShaderNodeInput::_validate_property(PropertyInfo &property) const { while (ports[idx].mode != Shader::MODE_MAX) { if (ports[idx].mode == shader_mode && ports[idx].shader_type == shader_type) { - if (port_list != String()) { + if (!port_list.is_empty()) { port_list += ","; } port_list += ports[idx].name; @@ -2613,7 +2613,7 @@ void VisualShaderNodeInput::_validate_property(PropertyInfo &property) const { idx++; } - if (port_list == "") { + if (port_list.is_empty()) { port_list = TTR("None"); } property.hint_string = port_list; @@ -3063,7 +3063,7 @@ String VisualShaderNodeOutput::generate_code(Shader::Mode p_mode, VisualShader:: String code; while (ports[idx].mode != Shader::MODE_MAX) { if (ports[idx].mode == shader_mode && ports[idx].shader_type == shader_type) { - if (p_input_vars[count] != String()) { + if (!p_input_vars[count].is_empty()) { String s = ports[idx].string; if (s.find(":") != -1) { code += " " + s.get_slicec(':', 0) + " = " + p_input_vars[count] + "." + s.get_slicec(':', 1) + ";\n"; diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp index e6870971d4..51e7ec8092 100644 --- a/scene/resources/visual_shader_nodes.cpp +++ b/scene/resources/visual_shader_nodes.cpp @@ -535,15 +535,15 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader: if (source == SOURCE_TEXTURE) { String id = make_unique_id(p_type, p_id, "tex"); String code; - if (p_input_vars[0] == String()) { // Use UV by default. + if (p_input_vars[0].is_empty()) { // Use UV by default. - if (p_input_vars[1] == String()) { + if (p_input_vars[1].is_empty()) { code += " vec4 " + id + "_read = texture(" + id + ", " + default_uv + ");\n"; } else { code += " vec4 " + id + "_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n"; } - } else if (p_input_vars[1] == String()) { + } else if (p_input_vars[1].is_empty()) { //no lod code += " vec4 " + id + "_read = texture(" + id + ", " + p_input_vars[0] + ".xy);\n"; } else { @@ -560,18 +560,18 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader: String code; code += " {\n"; - if (id == String()) { + if (id.is_empty()) { code += " vec4 " + id + "_tex_read = vec4(0.0);\n"; } else { - if (p_input_vars[0] == String()) { // Use UV by default. + if (p_input_vars[0].is_empty()) { // Use UV by default. - if (p_input_vars[1] == String()) { + if (p_input_vars[1].is_empty()) { code += " vec4 " + id + "_tex_read = texture(" + id + ", " + default_uv + ");\n"; } else { code += " vec4 " + id + "_tex_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n"; } - } else if (p_input_vars[1] == String()) { + } else if (p_input_vars[1].is_empty()) { //no lod code += " vec4 " + id + "_tex_read = texture(" + id + ", " + p_input_vars[0] + ".xy);\n"; } else { @@ -587,15 +587,15 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader: if (source == SOURCE_SCREEN && (p_mode == Shader::MODE_SPATIAL || p_mode == Shader::MODE_CANVAS_ITEM) && p_type == VisualShader::TYPE_FRAGMENT) { String code = " {\n"; - if (p_input_vars[0] == String() || p_for_preview) { // Use UV by default. + if (p_input_vars[0].is_empty() || p_for_preview) { // Use UV by default. - if (p_input_vars[1] == String()) { + if (p_input_vars[1].is_empty()) { code += " vec4 _tex_read = textureLod(SCREEN_TEXTURE, " + default_uv + ", 0.0 );\n"; } else { code += " vec4 _tex_read = textureLod(SCREEN_TEXTURE, " + default_uv + ", " + p_input_vars[1] + ");\n"; } - } else if (p_input_vars[1] == String()) { + } else if (p_input_vars[1].is_empty()) { //no lod code += " vec4 _tex_read = textureLod(SCREEN_TEXTURE, " + p_input_vars[0] + ".xy, 0.0);\n"; } else { @@ -610,15 +610,15 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader: if (source == SOURCE_2D_TEXTURE && p_mode == Shader::MODE_CANVAS_ITEM && p_type == VisualShader::TYPE_FRAGMENT) { String code = " {\n"; - if (p_input_vars[0] == String()) { // Use UV by default. + if (p_input_vars[0].is_empty()) { // Use UV by default. - if (p_input_vars[1] == String()) { + if (p_input_vars[1].is_empty()) { code += " vec4 _tex_read = texture(TEXTURE, " + default_uv + ");\n"; } else { code += " vec4 _tex_read = textureLod(TEXTURE, " + default_uv + ", " + p_input_vars[1] + ");\n"; } - } else if (p_input_vars[1] == String()) { + } else if (p_input_vars[1].is_empty()) { //no lod code += " vec4 _tex_read = texture(TEXTURE, " + p_input_vars[0] + ".xy);\n"; } else { @@ -633,15 +633,15 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader: if (source == SOURCE_2D_NORMAL && p_mode == Shader::MODE_CANVAS_ITEM && p_type == VisualShader::TYPE_FRAGMENT) { String code = " {\n"; - if (p_input_vars[0] == String()) { // Use UV by default. + if (p_input_vars[0].is_empty()) { // Use UV by default. - if (p_input_vars[1] == String()) { + if (p_input_vars[1].is_empty()) { code += " vec4 _tex_read = texture(NORMAL_TEXTURE, " + default_uv + ");\n"; } else { code += " vec4 _tex_read = textureLod(NORMAL_TEXTURE, " + default_uv + ", " + p_input_vars[1] + ");\n"; } - } else if (p_input_vars[1] == String()) { + } else if (p_input_vars[1].is_empty()) { //no lod code += " vec4 _tex_read = texture(NORMAL_TEXTURE, " + p_input_vars[0] + ".xy);\n"; } else { @@ -666,15 +666,15 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader: if (source == SOURCE_DEPTH && p_mode == Shader::MODE_SPATIAL && p_type == VisualShader::TYPE_FRAGMENT) { String code = " {\n"; - if (p_input_vars[0] == String()) { // Use UV by default. + if (p_input_vars[0].is_empty()) { // Use UV by default. - if (p_input_vars[1] == String()) { + if (p_input_vars[1].is_empty()) { code += " float _depth = texture(DEPTH_TEXTURE, " + default_uv + ").r;\n"; } else { code += " float _depth = textureLod(DEPTH_TEXTURE, " + default_uv + ", " + p_input_vars[1] + ").r;\n"; } - } else if (p_input_vars[1] == String()) { + } else if (p_input_vars[1].is_empty()) { //no lod code += " float _depth = texture(DEPTH_TEXTURE, " + p_input_vars[0] + ".xy).r;\n"; } else { @@ -883,7 +883,7 @@ String VisualShaderNodeCurveTexture::generate_global(Shader::Mode p_mode, Visual } String VisualShaderNodeCurveTexture::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - if (p_input_vars[0] == String()) { + if (p_input_vars[0].is_empty()) { return " " + p_output_vars[0] + " = 0.0;\n"; } String id = make_unique_id(p_type, p_id, "curve"); @@ -968,7 +968,7 @@ String VisualShaderNodeCurveXYZTexture::generate_global(Shader::Mode p_mode, Vis } String VisualShaderNodeCurveXYZTexture::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - if (p_input_vars[0] == String()) { + if (p_input_vars[0].is_empty()) { return " " + p_output_vars[0] + " = vec3(0.0);\n"; } String id = make_unique_id(p_type, p_id, "curve3d"); @@ -1076,14 +1076,14 @@ String VisualShaderNodeSample3D::generate_code(Shader::Mode p_mode, VisualShader } else { id = p_input_vars[2]; } - if (id != String()) { - if (p_input_vars[0] == String()) { // Use UV by default. - if (p_input_vars[1] == String()) { + if (!id.is_empty()) { + if (p_input_vars[0].is_empty()) { // Use UV by default. + if (p_input_vars[1].is_empty()) { code += " vec4 " + id + "_tex_read = texture(" + id + ", " + default_uv + ");\n"; } else { code += " vec4 " + id + "_tex_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n"; } - } else if (p_input_vars[1] == String()) { + } else if (p_input_vars[1].is_empty()) { //no lod code += " vec4 " + id + "_tex_read = texture(" + id + ", " + p_input_vars[0] + ");\n"; } else { @@ -1364,7 +1364,7 @@ String VisualShaderNodeCubemap::generate_code(Shader::Mode p_mode, VisualShader: code += " {\n"; - if (id == String()) { + if (id.is_empty()) { code += " vec4 " + id + "_read = vec4(0.0);\n"; code += " " + p_output_vars[0] + " = " + id + "_read.rgb;\n"; code += " " + p_output_vars[1] + " = " + id + "_read.a;\n"; @@ -1372,15 +1372,15 @@ String VisualShaderNodeCubemap::generate_code(Shader::Mode p_mode, VisualShader: return code; } - if (p_input_vars[0] == String()) { // Use UV by default. + if (p_input_vars[0].is_empty()) { // Use UV by default. - if (p_input_vars[1] == String()) { + if (p_input_vars[1].is_empty()) { code += " vec4 " + id + "_read = texture(" + id + ", " + default_uv + ");\n"; } else { code += " vec4 " + id + "_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + " );\n"; } - } else if (p_input_vars[1] == String()) { + } else if (p_input_vars[1].is_empty()) { //no lod code += " vec4 " + id + "_read = texture(" + id + ", " + p_input_vars[0] + ");\n"; } else { @@ -4902,13 +4902,13 @@ String VisualShaderNodeTextureUniform::generate_code(Shader::Mode p_mode, Visual String id = get_uniform_name(); String code = " {\n"; - if (p_input_vars[0] == String()) { // Use UV by default. - if (p_input_vars[1] == String()) { + if (p_input_vars[0].is_empty()) { // Use UV by default. + if (p_input_vars[1].is_empty()) { code += " vec4 n_tex_read = texture(" + id + ", " + default_uv + ");\n"; } else { code += " vec4 n_tex_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n"; } - } else if (p_input_vars[1] == String()) { + } else if (p_input_vars[1].is_empty()) { //no lod code += " vec4 n_tex_read = texture(" + id + ", " + p_input_vars[0] + ".xy);\n"; } else { @@ -5070,11 +5070,11 @@ String VisualShaderNodeTextureUniformTriplanar::generate_code(Shader::Mode p_mod String id = get_uniform_name(); String code = " {\n"; - if (p_input_vars[0] == String() && p_input_vars[1] == String()) { + if (p_input_vars[0].is_empty() && p_input_vars[1].is_empty()) { code += " vec4 n_tex_read = triplanar_texture(" + id + ", triplanar_power_normal, triplanar_pos);\n"; - } else if (p_input_vars[0] != String() && p_input_vars[1] == String()) { + } else if (!p_input_vars[0].is_empty() && p_input_vars[1].is_empty()) { code += " vec4 n_tex_read = triplanar_texture(" + id + ", " + p_input_vars[0] + ", triplanar_pos);\n"; - } else if (p_input_vars[0] == String() && p_input_vars[1] != String()) { + } else if (p_input_vars[0].is_empty() && !p_input_vars[1].is_empty()) { code += " vec4 n_tex_read = triplanar_texture(" + id + ", triplanar_power_normal, " + p_input_vars[1] + ");\n"; } else { code += " vec4 n_tex_read = triplanar_texture(" + id + ", " + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; @@ -5600,12 +5600,12 @@ bool VisualShaderNodeFresnel::is_generate_input_var(int p_port) const { String VisualShaderNodeFresnel::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { String normal; String view; - if (p_input_vars[0] == String()) { + if (p_input_vars[0].is_empty()) { normal = "NORMAL"; } else { normal = p_input_vars[0]; } - if (p_input_vars[1] == String()) { + if (p_input_vars[1].is_empty()) { view = "VIEW"; } else { view = p_input_vars[1]; diff --git a/scene/resources/visual_shader_sdf_nodes.cpp b/scene/resources/visual_shader_sdf_nodes.cpp index 14c655b129..0fe7c33396 100644 --- a/scene/resources/visual_shader_sdf_nodes.cpp +++ b/scene/resources/visual_shader_sdf_nodes.cpp @@ -61,7 +61,7 @@ String VisualShaderNodeSDFToScreenUV::get_output_port_name(int p_port) const { } String VisualShaderNodeSDFToScreenUV::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - return " " + p_output_vars[0] + " = vec3(sdf_to_screen_uv(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + "), 0.0f);\n"; + return " " + p_output_vars[0] + " = vec3(sdf_to_screen_uv(" + (p_input_vars[0].is_empty() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + "), 0.0f);\n"; } VisualShaderNodeSDFToScreenUV::VisualShaderNodeSDFToScreenUV() { @@ -105,7 +105,7 @@ String VisualShaderNodeScreenUVToSDF::get_input_port_default_hint(int p_port) co } String VisualShaderNodeScreenUVToSDF::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - return " " + p_output_vars[0] + " = vec3(screen_uv_to_sdf(" + (p_input_vars[0] == String() ? "SCREEN_UV" : p_input_vars[0] + ".xy") + "), 0.0f);\n"; + return " " + p_output_vars[0] + " = vec3(screen_uv_to_sdf(" + (p_input_vars[0].is_empty() ? "SCREEN_UV" : p_input_vars[0] + ".xy") + "), 0.0f);\n"; } VisualShaderNodeScreenUVToSDF::VisualShaderNodeScreenUVToSDF() { @@ -142,7 +142,7 @@ String VisualShaderNodeTextureSDF::get_output_port_name(int p_port) const { } String VisualShaderNodeTextureSDF::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - return " " + p_output_vars[0] + " = texture_sdf(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + ");\n"; + return " " + p_output_vars[0] + " = texture_sdf(" + (p_input_vars[0].is_empty() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + ");\n"; } VisualShaderNodeTextureSDF::VisualShaderNodeTextureSDF() { @@ -179,7 +179,7 @@ String VisualShaderNodeTextureSDFNormal::get_output_port_name(int p_port) const } String VisualShaderNodeTextureSDFNormal::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const { - return " " + p_output_vars[0] + " = vec3(texture_sdf_normal(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + "), 0.0f);\n"; + return " " + p_output_vars[0] + " = vec3(texture_sdf_normal(" + (p_input_vars[0].is_empty() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + "), 0.0f);\n"; } VisualShaderNodeTextureSDFNormal::VisualShaderNodeTextureSDFNormal() { @@ -242,13 +242,13 @@ String VisualShaderNodeSDFRaymarch::generate_code(Shader::Mode p_mode, VisualSha code += " {\n"; - if (p_input_vars[0] == String()) { + if (p_input_vars[0].is_empty()) { code += " vec2 __from_pos = vec2(0.0f);\n"; } else { code += " vec2 __from_pos = " + p_input_vars[0] + ".xy;\n"; } - if (p_input_vars[1] == String()) { + if (p_input_vars[1].is_empty()) { code += " vec2 __to_pos = vec2(0.0f);\n"; } else { code += " vec2 __to_pos = " + p_input_vars[1] + ".xy;\n"; |