def test_create_node_and_save(tmp_path, echoes_game_data, skip_qtbot): # Setup tmp_path.joinpath("test-game", "game").mkdir(parents=True) tmp_path.joinpath("human-readable").mkdir() db_path = Path(tmp_path.joinpath("test-game", "game")) window = DataEditorWindow(echoes_game_data, db_path, True, True) window.set_warning_dialogs_disabled(True) skip_qtbot.addWidget(window) # Run window._do_create_node("Some Node", None) window._save_as_internal_database() # Assert exported_data = data_reader.read_split_file(db_path) exported_game = data_reader.decode_data(exported_data) pretty_print.write_human_readable_game(exported_game, tmp_path.joinpath("human-readable")) new_files = { f.name: f.read_text("utf-8") for f in tmp_path.joinpath("human-readable").glob("*.txt") } existing_files = { f.name: f.read_text("utf-8") for f in tmp_path.joinpath("test-game", "game").glob("*.txt") } assert list(new_files.keys()) == list(existing_files.keys()) assert new_files == existing_files
def update_human_readable_logic(args): from randovania.game_description import pretty_print from randovania.game_description import data_reader game = RandovaniaGame(args.game) path, data = default_data.read_json_then_binary(game) gd = data_reader.decode_data(data) path.with_suffix("").mkdir(parents=True, exist_ok=True) pretty_print.write_human_readable_game(gd, path.with_suffix(""))
def test_committed_human_readable_description(game: RandovaniaGame, tmp_path): pretty_print.write_human_readable_game( default_database.game_description_for(game), tmp_path) new_files = {f.name: f.read_text("utf-8") for f in tmp_path.glob("*.txt")} existing_files = { f.name: f.read_text("utf-8") for f in game.data_path.joinpath("json_data").glob("*.txt") } assert new_files == existing_files
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(""))
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(""))
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)
def _save_as_internal_database(self): if self._save_database(self._data_path): pretty_print.write_human_readable_game( self.game_description, self._data_path.with_suffix("")) default_database.game_description_for.cache_clear()