def test_load_multiworld(test_files_dir): file_path = Path(test_files_dir).joinpath("log_files", "multiworld.rdvgame") with file_path.open("r") as open_file: input_data = json.load(open_file) # Run result = LayoutDescription.from_json_dict(input_data) # Assert as_json = result.as_json del input_data["info"]["permalink"] del as_json["info"]["permalink"] assert as_json == input_data
def test_load_multiworld(test_files_dir): file_path = Path(test_files_dir).joinpath("log_files", "multiworld.rdvgame") with file_path.open("r") as open_file: input_data = json.load(open_file) # Run result = LayoutDescription.from_json_dict(input_data) input_data["schema_version"] = description_migration.CURRENT_VERSION # Assert as_json = result.as_json() del input_data["info"] del as_json["info"] assert as_json == input_data
async def on_message(self, message: discord.Message): if message.author == self.bot.user: return for attachment in message.attachments: filename: str = attachment.filename if filename.endswith(VersionedPreset.file_extension()): data = await attachment.read() versioned_preset = VersionedPreset(json.loads(data.decode("utf-8"))) await reply_for_preset(message, versioned_preset) elif filename.endswith(LayoutDescription.file_extension()): data = await attachment.read() description = LayoutDescription.from_json_dict(json.loads(data.decode("utf-8"))) await reply_for_layout_description(message, description) await look_for_permalinks(message)
def _change_layout_description(sio: ServerApp, session: GameSession, description_json: Optional[dict]): _verify_has_admin(sio, session.id, None) _verify_in_setup(session) rows_to_update = [] if description_json is None: description = None else: if session.generation_in_progress != sio.get_current_user(): if session.generation_in_progress is None: raise InvalidAction(f"Not waiting for a layout.") else: raise InvalidAction( f"Waiting for a layout from {session.generation_in_progress.name}." ) _verify_no_layout_description(session) description = LayoutDescription.from_json_dict(description_json) if description.player_count != session.num_rows: raise InvalidAction( f"Description is for a {description.player_count} players," f" while the session is for {session.num_rows}.") for permalink_preset, preset_row in zip(description.all_presets, session.presets): preset_row = typing.cast(GameSessionPreset, preset_row) if _get_preset(json.loads( preset_row.preset)).get_preset() != permalink_preset: preset = VersionedPreset.with_preset(permalink_preset) if preset.game not in session.allowed_games: raise InvalidAction(f"{preset.game} preset not allowed.") preset_row.preset = json.dumps(preset.as_json) rows_to_update.append(preset_row) with database.db.atomic(): for preset_row in rows_to_update: preset_row.save() session.generation_in_progress = None session.layout_description = description session.save() _add_audit_entry( sio, session, "Removed generated game" if description is None else f"Set game to {description.shareable_word_hash}")
def test_patch_data_creation(test_files_dir): # Load the RDV game game_file = test_files_dir.joinpath("sdm_test_game.rdvgame").open() game_json = json.load(game_file) game_file.close() layout = LayoutDescription.from_json_dict(game_json) # Create patch_data from layout player_configuration = PlayersConfiguration(0, {0: "Player"}) cosmetic_patches = SuperMetroidCosmeticPatches() patch_data = SuperMetroidPatchDataFactory(layout, player_configuration, cosmetic_patches).create_data() # Load control patch_data and compare the two for differences json_file = test_files_dir.joinpath("sdm_expected_result.json").open() expected_json = json.load(json_file) json_file.close() assert expected_json == patch_data
def _change_layout_description(sio: ServerApp, session: GameSession, description_json: Optional[dict]): _verify_has_admin(sio, session.id, None) _verify_in_setup(session) rows_to_update = [] if description_json is None: description = None else: if session.generation_in_progress != sio.get_current_user(): if session.generation_in_progress is None: raise InvalidAction(f"Not waiting for a layout.") else: raise InvalidAction( f"Waiting for a layout from {session.generation_in_progress.name}." ) _verify_no_layout_description(session) description = LayoutDescription.from_json_dict(description_json) permalink = description.permalink if permalink.player_count != session.num_rows: raise InvalidAction( f"Description is for a {permalink.player_count} players," f" while the session is for {session.num_rows}.") for permalink_preset, preset_row in zip(permalink.presets.values(), session.presets): preset_row = typing.cast(GameSessionPreset, preset_row) if _get_preset(json.loads( preset_row.preset)).get_preset() != permalink_preset: preset = VersionedPreset.with_preset(permalink_preset) if preset.game != RandovaniaGame.PRIME2: raise InvalidAction("Only Prime 2 presets allowed.") preset_row.preset = json.dumps(preset.as_json) rows_to_update.append(preset_row) with database.db.atomic(): for preset_row in rows_to_update: preset_row.save() session.generation_in_progress = None session.layout_description = description session.save()
def test_round_trip_default(permalink: Permalink, item_locations: Dict[str, Dict[str, str]], solver_path: Tuple[SolverPath, ...]): game = data_reader.decode_data(permalink.layout_configuration.game_data) original = LayoutDescription( version=randovania.VERSION, permalink=permalink, patches=GamePatches( _item_locations_to_pickup_assignment(game, item_locations), claris_randomizer.elevator_connections_for_seed_number( permalink.seed_number), {}, {}, (), game.starting_location), solver_path=solver_path, ) # Run decoded = LayoutDescription.from_json_dict(original.as_json) # Assert assert decoded == original
def _decode_layout_description(s): return LayoutDescription.from_json_dict(json.loads(s))