From 84687d2141c9c5a2e09742c5463e06f97f443a17 Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Wed, 26 Feb 2020 23:42:19 +0100 Subject: [PATCH] Detect correctly when loading incorrect files --- material_maker/graph_edit.gd | 17 +++++++++++++---- material_maker/main_window.gd | 12 +++++++----- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/material_maker/graph_edit.gd b/material_maker/graph_edit.gd index 9892eea..bb8922e 100644 --- a/material_maker/graph_edit.gd +++ b/material_maker/graph_edit.gd @@ -211,16 +211,25 @@ func create_nodes(data, position : Vector2 = Vector2(0, 0)) -> Array: func create_gen_from_type(gen_name) -> void: create_nodes({ type=gen_name, parameters={} }, scroll_offset+0.5*rect_size) -func load_file(filename) -> void: - clear_material() - top_generator = mm_loader.load_gen(filename) - if top_generator != null: +func load_file(filename) -> bool: + var new_generator = mm_loader.load_gen(filename) + if new_generator != null: + clear_material() + top_generator = new_generator add_child(top_generator) move_child(top_generator, 0) update_view(top_generator) center_view() set_save_path(filename) set_need_save(false) + return true + else: + var dialog : AcceptDialog = AcceptDialog.new() + add_child(dialog) + dialog.window_title = "Load failed!" + dialog.dialog_text = "Failed to load "+filename + dialog.popup_centered() + return false func save_file(filename) -> void: var data = top_generator.serialize() diff --git a/material_maker/main_window.gd b/material_maker/main_window.gd index 22bab21..d6df5ab 100644 --- a/material_maker/main_window.gd +++ b/material_maker/main_window.gd @@ -175,7 +175,6 @@ func create_menu(menu, menu_name) -> PopupMenu: func create_menu_load_recent(menu) -> void: menu.clear() - if recent_files.empty(): menu.add_item("No items found", 0) menu.set_item_disabled(0, true) @@ -186,7 +185,8 @@ func create_menu_load_recent(menu) -> void: menu.connect("id_pressed", self, "_on_LoadRecent_id_pressed") func _on_LoadRecent_id_pressed(id) -> void: - do_load_material(recent_files[id]) + if !do_load_material(recent_files[id]): + recent_files.remove(id) func load_recents() -> void: var f = File.new() @@ -313,7 +313,7 @@ func do_load_materials(filenames) -> void: for f in filenames: do_load_material(f) -func do_load_material(filename) -> void: +func do_load_material(filename) -> bool: var graph_edit : MMGraphEdit = get_current_graph_edit() var node_count = 2 # So test below succeeds if graph_edit is null... if graph_edit != null: @@ -325,8 +325,10 @@ func do_load_material(filename) -> void: break if node_count > 1: graph_edit = new_pane() - graph_edit.load_file(filename) - add_recent(filename) + if graph_edit.load_file(filename): + add_recent(filename) + return true + return false func save_material() -> void: var graph_edit : MMGraphEdit = get_current_graph_edit()