Add CATEGORY_EQUIP to cards that equip itself to other cards
use python script to detect
#!/usr/bin/env python3
import sqlite3
import re
from pathlib import Path
# --- config ---
CDB_PATH = "cards.cdb"
SCRIPT_DIR = Path("script")
WHITELIST_PATH = Path("whitelist.txt")
# ----------------
# any SetCategory(...) that mentions CATEGORY_EQUIP
RE_SETCAT_EQUIP = re.compile(r'SetCategory\s*\([^)]*CATEGORY_EQUIP', re.IGNORECASE)
def load_ids(path: Path):
"""Load whitelist.txt with BOM detection."""
ids = set()
if not path.exists():
return ids
raw = path.read_bytes()
if raw.startswith(b'\xff\xfe'):
text = raw.decode('utf-16le')
elif raw.startswith(b'\xfe\xff'):
text = raw.decode('utf-16be')
elif raw.startswith(b'\xef\xbb\xbf'):
text = raw.decode('utf-8-sig')
else:
text = raw.decode('utf-8', errors="ignore")
for line in text.splitlines():
line = line.strip()
if line and not line.startswith("#"):
try:
ids.add(int(line))
except:
pass
return ids
def main():
whitelist_ids = load_ids(WHITELIST_PATH)
conn = sqlite3.connect(CDB_PATH)
cur = conn.cursor()
# Only cards we care about: whitelist + equip spells + union monsters
q_marks = ",".join("?" for _ in whitelist_ids) if whitelist_ids else "NULL"
whitelist_clause = f"d.id IN ({q_marks})" if whitelist_ids else "0"
cur.execute(f"""
SELECT d.id, d.type, t.name
FROM datas d
LEFT JOIN texts t ON d.id = t.id
WHERE d.type = 262146 -- equip spell
OR d.type = 1057 -- union monster
OR ({whitelist_clause}) -- whitelisted cards
""", tuple(whitelist_ids))
rows = cur.fetchall()
conn.close()
bucket_whitelist = []
bucket_equip = []
bucket_union = []
for cid, ctype, name in rows:
lua_path = SCRIPT_DIR / f"c{cid}.lua"
if not lua_path.exists():
continue
content = lua_path.read_text(encoding="utf-8", errors="ignore")
# GOOD if any of:
# - SetCategory(...CATEGORY_EQUIP...)
# - aux.EnableUnionAttribute
# - aux.AddEquipSpellEffect
if RE_SETCAT_EQUIP.search(content):
continue
if "aux.EnableUnionAttribute" in content:
continue
if "aux.AddEquipSpellEffect" in content:
continue
# From here, this card is "missing"
name = name or ""
if cid in whitelist_ids:
bucket_whitelist.append((cid, name))
if ctype == 262146:
bucket_equip.append((cid, name))
if ctype == 1057:
bucket_union.append((cid, name))
bucket_whitelist.sort()
bucket_equip.sort()
bucket_union.sort()
print("=== WHITELIST (missing equip handling) ===")
for cid, name in bucket_whitelist:
print(f"{cid}\t{name}")
print("\n=== EQUIP SPELL (missing equip handling) ===")
for cid, name in bucket_equip:
print(f"{cid}\t{name}")
print("\n=== UNION MONSTER (missing equip handling) ===")
for cid, name in bucket_union:
print(f"{cid}\t{name}")
if __name__ == "__main__":
main()