🧹 Massive Asset Reorganization: Cleaned filenames, removed duplicates, and sorted into UI/Items/Env/Chars/Animals folders.
This commit is contained in:
77
scripts/fix_npc_buildings.py
Normal file
77
scripts/fix_npc_buildings.py
Normal file
@@ -0,0 +1,77 @@
|
||||
import os
|
||||
import shutil
|
||||
import hashlib
|
||||
|
||||
BASE_DIR = os.path.abspath("assets/slike/glavna_referenca")
|
||||
NPC_DIR = os.path.join(BASE_DIR, "_FOLDER_NPC")
|
||||
BUILD_DIR = os.path.join(BASE_DIR, "_FOLDER_BUILDINGS")
|
||||
|
||||
BUILD_KEYWORDS = [
|
||||
"house", "hut", "home", "shop", "store", "market", "stall", "inn", "tavern",
|
||||
"barn", "shed", "silo", "mill", "castle", "tower", "fort", "wall", "gate",
|
||||
"temple", "ruin", "shrine", "monument", "building", "structure", "tent",
|
||||
"cabin", "shack", "architecture", "gradnja", "objekti", "zgradba", "hisa"
|
||||
]
|
||||
|
||||
def get_hash(filepath):
|
||||
try:
|
||||
with open(filepath, 'rb') as f:
|
||||
return hashlib.md5(f.read()).hexdigest()
|
||||
except:
|
||||
return None
|
||||
|
||||
def move_wrong_buildings():
|
||||
print("🏚️ Scanning _FOLDER_NPC for misplaced buildings...")
|
||||
moved = 0
|
||||
if not os.path.exists(NPC_DIR):
|
||||
print("❌ NPC Folder not found!")
|
||||
return
|
||||
|
||||
for filename in os.listdir(NPC_DIR):
|
||||
if filename.startswith("."): continue
|
||||
|
||||
# Check if it's a building
|
||||
lower = filename.lower()
|
||||
if any(k in lower for k in BUILD_KEYWORDS):
|
||||
src = os.path.join(NPC_DIR, filename)
|
||||
dst = os.path.join(BUILD_DIR, filename)
|
||||
|
||||
# Use unique name if exists
|
||||
if os.path.exists(dst):
|
||||
name, ext = os.path.splitext(filename)
|
||||
c = 1
|
||||
while os.path.exists(os.path.join(BUILD_DIR, f"{name}_{c}{ext}")):
|
||||
c += 1
|
||||
dst = os.path.join(BUILD_DIR, f"{name}_{c}{ext}")
|
||||
|
||||
shutil.move(src, dst)
|
||||
moved += 1
|
||||
# print(f" Moved {filename} -> BUILDINGS")
|
||||
|
||||
print(f"✅ Moved {moved} misplaced buildings to _FOLDER_BUILDINGS.")
|
||||
|
||||
def remove_duplicates_in_folder(folder_path):
|
||||
print(f"🔍 Removing duplicates in {os.path.basename(folder_path)}...")
|
||||
seen_hashes = {}
|
||||
deleted = 0
|
||||
|
||||
for filename in os.listdir(folder_path):
|
||||
if filename.startswith("."): continue
|
||||
path = os.path.join(folder_path, filename)
|
||||
if not os.path.isfile(path): continue
|
||||
|
||||
h = get_hash(path)
|
||||
if h:
|
||||
if h in seen_hashes:
|
||||
# Duplicate!
|
||||
os.remove(path)
|
||||
deleted += 1
|
||||
else:
|
||||
seen_hashes[h] = path
|
||||
|
||||
print(f"✨ Removed {deleted} duplicates in {os.path.basename(folder_path)}.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
move_wrong_buildings()
|
||||
remove_duplicates_in_folder(NPC_DIR)
|
||||
remove_duplicates_in_folder(BUILD_DIR)
|
||||
Reference in New Issue
Block a user