Skip to content

Commit

Permalink
Propagate file system changes to Pandora data (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
shomykohai authored Sep 18, 2024
1 parent a92bb2f commit 0cfcc8b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions addons/pandora/ui/editor/pandora_editor.gd
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func _ready() -> void:
Pandora.data_loaded_failure.connect(self._data_load_failure)
Pandora.import_progress.connect(self._on_progress)

# Handle file system changes
if Engine.is_editor_hint():
EditorInterface.get_file_system_dock().file_removed.connect(_handle_file_deleted)
EditorInterface.get_file_system_dock().files_moved.connect(_handle_file_moved)

func reattempt_load_on_error() -> void:
if _load_error:
Expand Down Expand Up @@ -194,3 +198,33 @@ func _on_import_ended(data: Array[PandoraEntity]) -> void:
save_button.disabled = false
reset_button.disabled = false
import_button.disabled = false


func _handle_file_moved(old_path: String, new_path: String) -> void:
var entities: Array[PandoraEntity] = []
entities.append_array(Pandora.get_all_entities())
entities.append_array(Pandora.get_all_categories())
for entity in entities:
if entity.get_icon_path() == old_path:
entity._icon_path = new_path

# Handle properties which we can't automatically update,
# like strings. We don't need to update resources as they
# are automatically updated by the engine.
for property in entity._properties:
if property.get_property_type() == null:
continue
if property.get_default_value() == null:
continue
if property.get_property_type()._type_name == "string" && property._default_value == old_path:
property._default_value = new_path
await Engine.get_main_loop().process_frame

Pandora.save_data()
_populate_data.call_deferred()
for property in property_editor.property_list.get_children():
property._refresh()

func _handle_file_deleted(file: String) -> void:
await _handle_file_moved(file, "")

0 comments on commit 0cfcc8b

Please sign in to comment.