def from_json_dict(cls, json_dict: dict) -> "LayoutDescription": json_dict = migrate_description(json_dict) has_spoiler = "game_modifications" in json_dict if not has_spoiler: raise ValueError( "Unable to read details of seed log with spoiler disabled") permalink = Permalink( seed_number=json_dict["info"]["seed"], spoiler=has_spoiler, presets={ index: VersionedPreset(preset).get_preset() for index, preset in enumerate(json_dict["info"]["presets"]) }, ) return LayoutDescription( version=json_dict["info"]["version"], permalink=permalink, all_patches=game_patches_serializer.decode( json_dict["game_modifications"], { index: preset.configuration for index, preset in permalink.presets.items() }), item_order=json_dict["item_order"], )
def test_round_trip_generated_patches(echoes_game_data, preset_manager): # Setup preset = dataclasses.replace( preset_manager.default_preset, layout_configuration=dataclasses.replace( preset_manager.default_preset.layout_configuration, trick_level_configuration=TrickLevelConfiguration( global_level=LayoutTrickLevel.MINIMAL_RESTRICTIONS, specific_levels={}, ) ) ) patches = generator._create_randomized_patches( permalink=Permalink( seed_number=1000, spoiler=True, preset=preset, ), game=data_reader.decode_data(echoes_game_data), status_update=lambda x: None, ) # Run encoded = game_patches_serializer.serialize(patches, echoes_game_data) decoded = game_patches_serializer.decode(encoded, preset.layout_configuration) # Assert assert patches == decoded
def test_round_trip_generated_patches(echoes_game_data, preset_manager): # Setup preset = dataclasses.replace( preset_manager.default_preset, layout_configuration=dataclasses.replace( preset_manager.default_preset.layout_configuration, trick_level_configuration=TrickLevelConfiguration( global_level=LayoutTrickLevel.MINIMAL_RESTRICTIONS, specific_levels={}, ))) all_patches = generator._async_create_description( permalink=Permalink( seed_number=1000, spoiler=True, presets={0: preset}, ), status_update=lambda x: None, ).all_patches # Run encoded = game_patches_serializer.serialize(all_patches, {0: echoes_game_data}) decoded = game_patches_serializer.decode(encoded, {0: preset.layout_configuration}) # Assert assert all_patches == decoded
def test_round_trip_generated_patches(echoes_game_data): # Setup configuration = LayoutConfiguration.from_params( trick_level_configuration=TrickLevelConfiguration( global_level=LayoutTrickLevel.MINIMAL_RESTRICTIONS, specific_levels={}, )) patches = generator._create_randomized_patches( permalink=Permalink( seed_number=1000, spoiler=True, patcher_configuration=PatcherConfiguration.default(), layout_configuration=configuration, ), game=data_reader.decode_data(echoes_game_data), status_update=lambda x: None, ) # Run encoded = game_patches_serializer.serialize(patches, echoes_game_data) decoded = game_patches_serializer.decode(encoded, configuration) # Assert assert patches == decoded
def test_round_trip_generated_patches(echoes_game_data, default_preset): # Setup preset = dataclasses.replace( default_preset, base_preset_name=default_preset.name, configuration=dataclasses.replace( default_preset.configuration, trick_level=TrickLevelConfiguration( minimal_logic=True, specific_levels={}, game=RandovaniaGame.PRIME2, ) ) ) all_patches = generator._async_create_description( permalink=Permalink( seed_number=1000, spoiler=True, presets={0: preset}, ), status_update=lambda x: None, attempts=0, ).all_patches # Run encoded = game_patches_serializer.serialize(all_patches, {0: echoes_game_data}) decoded = game_patches_serializer.decode(encoded, {0: preset.configuration}) # Assert assert all_patches == decoded
def from_json_dict(cls, json_dict: dict) -> "LayoutDescription": json_dict = description_migration.convert_to_current_version(json_dict) if "game_modifications" not in json_dict: raise ValueError("Unable to read details of a race game file") generator_parameters = GeneratorParameters( seed_number=json_dict["info"]["seed"], spoiler=json_dict["info"]["has_spoiler"], presets=[ VersionedPreset(preset).get_preset() for preset in json_dict["info"]["presets"] ], ) return LayoutDescription( randovania_version_text=json_dict["info"]["randovania_version"], randovania_version_git=bytes.fromhex( json_dict["info"]["randovania_version_git"]), generator_parameters=generator_parameters, all_patches=game_patches_serializer.decode( json_dict["game_modifications"], { index: preset.configuration for index, preset in enumerate( generator_parameters.presets) }), item_order=json_dict["item_order"], )
async def test_round_trip_generated_patches(default_preset): # Setup preset = dataclasses.replace( default_preset, uuid=uuid.UUID('b41fde84-1f57-4b79-8cd6-3e5a78077fa6'), base_preset_uuid=default_preset.uuid, configuration=dataclasses.replace(default_preset.configuration, trick_level=TrickLevelConfiguration( minimal_logic=True, specific_levels={}, game=default_preset.game, ))) description = await generator._create_description( permalink=Permalink( seed_number=1000, spoiler=True, presets={0: preset}, ), status_update=lambda x: None, attempts=0, ) all_patches = description.all_patches # Run encoded = game_patches_serializer.serialize(all_patches, {0: default_preset.game}) decoded = game_patches_serializer.decode(encoded, {0: preset.configuration}) # Assert assert all_patches == decoded
async def test_round_trip_generated_patches(default_preset): # Setup preset = dataclasses.replace( default_preset, uuid=uuid.UUID('b41fde84-1f57-4b79-8cd6-3e5a78077fa6'), base_preset_uuid=default_preset.uuid, configuration=dataclasses.replace(default_preset.configuration, trick_level=TrickLevelConfiguration( minimal_logic=True, specific_levels={}, game=default_preset.game, ))) description = await generator._create_description( generator_params=GeneratorParameters( seed_number=1000, spoiler=True, presets=[preset], ), status_update=lambda x: None, attempts=0, ) all_patches = description.all_patches # Run encoded = game_patches_serializer.serialize(all_patches) decoded = game_patches_serializer.decode(encoded, {0: preset.configuration}) decoded_with_original_game = { i: dataclasses.replace(d, game=orig.game) for (i, d), orig in zip(decoded.items(), all_patches.values()) } # Assert assert all_patches == decoded_with_original_game
def from_json_dict(cls, json_dict: dict) -> "LayoutDescription": version = json_dict.get("schema_version") if version != cls.schema_version(): raise RuntimeError("Unsupported log file version '{}'. Expected {}.".format(version, cls.schema_version())) has_spoiler = "game_modifications" in json_dict if not has_spoiler: raise ValueError("Unable to read details of seed log with spoiler disabled") permalink = Permalink( seed_number=json_dict["info"]["seed"], spoiler=has_spoiler, presets={ index: VersionedPreset(preset).get_preset() for index, preset in enumerate(json_dict["info"]["presets"]) }, ) return LayoutDescription( version=json_dict["info"]["version"], permalink=permalink, all_patches=game_patches_serializer.decode( json_dict["game_modifications"], { index: preset.layout_configuration for index, preset in permalink.presets.items() }), item_order=json_dict["item_order"], )
def test_decode(patches_with_data, default_layout_configuration): encoded, expected = patches_with_data # Run decoded = game_patches_serializer.decode(encoded, default_layout_configuration) # Assert assert decoded == expected
def test_decode(patches_with_data): encoded, expected = patches_with_data # Run decoded = game_patches_serializer.decode(encoded, LayoutConfiguration.default()) # Assert assert decoded == expected
def from_json_dict(cls, json_dict: dict) -> "LayoutDescription": version = json_dict["info"]["version"] # version_as_obj = StrictVersion(version) # # if version_as_obj < StrictVersion("0.26.0"): # raise RuntimeError("Unsupported log file version '{}'.".format(version)) # TODO: add try/catch to throw convert potential errors in "seed from future version broke" permalink = Permalink.from_json_dict(json_dict["info"]["permalink"]) if not permalink.spoiler: raise ValueError( "Unable to read details of seed log with spoiler disabled") return LayoutDescription( version=version, permalink=permalink, patches=game_patches_serializer.decode( json_dict["game_modifications"], permalink.layout_configuration), solver_path=_playthrough_list_to_solver_path( json_dict["playthrough"]), )
def from_json_dict(cls, json_dict: dict) -> "LayoutDescription": version = json_dict["info"]["version"] # version_as_obj = StrictVersion(version) # # if version_as_obj < StrictVersion("0.26.0"): # raise RuntimeError("Unsupported log file version '{}'.".format(version)) # TODO: add try/catch to throw convert potential errors in "seed from future version broke" permalink = Permalink.from_json_dict(json_dict["info"]["permalink"]) if not permalink.spoiler: raise ValueError( "Unable to read details of seed log with spoiler disabled") return LayoutDescription( version=version, permalink=permalink, all_patches=game_patches_serializer.decode( json_dict["game_modifications"], { index: preset.layout_configuration for index, preset in permalink.presets.items() }), item_order=json_dict["item_order"], )