def decode_default_prime2() -> dict: json_database = prime2_json_path() if json_database.exists(): with json_database.open("r") as open_file: return json.load(open_file) return decode_file_path(get_data_path().joinpath("binary_data", "prime2.bin"))
def read_json_then_binary(game: RandovaniaGame) -> Tuple[Path, dict]: json_path = get_data_path().joinpath("json_data", f"{game.value}.json") if json_path.exists(): with json_path.open("r") as open_file: return json_path, json.load(open_file) binary_path = get_data_path().joinpath("binary_data", f"{game.value}.bin") return binary_path, decode_file_path(binary_path)
def test_complex_decode(test_files_dir): # Run decoded_data = binary_data.decode_file_path(Path(test_files_dir.joinpath("prime_data_as_binary.bin"))) # Assert with test_files_dir.joinpath("prime_data_as_json.json").open("r") as data_file: saved_data = json.load(data_file) assert decoded_data == saved_data
def decode_data_file(args) -> Dict: json_database: Optional[Path] = args.json_database if json_database is not None: with json_database.open() as data_file: return json.load(data_file) data_file_path: Optional[Path] = args.binary_database if data_file_path is None: return default_data.decode_default_prime2() else: return binary_data.decode_file_path(data_file_path)
def decode_data_file(args) -> Dict: json_database: Optional[Path] = args.json_database if json_database is not None: with json_database.open() as data_file: return json.load(data_file) data_file_path: Optional[Path] = args.binary_database if data_file_path is None: return default_data.decode_default_prime2() else: extra_path = data_file_path.parent.joinpath(data_file_path.stem + "_extra.json") return binary_data.decode_file_path(data_file_path, extra_path)