-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparsers.py
284 lines (234 loc) · 8.42 KB
/
parsers.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
import json
import re
from dataclasses import dataclass
from dataclasses_json import dataclass_json
@dataclass_json
@dataclass
class Recipe:
"""Class for a recipe."""
type: str = ""
result: str = ""
qty1: int = 0
item1: str = ""
qty2: int = 0
item2: str = ""
qty3: int = 0
item3: str = ""
alchemiracle: bool = False
notes: str = ""
image: str = ""
@dataclass_json
@dataclass
class Quest:
"""Class for a quest."""
number: int = 0
name: str = ""
story: bool = False
location: str = ""
request: str = ""
solution: str = ""
reward: str = ""
prerequisite: str = ""
repeat: bool = False
@dataclass_json
@dataclass
class Monster:
"""Class for a monster."""
number: str = ""
level: str = ""
name: str = ""
exp: int = 0
gold: int = 0
family: str = ""
hp: int = 0
mp: int = 0
atk: int = 0
defn: int = 0
agi: int = 0
fire: int = 0
ice: int = 0
wind: int = 0
blast: int = 0
earth: int = 0
dark: int = 0
light: int = 0
dazzle: int = 0
sleep: int = 0
death: int = 0
haunts: str = ""
drop1: str = ""
drop2: str = ""
drop3: str = ""
image: str = ""
@dataclass_json
@dataclass
class Translation:
"""Class for a translation."""
english: str = ""
japanese: str = ""
spanish: str = ""
french: str = ""
german: str = ""
italian: str = ""
@dataclass_json
@dataclass
class Song:
"""Class for a song."""
title: str = ""
url: str = ""
@dataclass
class Grotto:
"""Class for a grotto."""
name: str
url: str
special: int
seed: str
rank: str
type: str
floors: str
boss: str
monster_rank: str
chests: str
locations: str
notes: str = ""
owner: str = ""
@dataclass_json
@dataclass
class Quote:
"""Class for a quote."""
name: str
author: int
content: str
image: str = None
aliases: list[str] = None
translation_languages = ["English", "Japanese (日本語)", "Spanish (Español)", "French (Français)", "German (Deutsch)",
"Italian (Italiano)"]
translation_languages_simple = ["english", "japanese", "spanish", "french", "german", "italian"]
with open('data/translations/grottos.json', 'r', encoding='utf-8') as f:
data = json.load(f)
grotto_prefixes = {lang: [] for lang in translation_languages_simple}
grotto_environments = {lang: [] for lang in translation_languages_simple}
grotto_suffixes = {lang: [] for lang in translation_languages_simple}
for index, translation in enumerate(data['translations']):
if index < 16:
for lang in translation_languages_simple:
grotto_prefixes[lang].append(translation[lang])
elif index < 16 + 24:
for lang in translation_languages_simple:
grotto_environments[lang].append(translation[lang])
elif index < 16 + 24 + 16:
for lang in translation_languages_simple:
grotto_suffixes[lang].append(translation[lang])
grotto_special = "Has a special floor"
grotto_keys = ("Seed", "Rank", "Name", "Boss", "Type", "Floors", "Monster Rank", "Chests", "Locations")
grotto_chest_ranks = ["**S**", "**A**", "**B**", "**C**", "**D**", "**E**", "**F**", "**G**", "**H**", "**I**"]
grotto_ranks = {1: "02", 2: "38", 3: "3D", 4: "4C", 5: "51", 6: "65", 7: "79", 8: "8D", 9: "A1", 10: "B5", 11: "C9",
12: "DD"}
quests_regex = r'^(?:(?:(⭐) )?\*\*Quest #(\d+) - (.+)\*\*(?: \1)?(?:```yml)?|(\w+): (.+?)(?:```)?)$'
cleanup_regex = r'([\w\d\.\-:/() ]+)'
item_types = ["items"]
weapon_types = ["claws", "axes", "fans", "bows", "wands", "knives", "boomerangs", "staves", "whips", "spears", "swords",
"hammers"]
armor_types = ["torso", "legs", "feet", "head", "arms"]
accessory_types = ["accessories"]
tourney_data_types = ["Monsters"]
songs = ["00 - Overture IX", "01 - Intermezzo", "02 - Come to Our Town", "03 - Our Dreaming Town",
"04 - The Sun Gathering Village", "05 - Evening in the Village", "06 - Pub Polka", "07 - Alchemy Pot",
"08 - Healed by a Hymn", "09 - The Palace Oboe", "10 - Heaven's Prayer", "11 - Assemble, People",
"12 - Cross the Fields, Cross the Mountains", "13 - Guide Them to Their Fate", "14 - With My Companions",
"15 - Sea Breeze", "16 - Riding in the Ark", "17 - Dark Den of Thieves", "18 - Omen of Towering Death",
"19 - A Temple With No Master", "20 - Dungeon", "21 - Are You a Loser", "22 - Swirling Desire",
"23 - The Time of the Decisive Battle", "24 - The Dragonlord", "25 - Malroth ~ The True Evil",
"26 - Gruelling Fight", "27 - Hero's Challenge", "28 - Incarnation of Evil", "29 - Evil One",
"30 - Lord Mildrath", "31 - Monsters", "32 - Demon Combat", "33 - Orgo Demila", "34 - Dhoulmagus",
"35 - Battle in the Heavens", "36 - Verse of Prayer", "37 - Sandy's Theme",
"38 - Protectors of the Starry Sky", "39 - Painful Feelings", "40 - Toward the Starry Sky",
"41 - Sandy's Tears", "42 - Cave Waltz", "43 - Accepting a Quest", "44 - Quest Clear", "45 - Job Change",
"46 - Level Up", "47 - Victory", "48 - Stay at the Inn", "49 - Gained an Ally", "50 - Found Mini Medal",
"51 - Defeated", "52 - Church Treatment", "53 - Pray at the Church", "54 - Cursed", "55 - Fanfare1",
"56 - Fanfare2", "57 - Found Precious Item", "58 - Harp Melody", "59 - Superstar", "60 - Surprise",
"61 - You Lose", "62 - Tragic Prologue (with Effects)", "63 - Swirling Desire ~ Destiny (with Effects)"]
def remove_extra_whitespace(string):
return re.sub(' +', ' ', string).strip()
def _hex(value):
n = int(value)
if n <= 16:
return n
n = int(value, base=16)
hex_str = str.upper(hex(n)[2:])
return hex_str.zfill(2)
def is_special(data):
try:
return data[0] == grotto_special
except ValueError:
return False
def create_grotto(datas):
converters = (_hex, int, str)
res = []
seed_found = False
next_grotto = False
for data in datas:
match_found = re.compile(cleanup_regex).match(data)
if match_found:
stripped = str.strip(match_found.group(), "' ")
if stripped != "":
for i, converter in enumerate(converters):
try:
converted = converter(stripped)
except:
continue
else:
if isinstance(converted, str):
if converted.find(":") > -1:
if converted == "Seed:":
if not seed_found:
seed_found = True
else:
next_grotto = True
continue
elif converted == grotto_special:
res.insert(0, converted)
else:
res.append(converted)
else:
res.append(converted)
break
finally:
if next_grotto:
yield tuple(res)
res = []
next_grotto = False
if len(res) > 0:
yield tuple(res)
def parse_regex(type, string):
regex = ""
if type == Quest:
regex = quests_regex
matches = re.findall(regex, string, flags=re.MULTILINE)
if type == Quest:
number = int(matches[0][1])
name = matches[0][2]
story = matches[0][0] == "⭐"
location = ""
request = ""
solution = ""
reward = ""
prerequisite = ""
repeat = False
for info in matches[1:]:
title = info[3].lower()
data = remove_extra_whitespace(info[4].strip())
if title == "location":
location = data
if title == "request":
request = data
if title == "solution":
solution = data
if title == "reward":
reward = data
if title == "prerequisite":
prerequisite = data
if title == "repeat":
repeat = data.lower() == "yes"
quest = Quest(number, name, story, location, request, solution, reward, prerequisite, repeat)
return quest.to_dict()