From 6b69ae8dd09bc7e94f6c7c254c651641dc0ed40c Mon Sep 17 00:00:00 2001 From: kobewi Date: Wed, 17 Apr 2024 20:43:00 +0200 Subject: [PATCH] Reuse single erase pattern in tile editor --- editor/plugins/tiles/tile_map_layer_editor.cpp | 12 +++--------- editor/plugins/tiles/tile_map_layer_editor.h | 1 + 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/editor/plugins/tiles/tile_map_layer_editor.cpp b/editor/plugins/tiles/tile_map_layer_editor.cpp index e1a58a0998c0..f177245acc21 100644 --- a/editor/plugins/tiles/tile_map_layer_editor.cpp +++ b/editor/plugins/tiles/tile_map_layer_editor.cpp @@ -1079,9 +1079,6 @@ HashMap TileMapLayerEditorTilesPlugin::_draw_line(Vector2 } // Get or create the pattern. - Ref erase_pattern; - erase_pattern.instantiate(); - erase_pattern->set_cell(Vector2i(0, 0), TileSet::INVALID_SOURCE, TileSetSource::INVALID_ATLAS_COORDS, TileSetSource::INVALID_TILE_ALTERNATIVE); Ref pattern = p_erase ? erase_pattern : selection_pattern; HashMap output; @@ -1132,9 +1129,6 @@ HashMap TileMapLayerEditorTilesPlugin::_draw_rect(Vector2 rect.size += Vector2i(1, 1); // Get or create the pattern. - Ref erase_pattern; - erase_pattern.instantiate(); - erase_pattern->set_cell(Vector2i(0, 0), TileSet::INVALID_SOURCE, TileSetSource::INVALID_ATLAS_COORDS, TileSetSource::INVALID_TILE_ALTERNATIVE); Ref pattern = p_erase ? erase_pattern : selection_pattern; HashMap err_output; @@ -1189,9 +1183,6 @@ HashMap TileMapLayerEditorTilesPlugin::_draw_bucket_fill( HashMap output; // Get or create the pattern. - Ref erase_pattern; - erase_pattern.instantiate(); - erase_pattern->set_cell(Vector2i(0, 0), TileSet::INVALID_SOURCE, TileSetSource::INVALID_ATLAS_COORDS, TileSetSource::INVALID_TILE_ALTERNATIVE); Ref pattern = p_erase ? erase_pattern : selection_pattern; if (!pattern->is_empty()) { @@ -2200,6 +2191,9 @@ TileMapLayerEditorTilesPlugin::TileMapLayerEditorTilesPlugin() { tile_map_clipboard.instantiate(); selection_pattern.instantiate(); + erase_pattern.instantiate(); + erase_pattern->set_cell(Vector2i(0, 0), TileSet::INVALID_SOURCE, TileSetSource::INVALID_ATLAS_COORDS, TileSetSource::INVALID_TILE_ALTERNATIVE); + // --- Toolbar --- toolbar = memnew(HBoxContainer); diff --git a/editor/plugins/tiles/tile_map_layer_editor.h b/editor/plugins/tiles/tile_map_layer_editor.h index 26032614495e..7d749be1bacd 100644 --- a/editor/plugins/tiles/tile_map_layer_editor.h +++ b/editor/plugins/tiles/tile_map_layer_editor.h @@ -154,6 +154,7 @@ private: RBSet tile_map_selection; Ref tile_map_clipboard; Ref selection_pattern; + Ref erase_pattern; void _set_tile_map_selection(const TypedArray &p_selection); TypedArray _get_tile_map_selection() const;