1717using System ;
1818using System . Collections . Generic ;
1919using System . Collections . ObjectModel ;
20+ using System . Linq ;
2021using Unity . VisualScripting ;
2122using UnityEngine ;
2223using VisualPinball . Engine . Game . Engines ;
@@ -58,6 +59,9 @@ public int inputCount
5859 [ DoNotSerialize ]
5960 public ValueInput Value { get ; private set ; }
6061
62+ [ DoNotSerialize ]
63+ private readonly Dictionary < string , float > _intensityMultipliers = new ( ) ;
64+
6165 protected override void Definition ( )
6266 {
6367 InputTrigger = ControlInput ( nameof ( InputTrigger ) , Process ) ;
@@ -105,7 +109,7 @@ private ControlOutput Process(Flow flow)
105109 Player . SetLamp ( lampId , flow . GetValue < LampStatus > ( Value ) ) ;
106110 break ;
107111 case LampDataType . Intensity :
108- Player . SetLamp ( lampId , flow . GetValue < float > ( Value ) ) ;
112+ Player . SetLamp ( lampId , flow . GetValue < float > ( Value ) * GetIntensityMultiplier ( lampId ) ) ;
109113 break ;
110114 case LampDataType . Color :
111115 Player . SetLamp ( lampId , flow . GetValue < UnityEngine . Color > ( Value ) . ToEngineColor ( ) ) ;
@@ -117,5 +121,22 @@ private ControlOutput Process(Flow flow)
117121
118122 return OutputTrigger ;
119123 }
124+
125+ private float GetIntensityMultiplier ( string id )
126+ {
127+ if ( _intensityMultipliers . ContainsKey ( id ) ) {
128+ return _intensityMultipliers [ id ] ;
129+ }
130+
131+ var mapping = Player . LampMapping . FirstOrDefault ( l => l . Id == id ) ;
132+ if ( mapping == null ) {
133+ Debug . LogError ( $ "Unknown lamp ID { id } .") ;
134+ _intensityMultipliers [ id ] = 1 ;
135+ return 1 ;
136+ }
137+
138+ _intensityMultipliers [ id ] = mapping . Type == LampType . Rgb ? 255 : 1 ;
139+ return _intensityMultipliers [ id ] ;
140+ }
120141 }
121142}
0 commit comments