forked from icebound777/PMR-SeedGenerator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spoilerlog.py
72 lines (63 loc) · 2.92 KB
/
spoilerlog.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
import io
from metadata.verbose_area_names import verbose_area_names
from metadata.verbose_item_names import verbose_item_names
from metadata.verbose_item_locations import verbose_item_locations
from optionset import OptionSet
def write_spoiler_log(
placed_items:list,
random_chapter_difficulty:dict=None,
settings:OptionSet=False,
spoilerlog_file:str=None,
is_web_spoiler_log=False,
spheres_text = None
):
"""
Outputs a log file listing the final locations of all items
after randomization and randomized chapter difficulty
"""
sorted_by_key = sorted(placed_items, key=lambda node: node.key_name_item)
sorted_by_map = sorted(sorted_by_key, key=lambda node: node.map_area.map_id)
sorted_by_area = sorted(sorted_by_map, key=lambda node: node.map_area.area_id)
if is_web_spoiler_log:
file = io.StringIO()
else:
file = open(spoilerlog_file, "w", encoding="utf-8")
# Print chapter difficulties
if random_chapter_difficulty and not settings.progressive_scaling["value"]:
file.write("Modified Chapter Difficulty:")
for old_chapter, new_chapter in random_chapter_difficulty.items():
file.write(f"\nChapter {old_chapter} -> Chapter {new_chapter}")
file.write("\n\n")
# Print item locations
if settings.pretty_spoilerlog:
current_area_name = None
for node in sorted_by_area:
new_area_name = verbose_area_names.get(node.map_area.name[:3])
if (current_area_name is None):
file.write(f"{new_area_name}:\n")
elif (new_area_name != current_area_name):
file.write(f"\n{new_area_name}:\n")
current_item_name = node.current_item.item_name
map_verbose_name = node.map_area.verbose_name
if current_item_name in verbose_item_names:
current_item_name = verbose_item_names.get(current_item_name)
if ( node.map_area.name in verbose_item_locations
and node.key_name_item in verbose_item_locations.get(node.map_area.name)):
item_location = (f"{map_verbose_name} - "
f"{verbose_item_locations.get(node.map_area.name).get(node.key_name_item)}")
else:
item_location = f"{map_verbose_name} - {node.key_name_item}"
if node.current_item.is_trapped():
file.write(f" ({item_location}): TRAP ({current_item_name})\n")
else:
file.write(f" ({item_location}): {current_item_name}\n")
current_area_name = verbose_area_names.get(node.map_area.name[:3])
else:
for node in sorted_by_area:
file.write(f"[{node.map_area.name}] {node.key_name_item} - "
f"{node.current_item.item_name}\n")
if(spheres_text):
file.write(f'\n{spheres_text}')
if is_web_spoiler_log:
file.seek(0)
return file