-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathability_names.py
More file actions
66 lines (56 loc) · 2.4 KB
/
ability_names.py
File metadata and controls
66 lines (56 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import csv
import os
from read_swsh import TextFile
# data_path contains the countents of the `message` folder found in sword/shield's romfs:/bin/
if __name__ == "__main__":
path = os.path.abspath(os.path.dirname(__file__))
data_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "..", "..", "..", "data")
csv_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "..", "..", "..", "pokedex", "data", "csv")
languages = {
"JPN": 1,
"Korean": 3,
"Trad_Chinese": 4,
"French": 5,
"German": 6,
"Spanish": 7,
"Italian": 8,
"English": 9,
"JPN_KANJI": 11,
"Simp_Chinese": 12,
}
header = ["ability_id", "local_language_id", "name"]
entries = []
# conquest abilities
with open(os.path.join(csv_path, "ability_names.csv"), "r", encoding="utf-8", newline="") as csv_file:
reader = csv.reader(csv_file, delimiter=",")
for row in reader:
if row[0].isnumeric() and int(row[0]) > 10000:
entries.append([int(row[0]), int(row[1]), row[2]])
with open(os.path.join(csv_path, "ability_names.csv"), "w", encoding="utf-8", newline="") as csv_file:
writer = csv.writer(csv_file, delimiter=",", lineterminator="\n")
for language_dir, language_id in languages.items():
try:
# Parse through the .dat and .tbl
textFile = TextFile(
os.path.join(data_path, language_dir, "common", "tokusei.dat"),
os.path.join(data_path, language_dir, "common", "tokusei.tbl"),
)
dictionary = textFile.GetDict()
except UserWarning as error:
print(error)
try:
if len(dictionary) == 0:
raise UserWarning("Error: the files returned no data")
# Loop through the text file's dictionary and append the parsed data into the list
for label, text in dictionary.items():
id = int(label[0].split("_")[1])
if id == 0:
continue
entries.append([id, language_id, text])
except UserWarning as error:
print(error)
# Sort the list based on species id
writer.writerow(header)
entries.sort()
writer.writerows(entries)
print("Done")