82 lines
2.5 KiB
Python
82 lines
2.5 KiB
Python
import cv2
|
|
import numpy as np
|
|
import os
|
|
import shutil
|
|
|
|
def deploy_inventory_ui():
|
|
artifacts_dir = '/Users/davidkotnik/.gemini/antigravity/brain/07019d04-a214-43ab-9565-86f4e8f17e5b'
|
|
|
|
mapping = {
|
|
'ui_hotbar_background': 'hotbar_background.png',
|
|
'ui_big_inventory_panel': 'inventory_panel.png'
|
|
}
|
|
|
|
# Destination in projects
|
|
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():
|
|
found_path = None
|
|
# 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
|
|
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
|
|
# Hotbar: Needs to be roughly wide enough for 9 slots. Maybe 600-800px wide.
|
|
# Panel: Maybe 500-600px square.
|
|
h, w = img.shape[:2]
|
|
new_w, new_h = w, h
|
|
|
|
if 'hotbar' in dest_name and w > 800:
|
|
scale = 800 / w
|
|
new_w, new_h = int(w*scale), int(h*scale)
|
|
elif 'panel' in dest_name and w > 600:
|
|
scale = 600 / 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_inventory_ui()
|