Last active
July 3, 2018 14:08
-
-
Save jedStevens/bd9f6767971937ede1aeccd2bb6ed4d3 to your computer and use it in GitHub Desktop.
This finds all of the PNGs in a folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node | |
var image_db = {} | |
func _ready(): | |
image_db = load_pngs_from_directory("res://") | |
print(image_db) | |
func load_pngs_from_directory(path): | |
var files = {} | |
var dir = Directory.new() | |
dir.open(path) | |
dir.list_dir_begin() | |
while true: | |
var file = dir.get_next() | |
if file == "": | |
break | |
elif dir.current_is_dir() and not file.begins_with("."): | |
print("getting sub folder: ", file) | |
var sub_files = load_pngs_from_directory(path+"/"+file) | |
if not sub_files.empty(): | |
files[file] = sub_files | |
elif not file.begins_with(".") and file.ends_with(".png"): | |
files[file] = load(path+"/"+file) | |
dir.list_dir_end() | |
return files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment