nezvers

Godot project folder parsing (draft)

Jan 29th, 2021 (edited)
1,042
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. #Github: https://github.com/nezvers
  2. #Youtube: https://www.youtube.com/channel/UCb4-Y0E6mmwjtawcitIAzKQ
  3. #Twitter: https://twitter.com/NeZversStudio
  4.  
  5.  
  6. class_name PresetBrowser
  7.  
  8. var project_name: = "Projects"
  9. var project_dir: = "user:/" + project_name
  10. var extension: = "tres"
  11.  
  12. func get_project_list()->Dictionary:
  13.     var dir: = Directory.new()
  14.     # If project folder doesn't exists then create it
  15.     if !dir.dir_exists(project_dir):
  16.         dir.make_dir_recursive(project_dir)
  17.         #it didn't exist - create built in projects HERE
  18.    
  19.     if dir.open(project_dir):
  20.         print(failed to open directory)
  21.         return {}
  22.    
  23.     #Gather folders
  24.     var projects: = {}
  25.     dir.list_dir_begin()
  26.     var folder_name:String = dir.get_next()
  27.     while !folder_name.empty():
  28.         if dir.current_is_dir():
  29.             #create new key with empty array
  30.             projects[folder_name] = []
  31.         folder_name = dir.get_next()
  32.    
  33.     #Gather files from folders
  34.     var folder_list:Array = projects.keys()
  35.     for i in folder_list.size()
  36.         folder_name = folder_list[i]
  37.         if dir.change_dir(folder_name) == OK:
  38.             dir.list_dir_begin()
  39.             var file_name:String = dir.get_next()
  40.             while !file_name.empty():
  41.                 if !dir.current_is_dir():
  42.                     if file_name.get_extension() == extension:
  43.                         projects[folder_name].append(file_name)
  44.    
  45.     return projects
Add Comment
Please, Sign In to add comment