Importing brushes from the Brushes folder now looks inside the subfolders too
But not the subfolders of the subfolders. Also moved the code of brush importing from Main.gd to Import.gd
Before Width: | Height: | Size: 140 B After Width: | Height: | Size: 140 B |
Before Width: | Height: | Size: 108 B After Width: | Height: | Size: 108 B |
Before Width: | Height: | Size: 72 B After Width: | Height: | Size: 72 B |
Before Width: | Height: | Size: 79 B After Width: | Height: | Size: 79 B |
|
@ -1,5 +1,40 @@
|
|||
extends Node
|
||||
|
||||
func import_brushes(path : String) -> void:
|
||||
var brushes_dir := Directory.new()
|
||||
if !brushes_dir.dir_exists(path):
|
||||
brushes_dir.make_dir(path)
|
||||
|
||||
var subdirectories := find_brushes(brushes_dir, path)
|
||||
for subdir_str in subdirectories:
|
||||
var subdir := Directory.new()
|
||||
find_brushes(subdir, "%s/%s" % [path, subdir_str])
|
||||
|
||||
Global.brushes_from_files = Global.custom_brushes.size()
|
||||
|
||||
func find_brushes(brushes_dir : Directory, path : String) -> Array:
|
||||
var subdirectories := []
|
||||
brushes_dir.open(path)
|
||||
brushes_dir.list_dir_begin(true)
|
||||
var file := brushes_dir.get_next()
|
||||
while file != "":
|
||||
print(file)
|
||||
if file.get_extension().to_upper() == "PNG":
|
||||
var image := Image.new()
|
||||
var err := image.load(path.plus_file(file))
|
||||
if err == OK:
|
||||
image.convert(Image.FORMAT_RGBA8)
|
||||
Global.custom_brushes.append(image)
|
||||
Global.create_brush_button(image, Global.BRUSH_TYPES.FILE, file.trim_suffix(".png"))
|
||||
elif file.get_extension() == "": # Probably a directory
|
||||
var subdir := "./%s" % [file]
|
||||
if brushes_dir.dir_exists(subdir): # If it's an actual directory
|
||||
subdirectories.append(subdir)
|
||||
|
||||
file = brushes_dir.get_next()
|
||||
brushes_dir.list_dir_end()
|
||||
return subdirectories
|
||||
|
||||
func import_gpl(path : String) -> Palette:
|
||||
var result : Palette = null
|
||||
var file = File.new()
|
||||
|
|
|
@ -172,25 +172,7 @@ func _ready() -> void:
|
|||
export_project_hbox.add_child(export_as_single_file)
|
||||
export_project_hbox.add_child(export_vertical_spritesheet)
|
||||
|
||||
var path := "Brushes"
|
||||
var brushes_dir := Directory.new()
|
||||
if !brushes_dir.dir_exists(path):
|
||||
brushes_dir.make_dir(path)
|
||||
|
||||
brushes_dir.open(path)
|
||||
brushes_dir.list_dir_begin(true, true)
|
||||
var file := brushes_dir.get_next()
|
||||
while file != "":
|
||||
if file.get_extension().to_upper() == "PNG":
|
||||
var image := Image.new()
|
||||
var err := image.load(path.plus_file(file))
|
||||
if err == OK:
|
||||
image.convert(Image.FORMAT_RGBA8)
|
||||
Global.custom_brushes.append(image)
|
||||
Global.create_brush_button(image, Global.BRUSH_TYPES.FILE, file.trim_suffix(".png"))
|
||||
file = brushes_dir.get_next()
|
||||
brushes_dir.list_dir_end()
|
||||
Global.brushes_from_files = Global.custom_brushes.size()
|
||||
Import.import_brushes("Brushes")
|
||||
|
||||
func _input(event : InputEvent) -> void:
|
||||
Global.left_cursor.position = get_global_mouse_position() + Vector2(-32, 32)
|
||||
|
|