108 lines
4.3 KiB
Python
108 lines
4.3 KiB
Python
|
|
import os
|
|
import shutil
|
|
from PIL import Image
|
|
|
|
# Configuration
|
|
SOURCE_ROOT = "."
|
|
DEST_LIB = "src/assets/library"
|
|
EXCLUDE_DIRS = {".git", "node_modules", "src", ".agent", ".vscode"} # Don't scan inside src (destination is in src), but we want to scan other folders
|
|
# We specifically want to target 'godot', 'backups', 'generated', etc.
|
|
# We will SKIP 'assets' to prevent breaking the currently running game logic until confirmed.
|
|
SKIP_GAME_ASSETS = True
|
|
GAME_ASSETS_DIR = "assets"
|
|
|
|
def manage_assets():
|
|
if not os.path.exists(DEST_LIB):
|
|
os.makedirs(DEST_LIB)
|
|
|
|
total_images = 0
|
|
size_256 = 0
|
|
size_1024 = 0
|
|
moved_count = 0
|
|
|
|
locations = {}
|
|
|
|
print(f"🚀 Starting Asset Audit & Consolidation...")
|
|
print(f"📂 Target Library: {DEST_LIB}")
|
|
|
|
for root, dirs, files in os.walk(SOURCE_ROOT):
|
|
# Exclude directories
|
|
dirs[:] = [d for d in dirs if d not in EXCLUDE_DIRS and not d.startswith('.')]
|
|
|
|
# Avoid recursion into destination
|
|
if os.path.abspath(root).startswith(os.path.abspath(DEST_LIB)):
|
|
continue
|
|
|
|
# Check if we are in the 'assets' folder (Game root)
|
|
in_game_assets = root.startswith("./assets") or root == "./assets" or root.startswith("assets")
|
|
|
|
for file in files:
|
|
if file.lower().endswith(('.png', '.jpg', '.jpeg')):
|
|
src_path = os.path.join(root, file)
|
|
|
|
try:
|
|
with Image.open(src_path) as img:
|
|
width, height = img.size
|
|
total_images += 1
|
|
|
|
if width == 256 and height == 256:
|
|
size_256 += 1
|
|
elif width == 1024 and height == 1024:
|
|
size_1024 += 1
|
|
|
|
# Record location stats
|
|
folder = os.path.dirname(src_path)
|
|
if folder not in locations:
|
|
locations[folder] = 0
|
|
locations[folder] += 1
|
|
|
|
# MOVE LOGIC
|
|
# If it's NOT in the official assets folder (and we are skipping it), move it.
|
|
should_move = True
|
|
if SKIP_GAME_ASSETS and in_game_assets:
|
|
should_move = False
|
|
|
|
# Also don't move if it's already in src (but we excluded src in walk, so handled)
|
|
# Wait, we excluded 'src' in dirs, so we won't find anything there.
|
|
# What if there are images in src/scenes/img?
|
|
# User said "premakni ... v src/assets/library".
|
|
|
|
if should_move:
|
|
# Calculate relative path to maintain structure
|
|
# e.g. godot/ostalo/img.png -> src/assets/library/godot/ostalo/img.png
|
|
rel_path = os.path.relpath(src_path, SOURCE_ROOT)
|
|
dest_path = os.path.join(DEST_LIB, rel_path)
|
|
|
|
dest_dir = os.path.dirname(dest_path)
|
|
if not os.path.exists(dest_dir):
|
|
os.makedirs(dest_dir)
|
|
|
|
shutil.move(src_path, dest_path)
|
|
moved_count += 1
|
|
# print(f"Moved: {rel_path}")
|
|
|
|
except Exception as e:
|
|
print(f"⚠️ Error reading {src_path}: {e}")
|
|
|
|
print("\n" + "="*40)
|
|
print(f"📊 AUDIT REPORT")
|
|
print("="*40)
|
|
print(f"Total Images Found: {total_images}")
|
|
print(f"Moved to Library: {moved_count}")
|
|
print(f"Kept in Game Assets: {total_images - moved_count}")
|
|
print("-" * 20)
|
|
print(f"📐 SIZE STATUS:")
|
|
print(f" - 256x256 (Optimized): {size_256}")
|
|
print(f" - 1024x1024 (High-Res): {size_1024}")
|
|
print(f" - Other Dimensions: {total_images - size_256 - size_1024}")
|
|
print("="*40)
|
|
|
|
print("\n📂 MAIN LOCATIONS (Before Move):")
|
|
sorted_locs = sorted(locations.items(), key=lambda item: item[1], reverse=True)[:10]
|
|
for loc, count in sorted_locs:
|
|
print(f" - {loc}: {count} images")
|
|
|
|
if __name__ == "__main__":
|
|
manage_assets()
|