using Artemis.Core; namespace Artemis.UI.Shared.Services.ProfileEditor.Commands; /// /// Represents a profile editor command that can be used to reset a layer property to it's default value. /// public class ResetLayerProperty : IProfileEditorCommand { private readonly bool _keyframesEnabled; private readonly LayerProperty _layerProperty; private readonly T _originalBaseValue; /// /// Creates a new instance of the class. /// public ResetLayerProperty(LayerProperty layerProperty) { if (layerProperty.DefaultValue == null) throw new ArtemisSharedUIException("Can't reset a layer property without a default value."); _layerProperty = layerProperty; _originalBaseValue = _layerProperty.BaseValue; _keyframesEnabled = _layerProperty.KeyframesEnabled; } #region Implementation of IProfileEditorCommand /// public string DisplayName => "Reset layer property"; /// public void Execute() { string json = CoreJson.Serialize(_layerProperty.DefaultValue); if (_keyframesEnabled) _layerProperty.KeyframesEnabled = false; _layerProperty.SetCurrentValue(CoreJson.Deserialize(json)!); } /// public void Undo() { _layerProperty.SetCurrentValue(_originalBaseValue); if (_keyframesEnabled) _layerProperty.KeyframesEnabled = true; } #endregion }