-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
816 lines (668 loc) · 33 KB
/
Copy pathmain.py
File metadata and controls
816 lines (668 loc) · 33 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
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
import argparse
import json
import re
import shutil
from pathlib import Path
from jinja2 import Environment, FileSystemLoader
from urllib.parse import urlparse
npc_ids = {}
stage_nos = {}
spot_ids = {}
category_map = {
'main_quest': 'Main Quests',
# 'pawn_quest': 'Pawn Quests',
'personal_quest': 'Personal Quests',
'world_quest': 'World Quests',
}
# {"title": "Season 1.0", "content": "Season 1", "url": "season_1_0.html"},
search_index = []
# Global used to track references of item
item_reference_map = {}
def add_item_reference(item_id, reftype, title, link):
if item_id not in item_reference_map:
item_reference_map[item_id] = {}
if reftype not in item_reference_map[item_id]:
item_reference_map[item_id][reftype] = {}
if title in item_reference_map[item_id][reftype]:
return
item_reference_map[item_id][reftype][title] = {
"type": reftype,
"title": title,
"link": link,
}
def _genric_replace(match, type_map, tag_name):
type_id = int(match.group(1))
if type_id in type_map:
return f'<span class="translated-text" title="{tag_name}={type_id}">{type_map[type_id]}</span>'
return f"<{tag_name} {type_id}>"
def _replace_npc_id(match):
return _genric_replace(match, npc_ids, 'NPC')
def _replace_stage_id(match):
return _genric_replace(match, stage_nos, 'STG')
def _replace_spot_id(match):
return _genric_replace(match, spot_ids, 'SPOT')
def _breakup_camelcase_string(string):
if ' ' in string:
return string
res = re.findall('[A-Z][^A-Z]*', string)
return ' '.join(filter(None, res))
def _get_quest_link(quest_map, quest_id):
quest_name = f'q{quest_id:08d}'
if quest_id in quest_map:
quest_name = quest_map[quest_id]['name']
return (f'q{quest_id:08d}', quest_name)
def _generate_quest_references(quest_data):
if 'references' not in quest_data:
return []
references = []
for reference in quest_data['references']:
a = urlparse(reference)
hostname = a.hostname
if 'youtube' in hostname:
hostname = 'yt'
references.append((reference, hostname))
return references
def _get_quest_unlocks(unlocks):
if unlocks is None or len(unlocks) == 0:
return []
results = []
for unlock in unlocks:
results.append(_breakup_camelcase_string(unlock))
return results
def _get_quest_name_from_condition(quest_map, condition):
param01 = condition['param01']
if param01 in quest_map:
param01 = quest_map[param01]['name']
return param01
def _get_quest_link_from_condition(args, quest_map, condition):
quest_id = condition['param01']
quest_name = _get_quest_name_from_condition(quest_map, condition)
return f'<a href="q{quest_id:08d}.html">{quest_name}</a>'
def _get_condition(args, quest_map, quest, condition):
condition_type = condition['type']
if condition_type == 'MinimumLevel':
param01 = condition['param01']
return f"Minimum level of <tt><b>{param01}</b></tt> or higher in any vocation"
elif condition_type == 'ClearPersonalQuest':
param01 = _get_quest_link_from_condition(args, quest_map, condition)
return f'Clear the personal quest <b>{param01}</b>'
elif condition_type == 'MainQuestCompleted':
param01 = _get_quest_link_from_condition(args, quest_map, condition)
return f'Clear the main story quest <b>{param01}</b>'
elif condition_type == 'ClearExtremeMission':
param01 = _get_quest_link_from_condition(args, quest_map, condition)
return f'Clear the extreme mission <b>{param01}</b>'
elif condition_type == 'ArisenTactics':
return 'Complete the Arisen\'s Tactics Trial for Shield Sage, Hunter, Priest or Fighter'
elif condition_type == 'AreaRank':
param01 = _breakup_camelcase_string(condition['param01'])
param02 = condition['param02']
return f'Area rank of <tt><b>{param02}</b></tt> or higher in <tt><b>{param01}</b></tt>'
elif condition_type == 'ItemRank':
param01 = condition['param01']
return f'Minimum item level of <tt><b>{param01}</b></tt> is required'
elif condition_type == 'Message':
return condition['param01']
elif condition_type == 'MinimumVocationLevel':
jobId = _breakup_camelcase_string(condition['param01'])
level = condition['param02']
return f'Vocation restriction: <tt><b>{jobId}</b></tt>, at least level <tt><b>{level}</b></tt>'
return _breakup_camelcase_string(condition_type)
def _get_quest_order_conditions(args, quest_map, quest_data):
conditions = []
for condition in quest_data['order_conditions']:
conditions.append(_get_condition(args, quest_map, quest_data, condition))
return conditions
def _get_quest_starting_npc(quest_data):
npc_info = quest_data['starting_npc']
if npc_info is not None:
npc_info = f"{quest_data['starting_npc']['name']} ({quest_data['starting_npc']['stage']['name']})"
else:
npc_info = 'None'
return npc_info
def _get_quest_subcategory(subcategory, quest_data):
quest_type = quest_data['type']
if quest_type == 'World':
return _breakup_camelcase_string(quest_data['area_id'])
elif quest_type == 'Main':
return subcategory.replace('_', ' ', 1).replace('_', '.').title()
return quest_type
def _get_quest_chain(quest_map, quest_data, key):
quest = None
if quest_data["quest_chain"][key] != 0:
quest = _get_quest_link(quest_map, quest_data["quest_chain"][key])
return quest
def _generate_reward_entries(quest_data, unlocks, rewards):
content = ''
for slot in rewards:
if 'type' not in slot:
reward_type = 'Unlocks'
else:
reward_type = slot["type"]
if reward_type == 'Select1':
reward_type = 'Select one of the following'
elif reward_type == 'Fixed':
reward_type = 'Fixed Rewards'
if len(content):
content = f'{content}<br>・{reward_type}\n'
else:
content = f'・{reward_type}\n'
pools = slot['pools']
for i in range(0, len(pools)):
item_list = ''
for item in pools[i]:
result = f'{item["name"]} x{item["amount"]}'
if 'item_id' in item:
item_id = item['item_id']
result = f'<a href="i{item_id:08d}.html">{result}</a>'
quest_link = f'q{quest_data['quest_id']:08d}.html'
add_item_reference(item_id, 'Quest', quest_data['name'], quest_link)
if 'Bloodorb' in result:
result = f'<span class="reward-bloodorb">{result}</span>'
if len(item_list) == 0:
item_list = result
else:
item_list = f'{item_list}, {result}'
if len(pools) == 1 or (len(pools) - 1) == i:
item_list = f'└{item_list}'
else:
item_list = f'├{item_list}'
content = f'{content}<br>{item_list}'
if len(unlocks):
unlock_string = ''
for unlock in unlocks:
unlock = _breakup_camelcase_string(unlock)
unlock = f'<span class="reward-unlock">《{unlock}》</span>'
if len(unlock_string):
unlock_string = f'{unlock_string}, {unlock}'
else:
unlock_string = unlock
if len(content):
content = f'{content}<br><br>{unlock_string}'
else:
content = unlock_string
return content
def _get_quest_variations(quest_data):
variants = []
keys = ['level', 'xp', 'gold', 'rift', 'ap', 'rewards']
for variant in quest_data['variants']:
result = []
for key in keys:
value = variant[key]
width = 5
alignment = 'center'
if key == 'rewards':
width = 75
alignment = 'left'
value = _generate_reward_entries(quest_data, [], value)
if len(value) == 0:
value = 'None'
elif key == 'level' and variant['is_bounty']:
value = f'{value}<br>(bounty)'
style = f'width: {width}%; text-align: {alignment};'
result.append((value, style))
variants.append(result)
return variants
def _translate_string(string):
if '<NPC' in string:
string = re.sub(r'<NPC (\d+)>', _replace_npc_id, string)
if '<STG' in string:
string = re.sub(r'<STG (\d+)>', _replace_stage_id, string)
if '<SPOT' in string:
string = re.sub(r'<SPOT (\d+)>', _replace_spot_id, string)
return ' '.join(string.split())
_tags_regx = re.compile('<.*?>')
def _strip_tags(string):
return re.sub(_tags_regx, '', string)
def build_quest_info(args, titles_map, info_template, quest_map, quest_data):
quest_id = quest_data['quest_id']
area_rank = None
if quest_data['minimum_area_rank'] > 0:
area_rank = f"{_breakup_camelcase_string(quest_data['area_id'])} {quest_data['minimum_area_rank']}"
quest_walkthrough = None
if 'walkthrough' in quest_data:
quest_walkthrough = quest_data['walkthrough']
translated_description = _translate_string(quest_data['description'])
translated_steps = []
for step in quest_data['steps']:
translated_steps.append(_translate_string(step))
content = info_template.render(
quest_title_category=quest_data['title_category'],
quest_title_subcategory =_get_quest_subcategory(quest_data['title_subcategory'], quest_data),
quest_name=quest_data['name'],
quest_id=quest_data['quest_id'],
quest_jp_name=titles_map[quest_id]['jp_name'],
quest_type=quest_data['type'],
quest_style=quest_data['type'].lower(),
quest_starting_npc=_get_quest_starting_npc(quest_data),
quest_category=_breakup_camelcase_string(quest_data['guide_type']),
quest_is_repeatable="Yes" if quest_data['repeatable'] else "No",
quest_minimum_area_rank = area_rank,
quest_description=translated_description,
quest_references=_generate_quest_references(quest_data),
quest_order_conditions=_get_quest_order_conditions(args, quest_map, quest_data),
quest_tutorial_unlocks = _get_quest_unlocks(quest_data['unlocks']['tutorials']),
quest_content_unlocks = _get_quest_unlocks(quest_data['unlocks']['contents']),
next_quest = _get_quest_chain(quest_map, quest_data, 'next_quest_id'),
prev_quest = _get_quest_chain(quest_map, quest_data, 'previous_quest_id'),
quest_variations = _get_quest_variations(quest_data),
quest_steps = translated_steps,
quest_walkthrough = quest_walkthrough
)
search_index.append({
'title': quest_data['name'],
'content': quest_data['description'],
'content_id': f'q{quest_id:08d}',
'url': f'q{quest_id:08d}.html',
'type': quest_data['type'],
'icon': None
})
output_file = Path(f'{args.output_dir}/q{quest_id:08d}.html')
with open(output_file, mode='w', encoding='utf-8') as f:
f.write(content)
print(f"... wrote {output_file}")
def _get_subcat_name(category, subcat):
subcat_name = subcat
if 'World Quests' == category:
subcat_name = subcat.split('_', 1)[1].replace("_", ' ').title()
elif 'Main Quests' == category:
subcat_name = subcat.replace('_', ' ', 1).replace('_', '.').title()
elif 'Personal Quests' == category:
subcat_name = subcat.replace('_', ' ').title()
return subcat_name
def build_category_list(args, titles_map, category_template, quest_map, category, quests):
subcat_names = {}
quests_by_subcat = {}
for quest in quests:
subcat = quest['title_subcategory']
if subcat not in quests_by_subcat:
quests_by_subcat[subcat] = []
quests_by_subcat[subcat].append(quest)
if subcat not in subcat_names:
subcat_name = _get_subcat_name(category, subcat)
subcat_names[subcat] = (subcat, subcat_name)
for subcat in quests_by_subcat:
subcat_name = _get_subcat_name(category, subcat)
quests_ = []
for quest in quests_by_subcat[subcat]:
quest_id = quest['quest_id']
en_name = quest['name']
jp_name = ''
if quest_id in titles_map:
jp_name = titles_map[quest_id]['jp_name']
name = f'{en_name}'
if len(jp_name):
name = f'{name}<br>{jp_name}'
res_page = f'<a href="https://github.com/ddon-research/ddon-data/tree/main/client/03040008/quest/q{quest_id:08d}" target="_blank">q{quest_id:08d}</a>'
info_page = f'<a href="q{quest_id:08d}.html">{name}</a>'
keys = ['level', 'xp', 'gold', 'rift', 'ap', 'rewards']
variants = []
for variant in quest['variants']:
values = []
for key in keys:
value = variant[key]
if key == 'rewards':
unlocks = quest['unlocks']['contents']
value = _generate_reward_entries(quest, unlocks, value)
elif key == 'level' and variant['is_bounty']:
value = f'{value}<br>(bounty)'
values.append(value)
variants.append(values)
quests_.append({
'quest_res': res_page,
'quest_info': info_page,
'name': en_name,
'variants': variants
})
content = category_template.render(
title = f'{category} / {subcat_name}',
main_category = category,
sub_category = subcat_name,
quests = quests_,
subcats = subcat_names.values()
)
subcat_fname = subcat.replace(' ', '_').replace('.', '_')
output_file = Path(f'{args.output_dir}/{subcat_fname}.html')
with open(output_file, mode='w', encoding='utf-8') as f:
f.write(content)
print(f"... wrote {output_file}")
def build_item_category_list(args, template, category, categories):
subcats = {}
for c in categories.keys():
subcat_name = c.replace('_', ' ').title()
subcats[c] = (f'items_{c}', subcat_name)
item_order_map = {}
for item in categories[category]:
item_name = item['name']
first_letter = item_name[0]
if first_letter not in item_order_map:
item_order_map[first_letter] = {}
if item_name not in item_order_map[first_letter]:
item_order_map[first_letter][item_name] = []
item['link'] = f'i{item["item_id"]:08d}.html'
item['quality_name'] = '{}<br><span style="color: #8d7934;">{}</span>'.format(item_name, '★' * item['quality'] if item['quality'] > 0 else '')
# filter stats
stats = {}
if 'stats' in item:
for stat_name in item['stats']:
stat = item['stats'][stat_name]
if stat == 0 or stat_name == 'ele_slot':
continue
stats[stat_name.replace('_', ' ').title()] = stat
stats['Weight'] = item['weight']
item['filtered_stats'] = stats
item['icon_path'] = f"images/icons/large/ii{item['icon']['icon_id']:06d}.png"
item['info'] = _strip_tags(item['info'])
item_order_map[first_letter][item_name].append(item)
item_order_map[first_letter][item_name] = sorted(item_order_map[first_letter][item_name], key=lambda x: x['quality'])
# Put them in ABC order
item_order_map = dict(sorted(item_order_map.items()))
category_name = category.replace('_', ' ').title()
content = template.render(
title = f'Items / {category_name}',
subcats=subcats.values(),
items_map = item_order_map,
category=category
)
output_file = Path(f'{args.output_dir}/items_{category}.html')
with open(output_file, mode='w', encoding='utf-8') as f:
f.write(content)
print(f"... wrote {output_file}")
def _create_name_with_quality(item):
quality = ''
if item['quality'] > 0:
quality = item['quality'] * '★'
item_name = item['name']
if len(quality):
item_name = f'{item_name} {quality}'
return item_name
def _create_item_link(key, item, item_map):
link = None
if item[key] in item_map:
data = item_map[item[key]]
item_id = data['item_id']
link_name = _create_name_with_quality(data)
link = f'<a href="i{item_id:08d}.html">{link_name}</a>'
return link
def build_item_info(args, template, item, item_map):
item_id = item['item_id']
subcat_name = item['title_subcategory'].title()
quality = ''
if item['quality'] > 0:
quality = item['quality'] * '★'
# filter stats
stats = {}
if 'stats' in item:
for stat_name in item['stats']:
stat = item['stats'][stat_name]
if stat == 0 or stat_name == 'ele_slot':
continue
stats[stat_name] = stat
stats['Weight'] = item['weight']
job_icons = []
if 'jobs' in item:
for job in item['jobs']:
name = job.lower().replace(' ', '')
title = _breakup_camelcase_string(job)
job_icons.append(f'<img src="images/icon-job_{name}.png" title="{title}" width="48" height="54">')
previous_item_link = _create_item_link('previous_item_id', item, item_map)
next_item_link = _create_item_link('next_item_id', item, item_map)
craft_recipe = []
for material in item['craft_recipe']:
add_item_reference(material['item_id'], 'Craft', _create_name_with_quality(item), f'i{item_id:08d}.html')
craft_recipe.append({
"link": _create_item_link('item_id', material, item_map),
"amount": material['amount']
})
gradeup_recipe = []
for material in item['gradeup_recipe']:
add_item_reference(material['item_id'], 'Gradeup', _create_name_with_quality(item), f'i{item_id:08d}.html')
gradeup_recipe.append({
"link": _create_item_link('item_id', material, item_map),
"amount": material['amount']
})
content = template.render(
title = f'Items / {subcat_name}',
subcat_name = subcat_name.replace('_', ' ').title(),
record_type = item['type'],
item_name = item['name'],
item_type = item['type'].title(),
item_id = item_id,
item_level = item['level'] if 'level' in item else 0,
item_rank = item['item_level'] if 'item_level' in item else 0,
icon_id = f"ii{item['icon']['icon_id']:06d}",
item_stats = stats,
item_params = item['params'] if 'params' in item else [],
item_info = item["info"].replace("\n", " "),
item_can_baz = 'Yes' if item['can_bazaar'] else 'No',
item_sell_price = item['sell_price'],
item_quality = quality,
job_icons=job_icons,
reference_map=item_reference_map[item_id] if item_id in item_reference_map else {},
item_craft_recipe=craft_recipe,
item_grade_up_recipe=gradeup_recipe,
item_gather = item['gather'] if 'gather' in item else [],
item_hunt = item['hunt'] if 'hunt' in item else [],
item_shop = item['shop'] if 'shop' in item else [],
prev_item=previous_item_link,
next_item=next_item_link
)
search_index.append({
'title': '{} {}'.format(item['name'], quality),
'content': item['info'],
'content_id': f'i{item_id:08d}',
'url': f'i{item_id:08d}.html',
'type': item['type'].title(),
'icon': f"images/icons/small/ii{item['icon']['icon_id']:06d}.png"
})
output_file = Path(f'{args.output_dir}/i{item_id:08d}.html')
with open(output_file, mode='w', encoding='utf-8') as f:
f.write(content)
print(f"... wrote {output_file}")
def build_index(args, index_template, titles_map, quest_map, quest_data):
content = index_template.render()
output_file = Path(f'{args.output_dir}/index.html')
with open(output_file, mode='w', encoding='utf-8') as f:
f.write(content)
print(f"... wrote {output_file}")
def build_site(args):
# Assign to global fot lambda replacement
parse_npc_ids(args)
parse_stage_list(args)
parse_spot_names(args)
titles_map = parse_titles(args)
environment = Environment(loader=FileSystemLoader("templates/"))
info_template = environment.get_template("info.html")
category_template = environment.get_template("category.html")
item_info_template = environment.get_template("item_info.html")
item_category_template = environment.get_template("item_category.html")
index_template = environment.get_template("index.html")
item_map = {}
items_by_category = {}
for subcategory in Path(f'{args.data_root}/items').iterdir():
if not subcategory.is_dir():
continue
print(subcategory.name)
for item in subcategory.iterdir():
with open(item, 'r', encoding='utf-8') as f:
item_data = json.load(f)
item_data['title_category'] = 'Items'
item_data['title_subcategory'] = subcategory.name
item_map[item_data['item_id']] = item_data
if subcategory.name not in items_by_category:
items_by_category[subcategory.name] = []
items_by_category[subcategory.name].append(item_data)
quest_map = {}
quests_by_category = {}
for filepath in Path(args.data_root).iterdir():
if filepath.name not in category_map:
continue
quest_category = category_map[filepath.name]
if not filepath.is_dir():
continue
for subcategory in filepath.iterdir():
if not subcategory.is_dir():
continue
for quest in subcategory.iterdir():
with open(quest, 'r', encoding='utf-8') as f:
quest_data = json.load(f)
quest_data['title_category'] = quest_category
quest_data['title_subcategory'] = subcategory.name
quest_map[quest_data['quest_id']] = quest_data
if quest_category not in quests_by_category:
quests_by_category[quest_category] = []
quests_by_category[quest_category].append(quest_data)
for category in quests_by_category:
build_category_list(args, titles_map, category_template, quest_map, category, quests_by_category[category])
for quest_id in quest_map:
quest_data = quest_map[quest_id]
build_quest_info(args, titles_map, info_template, quest_map, quest_data)
# If we build these after quests and eney data parsing
# we can grab back reference information about being mentioned
for category in items_by_category:
build_item_category_list(args, item_category_template, category, items_by_category)
for item_id in item_map:
item_data = item_map[item_id]
build_item_info(args, item_info_template, item_data, item_map)
build_index(args, index_template, titles_map, quest_map, quest_data)
with open(f'{args.output_dir}/search_data.json', 'w', encoding='utf-8') as f:
f.write(json.dumps(search_index, indent=4))
def parse_npc_ids(args):
with open(args.npcs, 'r', encoding='utf-8') as f:
data = json.load(f)
for name in data:
npc_id = data[name]
name = _breakup_camelcase_string(name)
npc_ids[npc_id] = ''.join([char for char in name if not char.isnumeric()])
def parse_spot_names(args):
with open(args.spots, 'r', encoding='utf-8') as f:
lines = f.readlines()
# SPOT_NAME_450,白竜神殿レーゼ,The White Dragon Temple
i = 0
for line in lines:
if i == 0:
i += 1
continue
spot, jp_name, en_name = line.split(',', 2)
spot_id = int(spot.rsplit('_', 1)[1])
spot_ids[spot_id] = en_name
def parse_stage_list(args):
with open(args.stages, 'r', encoding='utf-8') as f:
data = json.load(f)
for stage_info in data['StageListInfoList']:
stage_no = stage_info['StageNo']
stage_nos[stage_no] = stage_info['StageName']['En']
def parse_titles(args):
with open(args.titles, 'r', encoding='utf-8') as f:
lines = f.readlines()
title_map = {}
for line in lines:
quest_id, line = line.split(':', 1)
en_name, jp_name = line.split('|')
quest_id = int(quest_id.split('_')[0].strip()[1:])
en_name = en_name.strip()
jp_name = jp_name.strip()
title_map[quest_id] = {'en_name': en_name, 'jp_name': jp_name}
# Add on off missing information
title_map[22020000] = {'en_name': 'Furious Charge', 'jp_name': '激昂の突進'}
title_map[22018051] = {'en_name': 'Flickering Shadow of Flame', 'jp_name': '徘徊する炎の影'}
title_map[22018052] = {'en_name': 'A Difficult Journey', 'jp_name': '石拾うにも苦難の道程'}
title_map[22018053] = {'en_name': 'Judge of Truth', 'jp_name': '真偽の判定者'}
title_map[22018054] = {'en_name': 'Unshakeable Anxiety', 'jp_name': '拭えぬ心労'}
title_map[22018055] = {'en_name': 'Lost in the Haze', 'jp_name': '行方を眩ます陽炎'}
title_map[22018056] = {'en_name': 'Time Restriction: Collecting Ash Before the Demons Return', 'jp_name': '【時限採取】鬼の居ぬ間の採灰道'}
title_map[30210] = {'en_name': 'The Missing Prince', 'jp_name': '消えた王子'}
title_map[30220] = {'en_name': 'Nedo\'s Trail', 'jp_name':'ネドの足取り'}
title_map[30230] = {'en_name': 'The Royal Family Mausoleum', 'jp_name':'王家の墓'}
title_map[30240] = {'en_name': 'The Dreadful Passage', 'jp_name':'恐ろしき道'}
title_map[30250] = {'en_name': 'The Relics of the First King', 'jp_name':'初代王の遺品'}
title_map[30260] = {'en_name': 'Hope\'s Bitter End', 'jp_name':'望みの果て'}
title_map[30270] = {'en_name': 'Those Who Follow the Dragon', 'jp_name':'竜を継ぐ者'}
title_map[30410] = {'en_name': 'Breakdown of Reason', 'jp_name':'理の崩壊'}
title_map[30420] = {'en_name': 'Spun Together Hope', 'jp_name':'紡ぎし望み'}
title_map[30430] = {'en_name': 'The White Dragon\'s Arisen', 'jp_name':'白竜の覚者'}
title_map[30440] = {'en_name': 'The Fate of All', 'jp_name':'すべての行く末'}
title_map[60301052] = {
'jp_name': '緊急! お菓子が足りない!<1>',
'en_name': 'Emergency! Not Enough Candy! (1)'
}
title_map[60301053] = {
'jp_name': '事件? お菓子が足りない!<2>',
'en_name': 'Emergency! Not Enough Candy! (2)'
}
title_map[60301056] = {'jp_name': '笑顔振りまくメリークリスマス<2>', 'en_name': 'A Merry Christmas Spreading Cheer (2)'}
title_map[60350000] = {'jp_name': 'ガルドノック砦の異変', 'en_name': 'Strange Happening at Guardknock Fortress'}
title_map[60350001] = {'jp_name': '神殿を狙うは――', 'en_name': 'Aiming for the Temple'}
title_map[60350002] = {'jp_name': '次代の竜となる者へ', 'en_name': 'To The One Who Will Become the Next Dragon'}
title_map[60321002] = {'jp_name': 'ウルテカ山岳 試練:静かな抗戦跡', 'en_name': 'Urteca Mountains Trial: Quiet Battlefield of the Resistance'}
title_map[60321001] = {'jp_name': 'ウルテカ山岳 試練:痛刻の洞', 'en_name': 'Urteca Mountains Trial: The Scarred Cavern'}
title_map[60300110] = {'jp_name': '冒険スポットの手引き:ウルテカ山岳1', 'en_name': 'Adventure Spot Guide: Urteca Mountains I'}
title_map[60321000] = {'jp_name': 'ウルテカ山岳 試練:原種の縄張り', 'en_name': 'Urteca Mountains Trial: Territory of the Ancestors'}
title_map[60300200] = {'jp_name': '王冠と王笏<1>', 'en_name': 'Crown and Scepter I'}
title_map[60300201] = {'jp_name': '王冠と王笏<2>', 'en_name': 'Crown and Scepter II'}
title_map[60300202] = {'jp_name': '王冠と王笏<3>', 'en_name': 'Crown and Scepter III'}
title_map[60300203] = {'jp_name': '王冠と王笏<4>', 'en_name': 'Crown and Scepter IV'}
title_map[60321003] = {'jp_name': 'ウルテカ山岳 試練:原初の集落', 'en_name': 'Urteca Mountains Trial: Primitive Settlement'}
title_map[60300111] = {'jp_name': '冒険スポットの手引き:ウルテカ山岳2', 'en_name': 'Adventure Spot Guide: Urteca Mountains II'}
title_map[60300112] = {'jp_name': '冒険スポットの手引き:ウルテカ山岳3', 'en_name': 'Adventure Spot Guide: Urteca Mountains III'}
title_map[60321004] = {'jp_name': 'ウルテカ山岳 試練:建設資材集積場', 'en_name': 'Urteca Mountains Trial: Construction Materials Collection Spot'}
title_map[60300023] = {'jp_name': '英霊眠りし道へ ウルテカ地方', 'en_name': 'To the Heroic Spirit Sleeping Path Urteca District'}
title_map[60321010] = {'jp_name': 'ウルテカ山岳 試練:闇の滴り', 'en_name': 'Urteca Mountains Trial: A Trickle in the Darkness'}
title_map[60321011] = {'jp_name': '彼方より堕ち呼ばれし魔道', 'en_name': 'Magick Called to the Deepest Depths'}
title_map[60300043] = {'jp_name': '王家再興の褒章4', 'en_name': 'Restored Medal of the Royal Family 4'}
title_map[61000000] = {'jp_name': 'ワイルドハントのご案内', 'en_name': 'Information on Wild Hunt'}
title_map[61000001] = {'jp_name': '竜の力を帯びた武具<1>', 'en_name': 'Arms With the Power of the Dragon I'}
title_map[61000002] = {'jp_name': '竜の力を帯びた武具<2>', 'en_name': 'Arms With the Power of the Dragon II'}
title_map[61000004] = {'jp_name': '黒呪の迷宮 深淵への案内', 'en_name': 'Information on Bitterblack Maze Abyss'}
title_map[61000005] = {'jp_name': '途絶えぬ闇', 'en_name': 'Unending Darkness'}
title_map[60300401] = {'jp_name': '求道の師を求めて ハイセプター', 'en_name': 'Seeking the Master: High Scepter'}
title_map[60300042] = {'jp_name': '王家再興の褒章3', 'en_name': 'Restored Medal of the Royal Family 3'}
title_map[60300105] = {'jp_name': '冒険スポットの手引き:フェルヤナ荒原2', 'en_name': 'Adventure Spot Guide: Feryana Wilderness II'}
title_map[60300041] = {'jp_name': '王家再興の褒章2', 'en_name': 'Restored Medal of the Royal Family 2'}
title_map[60300002] = {'jp_name': 'カスタムメイド工房1 探求者の帰還', 'en_name': 'Custom-Made Workshop 1: Searcher\'s Return'}
title_map[60300003] = {'jp_name': 'カスタムメイド工房2 リミット解除', 'en_name': 'Custom-Made Workshop 2: Limit Break'}
title_map[60300004] = {'jp_name': 'カスタムメイド工房3 武具極限合成', 'en_name': 'Custom-Made Workshop 3: Ultimate Arms Synthesis'}
title_map[60300101] = {'jp_name': '冒険スポットの手引き:ラスニテ山麓2', 'en_name': 'Adventure Spot Guide: Rathnite Foothills II'}
title_map[60200007] = {'jp_name': '辺境に眠りし宝2', 'en_name': 'The Treasure Lying in the Frontier 2'}
title_map[60200004] = {'jp_name': '至高の耀き', 'en_name': 'Supreme Radiance'}
return title_map
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('-o', '--output_dir', default='build', help='Controls the output directory')
parser.add_argument('-t', '--titles', default='resources/titles.txt', help='Path to the file containing quest titles')
parser.add_argument('-n', '--npcs', default='resources/npc_id.json', help='Path to npc_id.json')
parser.add_argument('-p', '--spots', default='resources/spot_name.csv', help='Path to spot_name.csv')
parser.add_argument('-s', '--stages', default='resources/stage_list.slt.json', help='Path to stage_list.slt.json')
parser.add_argument('data_root', help='Path to quest data')
args = parser.parse_args()
paths = [args.data_root]
for p in paths:
path = Path(p)
if not path.exists():
print(f'The path "{path}" is invalid. Exiting.')
return None
if not path.is_dir():
print(f'The path "{path}" is not a directory. Exiting.')
return None
paths = [args.titles, args.npcs, args.stages, args.spots]
for p in paths:
if not Path(p).exists():
print('The path "{p}" is invalid. Exiting.')
return None
# create the output dir
Path(args.output_dir).mkdir(parents=True, exist_ok=True)
return args
def copy_deps(args):
Path(f'{args.output_dir}/css').mkdir(parents=True, exist_ok=True)
shutil.copytree("css", f'{args.output_dir}/css', dirs_exist_ok=True)
shutil.copytree("webfonts", f'{args.output_dir}/webfonts', dirs_exist_ok=True)
shutil.copytree("images", f'{args.output_dir}/images', dirs_exist_ok=True)
shutil.copytree("scripts", f'{args.output_dir}/scripts', dirs_exist_ok=True)
def main():
args = parse_args()
if args is None:
return
copy_deps(args)
build_site(args)
if __name__ == '__main__':
main()