mirror of
https://github.com/Relintai/material-maker.git
synced 2025-01-09 05:39:38 +01:00
Detect correctly when loading incorrect files
This commit is contained in:
parent
2b593beb32
commit
84687d2141
@ -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()
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user