Added an option to save the library and updated the library

This commit is contained in:
RodZill4 2019-11-05 20:00:28 +01:00
parent c121f7c00a
commit df07cfab06
19 changed files with 1828 additions and 402 deletions

View File

@ -109,17 +109,27 @@ func add_item(item, item_name, item_icon = null, item_parent = null, force_expan
new_parent.set_text(0, prefix)
return add_item(item, suffix, item_icon, new_parent, force_expand)
func serialize_library(array : Array, library_name : String = "", item : TreeItem = null) -> void:
func serialize_library(array : Array, library_name : String = "", item : TreeItem = null, icon_path : String = "") -> void:
if item == null:
item = tree.get_root()
item = item.get_children()
while item != null:
if item.get_metadata(0) != null:
var m : Dictionary = item.get_metadata(0)
if icon_path != "":
pass
if library_name == "" or (m.has("library") and m.library == library_name):
var copy : Dictionary = m.duplicate()
copy.erase("library")
copy.collapsed = item.collapsed
array.append(copy)
elif !item.collapsed:
var item_path = item.get_text(0)
var item_parent = item.get_parent()
while item_parent != tree.get_root():
item_path = item_parent.get_text(0)+"/"+item_path
item_parent = item_parent.get_parent()
array.append({ tree_item=item_path, collapsed=false })
serialize_library(array, library_name, item)
item = item.get_next()
@ -131,5 +141,16 @@ func save_library(library_name : String, item : TreeItem = null) -> void:
file.store_string(JSON.print({lib=array}, "\t", true))
file.close()
func _on_Filter_text_changed(filter) -> void:
func _on_Filter_text_changed(filter : String) -> void:
update_tree(filter)
func export_libraries(path : String) -> void:
var dir : Directory = Directory.new()
var icon_path = path.get_basename()
dir.make_dir(icon_path)
var array = []
serialize_library(array, "", null, icon_path)
var file = File.new()
if file.open(path, File.WRITE) == OK:
file.store_string(JSON.print({lib=array}, "\t", true))
file.close()

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 B

After

Width:  |  Height:  |  Size: 241 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 282 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 252 B

After

Width:  |  Height:  |  Size: 393 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 277 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 478 B

After

Width:  |  Height:  |  Size: 597 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

@ -36,6 +36,7 @@ const MENU = [
{ menu="Tools", command="make_selected_nodes_editable", shortcut="Control+E", description="Make selected nodes editable" },
{ menu="Tools" },
{ menu="Tools", command="add_to_user_library", description="Add selected node to user library" },
{ menu="Tools", command="export_library", description="Export the nodes library" },
{ menu="Help", command="show_doc", description="User manual" },
{ menu="Help", command="bug_report", description="Report a bug" },
@ -351,6 +352,19 @@ func do_add_to_user_library(name, nodes) -> void:
library.add_item(data, name, library.get_preview_texture(data))
library.save_library("user://library/user.json")
func export_library() -> void:
var dialog : FileDialog = FileDialog.new()
add_child(dialog)
dialog.rect_min_size = Vector2(500, 500)
dialog.access = FileDialog.ACCESS_FILESYSTEM
dialog.mode = FileDialog.MODE_SAVE_FILE
dialog.add_filter("*.json;JSON files")
dialog.connect("file_selected", self, "do_export_library")
dialog.popup_centered()
func do_export_library(path : String) -> void:
library.export_libraries(path)
func show_doc() -> void:
var base_dir = OS.get_executable_path().replace("\\", "/").get_base_dir()