Ejemplo n.º 1
0
def create_permalink(args):
    from randovania.layout.permalink import Permalink
    from randovania.layout.generator_parameters import GeneratorParameters
    from randovania.interface_common.preset_manager import PresetManager

    game: RandovaniaGame = RandovaniaGame(args.game)
    preset_manager = PresetManager(None)
    presets = []
    for preset_name in args.preset_name:
        versioned = preset_manager.included_preset_with(game, preset_name)
        if versioned is None:
            raise ValueError(
                "Unknown included preset '{}' for game {}. Valid options are: {}"
                .format(preset_name, game.long_name, [
                    preset.name
                    for preset in preset_manager.included_presets.values()
                    if preset.game == game
                ]))
        presets.append(versioned.get_preset())

    seed = args.seed_number
    if seed is None:
        seed = random.randint(0, 2**31)

    return Permalink.from_parameters(
        GeneratorParameters(
            seed,
            spoiler=not args.race,
            presets=presets,
        ), )
Ejemplo n.º 2
0
    def bit_pack_unpack(cls, decoder: BitPackDecoder, metadata) -> "Permalink":
        version, seed_number = decoder.decode(_PERMALINK_MAX_VERSION,
                                              _PERMALINK_MAX_SEED)
        cls._raise_if_different_version(version)

        spoiler = bitpacking.decode_bool(decoder)
        player_count = bitpacking.decode_int_with_limits(
            decoder, _PERMALINK_PLAYER_COUNT_LIMITS)
        manager = PresetManager(None)

        previous_unique_presets = []
        presets = {}

        for index in range(player_count):
            in_previous_presets = bitpacking.decode_bool(decoder)
            if in_previous_presets:
                presets[index] = decoder.decode_element(
                    previous_unique_presets)
                continue

            preset = _decode_preset(decoder, manager)
            previous_unique_presets.append(preset)
            presets[index] = preset

        return Permalink(seed_number, spoiler, presets)
Ejemplo n.º 3
0
async def show_game_session(app: QtWidgets.QApplication, options, session_id: int):
    from randovania.gui.game_session_window import GameSessionWindow
    from randovania.gui.lib.qt_network_client import QtNetworkClient
    from randovania.interface_common.preset_manager import PresetManager

    network_client: QtNetworkClient = app.network_client

    sessions = [
        session
        for session in await network_client.get_game_session_list(False)
        if session.id == session_id
    ]
    if not sessions:
        app.quit()
        return
    await network_client.join_game_session(sessions[0], None)

    preset_manager = PresetManager(options.presets_path)

    app.game_session_window = await GameSessionWindow.create_and_update(
        network_client,
        app.game_connection,
        preset_manager,
        None,
        options
    )
    app.game_session_window.show()
Ejemplo n.º 4
0
async def show_main_window(app: QtWidgets.QApplication, options, is_preview: bool):
    from randovania.interface_common.preset_manager import PresetManager
    from randovania.interface_common.options import Options
    options = typing.cast(Options, options)
    preset_manager = PresetManager(options.presets_path)

    logger.info("Loading user presets...")
    await preset_manager.load_user_presets()
    logger.info("Finished loading presets!")

    from randovania.gui.lib.qt_network_client import QtNetworkClient
    network_client: QtNetworkClient = app.network_client

    async def attempt_login():
        from randovania.network_client.network_client import UnableToConnect
        from randovania.gui.lib import async_dialog

        try:
            from randovania.gui import main_online_interaction
            if not await main_online_interaction.ensure_logged_in(None, network_client):
                await async_dialog.warning(None, "Login required",
                                           "Logging in is required to use dev builds.")
                return False

        except UnableToConnect as e:
            s = e.reason.replace('\n', '<br />')
            await async_dialog.warning(
                None, "Connection Error",
                f"<b>Unable to connect to the server:</b><br /><br />{s}<br /><br />"
                f"Logging in is required to use dev builds.")
            return False

        return True

    if randovania.is_frozen() and randovania.is_dev_version():
        try:
            logger.info("Disabling quit on last window closed")
            app.setQuitOnLastWindowClosed(False)
            if not await attempt_login():
                app.quit()
                return
        finally:
            def reset_last_window_quit():
                logger.info("Re-enabling quit on last window closed")
                app.setQuitOnLastWindowClosed(True)

            QtCore.QTimer.singleShot(1000, reset_last_window_quit)

    from randovania.gui.main_window import MainWindow
    logger.info("Preparing main window...")
    main_window = MainWindow(options, preset_manager, network_client, is_preview)
    app.main_window = main_window

    logger.info("Displaying main window")
    main_window.show()
    await main_window.request_new_data()
