🧹 Massive Asset Reorganization: Cleaned filenames, removed duplicates, and sorted into UI/Items/Env/Chars/Animals folders.
This commit is contained in:
53
scripts/flatten_game_folders.py
Normal file
53
scripts/flatten_game_folders.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
ROOT_ASSETS = os.path.abspath("assets/slike")
|
||||
TARGET_DIRS = ["ui", "items", "environment", "characters", "animals"]
|
||||
|
||||
def flatten_folder(folder_name):
|
||||
base_dir = os.path.join(ROOT_ASSETS, folder_name)
|
||||
if not os.path.exists(base_dir):
|
||||
print(f"⚠️ Folder not found: {folder_name}")
|
||||
return
|
||||
|
||||
print(f"🚜 Flattening {folder_name}...")
|
||||
moved_count = 0
|
||||
|
||||
# Walk bottom-up to handle nested dirs
|
||||
for root, dirs, files in os.walk(base_dir, topdown=False):
|
||||
if root == base_dir:
|
||||
continue # Don't move files already in root
|
||||
|
||||
# SPECIAL EXCEPTION: Skip 'blueprints' folder in 'items'
|
||||
if folder_name == "items" and "blueprints" in root:
|
||||
continue
|
||||
|
||||
for filename in files:
|
||||
if filename.startswith("."): continue
|
||||
|
||||
src = os.path.join(root, filename)
|
||||
dst = os.path.join(base_dir, filename)
|
||||
|
||||
# 1. Handle Collisions (Rename if exists)
|
||||
if os.path.exists(dst):
|
||||
name, ext = os.path.splitext(filename)
|
||||
counter = 1
|
||||
while os.path.exists(os.path.join(base_dir, f"{name}_{counter}{ext}")):
|
||||
counter += 1
|
||||
dst = os.path.join(base_dir, f"{name}_{counter}{ext}")
|
||||
|
||||
# 2. Move
|
||||
shutil.move(src, dst)
|
||||
moved_count += 1
|
||||
|
||||
# 3. Remove empty dir
|
||||
try:
|
||||
os.rmdir(root)
|
||||
except OSError:
|
||||
pass # Directory not empty (maybe contains .DS_Store or skipped files)
|
||||
|
||||
print(f" ✅ Moved {moved_count} images to root of /{folder_name}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
for d in TARGET_DIRS:
|
||||
flatten_folder(d)
|
||||
Reference in New Issue
Block a user