コード例 #1
0
    def bit_pack_unpack(cls, decoder: BitPackDecoder, metadata):
        from randovania.game_description import default_database
        item_database = default_database.default_prime2_item_database()

        default = cls.default()
        has_value = {
            item_key: bool(decoder.decode_single(2))
            for item_key in default.maximum_ammo.keys()
        }

        maximum_ammo = {
            item_key: decoder.decode_single(256)
            if has_value[item_key] else default.maximum_ammo[item_key]
            for item_key, default_value in default.maximum_ammo.items()
        }

        num_items = decoder.decode_single(len(default.items_state))
        indices_with_custom = {
            decoder.decode_single(len(default.items_state))
            for _ in range(num_items)
        }

        items_state = {}
        for index, item in enumerate(item_database.ammo.values()):
            if index in indices_with_custom:
                items_state[item] = AmmoState.bit_pack_unpack(decoder, {})
            else:
                items_state[item] = default.items_state[item]

        return cls(maximum_ammo, items_state)
コード例 #2
0
def test_decode(state_with_data):
    # Setup
    data, expected = state_with_data

    # Run
    decoder = BitPackDecoder(data)
    result = AmmoState.bit_pack_unpack(decoder, {})

    # Assert
    assert result == expected
コード例 #3
0
    def bit_pack_unpack(cls, decoder: BitPackDecoder, metadata):
        default: AmmoConfiguration = metadata["reference"]

        # Maximum Ammo
        maximum_ammo = {}
        for item_key, default_value in default.maximum_ammo.items():
            is_different = bitpacking.decode_bool(decoder)
            if is_different:
                maximum_ammo[item_key] = decoder.decode_single(256)
            else:
                maximum_ammo[item_key] = default_value

        items_state = {}
        for item, default_state in default.items_state.items():
            is_different = bitpacking.decode_bool(decoder)
            if is_different:
                items_state[item] = AmmoState.bit_pack_unpack(decoder, {})
            else:
                items_state[item] = default_state

        return cls(maximum_ammo, items_state)