Skip to content

Commit 00fc1eb

Browse files
committed
Added script to generate [build]_abilities.csv file from balance data exports.
1 parent d46a21e commit 00fc1eb

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

generate_abilities.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import argparse
2+
import csv
3+
import glob
4+
import os
5+
import xml.etree.ElementTree
6+
7+
8+
def generate_abilities(balance_data_path):
9+
abilities = []
10+
11+
for xml_file_path in glob.glob(os.path.join(balance_data_path, "*.xml")):
12+
tree = xml.etree.ElementTree.parse(xml_file_path)
13+
root = tree.getroot()
14+
15+
ability_elements = root.findall(".//abilities/ability")
16+
abilities.extend(
17+
[
18+
(element.get("index"), element.get("id"))
19+
for element in ability_elements
20+
if element.get("index") and element.get("id")
21+
])
22+
23+
unit_name = root.get("id")
24+
25+
26+
27+
return abilities
28+
29+
30+
def main():
31+
parser = argparse.ArgumentParser(description='Generate a [BUILD]_abilities.csv file from exported balance data.')
32+
parser.add_argument('build_version', metavar='BUILD_VERSION', type=int,
33+
help='the build version of the balance data export')
34+
parser.add_argument('balance_data_path', metavar='BALANCE_DATA_PATH', type=str,
35+
help='the path to the balance data export')
36+
37+
args = parser.parse_args()
38+
39+
abilities = generate_abilities(args.balance_data_path)
40+
41+
if not abilities:
42+
raise ValueError("No balance data found at provided balance data path.")
43+
44+
with open('{}_abilities.txt'.format(args.build_version), 'w', newline='') as csvfile:
45+
csv_writer = csv.writer(csvfile, delimiter=',')
46+
for ability_index, ability_name in abilities:
47+
csv_writer.writerow([ability_index, ability_name])
48+
49+
50+
if __name__ == "__main__":
51+
main()

0 commit comments

Comments
 (0)