Advertisement
swordandquill

Load Items into Database (+ Build Support)

Oct 26th, 2024
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GDScript 0.69 KB | Gaming | 0 0
  1. var folder_path: String # something like "res://data/resources/items/"
  2. var item_database: Array
  3.  
  4. func _load_all_items():
  5.     var dir = DirAccess.open(_path)
  6.     if dir:
  7.         dir.list_dir_begin()
  8.         var file_name = dir.get_next()
  9.        
  10.         while file_name != "":
  11.             if dir.current_is_dir():
  12.                 print("Found directory: " + file_name)
  13.             else:
  14.                 if file_name.ends_with(".remap"): #---For build
  15.                     file_name = file_name.replace(".remap", "") #---For build
  16.                
  17.                 print("Found file: " + file_name)
  18.                 var item  = load(folder_path + file_name)
  19.                 item_database.append(item)
  20.  
  21.             file_name = dir.get_next()
  22.     else:
  23.         print("An error occurred when trying to access the path.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement