Repository: godotengine/godot
File: editor/plugins/sprite_frames_editor_plugin.cpp (C++)

Code before:
void SpriteFramesEditor::_prepare_sprite_sheet(const String &p_file) {
	Ref<Texture2D> texture = ResourceLoader::load(p_file);
	if (texture.is_null()) {
		EditorNode::get_singleton()->show_warning(TTR("Unable to load images"));
		ERR_FAIL_COND(texture.is_null());
	}
	frames_selected.clear();
	selected_count = 0;
	last_frame_selected = -1;

	bool new_texture = texture != split_sheet_preview->get_texture();
	split_sheet_preview->set_texture(texture);
	if (new_texture) {
		// Reset spin max.
		const Size2i size = texture->get_size();
		split_sheet_size_x->set_max(size.x);
		split_sheet_size_y->set_max(size.y);
		split_sheet_sep_x->set_max(size.x);
		split_sheet_sep_y->set_max(size.y);
		split_sheet_offset_x->set_max(size.x);
		split_sheet_offset_y->set_max(size.y);

		// Different texture, reset to 4x4.
		dominant_param = PARAM_FRAME_COUNT;
		updating_split_settings = true;
		split_sheet_h->set_value(4);
		split_sheet_v->set_value(4);
		split_sheet_size_x->set_value(size.x / 4);
		split_sheet_size_y->set_value(size.y / 4);
		split_sheet_sep_x->set_value(0);
		split_sheet_sep_y->set_value(0);
		split_sheet_offset_x->set_value(0);
		split_sheet_offset_y->set_value(0);
		updating_split_settings = false;

		// Reset zoom.
		_sheet_zoom_reset();
	}

	split_sheet_dialog->popup_centered_ratio(0.65);
}

void SpriteFramesEditor::_notification(int p_what) {
	switch (p_what) {
		case NOTIFICATION_ENTER_TREE: {
			get_tree()->connect("node_removed", callable_mp(this, &SpriteFramesEditor::_node_removed));

			[[fallthrough]];
		}
		case NOTIFICATION_THEME_CHANGED: {
			autoplay_icon = get_editor_theme_icon(SNAME("AutoPlay"));

Review comment (suggestion):
Is `first_time_opened` even needed? `previous_texture_size` is zero initially, so the new size will always be different.

Code after:
void SpriteFramesEditor::_prepare_sprite_sheet(const String &p_file) {
	Ref<Texture2D> texture = ResourceLoader::load(p_file);
	if (texture.is_null()) {
		EditorNode::get_singleton()->show_warning(TTR("Unable to load images"));
		ERR_FAIL_COND(texture.is_null());
	}
	frames_selected.clear();
	selected_count = 0;
	last_frame_selected = -1;

	bool new_texture = texture != split_sheet_preview->get_texture();
	split_sheet_preview->set_texture(texture);
	if (new_texture) {
		// Reset spin max.
		const Size2i size = texture->get_size();
		split_sheet_size_x->set_max(size.x);
		split_sheet_size_y->set_max(size.y);
		split_sheet_sep_x->set_max(size.x);
		split_sheet_sep_y->set_max(size.y);
		split_sheet_offset_x->set_max(size.x);
		split_sheet_offset_y->set_max(size.y);

		if (size != previous_texture_size) {
			// Different texture, reset to 4x4.
			dominant_param = PARAM_FRAME_COUNT;
			updating_split_settings = true;
			split_sheet_h->set_value(4);
			split_sheet_v->set_value(4);
			split_sheet_size_x->set_value(size.x / 4);
			split_sheet_size_y->set_value(size.y / 4);
			split_sheet_sep_x->set_value(0);
			split_sheet_sep_y->set_value(0);
			split_sheet_offset_x->set_value(0);
			split_sheet_offset_y->set_value(0);
			updating_split_settings = false;
		}
		previous_texture_size = size;

		// Reset zoom.
		_sheet_zoom_reset();
	}

	split_sheet_dialog->popup_centered_ratio(0.65);
}

void SpriteFramesEditor::_notification(int p_what) {
	switch (p_what) {
		case NOTIFICATION_ENTER_TREE: {
			get_tree()->connect("node_removed", callable_mp(this, &SpriteFramesEditor::_node_removed));

			[[fallthrough]];