1414// You should have received a copy of the GNU General Public License
1515// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
17+ // ReSharper disable InconsistentNaming
18+
1719using System ;
20+ using System . Linq ;
1821using Unity . VisualScripting ;
1922using UnityEngine ;
2023using VisualPinball . Engine . Game . Engines ;
@@ -25,19 +28,19 @@ namespace VisualPinball.Unity.VisualScripting
2528 [ AddComponentMenu ( "Visual Pinball/Game Logic Engine/Visual Scripting Game Logic" ) ]
2629 public class VisualScriptingGamelogicEngine : MonoBehaviour , IGamelogicEngine
2730 {
28- public string Name { get ; } = "Visual Scripting Gamelogic Engine" ;
31+ public string Name => "Visual Scripting Gamelogic Engine" ;
2932
3033 [ Tooltip ( "The switches that are exposed in the Visual Scripting nodes." ) ]
3134 public VisualScriptingSwitch [ ] Switches ;
3235 public VisualScriptingCoil [ ] Coils ;
3336 public GamelogicEngineLamp [ ] Lamps ;
3437 public GamelogicEngineWire [ ] Wires ;
3538
36- public GamelogicEngineSwitch [ ] AvailableSwitches => Switches ;
39+ public GamelogicEngineSwitch [ ] AvailableSwitches => Switches . Select ( sw => sw as GamelogicEngineSwitch ) . ToArray ( ) ;
3740
3841 public GamelogicEngineLamp [ ] AvailableLamps => Lamps ;
3942
40- public GamelogicEngineCoil [ ] AvailableCoils => Coils ;
43+ public GamelogicEngineCoil [ ] AvailableCoils => Coils . Select ( c => c as GamelogicEngineCoil ) . ToArray ( ) ;
4144
4245 public GamelogicEngineWire [ ] AvailableWires => Wires ;
4346
@@ -47,19 +50,31 @@ public class VisualScriptingGamelogicEngine : MonoBehaviour, IGamelogicEngine
4750 public event EventHandler < LampsEventArgs > OnLampsChanged ;
4851 public event EventHandler < LampColorEventArgs > OnLampColorChanged ;
4952 public event EventHandler < CoilEventArgs > OnCoilChanged ;
53+ public event EventHandler < SwitchEventArgs2 > OnSwitchChanged ;
5054
5155 public void OnInit ( Player player , TableApi tableApi , BallManager ballManager )
5256 {
5357 }
5458
59+ public void Switch ( string id , bool isClosed )
60+ {
61+ OnSwitchChanged ? . Invoke ( this , new SwitchEventArgs2 ( id , isClosed ) ) ;
62+ EventBus . Trigger ( EventNames . SwitchEvent , new SwitchEventArgs2 ( id , isClosed ) ) ;
63+ }
64+
5565 public void SetCoil ( string id , bool isEnabled )
5666 {
5767 OnCoilChanged ? . Invoke ( this , new CoilEventArgs ( id , isEnabled ) ) ;
5868 }
5969
60- public void Switch ( string id , bool isClosed )
70+ public void SetLamp ( string id , int value , bool isCoil = false , LampSource source = LampSource . Lamp )
71+ {
72+ OnLampChanged ? . Invoke ( this , new LampEventArgs ( id , value , isCoil , source ) ) ;
73+ }
74+
75+ public void SetLamp ( string id , Color color )
6176 {
62- EventBus . Trigger ( EventNames . SwitchEvent , new VisualScriptingScriptEvent ( id , isClosed ) ) ;
77+ OnLampColorChanged ? . Invoke ( this , new LampColorEventArgs ( id , color ) ) ;
6378 }
6479 }
6580}
0 commit comments