Files
WoW-Hybrid-gateway/ops/collection_spellbook.py

50 lines
1.8 KiB
Python

#!/usr/bin/env python3
"""Export supported original collection category memberships for the player spellbook."""
import argparse
from pathlib import Path
from turtle_data import DBC
COLLECTION_LINES = {1005: "Companions", 1006: "Mounts", 1008: "Toys"}
def collect(directory):
lines = DBC(directory / "SkillLine.dbc")
for line, name in COLLECTION_LINES.items():
if lines.string(lines.by_id[line][3]) != name:
raise ValueError(f"Collection line {line} no longer names {name}")
spells = DBC(directory / "Spell.dbc")
entries = DBC(directory / "SkillLineAbility.dbc", 15)
result = {key: set() for key in COLLECTION_LINES}
for row in entries.rows:
line, spell = row[1:3]
if line in result and spell in spells.by_id:
result[line].add(spell)
if any(not ids for ids in result.values()):
raise ValueError("Incomplete source collection categories")
return result
def lua(categories):
lines = [
"-- Generated by ops/collection_spellbook.py from the original collection skill lines.",
"-- An entry is displayed only when the current player actually knows the spell.",
"WoWHybridCollectionSpells = {",
]
for line, ids in sorted(categories.items()):
lines.append(f" [{line}] = {{ -- {COLLECTION_LINES[line]}")
ids = sorted(ids)
for pos in range(0, len(ids), 12):
lines.append(" " + ", ".join(map(str, ids[pos:pos + 12])) + ",")
lines.append(" },")
return "\n".join([*lines, "}", ""])
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("source", type=Path)
parser.add_argument("output", type=Path)
args = parser.parse_args()
args.output.write_text(lua(collect(args.source)), encoding="utf-8")