From b7bfd13ec4abcd1145e2445921c969e801b1cba1 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 7 Apr 2025 17:37:26 +0200 Subject: [PATCH] Added a force save all chunks button to TerrainWorld's inspector if a TerrainWorldChunkDataManager is set. --- modules/terraman/world/terrain_world.cpp | 14 ++++++++++++++ modules/terraman/world/terrain_world.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/modules/terraman/world/terrain_world.cpp b/modules/terraman/world/terrain_world.cpp index 796315c5c..467913509 100644 --- a/modules/terraman/world/terrain_world.cpp +++ b/modules/terraman/world/terrain_world.cpp @@ -1505,6 +1505,18 @@ void TerrainWorld::_generate_chunk(Ref chunk) { } } +void TerrainWorld::_editor_button_property_pressed(const StringName &p_property) { + if (p_property == "force_save_all_chunks") { + force_save_all_chunks(); + } +} + +void TerrainWorld::_get_property_list(List *p_list) const { + if (_world_chunk_data_manager.is_valid()) { + p_list->push_back(PropertyInfo(Variant::NIL, "force_save_all_chunks", PROPERTY_HINT_BUTTON, "_editor_button_property_pressed:Save/EditorIcons")); + } +} + void TerrainWorld::_validate_property(PropertyInfo &property) const { if (property.name == "chunks") { if (_world_chunk_data_manager.is_valid()) { @@ -1872,6 +1884,8 @@ void TerrainWorld::_bind_methods() { ClassDB::bind_method(D_METHOD("get_editor_camera"), &TerrainWorld::get_editor_camera); + ClassDB::bind_method(D_METHOD("_editor_button_property_pressed"), &TerrainWorld::_editor_button_property_pressed); + #ifdef MODULE_VERTEX_LIGHTS_3D_ENABLED ClassDB::bind_method(D_METHOD("_on_vertex_lights_3d_map_changed"), &TerrainWorld::_on_vertex_lights_3d_map_changed); #endif diff --git a/modules/terraman/world/terrain_world.h b/modules/terraman/world/terrain_world.h index fc9a7c580..6e22bc387 100644 --- a/modules/terraman/world/terrain_world.h +++ b/modules/terraman/world/terrain_world.h @@ -240,6 +240,8 @@ protected: virtual Ref _create_chunk(int x, int z, Ref p_chunk); virtual int _get_channel_index_info(const ChannelTypeInfo channel_type); + void _editor_button_property_pressed(const StringName &p_property); + void _get_property_list(List *p_list) const; virtual void _validate_property(PropertyInfo &property) const; virtual void _notification(int p_what); static void _bind_methods();