Ejemplo n.º 5
0
    async def _create_permalink(args_) -> Permalink:
        from randovania.interface_common.preset_manager import PresetManager

        preset_manager = PresetManager(None)
        preset = preset_manager.included_preset_with(RandovaniaGame(args_.game), args_.preset_name).get_preset()

        return Permalink(
            args_.seed_number,
            spoiler=True,
            presets={i: preset for i in range(args_.player_count)},
        )
Ejemplo n.º 6
0
    def bit_pack_encode(self, metadata) -> Iterator[Tuple[int, int]]:
        yield from encode_game_list(tuple(preset.game for preset in self.presets))
        yield self.seed_number, _PERMALINK_MAX_SEED
        yield from bitpacking.encode_bool(self.spoiler)

        manager = PresetManager(None)
        for preset in self.presets:
            yield from preset.bit_pack_encode({"manager": manager})

        for game in _get_unique_games(self.presets):
            yield _game_db_hash(game), 256
Ejemplo n.º 7
0
async def show_main_window(app: QApplication, options, is_preview: bool):
    from randovania.interface_common.preset_manager import PresetManager
    preset_manager = PresetManager(options.data_dir)

    await preset_manager.load_user_presets()

    from randovania.gui.main_window import MainWindow
    main_window = MainWindow(options, preset_manager, app.network_client,
                             is_preview)
    app.main_window = main_window
    main_window.show()
    await main_window.request_new_data()
Ejemplo n.º 8
0
async def _create_permalink(args) -> Permalink:
    from randovania.interface_common import persistence
    preset_manager = PresetManager(persistence.user_data_dir())
    await preset_manager.load_user_presets()
    preset = preset_manager.preset_for_name(args.preset_name).get_preset()

    return Permalink(
        args.seed_number,
        spoiler=True,
        presets={i: preset
                 for i in range(args.player_count)},
    )
Ejemplo n.º 9
0
def show_main_window(app: QApplication, args):
    options = Options.with_default_data_dir()
    preset_manager = PresetManager(options.data_dir)

    if not load_options_from_disk(options):
        raise SystemExit(1)

    if not load_user_presets(preset_manager):
        raise SystemExit(2)

    from randovania.gui.main_window import MainWindow
    main_window = MainWindow(options, preset_manager, getattr(args, "preview", False))
    app.main_window = main_window
    main_window.show()
    main_window.request_new_data()
Ejemplo n.º 10
0
    def bit_pack_encode(self, metadata) -> Iterator[Tuple[int, int]]:
        yield self.current_version(), _PERMALINK_MAX_VERSION
        yield self.seed_number, _PERMALINK_MAX_SEED
        yield from bitpacking.encode_bool(self.spoiler)
        yield from bitpacking.encode_int_with_limits(self.player_count, _PERMALINK_PLAYER_COUNT_LIMITS)

        manager = PresetManager(None)

        previous_unique_presets = []
        for preset in self.presets.values():
            yield from bitpacking.encode_bool(preset in previous_unique_presets)
            if preset in previous_unique_presets:
                yield from bitpacking.pack_array_element(preset, previous_unique_presets)
                continue

            previous_unique_presets.append(preset)
            yield from _encode_preset(preset, manager)
Ejemplo n.º 11
0
async def show_main_window(app: QtWidgets.QApplication, options,
                           is_preview: bool):
    from randovania.interface_common.preset_manager import PresetManager
    preset_manager = PresetManager(options.data_dir)

    logger.info("Loading user presets...")
    await preset_manager.load_user_presets()
    logger.info("Finished loading presets!")

    from randovania.gui.main_window import MainWindow
    logger.info("Preparing main window...")
    main_window = MainWindow(options, preset_manager, app.network_client,
                             is_preview)
    app.main_window = main_window

    logger.info("Displaying main window")
    main_window.show()
    await main_window.request_new_data()
