示例#1
0
def prompt_user_for_input_game_log(window: QMainWindow) -> Optional[Path]:
    """
    Shows an QFileDialog asking the user for a Randovania seed log
    :param window:
    :return: A string if the user selected a file, None otherwise
    """
    return _prompt_user_for_file(window, caption="Select a Randovania seed log.",
                                 filter="Randovania Game, *.{}".format(LayoutDescription.file_extension()),
                                 new_file=False)
示例#2
0
async def prompt_input_layout(parent: QtWidgets.QWidget) -> Optional[Path]:
    """
    Shows an QFileDialog asking the user for a Randovania LayoutDescription
    :param parent:
    :return: A string if the user selected a file, None otherwise
    """
    from randovania.layout.layout_description import LayoutDescription
    return await _prompt_user_for_file(
        parent,
        caption="Select a Randovania seed log.",
        file_filter="Randovania Game, *.{}".format(
            LayoutDescription.file_extension()),
        new_file=False,
    )
示例#3
0
def prompt_user_for_output_game_log(window: QtWidgets.QWidget,
                                    default_name: str) -> Optional[Path]:
    """
    Shows an QFileDialog asking the user for a Randovania seed log
    :param window:
    :param default_name:
    :return: A string if the user selected a file, None otherwise
    """
    from randovania.layout.layout_description import LayoutDescription
    return _prompt_user_for_file(window,
                                 caption="Select a Randovania seed log.",
                                 dir=default_name,
                                 filter="Randovania Game, *.{}".format(
                                     LayoutDescription.file_extension()),
                                 new_file=True)
示例#4
0
    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)
示例#5
0
    def dragEnterEvent(self, event: QtGui.QDragEnterEvent):
        from randovania.layout.preset_migration import VersionedPreset

        valid_extensions = [
            LayoutDescription.file_extension(),
            VersionedPreset.file_extension(),
        ]
        valid_extensions_with_dot = {
            f".{extension}"
            for extension in valid_extensions
        }

        for url in event.mimeData().urls():
            ext = os.path.splitext(url.toLocalFile())[1]
            if ext in valid_extensions_with_dot:
                event.acceptProposedAction()
                return
示例#6
0
def test_apply_layout(
    mock_ensure_no_menu_mod: MagicMock,
    mock_create_pak_backups: MagicMock,
    mock_add_menu_mod_to_files: MagicMock,
    mock_modern_api: MagicMock,
    mock_apply_patches: MagicMock,
    mock_create_progress_update_from_successive_messages: MagicMock,
    mock_save_to_file: MagicMock,
    include_menu_mod: bool,
    has_backup_path: bool,
):
    # Setup
    cosmetic_patches = MagicMock()
    description = LayoutDescription(
        version=randovania.VERSION,
        permalink=Permalink(
            seed_number=1,
            spoiler=False,
            presets={
                0:
                Preset(name="Name",
                       description="Desc",
                       base_preset_name=None,
                       patcher_configuration=PatcherConfiguration(
                           menu_mod=include_menu_mod,
                           warp_to_start=MagicMock(),
                       ),
                       layout_configuration=MagicMock())
            },
        ),
        all_patches={0: MagicMock()},
        item_order=(),
    )

    game_root = MagicMock(spec=Path())
    backup_files_path = MagicMock() if has_backup_path else None
    progress_update = MagicMock()
    player_config = PlayersConfiguration(0, {0: "you"})
    status_update = mock_create_progress_update_from_successive_messages.return_value

    # Run
    claris_randomizer.apply_layout(description, player_config,
                                   cosmetic_patches, backup_files_path,
                                   progress_update, game_root)

    # Assert
    mock_create_progress_update_from_successive_messages.assert_called_once_with(
        progress_update, 400 if include_menu_mod else 100)
    mock_ensure_no_menu_mod.assert_called_once_with(game_root,
                                                    backup_files_path,
                                                    status_update)
    if has_backup_path:
        mock_create_pak_backups.assert_called_once_with(
            game_root, backup_files_path, status_update)
    else:
        mock_create_pak_backups.assert_not_called()
    game_root.joinpath.assert_called_once_with(
        "files", "randovania.{}".format(LayoutDescription.file_extension()))
    mock_save_to_file.assert_called_once_with(description,
                                              game_root.joinpath.return_value)

    mock_modern_api.assert_called_once_with(game_root, status_update,
                                            description, player_config,
                                            cosmetic_patches)
    mock_apply_patches.assert_called_once_with(game_root,
                                               description.all_patches[0],
                                               cosmetic_patches)

    if include_menu_mod:
        mock_add_menu_mod_to_files.assert_called_once_with(
            game_root, status_update)
    else:
        mock_add_menu_mod_to_files.assert_not_called()