@@ -41,7 +41,7 @@ public class LampPlayer
41
41
/// <summary>
42
42
/// Links the GLE's IDs to the mappings.
43
43
/// </summary>
44
- private readonly Dictionary < string , Dictionary < ILampDeviceComponent , LampMapping > > _lampMappings = new ( ) ;
44
+ private readonly Dictionary < string , Dictionary < int , Dictionary < ILampDeviceComponent , LampMapping > > > _lampMappings = new ( ) ;
45
45
46
46
private Player ? _player ;
47
47
private TableComponent ? _tableComponent ;
@@ -78,7 +78,7 @@ public void OnStart()
78
78
79
79
// turn it off
80
80
if ( _lamps . ContainsKey ( lampMapping . Device ) ) {
81
- HandleLampEvent ( lampMapping . Id , LampStatus . Off ) ;
81
+ HandleLampEvent ( lampMapping . Id , lampMapping . InternalId , LampStatus . Off ) ;
82
82
}
83
83
}
84
84
@@ -92,40 +92,43 @@ public void OnStart()
92
92
private void HandleLampsEvent ( object sender , LampsEventArgs lampsEvent )
93
93
{
94
94
foreach ( var lampEvent in lampsEvent . LampsChanged ) {
95
- Apply ( lampEvent . Id , lampEvent . Source , lampEvent . IsCoil , ( state , lamp , mapping ) => ApplyValue ( lampEvent . Id , lampEvent . InternalId , lampEvent . Value , state , lamp , mapping ) ) ;
95
+ Apply ( lampEvent . Id , lampEvent . InternalId , lampEvent . Source , lampEvent . IsCoil , ( state , lamp , mapping ) => ApplyValue ( lampEvent . Id , lampEvent . InternalId , lampEvent . Value , state , lamp , mapping ) ) ;
96
96
}
97
97
}
98
98
99
99
private void HandleLampEvent ( object sender , LampEventArgs lampEvent )
100
100
{
101
- Apply ( lampEvent . Id , lampEvent . Source , lampEvent . IsCoil , ( state , lamp , mapping ) => ApplyValue ( lampEvent . Id , lampEvent . InternalId , lampEvent . Value , state , lamp , mapping ) ) ;
101
+ Apply ( lampEvent . Id , lampEvent . InternalId , lampEvent . Source , lampEvent . IsCoil , ( state , lamp , mapping ) => ApplyValue ( lampEvent . Id , lampEvent . InternalId , lampEvent . Value , state , lamp , mapping ) ) ;
102
102
}
103
103
104
- public void HandleLampEvent ( string id , float value )
104
+ public void HandleLampEvent ( string id , int internalId , float value )
105
105
{
106
- Apply ( id , LampSource . Lamp , false , ( state , lamp , mapping ) => ApplyValue ( id , int . TryParse ( id , out var internalId ) ? internalId : 0 , value , state , lamp , mapping ) ) ;
106
+ Apply ( id , internalId , LampSource . Lamp , false , ( state , lamp , mapping ) => ApplyValue ( id , int . TryParse ( id , out var internalId ) ? internalId : 0 , value , state , lamp , mapping ) ) ;
107
107
}
108
108
109
- public void HandleLampEvent ( string id , LampStatus status )
109
+ public void HandleLampEvent ( string id , int internalId , LampStatus status )
110
110
{
111
- Apply ( id , LampSource . Lamp , false , ( state , lamp , _ ) => ApplyStatus ( id , status , state , lamp ) ) ;
111
+ Apply ( id , internalId , LampSource . Lamp , false , ( state , lamp , _ ) => ApplyStatus ( id , status , state , lamp ) ) ;
112
112
}
113
113
114
- public void HandleLampEvent ( string id , Color color )
114
+ public void HandleLampEvent ( string id , int internalId , Color color )
115
115
{
116
- Apply ( id , LampSource . Lamp , false , ( state , lamp , _ ) => ApplyColor ( id , color , state , lamp ) ) ;
116
+ Apply ( id , internalId , LampSource . Lamp , false , ( state , lamp , _ ) => ApplyColor ( id , color , state , lamp ) ) ;
117
117
}
118
118
119
119
public void HandleCoilEvent ( string id , bool isEnabled )
120
120
{
121
- Apply ( id , LampSource . Lamp , true , ( state , lamp , _ ) => ApplyStatus ( id , isEnabled ? LampStatus . On : LampStatus . Off , state , lamp ) ) ;
121
+ Apply ( id , 0 , LampSource . Lamp , true , ( state , lamp , _ ) => ApplyStatus ( id , isEnabled ? LampStatus . On : LampStatus . Off , state , lamp ) ) ;
122
122
}
123
123
124
- private void Apply ( string id , LampSource lampSource , bool isCoil , Action < LampState , IApiLamp ? , LampMapping ? > action )
124
+ private void Apply ( string id , int internalId , LampSource lampSource , bool isCoil , Action < LampState , IApiLamp ? , LampMapping ? > action )
125
125
{
126
126
if ( _lampAssignments . ContainsKey ( id ) ) {
127
127
foreach ( var component in _lampAssignments [ id ] ) {
128
- var mapping = _lampMappings [ id ] [ component ] ;
128
+ if ( ! _lampMappings [ id ] . ContainsKey ( internalId ) ) {
129
+ continue ;
130
+ }
131
+ var mapping = _lampMappings [ id ] [ internalId ] [ component ] ;
129
132
if ( mapping . Source != lampSource || mapping . IsCoil != isCoil ) {
130
133
// so, if we have a coil here that happens to have the same name as a lamp,
131
134
// or a GI light with the same name as an other lamp, skip.
@@ -222,10 +225,13 @@ private void AssignLampMapping(LampMapping lampMapping)
222
225
_lampAssignments [ id ] = new List < ILampDeviceComponent > ( ) ;
223
226
}
224
227
if ( ! _lampMappings . ContainsKey ( id ) ) {
225
- _lampMappings [ id ] = new Dictionary < ILampDeviceComponent , LampMapping > ( ) ;
228
+ _lampMappings [ id ] = new Dictionary < int , Dictionary < ILampDeviceComponent , LampMapping > > ( ) ;
226
229
}
227
230
_lampAssignments [ id ] . Add ( lampMapping . Device ) ;
228
- _lampMappings [ id ] [ lampMapping . Device ] = lampMapping ;
231
+ if ( ! _lampMappings [ id ] . ContainsKey ( lampMapping . InternalId ) ) {
232
+ _lampMappings [ id ] [ lampMapping . InternalId ] = new Dictionary < ILampDeviceComponent , LampMapping > ( ) ;
233
+ }
234
+ _lampMappings [ id ] [ lampMapping . InternalId ] [ lampMapping . Device ] = lampMapping ;
229
235
LampStates [ id ] = new LampState ( lampMapping . Device . LampStatus , lampMapping . Device . LampColor . ToEngineColor ( ) ) ;
230
236
}
231
237
0 commit comments