def _encode_preset(preset: Preset, manager: PresetManager): """ :param preset: :param manager: :return: """ # Is this a custom preset? is_custom_preset = preset.base_preset_name is not None if is_custom_preset: reference_versioned = manager.preset_for_name(preset.base_preset_name) if reference_versioned is None: reference_versioned = manager.default_preset reference_preset = reference_versioned.get_preset() else: reference_preset = preset included_presets = [versioned.get_preset() for versioned in manager.included_presets] yield from bitpacking.encode_bool(is_custom_preset) yield from bitpacking.pack_array_element(reference_preset, included_presets) if is_custom_preset: yield from preset.patcher_configuration.bit_pack_encode( {"reference": reference_preset.patcher_configuration}) yield from preset.layout_configuration.bit_pack_encode( {"reference": reference_preset.layout_configuration}) yield _dictionary_byte_hash(preset.layout_configuration.game_data), 256
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)}, )
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)
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})