def replace_references_to_area_identifier(self, old_identifier: AreaIdentifier, new_identifier: AreaIdentifier): if old_identifier == new_identifier: return for world in self.game.world_list.worlds: for area in world.areas: for i in range(len(area.nodes)): node = area.nodes[i] new_node = None if isinstance(node, TeleporterNode): if node.default_connection == old_identifier: new_node = dataclasses.replace( node, identifier=node.identifier.renamed( node.name.replace(old_identifier.area_name, new_identifier.area_name) ), default_connection=new_identifier, ) elif isinstance(node, DockNode): if node.default_connection.area_identifier == old_identifier: new_node = dataclasses.replace( node, identifier=node.identifier.renamed( node.name.replace(old_identifier.area_name, new_identifier.area_name), ), default_connection=NodeIdentifier( area_identifier=new_identifier, node_name=node.default_connection.node_name, ), ) if new_node is not None: self.replace_node(area, node, new_node)
def _create_new_dock(self, location: NodeLocation, target_area: Area): current_area = self.current_area target_identifier = self.world_list.identifier_for_area(target_area) source_identifier = self.world_list.identifier_for_area(current_area) dock_weakness = self.game_description.dock_weakness_database.default_weakness source_name_base = integrity_check.base_dock_name_raw( dock_weakness[0], dock_weakness[1], target_identifier) target_name_base = integrity_check.base_dock_name_raw( dock_weakness[0], dock_weakness[1], source_identifier) source_count = len( integrity_check.docks_with_same_base_name(current_area, source_name_base)) if source_count != len( integrity_check.docks_with_same_base_name( target_area, target_name_base)): raise ValueError( f"Expected {target_area.name} to also have {source_count} " f"docks with name {target_name_base}") if source_count > 0: source_name = f"{source_name_base} ({source_count + 1})" target_name = f"{target_name_base} ({source_count + 1})" else: source_name = source_name_base target_name = target_name_base new_node_this_area_identifier = NodeIdentifier( self.world_list.identifier_for_area(current_area), source_name) new_node_other_area_identifier = NodeIdentifier( self.world_list.identifier_for_area(target_area), target_name) new_node_this_area = DockNode( identifier=new_node_this_area_identifier, node_index=self.editor.new_node_index(), heal=False, location=location, description="", layers=("default", ), extra={}, dock_type=dock_weakness[0], default_connection=new_node_other_area_identifier, default_dock_weakness=dock_weakness[1], override_default_open_requirement=None, override_default_lock_requirement=None, ) new_node_other_area = DockNode( identifier=new_node_other_area_identifier, node_index=self.editor.new_node_index(), heal=False, location=location, description="", layers=("default", ), extra={}, dock_type=dock_weakness[0], default_connection=new_node_this_area_identifier, default_dock_weakness=dock_weakness[1], override_default_open_requirement=None, override_default_lock_requirement=None, ) self.editor.add_node(current_area, new_node_this_area) self.editor.add_node(target_area, new_node_other_area) if source_count == 1: self.editor.rename_node( current_area, current_area.node_with_name(source_name_base), f"{source_name_base} (1)", ) self.editor.rename_node( target_area, target_area.node_with_name(target_name_base), f"{target_name_base} (1)", ) self.on_select_area(new_node_this_area)