online multiplayer chess game (note server currently down)
Diffstat (limited to 'Utils.gd')
-rw-r--r--Utils.gd25
1 files changed, 25 insertions, 0 deletions
diff --git a/Utils.gd b/Utils.gd
index 62dab5f..660455e 100644
--- a/Utils.gd
+++ b/Utils.gd
@@ -48,3 +48,28 @@ func get_node_name(node):
return ["♘", "N"] if node.white else ["♞", "N"]
else:
return ["", ""]
+
+
+func walk_dir(path = "res://assets/pieces"): # walk the directory, finding the asset packs
+ var folders = [] # init the folders
+ var favoritism = false
+ if path == "res://assets/pieces": # put favorite on top
+ folders.append("california")
+ favoritism = true
+ var dir = Directory.new() # init the directory
+ if dir.open(path) == OK: # open the directory
+ dir.list_dir_begin() # list the directory
+ var file_name = dir.get_next() # get the next file
+ while file_name != "": # while there is a file
+ if dir.current_is_dir(): # if the current is a directory
+ if file_name == "." or file_name == "..": # if it is a dot or dot dot
+ file_name = dir.get_next() # get the next file
+ continue
+ if favoritism and file_name == "california":
+ file_name = dir.get_next()
+ continue
+ folders.append(file_name) # add the folder
+ file_name = dir.get_next() # get the next file
+ else:
+ printerr("An error occurred when trying to access the path " + path) # print the error
+ return folders # return the folders