Merge pull request #63496 from groud/fix_tile_set_not_saving

Fix TileSet not loading correctly when embedded in a scene
This commit is contained in:
Rémi Verschelde 2022-07-26 18:27:05 +02:00 committed by GitHub
commit 222e489dfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 17 deletions

View File

@ -226,14 +226,14 @@ void TilesEditorPlugin::synchronize_sources_list(Object *p_current_list, Object
} }
if (item_list->is_visible_in_tree()) { if (item_list->is_visible_in_tree()) {
if (atlas_sources_lists_current < 0 || atlas_sources_lists_current >= item_list->get_item_count()) {
item_list->deselect_all();
} else {
// Make sure the selection is not overwritten after sorting. // Make sure the selection is not overwritten after sorting.
int atlas_sources_lists_current_mem = atlas_sources_lists_current; int atlas_sources_lists_current_mem = atlas_sources_lists_current;
item_list->emit_signal(SNAME("sort_request")); item_list->emit_signal(SNAME("sort_request"));
atlas_sources_lists_current = atlas_sources_lists_current_mem; atlas_sources_lists_current = atlas_sources_lists_current_mem;
if (atlas_sources_lists_current < 0 || atlas_sources_lists_current >= item_list->get_item_count()) {
item_list->deselect_all();
} else {
item_list->set_current(atlas_sources_lists_current); item_list->set_current(atlas_sources_lists_current);
item_list->ensure_current_is_visible(); item_list->ensure_current_is_visible();
item_list->emit_signal(SNAME("item_selected"), atlas_sources_lists_current); item_list->emit_signal(SNAME("item_selected"), atlas_sources_lists_current);

View File

@ -2467,9 +2467,42 @@ Vector<Point2> TileSet::_get_half_offset_side_terrain_peering_bit_polygon(Vector
} }
void TileSet::reset_state() { void TileSet::reset_state() {
// Rendering
occlusion_layers.clear(); occlusion_layers.clear();
tile_lines_mesh.instantiate();
tile_filled_mesh.instantiate();
tile_meshes_dirty = true;
// Physics
physics_layers.clear(); physics_layers.clear();
// Terrains
terrain_sets.clear();
terrain_meshes.clear();
terrain_peering_bits_meshes.clear();
per_terrain_pattern_tiles.clear();
terrains_cache_dirty = true;
// Navigation
navigation_layers.clear();
custom_data_layers.clear(); custom_data_layers.clear();
custom_data_layers_by_name.clear();
// Proxies
source_level_proxies.clear();
coords_level_proxies.clear();
alternative_level_proxies.clear();
#ifndef DISABLE_DEPRECATED
for (const KeyValue<int, CompatibilityTileData *> &E : compatibility_data) {
memdelete(E.value);
}
compatibility_data.clear();
#endif // DISABLE_DEPRECATED
while (!source_ids.is_empty()) {
remove_source(source_ids[0]);
}
} }
const Vector2i TileSetSource::INVALID_ATLAS_COORDS = Vector2i(-1, -1); const Vector2i TileSetSource::INVALID_ATLAS_COORDS = Vector2i(-1, -1);
@ -3457,6 +3490,10 @@ void TileSetSource::set_tile_set(const TileSet *p_tile_set) {
tile_set = p_tile_set; tile_set = p_tile_set;
} }
void TileSetSource::reset_state() {
tile_set = nullptr;
};
void TileSetSource::_bind_methods() { void TileSetSource::_bind_methods() {
// Base tiles // Base tiles
ClassDB::bind_method(D_METHOD("get_tiles_count"), &TileSetSource::get_tiles_count); ClassDB::bind_method(D_METHOD("get_tiles_count"), &TileSetSource::get_tiles_count);
@ -3640,12 +3677,17 @@ void TileSetAtlasSource::remove_custom_data_layer(int p_index) {
} }
void TileSetAtlasSource::reset_state() { void TileSetAtlasSource::reset_state() {
// Reset all TileData. tile_set = nullptr;
for (KeyValue<Vector2i, TileAlternativesData> &E_tile : tiles) { for (KeyValue<Vector2i, TileAlternativesData> &E_tile : tiles) {
for (KeyValue<int, TileData *> &E_alternative : E_tile.value.alternatives) { for (const KeyValue<int, TileData *> &E_tile_data : E_tile.value.alternatives) {
E_alternative.value->reset_state(); memdelete(E_tile_data.value);
} }
} }
_coords_mapping_cache.clear();
tiles.clear();
tiles_ids.clear();
_queue_update_padded_texture();
} }
void TileSetAtlasSource::set_texture(Ref<Texture2D> p_texture) { void TileSetAtlasSource::set_texture(Ref<Texture2D> p_texture) {
@ -4975,13 +5017,6 @@ void TileData::remove_custom_data_layer(int p_index) {
custom_data.remove_at(p_index); custom_data.remove_at(p_index);
} }
void TileData::reset_state() {
occluders.clear();
physics.clear();
navigation.clear();
custom_data.clear();
}
void TileData::set_allow_transform(bool p_allow_transform) { void TileData::set_allow_transform(bool p_allow_transform) {
allow_transform = p_allow_transform; allow_transform = p_allow_transform;
} }

View File

@ -569,7 +569,7 @@ public:
virtual void add_custom_data_layer(int p_index){}; virtual void add_custom_data_layer(int p_index){};
virtual void move_custom_data_layer(int p_from_index, int p_to_pos){}; virtual void move_custom_data_layer(int p_from_index, int p_to_pos){};
virtual void remove_custom_data_layer(int p_index){}; virtual void remove_custom_data_layer(int p_index){};
virtual void reset_state() override{}; virtual void reset_state() override;
// Tiles. // Tiles.
virtual int get_tiles_count() const = 0; virtual int get_tiles_count() const = 0;
@ -847,7 +847,6 @@ public:
void add_custom_data_layer(int p_index); void add_custom_data_layer(int p_index);
void move_custom_data_layer(int p_from_index, int p_to_pos); void move_custom_data_layer(int p_from_index, int p_to_pos);
void remove_custom_data_layer(int p_index); void remove_custom_data_layer(int p_index);
void reset_state();
void set_allow_transform(bool p_allow_transform); void set_allow_transform(bool p_allow_transform);
bool is_allowing_transform() const; bool is_allowing_transform() const;