WIP
DirectOutput framework for virtual pinball cabinets WIP
Go to:
Overview 
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  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 }
TableElementTypeEnum TableElementType
The type of the table element.
bool Contains(string Name)
Checks if a INamedItem object with the specified name exists in the list.
int Number
The number of the table element.
A simple logger used to record important events and exceptions.
Definition: Log.cs:14
int Value
The value of the table element.
EventHandler< EventArgs > EffectNameChanged
Event is fired if the value of the property EffectName is changed.
void TableElementEffect_EffectNameChanged(object sender, EventArgs e)
Handles the EffectNameChanged event of the TableElementEffect control.
Common interface for all effects. If a new effect is implemented it is best to inherit from the abst...
Definition: IEffect.cs:13
Data representing the state of a table emlement
EffectList Effects
List of table specific effects.
Definition: Table.cs:187
The Table namespace contains all table specific classes like the Table class itself, TableElement and effect assigment classes.
Definition: Table.cs:14
Holds all table specific information and handles all TableElements
Definition: Table.cs:20
The namespace FX contains effect related classes. Effects can be assigned directly to a Table and wi...
Table()
Initializes a new instance of the Table class.
Definition: Table.cs:388
static void Exception(string Message, Exception E=null)
Writes a exception message to the log.
Definition: Log.cs:144
Handles the assignemt of a effect to a AssignedEffectList.