Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Github: https://github.com/nezvers
- #Youtube: https://www.youtube.com/channel/UCb4-Y0E6mmwjtawcitIAzKQ
- #Twitter: https://twitter.com/NeZversStudio
- class_name PresetBrowser
- var project_name: = "Projects"
- var project_dir: = "user:/" + project_name
- var extension: = "tres"
- func get_project_list()->Dictionary:
- var dir: = Directory.new()
- # If project folder doesn't exists then create it
- if !dir.dir_exists(project_dir):
- dir.make_dir_recursive(project_dir)
- #it didn't exist - create built in projects HERE
- if dir.open(project_dir):
- print(failed to open directory)
- return {}
- #Gather folders
- var projects: = {}
- dir.list_dir_begin()
- var folder_name:String = dir.get_next()
- while !folder_name.empty():
- if dir.current_is_dir():
- #create new key with empty array
- projects[folder_name] = []
- folder_name = dir.get_next()
- #Gather files from folders
- var folder_list:Array = projects.keys()
- for i in folder_list.size()
- folder_name = folder_list[i]
- if dir.change_dir(folder_name) == OK:
- dir.list_dir_begin()
- var file_name:String = dir.get_next()
- while !file_name.empty():
- if !dir.current_is_dir():
- if file_name.get_extension() == extension:
- projects[folder_name].append(file_name)
- return projects
Add Comment
Please, Sign In to add comment