Update chart randomizer to support a dry run
@@ -4,15 +4,24 @@ import copy
def randomize_charts(self):
# Shuffles around which chart points to each sector.
- randomizable_charts = [chart for chart in self.chart_list.charts if chart.type in [0, 1, 2, 6]]
+ original_item_names = list(self.island_number_to_chart_name.values())
+
+ # Shuffles the list of island numbers.
+ # The shuffled island numbers determine which sector each chart points to.
+ shuffled_island_numbers = list(self.island_number_to_chart_name.keys())
+ self.rng.shuffle(shuffled_island_numbers)
+ if not self.dry_run:
+ randomizable_charts = [chart for chart in self.chart_list.charts if chart.type in [0, 1, 2, 6]]
original_charts = copy.deepcopy(randomizable_charts)
- # Sort the charts by their texture ID so we get the same results even if we randomize them multiple times.
- original_charts.sort(key=lambda chart: chart.texture_id)
- self.rng.shuffle(original_charts)
- for chart in randomizable_charts:
- chart_to_copy_from = original_charts.pop()
+ for original_item_name in original_item_names:
+ shuffled_island_number = shuffled_island_numbers.pop()
+
+ if not self.dry_run:
+ # Finds the corresponding charts for the shuffled island number and original item name.
+ chart_to_copy_from = next(chart for chart in original_charts if chart.island_number == shuffled_island_number)
+ chart = next(chart for chart in randomizable_charts if chart.item_name == original_item_name)
chart.texture_id = chart_to_copy_from.texture_id
chart.sector_x = chart_to_copy_from.sector_x
@@ -36,6 +45,6 @@ def randomize_charts(self):
scob.chart_index_plus_1 = chart.owned_chart_index_plus_1
scob.save_changes()
- self.island_number_to_chart_name[chart_to_copy_from.island_number] = chart.item_name
+ self.island_number_to_chart_name[shuffled_island_number] = original_item_name
self.logic.update_chart_macros()