Ejemplo n.º 12
0
def create_game_session(sio: ServerApp, session_name: str):
    current_user = sio.get_current_user()

    with database.db.atomic():
        new_session = GameSession.create(
            name=session_name,
            password=None,
            creator=current_user,
        )
        GameSessionPreset.create(
            session=new_session,
            row=0,
            preset=json.dumps(PresetManager(None).default_preset.as_json))
        membership = GameSessionMembership.create(user=sio.get_current_user(),
                                                  session=new_session,
                                                  row=0,
                                                  admin=True)

    sio.join_game_session(membership)
    return new_session.create_session_entry()
Ejemplo n.º 13
0
    def bit_pack_unpack(cls, decoder: BitPackDecoder, metadata) -> "GeneratorParameters":
        games = decode_game_list(decoder)
        seed_number = decoder.decode_single(_PERMALINK_MAX_SEED)
        spoiler = bitpacking.decode_bool(decoder)

        manager = PresetManager(None)
        presets = [
            Preset.bit_pack_unpack(decoder, {"manager": manager, "game": game})
            for game in games
        ]
        for game in _get_unique_games(presets):
            included_data_hash = decoder.decode_single(256)
            expected_data_hash = _game_db_hash(game)
            if included_data_hash != expected_data_hash:
                raise ValueError("Given permalink is for a Randovania {} database with hash '{}', "
                                 "but current database has hash '{}'.".format(game.long_name,
                                                                              included_data_hash,
                                                                              expected_data_hash))

        return GeneratorParameters(seed_number, spoiler, presets)
Ejemplo n.º 14
0
def show_main_window(app: QApplication, is_preview: bool):
    options = Options.with_default_data_dir()
    preset_manager = PresetManager(options.data_dir)

    for old_preset in options.data_dir.joinpath("presets").glob(
            "*.randovania_preset"):
        old_preset.rename(
            old_preset.with_name(
                f"{old_preset.stem}.{Preset.file_extension()}"))

    if not load_options_from_disk(options):
        raise SystemExit(1)

    if not load_user_presets(preset_manager):
        raise SystemExit(2)

    from randovania.gui.main_window import MainWindow
    main_window = MainWindow(options, preset_manager, is_preview)
    app.main_window = main_window
    main_window.show()
    main_window.request_new_data()
Ejemplo n.º 15
0
    def bit_pack_unpack(cls, decoder: BitPackDecoder, metadata) -> "Permalink":
        version, seed, spoiler = decoder.decode(_PERMALINK_MAX_VERSION,
                                                _PERMALINK_MAX_SEED, 2)
        cls._raise_if_different_version(version)

        included_data_hash = decoder.decode_single(256)

        manager = PresetManager(None)
        is_custom_preset = bitpacking.decode_bool(decoder)
        reference_preset = decoder.decode_element(manager.included_presets)

        if is_custom_preset:
            patcher_configuration = PatcherConfiguration.bit_pack_unpack(
                decoder, {"reference": reference_preset.patcher_configuration})
            layout_configuration = LayoutConfiguration.bit_pack_unpack(
                decoder, {"reference": reference_preset.layout_configuration})
            preset = Preset(
                name="{} Custom".format(reference_preset.name),
                description="A customized preset.",
                base_preset_name=reference_preset.name,
                patcher_configuration=patcher_configuration,
                layout_configuration=layout_configuration,
            )

        else:
            preset = reference_preset

        expected_data_hash = _dictionary_byte_hash(
            preset.layout_configuration.game_data)
        if included_data_hash != expected_data_hash:
            raise ValueError(
                "Given permalink is for a Randovania database with hash '{}', "
                "but current database has hash '{}'.".format(
                    included_data_hash, expected_data_hash))

        return Permalink(
            seed,
            bool(spoiler),
            preset,
        )
