def import_preset_file(self, path: Path): preset = VersionedPreset.from_file_sync(path) try: preset.get_preset() except InvalidPreset: QtWidgets.QMessageBox.critical( self._window_manager, "Error loading preset", "The file at '{}' contains an invalid preset.".format(path) ) return existing_preset = self._window_manager.preset_manager.preset_for_uuid(preset.uuid) if existing_preset is not None: user_response = QtWidgets.QMessageBox.warning( self._window_manager, "Preset ID conflict", "The new preset '{}' has the same ID as existing '{}'. Do you want to overwrite it?".format( preset.name, existing_preset.name, ), QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No | QtWidgets.QMessageBox.Cancel, QtWidgets.QMessageBox.Cancel ) if user_response == QtWidgets.QMessageBox.Cancel: return elif user_response == QtWidgets.QMessageBox.No: preset = VersionedPreset.with_preset(dataclasses.replace(preset.get_preset(), uuid=uuid.uuid4())) self._add_new_preset(preset)
def refresh_presets_command_logic(args): for game in enum_lib.iterate_enum(RandovaniaGame): logging.info(f"Refreshing presets for {game.long_name}") base_path = game.data_path.joinpath("presets") for preset_relative_path in game.data.presets: preset_path = base_path.joinpath(preset_relative_path["path"]) preset = VersionedPreset.from_file_sync(preset_path) preset.ensure_converted() preset.save_to_file(preset_path)
def __init__(self, data_dir: Optional[Path]): self.logger = logging.getLogger("PresetManager") self.included_presets = { preset.uuid: preset for preset in [VersionedPreset.from_file_sync(f) for f in read_preset_list()] } self.custom_presets = {} if data_dir is not None: self._data_dir = data_dir else: self._data_dir = None
def test_elements_init(skip_qtbot, test_files_dir): preset_path = test_files_dir.joinpath( "presets/super_test_preset.rdvpreset") preset = VersionedPreset.from_file_sync(preset_path).get_preset() assert isinstance(preset.configuration, SuperMetroidConfiguration) editor = PresetEditor(preset) super_patches_tab = PresetSuperPatchConfiguration(editor) skip_qtbot.addWidget(super_patches_tab) # Test whether visual elements are initialized correctly patches = preset.configuration.patches for field_name, checkbox in super_patches_tab.checkboxes.items(): assert checkbox.isChecked() == getattr(patches, field_name)
def _load_previous_state( persistence_path: Path, game_configuration: BaseConfiguration, ) -> Optional[dict]: previous_layout_path = _persisted_preset_path(persistence_path) try: previous_configuration = VersionedPreset.from_file_sync( previous_layout_path).get_preset().configuration except (FileNotFoundError, json.JSONDecodeError, InvalidPreset): return None if previous_configuration != game_configuration: return None previous_state_path = persistence_path.joinpath("state.json") try: with previous_state_path.open() as previous_state_file: return json.load(previous_state_file) except (FileNotFoundError, json.JSONDecodeError): return None
def test_included_presets_are_valid(f): VersionedPreset.from_file_sync(f).get_preset()