DirectOuput Framework R2
DirectOutput framework R2 for virtual pinball cabinets
Go to:
Overview 
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros Pages
AssignedEffect.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using DirectOutput.FX;
6 using DirectOutput.Table;
7 using System.Xml.Serialization;
8 
9 namespace DirectOutput.FX
10 {
11  //TODO: Add conditions (expressions that evluate to true or false) for assigned effects. CSScript makes this easy, but unlopading of changed effects will not be possible without restarting the framework.
15  public class AssignedEffect
16  {
17 
18 
19  #region EffectName
20  private string _EffectName;
28  public string EffectName
29  {
30  get { return _EffectName; }
31  set
32  {
33  if (_EffectName != value)
34  {
35  _EffectName = value;
36  if (EffectNameChanged != null)
37  {
38  EffectNameChanged(this, new EventArgs());
39  }
40 
41  }
42  }
43  }
47  public event EventHandler<EventArgs> EffectNameChanged;
48 
54  protected void TableElementEffect_EffectNameChanged(object sender, EventArgs e)
55  {
56  _Effect = null;
57  }
58 
59  #endregion
60 
61 
62  #region Effect
63  private IEffect _Effect;
68  [XmlIgnoreAttribute]
69  public IEffect Effect
70  {
71  get
72  {
73  return _Effect;
74  }
75  private set
76  {
77  _Effect = value;
78  }
79  }
80 
81  private void ResolveEffectName(Table.Table Table)
82  {
83  if (!EffectName.IsNullOrWhiteSpace() && Table.Effects.Contains(EffectName))
84  {
85  Effect = Table.Effects[EffectName];
86  };
87 
88  }
89 
90  #endregion
91 
92 
98  public void Trigger(TableElementData TableElementData)
99  {
100  if (Effect != null)
101  {
102  try
103  {
104  Effect.Trigger(TableElementData);
105  }
106  catch (Exception E)
107  {
108 
109  Log.Exception("A exception occured when triggering effect {0} for table element {1} {2} with value {3}. Effect assignement will be deactivated.".Build(new object[] { Effect.Name, TableElementData.TableElementType, TableElementData.Number, TableElementData.Value }), E);
110  Effect = null;
111  }
112  }
113  }
114 
115 
120  public void Init(Table.Table Table)
121  {
122 
123  ResolveEffectName(Table);
124  }
125 
129  public void Finish()
130  {
131  Effect = null;
132  }
133 
134 
135  #region Constructor
136 
137 
138 
139  public AssignedEffect()
140  {
141  EffectNameChanged += new EventHandler<EventArgs>(TableElementEffect_EffectNameChanged);
142  }
143 
148  public AssignedEffect(string EffectName)
149  : this()
150  {
151  this.EffectName = EffectName;
152  }
153 
154 
155 
156  #endregion
157 
158 
159  }
160 }