Skip to content

Commit bfcd1a4

Browse files
committed
gle: Add bridge API.
1 parent f3117a4 commit bfcd1a4

File tree

5 files changed

+25
-50
lines changed

5 files changed

+25
-50
lines changed

Editor/GleUnitAnalyzer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616

1717
using System.Collections.Generic;
1818
using Unity.VisualScripting;
19+
using VisualPinball.Unity;
1920
using VisualPinball.Unity.VisualScripting;
2021

2122
namespace Editor
2223
{
2324

2425
[Analyser(typeof(SwitchEventUnit))]
25-
public class SwitchEventUnitAnalyzer : GleUnitAnalyser<VisualScriptingScriptEvent>
26+
public class SwitchEventUnitAnalyzer : GleUnitAnalyser<SwitchEventArgs2>
2627
{
2728
public SwitchEventUnitAnalyzer(GraphReference reference, SwitchEventUnit target) : base(reference, target)
2829
{

Runtime/Events/Nodes/SwitchEventUnit.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace VisualPinball.Unity.VisualScripting
2020
{
2121
[UnitTitle("On Switch Changed")]
2222
[UnitCategory("Events\\Visual Pinball")]
23-
public class SwitchEventUnit : GleEventUnit<VisualScriptingScriptEvent>
23+
public class SwitchEventUnit : GleEventUnit<SwitchEventArgs2>
2424
{
2525
[DoNotSerialize]
2626
[PortLabel("Switch ID")]
@@ -46,12 +46,12 @@ protected override void Definition()
4646
IsEnabled = ValueOutput<bool>(nameof(IsEnabled));
4747
}
4848

49-
protected override bool ShouldTrigger(Flow flow, VisualScriptingScriptEvent args)
49+
protected override bool ShouldTrigger(Flow flow, SwitchEventArgs2 args)
5050
{
5151
return flow.GetValue<string>(Id) == args.Id;
5252
}
5353

54-
protected override void AssignArguments(Flow flow, VisualScriptingScriptEvent args)
54+
protected override void AssignArguments(Flow flow, SwitchEventArgs2 args)
5555
{
5656
flow.SetValue(IsEnabled, args.IsEnabled);
5757
}

Runtime/Gamelogic/VisualScriptingEvents.cs

Lines changed: 0 additions & 30 deletions
This file was deleted.

Runtime/Gamelogic/VisualScriptingEvents.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
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+
1719
using System;
20+
using System.Linq;
1821
using Unity.VisualScripting;
1922
using UnityEngine;
2023
using 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

Comments
 (0)