81 lines
2.5 KiB
Python
81 lines
2.5 KiB
Python
import cv2
|
|
import numpy as np
|
|
import os
|
|
import shutil
|
|
|
|
def deploy_hud_extras():
|
|
artifacts_dir = '/Users/davidkotnik/.gemini/antigravity/brain/07019d04-a214-43ab-9565-86f4e8f17e5b'
|
|
|
|
mapping = {
|
|
'ui_minimap_frame': 'minimap_frame.png',
|
|
'ui_weather_icons': 'weather_icons_sheet.png',
|
|
'ui_weather_widget_retry': 'weather_widget.png'
|
|
}
|
|
|
|
targets = [
|
|
'/Users/davidkotnik/repos/novafarma/main/assets',
|
|
'/Users/davidkotnik/repos/novafarma/assets/DEMO_FAZA1/UI',
|
|
'/Users/davidkotnik/nova farma/main/assets'
|
|
]
|
|
for t in targets:
|
|
os.makedirs(t, exist_ok=True)
|
|
|
|
for key_pattern, dest_name in mapping.items():
|
|
# Find latest file
|
|
candidates = []
|
|
for f in os.listdir(artifacts_dir):
|
|
if key_pattern in f and f.endswith('.png'):
|
|
candidates.append(os.path.join(artifacts_dir, f))
|
|
|
|
if not candidates:
|
|
print(f"Skipping {key_pattern}")
|
|
continue
|
|
|
|
candidates.sort(key=os.path.getmtime, reverse=True)
|
|
found_path = candidates[0]
|
|
|
|
print(f"Processing {found_path}")
|
|
img = cv2.imread(found_path)
|
|
if img is None: continue
|
|
|
|
# BG Removal
|
|
img = cv2.cvtColor(img, cv2.COLOR_BGR2BGRA)
|
|
target = np.array([255, 0, 255])
|
|
tol = 60
|
|
lower = np.clip(target - tol, 0, 255)
|
|
upper = np.clip(target + tol, 0, 255)
|
|
mask = cv2.inRange(img[:,:,:3], lower, upper)
|
|
img[mask > 0, 3] = 0
|
|
|
|
# Crop Content
|
|
coords = cv2.findNonZero(img[:,:,3])
|
|
if coords is not None:
|
|
x, y, w, h = cv2.boundingRect(coords)
|
|
img = img[y:y+h, x:x+w]
|
|
|
|
# Resize Logic
|
|
h, w = img.shape[:2]
|
|
new_w, new_h = w, h
|
|
|
|
if 'minimap' in dest_name and w > 256:
|
|
scale = 256 / w
|
|
new_w, new_h = int(w*scale), int(h*scale)
|
|
elif 'widget' in dest_name and w > 256:
|
|
scale = 256 / w
|
|
new_w, new_h = int(w*scale), int(h*scale)
|
|
elif 'icons' in dest_name and w > 512:
|
|
scale = 512 / w
|
|
new_w, new_h = int(w*scale), int(h*scale)
|
|
|
|
if new_w != w:
|
|
img = cv2.resize(img, (new_w, new_h), interpolation=cv2.INTER_AREA)
|
|
|
|
# Distribute
|
|
for t in targets:
|
|
final_path = os.path.join(t, dest_name)
|
|
cv2.imwrite(final_path, img)
|
|
print(f"Saved to {final_path}")
|
|
|
|
if __name__ == "__main__":
|
|
deploy_hud_extras()
|