def bit_pack_unpack(cls, decoder: BitPackDecoder, metadata) -> "MajorItemsConfiguration": from randovania.game_description import default_database item_database = default_database.default_prime2_item_database() progressive_suit = bitpacking.decode_bool(decoder) progressive_grapple = bitpacking.decode_bool(decoder) progressive_launcher = bitpacking.decode_bool(decoder) default = MajorItemsConfiguration.default() 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.major_items.values()): if index in indices_with_custom: items_state[item] = MajorItemState.bit_pack_unpack( decoder, item) else: items_state[item] = default.items_state[item] minimum, maximum = decoder.decode(RANDOM_STARTING_ITEMS_LIMIT, RANDOM_STARTING_ITEMS_LIMIT) return cls(items_state, progressive_suit=progressive_suit, progressive_grapple=progressive_grapple, progressive_launcher=progressive_launcher, minimum_random_starting_items=minimum, maximum_random_starting_items=maximum)
def bit_pack_unpack(cls, decoder: BitPackDecoder, metadata) -> "MajorItemsConfiguration": reference: MajorItemsConfiguration = metadata["reference"] num_items = decoder.decode_single(len(reference.items_state)) indices_with_custom = { decoder.decode_single(len(reference.items_state)) for _ in range(num_items) } items_state = {} for index, item in enumerate(reference.items_state.keys()): if index in indices_with_custom: items_state[item] = MajorItemState.bit_pack_unpack( decoder, item) else: items_state[item] = reference.items_state[item] minimum, maximum = decoder.decode(RANDOM_STARTING_ITEMS_LIMIT, RANDOM_STARTING_ITEMS_LIMIT) return cls(items_state, minimum_random_starting_items=minimum, maximum_random_starting_items=maximum)
def test_decode(state_with_data): # Setup item, data, expected = state_with_data # Run decoder = BitPackDecoder(data) result = MajorItemState.bit_pack_unpack(decoder, item) # Assert assert result == expected
def bit_pack_unpack(cls, decoder: BitPackDecoder, metadata) -> "MajorItemsConfiguration": reference: MajorItemsConfiguration = metadata["reference"] num_items = decoder.decode_single(len(reference.items_state)) indices_with_custom = { decoder.decode_single(len(reference.items_state)) for _ in range(num_items) } items_state = {} for index, item in enumerate(reference.items_state.keys()): if index in indices_with_custom: items_state[item] = MajorItemState.bit_pack_unpack( decoder, item) else: items_state[item] = reference.items_state[item] # default_items default_items = {} for category in reference.default_items.keys(): all_major = [ major for major in reference.items_state.keys() if major.item_category == category ] default_items[category] = decoder.decode_element(all_major) # random starting items minimum, maximum = decoder.decode(RANDOM_STARTING_ITEMS_LIMIT, RANDOM_STARTING_ITEMS_LIMIT) return cls(items_state, default_items=default_items, minimum_random_starting_items=minimum, maximum_random_starting_items=maximum)