DirectOutputR1
DirectOutput framework R1 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  if (TableElementData != null)
109  {
110  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);
111  }
112  else
113  {
114  Log.Exception("A exception occured when triggering effect {0} as a static effect.Effect assignement will be deactivated.".Build(new object[] { Effect.Name}), E);
115  }
116  Effect = null;
117  }
118  }
119  }
120 
121 
126  public void Init(Table.Table Table)
127  {
128 
129  ResolveEffectName(Table);
130  }
131 
135  public void Finish()
136  {
137  Effect = null;
138  }
139 
140 
141  #region Constructor
142 
143 
144 
145  public AssignedEffect()
146  {
147  EffectNameChanged += new EventHandler<EventArgs>(TableElementEffect_EffectNameChanged);
148  }
149 
154  public AssignedEffect(string EffectName)
155  : this()
156  {
157  this.EffectName = EffectName;
158  }
159 
160 
161 
162  #endregion
163 
164 
165  }
166 }