SingleActionParam.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace Team.FFFeederService.Models
  9. {
  10. /// <summary>
  11. /// 单个平台振动动作参数
  12. /// </summary>
  13. public class SingleActionParam : INotifyPropertyChanged
  14. {
  15. private VoiceMotorParam _Motor1;
  16. public VoiceMotorParam Motor1
  17. {
  18. get { return _Motor1; }
  19. set { SetProperty(ref _Motor1, value); }
  20. }
  21. private VoiceMotorParam _Motor2;
  22. public VoiceMotorParam Motor2
  23. {
  24. get { return _Motor2; }
  25. set { SetProperty(ref _Motor2, value); }
  26. }
  27. private VoiceMotorParam _Motor3;
  28. public VoiceMotorParam Motor3
  29. {
  30. get { return _Motor3; }
  31. set { SetProperty(ref _Motor3, value); }
  32. }
  33. private VoiceMotorParam _Motor4;
  34. public VoiceMotorParam Motor4
  35. {
  36. get { return _Motor4; }
  37. set { SetProperty(ref _Motor4, value); }
  38. }
  39. private int _DurationValue;
  40. /// <summary>
  41. /// 持续时长
  42. /// </summary>
  43. public int DurationValue
  44. {
  45. get { return _DurationValue; }
  46. set { SetProperty(ref _DurationValue, value); }
  47. }
  48. public SingleActionParam Copy()
  49. {
  50. return new SingleActionParam()
  51. {
  52. Motor1 = new VoiceMotorParam()
  53. {
  54. Amplitude = this.Motor1.Amplitude,
  55. Frequency = this.Motor1.Frequency,
  56. Phase = this.Motor1.Phase,
  57. WaveShape = this.Motor1.WaveShape
  58. },
  59. Motor2 = new VoiceMotorParam()
  60. {
  61. Amplitude = this.Motor2.Amplitude,
  62. Frequency = this.Motor2.Frequency,
  63. Phase = this.Motor2.Phase,
  64. WaveShape = this.Motor2.WaveShape
  65. },
  66. Motor3 = new VoiceMotorParam()
  67. {
  68. Amplitude = this.Motor3.Amplitude,
  69. Frequency = this.Motor3.Frequency,
  70. Phase = this.Motor3.Phase,
  71. WaveShape = this.Motor3.WaveShape
  72. },
  73. Motor4 = new VoiceMotorParam()
  74. {
  75. Amplitude = this.Motor4.Amplitude,
  76. Frequency = this.Motor4.Frequency,
  77. Phase = this.Motor4.Phase,
  78. WaveShape = this.Motor4.WaveShape
  79. },
  80. DurationValue=this.DurationValue
  81. };
  82. }
  83. #region 属性更改通知
  84. /// <summary>
  85. /// Occurs when a property value changes.
  86. /// </summary>
  87. public event PropertyChangedEventHandler PropertyChanged;
  88. /// <summary>
  89. /// Checks if a property already matches a desired value. Sets the property and
  90. /// notifies listeners only when necessary.
  91. /// </summary>
  92. /// <typeparam name="T">Type of the property.</typeparam>
  93. /// <param name="storage">Reference to a property with both getter and setter.</param>
  94. /// <param name="value">Desired value for the property.</param>
  95. /// <param name="propertyName">Name of the property used to notify listeners. This
  96. /// value is optional and can be provided automatically when invoked from compilers that
  97. /// support CallerMemberName.</param>
  98. /// <returns>True if the value was changed, false if the existing value matched the
  99. /// desired value.</returns>
  100. protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string propertyName = null)
  101. {
  102. if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
  103. storage = value;
  104. RaisePropertyChanged(propertyName);
  105. return true;
  106. }
  107. /// <summary>
  108. /// Checks if a property already matches a desired value. Sets the property and
  109. /// notifies listeners only when necessary.
  110. /// </summary>
  111. /// <typeparam name="T">Type of the property.</typeparam>
  112. /// <param name="storage">Reference to a property with both getter and setter.</param>
  113. /// <param name="value">Desired value for the property.</param>
  114. /// <param name="propertyName">Name of the property used to notify listeners. This
  115. /// value is optional and can be provided automatically when invoked from compilers that
  116. /// support CallerMemberName.</param>
  117. /// <param name="onChanged">Action that is called after the property value has been changed.</param>
  118. /// <returns>True if the value was changed, false if the existing value matched the
  119. /// desired value.</returns>
  120. protected virtual bool SetProperty<T>(ref T storage, T value, Action onChanged, [CallerMemberName] string propertyName = null)
  121. {
  122. if (EqualityComparer<T>.Default.Equals(storage, value)) return false;
  123. storage = value;
  124. onChanged?.Invoke();
  125. RaisePropertyChanged(propertyName);
  126. return true;
  127. }
  128. /// <summary>
  129. /// Raises this object's PropertyChanged event.
  130. /// </summary>
  131. /// <param name="propertyName">Name of the property used to notify listeners. This
  132. /// value is optional and can be provided automatically when invoked from compilers
  133. /// that support <see cref="CallerMemberNameAttribute"/>.</param>
  134. protected void RaisePropertyChanged([CallerMemberName] string propertyName = null)
  135. {
  136. OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
  137. }
  138. /// <summary>
  139. /// Raises this object's PropertyChanged event.
  140. /// </summary>
  141. /// <param name="args">The PropertyChangedEventArgs</param>
  142. protected virtual void OnPropertyChanged(PropertyChangedEventArgs args)
  143. {
  144. PropertyChanged?.Invoke(this, args);
  145. }
  146. #endregion
  147. }
  148. }