Created
February 21, 2024 23:50
-
-
Save workhorsy/94c4ebc6f68cb89ad6dc6327f5edcafe to your computer and use it in GitHub Desktop.
Godot 4 check unique UIDS
This file contains hidden or 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
| import os | |
| from os.path import splitext | |
| uid_to_file = {} | |
| headers = ["[gd_scene ", "[gd_resource "] | |
| exts = [".tscn", ".tres"] | |
| for root, dirs, files in os.walk("project"): | |
| for file_name in files: | |
| full_name = os.path.join(root, file_name) | |
| # Skip if any path segment starts with . | |
| e = full_name.split(os.sep) | |
| e = [full_name.startswith(".") for full_name in e] | |
| has_dot = any(e) | |
| if has_dot: | |
| continue | |
| # Skip if does not have matchintg extensions | |
| ext = splitext(full_name)[1] | |
| if not ext in exts: | |
| continue | |
| # Get the UID | |
| uid = None | |
| with open(full_name, 'r') as f: | |
| line = f.readline() | |
| if line: | |
| e = [line.startswith(header) for header in headers] | |
| has_header = any(e) | |
| if has_header and " uid=" in line: | |
| uid = line.split(' uid="')[1].split('"]')[0] | |
| #print([line, uid]) | |
| if uid: | |
| #print([full_name, uid]) | |
| if uid in uid_to_file: | |
| #print('Files have same UID: {0} ("{1}" and "{2}")'.format(uid, full_name, uid_to_file[uid])) | |
| pass | |
| if uid not in uid_to_file: | |
| uid_to_file[uid] = [] | |
| uid_to_file[uid].append(full_name) | |
| for uid in uid_to_file: | |
| file_names = uid_to_file[uid] | |
| if len(file_names) > 1: | |
| print(uid) | |
| for file_name in file_names: | |
| print(' {0}'.format(file_name)) | |
| #print(uid_to_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment