示例#1
0
def test_round_trip_full():
    original_data = default_data.decode_default_prime2()

    game = data_reader.decode_data(original_data)
    encoded_data = data_writer.write_game_description(game)

    assert original_data == encoded_data
示例#2
0
def test_round_trip_full(game_enum: RandovaniaGame):
    original_data = default_data.read_json_then_binary(game_enum)[1]

    game = data_reader.decode_data(original_data)
    encoded_data = data_writer.write_game_description(game)

    assert list(encoded_data.keys()) == list(original_data.keys())
    assert encoded_data == original_data
def test_round_trip_small(test_files_dir):
    # Setup
    with test_files_dir.joinpath("prime2_small_v1.json").open("r") as data_file:
        original_data = game_migration.migrate_to_current(json.load(data_file))

    game = data_reader.decode_data(original_data)

    encoded_data = data_writer.write_game_description(game)
    assert encoded_data == original_data
示例#4
0
def test_round_trip_small(test_files_dir):
    # Setup
    with test_files_dir.joinpath("prime_data_as_json.json").open("r") as data_file:
        original_data = json.load(data_file)

    game = data_reader.decode_data(original_data)
    encoded_data = data_writer.write_game_description(game)

    assert original_data == encoded_data
示例#5
0
 def closeEvent(self, event: QtGui.QCloseEvent):
     if self._check_for_edit_dialog():
         event.ignore()
     else:
         if self.edit_mode:
             data = data_writer.write_game_description(
                 self.game_description)
             if data != self._last_data:
                 if not self.prompt_unsaved_changes_warning():
                     return event.ignore()
         super().closeEvent(event)
示例#6
0
    def _save_database(self):
        open_result = QFileDialog.getSaveFileName(
            self,
            caption="Select a Randovania database path.",
            filter="*.json")
        if not open_result or open_result == ("", ""):
            return None

        data = data_writer.write_game_description(self.game_description)
        with Path(open_result[0]).open("w") as open_file:
            json.dump(data, open_file, indent=4)
示例#7
0
 def closeEvent(self, event: QtGui.QCloseEvent):
     if self._check_for_edit_dialog():
         event.ignore()
     else:
         data = data_writer.write_game_description(self.game_description)
         if data != self._last_data:
             user_response = QMessageBox.warning(
                 self, "Unsaved changes",
                 "You have unsaved changes. Do you want to close and discard?",
                 QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
             if user_response == QMessageBox.No:
                 return event.ignore()
         super().closeEvent(event)
示例#8
0
def test_round_trip_small(test_files_dir, small_name):
    # Setup
    with test_files_dir.joinpath(small_name).open("r") as data_file:
        original_data = json.load(data_file)

    game = data_reader.decode_data(original_data)
    encoded_data = data_writer.write_game_description(game)

    # # Uncomment the following to update the file
    # with test_files_dir.joinpath(small_name).open("w", encoding="utf-8") as meta:
    #     json.dump(encoded_data, meta, indent=4); assert False

    assert encoded_data == original_data
示例#9
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(""))
示例#10
0
    def _save_database(self, path: Path) -> bool:
        errors = integrity_check.find_database_errors(self.game_description)
        if errors:
            if not self.display_integrity_errors_warning(errors):
                return False

        data = data_writer.write_game_description(self.game_description)
        if self._is_internal:
            path.with_suffix("").mkdir(exist_ok=True)
            data_writer.write_as_split_files(data, path.with_suffix(""))
        else:
            with path.open("w") as open_file:
                json.dump(data, open_file, indent=4)
        self._last_data = data
        return True
示例#11
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(""))
示例#12
0
def convert_database_command_logic(args):
    data = decode_data_file(args)

    if args.decode_to_game_description:
        data = data_writer.write_game_description(data_reader.decode_data(data))

    output_binary: Optional[Path] = args.output_binary
    output_json: Optional[Path] = args.output_json

    if output_binary is not None:
        export_as_binary(data, output_binary)

    elif output_json is not None:
        with output_json.open("w") as x:  # type: TextIO
            json.dump(data, x, indent=4)
    else:
        raise ValueError("Neither binary nor JSON set. Argparse is broken?")
示例#13
0
def refresh_all_logic(args):
    from randovania.game_description import pretty_print
    from randovania.game_description import data_reader, data_writer
    from randovania.game_description import integrity_check

    gd_per_game = {}
    path_per_game = {}
    idb_per_game = {}

    for game in iterate_enum(RandovaniaGame):
        logging.info("Reading %s", game.long_name)
        path, data = default_data.read_json_then_binary(game)
        path_per_game[game] = path
        gd = data_reader.decode_data(data)
        gd_per_game[game] = gd

        idb = default_database.item_database_for_game(game)
        idb_per_game[game] = idb

    should_stop = False
    if args.integrity_check:
        for game, gd in gd_per_game.items():
            errors = integrity_check.find_database_errors(gd)
            if errors:
                logging.warning("Integrity errors for %s:\n%s", game.long_name,
                                "\n".join(errors))
                if game.data.development_state.is_stable:
                    should_stop = True

    if should_stop:
        return

    for game, gd in gd_per_game.items():
        path = path_per_game[game]
        logging.info("Writing %s", game.long_name)
        new_data = data_writer.write_game_description(gd)
        data_writer.write_as_split_files(new_data, path)
        path.with_suffix("").mkdir(parents=True, exist_ok=True)
        pretty_print.write_human_readable_game(gd, path.with_suffix(""))

        default_database.write_item_database_for_game(idb_per_game[game], game)
示例#14
0
 def _save_database(self, path: Path):
     data = data_writer.write_game_description(self.game_description)
     with path.open("w") as open_file:
         json.dump(data, open_file, indent=4)