76 lines
2.4 KiB
Python
76 lines
2.4 KiB
Python
import os
|
|
import shutil
|
|
import hashlib
|
|
|
|
BASE_DIR = os.path.abspath("assets/slike/glavna_referenca")
|
|
BUILD_DIR = os.path.join(BASE_DIR, "_FOLDER_BUILDINGS")
|
|
NPC_DIR = os.path.join(BASE_DIR, "_FOLDER_NPC")
|
|
|
|
# Keywords that indicate a person/character (not a building)
|
|
NPC_KEYWORDS = [
|
|
"npc", "kai", "ana", "gronk", "susi", "player", "liki",
|
|
"character", "enemy", "zombie", "skeleton", "troll", "warrior",
|
|
"guard", "merchant", "trader", "baker", "smith", "doctor",
|
|
"man", "woman", "person", "face", "portrait", "boss"
|
|
]
|
|
|
|
def get_hash(filepath):
|
|
try:
|
|
with open(filepath, 'rb') as f:
|
|
return hashlib.md5(f.read()).hexdigest()
|
|
except:
|
|
return None
|
|
|
|
def clean_building_folder():
|
|
if not os.path.exists(BUILD_DIR):
|
|
print("❌ Buildings folder missing!")
|
|
return
|
|
|
|
print("👷♂️ Inspecting _FOLDER_BUILDINGS...")
|
|
|
|
moved_npcs = 0
|
|
deleted_dupes = 0
|
|
seen_hashes = {}
|
|
|
|
# 1. SCAN
|
|
for filename in os.listdir(BUILD_DIR):
|
|
if filename.startswith("."): continue
|
|
filepath = os.path.join(BUILD_DIR, filename)
|
|
|
|
# A) Check if NPC
|
|
lower = filename.lower()
|
|
if any(k in lower for k in NPC_KEYWORDS):
|
|
# It's an impostor! Move to NPC folder
|
|
dst = os.path.join(NPC_DIR, filename)
|
|
|
|
# Handle collision
|
|
if os.path.exists(dst):
|
|
name, ext = os.path.splitext(filename)
|
|
c=1
|
|
while os.path.exists(os.path.join(NPC_DIR, f"{name}_{c}{ext}")):
|
|
c+=1
|
|
dst = os.path.join(NPC_DIR, f"{name}_{c}{ext}")
|
|
|
|
shutil.move(filepath, dst)
|
|
moved_npcs += 1
|
|
# print(f" 👤 Moved NPC found in buildings: {filename}")
|
|
continue # Skip hash check since file is gone
|
|
|
|
# B) Check Duplicate (MD5)
|
|
h = get_hash(filepath)
|
|
if h:
|
|
if h in seen_hashes:
|
|
# Duplicate!
|
|
os.remove(filepath)
|
|
deleted_dupes += 1
|
|
# print(f" 🗑️ Deleted duplicate inside buildings: {filename}")
|
|
else:
|
|
seen_hashes[h] = filepath
|
|
|
|
print(f"✅ CLEANUP REPORT:")
|
|
print(f" 👤 Moved {moved_npcs} NPC files to _FOLDER_NPC")
|
|
print(f" 🗑️ Deleted {deleted_dupes} duplicate files in _FOLDER_BUILDINGS")
|
|
|
|
if __name__ == "__main__":
|
|
clean_building_folder()
|