コード例 #1
0
    def bit_pack_unpack(cls, decoder: BitPackDecoder, item: MajorItem,
                        reference: "MajorItemState") -> "MajorItemState":
        db = default_database.resource_database_for(item.game)
        if item.progression:
            main_index = item.progression[0]
        else:
            main_index = item.ammo_index[0]
        main_item = db.get_item(main_index)

        # original location
        original = False
        if item.original_index is not None:
            original = bitpacking.decode_bool(decoder)

        # num shuffled
        shuffled = bitpacking.decode_int_with_limits(decoder,
                                                     DEFAULT_MAXIMUM_SHUFFLED)

        # starting item
        if main_item.max_capacity > 1:
            starting = bitpacking.decode_int_with_limits(
                decoder, (2, main_item.max_capacity + 1))
        else:
            starting = decoder.decode_single(main_item.max_capacity + 1)

        # priority
        priority = bitpacking.BitPackFloat.bit_pack_unpack(
            decoder, PRIORITY_LIMITS)

        # ammo index
        if item.ammo_index:
            custom_ammo = bitpacking.decode_bool(decoder)
            if custom_ammo:
                all_equal = len(
                    item.ammo_index) <= 1 or bitpacking.decode_bool(decoder)
                if all_equal:
                    ammo = decoder.decode_single(
                        db.get_item(item.ammo_index[0]).max_capacity + 1)
                    included_ammo = [ammo] * len(item.ammo_index)
                else:
                    included_ammo = [
                        decoder.decode_single(
                            db.get_item(item).max_capacity + 1)
                        for item in item.ammo_index
                    ]
            else:
                included_ammo = reference.included_ammo
        else:
            included_ammo = []

        return cls(
            include_copy_in_original_location=original,
            num_shuffled_pickups=shuffled,
            num_included_in_starting_items=starting,
            priority=priority,
            included_ammo=tuple(included_ammo),
        )
コード例 #2
0
ファイル: ammo_state.py プロジェクト: randovania/randovania
    def bit_pack_unpack(cls, decoder: BitPackDecoder, metadata) -> "AmmoState":
        ammo: Ammo = metadata["ammo"]
        db = default_database.resource_database_for(ammo.game)

        # Ammo Count
        ammo_count = []
        for ammo_index in ammo.items:
            ammo_item = db.get_item(ammo_index)
            ammo_count.append(
                bitpacking.decode_int_with_limits(
                    decoder,
                    (ammo_item.max_capacity // 2, ammo_item.max_capacity + 1),
                ))

        # Pickup Count
        pickup_count = bitpacking.decode_big_int(decoder)

        # Require Major Item
        requires_major_item = True
        if ammo.unlocked_by is not None:
            requires_major_item = bitpacking.decode_bool(decoder)

        return cls(
            ammo_count=tuple(ammo_count),
            pickup_count=pickup_count,
            requires_major_item=requires_major_item,
        )
コード例 #3
0
ファイル: permalink.py プロジェクト: ThomasJRyan/randovania
    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)
コード例 #4
0
    def bit_pack_unpack(cls, decoder: BitPackDecoder,
                        item: MajorItem) -> "MajorItemState":
        original = decoder.decode_single(2)

        # num shuffled
        shuffled = bitpacking.decode_int_with_limits(decoder,
                                                     DEFAULT_MAXIMUM_SHUFFLED)

        # starting item
        starting = decoder.decode_single(
            ENERGY_TANK_MAXIMUM_COUNT if item.item_category ==
            ItemCategory.ENERGY_TANK else 2)

        if item.ammo_index:
            included_ammo = decoder.decode(*[256 for _ in item.ammo_index])
        else:
            included_ammo = []

        # allowed_as_random_starting_item
        allowed_as_random_starting_item = bitpacking.decode_bool(decoder)

        return cls(
            include_copy_in_original_location=bool(original),
            num_shuffled_pickups=shuffled,
            num_included_in_starting_items=starting,
            included_ammo=tuple(included_ammo),
            allowed_as_random_starting_item=allowed_as_random_starting_item,
        )
コード例 #5
0
def test_encode_int_with_limits_round_trip(value: int,
                                           limits: Tuple[int, ...],
                                           ):
    # Run
    data = bitpacking._pack_encode_results(list(bitpacking.encode_int_with_limits(value, limits)))
    decoded = bitpacking.decode_int_with_limits(bitpacking.BitPackDecoder(data), limits)

    # Assert
    assert decoded == value
コード例 #6
0
    def bit_pack_unpack(cls, decoder: BitPackDecoder, metadata) -> "BitPackPickupEntryList":
        result = []
        index_mapping = metadata["index_mapping"]
        num_players = metadata["num_players"]

        for _ in range(len(index_mapping)):
            index = PickupIndex(decoder.decode_single(255))
            target_player = bitpacking.decode_int_with_limits(decoder, (num_players,))
            pickup = BitPackPickupEntry.bit_pack_unpack(decoder, index_mapping[index], metadata["database"])
            result.append((index, PickupTarget(pickup, target_player)))

        return BitPackPickupEntryList(result, num_players, metadata["database"])
コード例 #7
0
def test_decode_int_with_limits(limits_fixture):
    # Setup
    value, limits, encoded = limits_fixture
    decoder = MagicMock()
    decoder.decode_single.side_effect = [part for part, _ in encoded]

    # Run
    result = bitpacking.decode_int_with_limits(decoder, limits)

    # Assert
    decoder.decode_single.assert_has_calls(
        [call(limit) for _, limit in encoded])
    assert result == value