Ejemplo n.º 1
0
def rename_docks_logic(args):
    from randovania.game_description import data_reader
    from randovania.game_description import data_writer
    from randovania.game_description import pretty_print
    from randovania.game_description.editor import Editor
    from randovania.game_description.world.dock_node import DockNode
    from randovania.game_description import integrity_check

    game = RandovaniaGame(args.game)

    path, data = default_data.read_json_then_binary(game)
    gd = data_reader.decode_data(data)

    # Make the changes
    editor = Editor(gd)

    for world in gd.world_list.worlds:
        for area in world.areas:
            for i in range(len(area.nodes)):
                node = area.nodes[i]
                if not isinstance(node, DockNode):
                    continue

                valid_name, suffix = integrity_check.dock_has_correct_name(
                    area, node)

                if not valid_name:
                    expected_name = integrity_check.base_dock_name(node)
                    docks_to_same_target = integrity_check.docks_with_same_base_name(
                        area, expected_name)

                    if suffix is None:
                        suffix = f" ({docks_to_same_target.index(node) + 1})"

                    print(
                        f"In {area.name}, renaming '{node.name}' to '{expected_name}{suffix}'"
                    )
                    editor.replace_node(
                        area, node,
                        dataclasses.replace(node,
                                            name=f"{expected_name}{suffix}"))

    # Write it back
    logging.info("Writing database files")
    new_data = data_writer.write_game_description(gd)
    data_writer.write_as_split_files(new_data, path)

    logging.info("Writing human readable")
    path.with_suffix("").mkdir(parents=True, exist_ok=True)
    pretty_print.write_human_readable_game(gd, path.with_suffix(""))
Ejemplo n.º 2
0
def bulk_move_node_logic(args):
    game = RandovaniaGame(args.game)

    path, data = default_data.read_json_then_binary(game)
    gd = data_reader.decode_data(data)

    # Make the changes
    editor = Editor(gd)
    world = gd.world_list.world_with_name(args.world)

    source_area = world.area_by_name(args.source_area)
    target_area = world.area_by_name(args.target_area)

    node_names = args.node_names

    requirements: dict[str, dict[str, Requirement]] = {
        node_name: {
            target.name: req
            for target, req in source_area.connections[
                source_area.node_with_name(node_name)].items()
        }
        for node_name in node_names
    }

    for node_name in node_names:
        logging.info("Moving node %s", node_name)
        editor.move_node_from_area_to_area(
            source_area, target_area, source_area.node_with_name(node_name))

    for name, connections in requirements.items():
        source_node = target_area.node_with_name(name)
        for target, req in connections.items():
            editor.edit_connections(
                target_area,
                source_node,
                target_area.node_with_name(target),
                req,
            )

    # Write it back
    logging.info("Writing database files")
    new_data = data_writer.write_game_description(gd)
    data_writer.write_as_split_files(new_data, path)

    logging.info("Writing human readable")
    path.with_suffix("").mkdir(parents=True, exist_ok=True)
    pretty_print.write_human_readable_game(gd, path.with_suffix(""))
Ejemplo n.º 3
0
def create_derived_nodes(game: GameDescription):
    """
    Creates any Nodes that are generated of core nodes.
    Currently, creates a DockLockNode for each DockNode.
    :return:
    """
    if not game.mutable:
        raise ValueError("game is not mutable")

    all_nodes = list(game.world_list.all_worlds_areas_nodes)
    editor = Editor(game)

    for world, area, node in all_nodes:
        if isinstance(node, DockNode):
            lock_node = DockLockNode.create_from_dock(node)
            # print(f"In {world.name}/{area.name}, create '{lock_node.name}' from '{node.name}'")
            editor.add_node(area, lock_node)
Ejemplo n.º 4
0
    def update_game(self, game: GameDescription):
        current_world = self.current_world
        current_area = self.current_area
        current_node = self.current_node

        self.game_description = game
        self.editor = Editor(self.game_description)
        self.world_list = self.game_description.world_list
        self.area_view_canvas.select_game(self.game_description.game)

        self.world_selector_box.clear()
        for world in sorted(self.world_list.worlds, key=lambda x: x.name):
            name = "{0.name} ({0.dark_name})".format(
                world) if world.dark_name else world.name
            self.world_selector_box.addItem(name, userData=world)

        if current_world:
            self.focus_on_world_by_name(current_world.name)
        if current_area:
            self.focus_on_area_by_name(current_area.name)
        if current_node:
            self.focus_on_node(current_node)
Ejemplo n.º 5
0
def _editor(echoes_game_data):
    return Editor(data_reader.decode_data(echoes_game_data))