Ejemplo n.º 16
0
async def permalink_command_body(args):
    from randovania.interface_common.preset_manager import PresetManager

    preset_manager = PresetManager(None)
    versioned_preset = preset_manager.included_preset_with(
        RandovaniaGame(args.game), args.preset)
    if versioned_preset is None:
        raise ValueError(f"Unknown preset: {args.preset}")

    seed = args.seed
    if seed is None:
        seed = random.randint(0, 2**31)

    preset = versioned_preset.get_preset()
    permalink = Permalink(
        seed_number=seed,
        spoiler=not args.race,
        presets={i: preset
                 for i in range(args.player_count)})
    print(permalink.as_base64_str)

    Permalink.from_str(permalink.as_base64_str)
Ejemplo n.º 17
0
async def permalink_command_body(args):
    from randovania.interface_common import persistence
    from randovania.interface_common.preset_manager import PresetManager

    preset_manager = PresetManager(persistence.user_data_dir())
    await preset_manager.load_user_presets()

    versioned_preset = preset_manager.preset_for_name(args.preset)
    if versioned_preset is None:
        raise ValueError(f"Unknown preset: {args.preset}")

    seed = args.seed
    if seed is None:
        seed = random.randint(0, 2**31)

    preset = versioned_preset.get_preset()
    permalink = Permalink(
        seed_number=seed,
        spoiler=not args.race,
        presets={i: preset
                 for i in range(args.player_count)})
    print(permalink.as_base64_str)

    Permalink.from_str(permalink.as_base64_str)
Ejemplo n.º 18
0
    def bit_pack_encode(self, metadata) -> Iterator[Tuple[int, int]]:
        yield self.current_version(), _PERMALINK_MAX_VERSION
        yield self.seed_number, _PERMALINK_MAX_SEED
        yield int(self.spoiler), 2
        yield _dictionary_byte_hash(self.layout_configuration.game_data), 256

        manager = PresetManager(None)

        # Is this a custom preset?
        is_custom_preset = self.preset.base_preset_name is not None
        if is_custom_preset:
            reference_preset = manager.preset_for_name(
                self.preset.base_preset_name)
        else:
            reference_preset = self.preset

        yield from bitpacking.encode_bool(is_custom_preset)
        yield from bitpacking.pack_array_element(reference_preset,
                                                 manager.included_presets)
        if is_custom_preset:
            yield from self.patcher_configuration.bit_pack_encode(
                {"reference": reference_preset.patcher_configuration})
            yield from self.layout_configuration.bit_pack_encode(
                {"reference": reference_preset.layout_configuration})
Ejemplo n.º 19
0
def default_blank_preset() -> Preset:
    return PresetManager(None).default_preset_for_game(
        RandovaniaGame.BLANK).get_preset()
Ejemplo n.º 20
0
def default_echoes_preset() -> Preset:
    return PresetManager(None).default_preset_for_game(RandovaniaGame.METROID_PRIME_ECHOES).get_preset()
Ejemplo n.º 21
0
def default_prime_preset() -> Preset:
    return PresetManager(None).default_preset_for_game(RandovaniaGame.METROID_PRIME).get_preset()
Ejemplo n.º 22
0
def default_blank_configuration() -> BlankConfiguration:
    preset = PresetManager(None).default_preset_for_game(RandovaniaGame.BLANK).get_preset()
    assert isinstance(preset.configuration, BlankConfiguration)
    return preset.configuration
Ejemplo n.º 23
0
def default_preset() -> Preset:
    return PresetManager(None).default_preset.get_preset()
Ejemplo n.º 24
0
def preset_manager(tmp_path) -> PresetManager:
    return PresetManager(tmp_path.joinpath("presets"))
Ejemplo n.º 25
0
def default_cs_preset() -> Preset:
    return PresetManager(None).default_preset_for_game(RandovaniaGame.CAVE_STORY).get_preset()
Ejemplo n.º 26
0
def preset_manager(tmpdir) -> PresetManager:
    return PresetManager(Path(tmpdir.join("presets")))
Ejemplo n.º 27
0
def default_prime_configuration() -> PrimeConfiguration:
    preset = PresetManager(None).default_preset_for_game(RandovaniaGame.METROID_PRIME).get_preset()
    assert isinstance(preset.configuration, PrimeConfiguration)
    return preset.configuration