Skip to content

Commit 651b553

Browse files
committed
refactor: Don't use separate event for enabled switch event.
1 parent 58fa9d8 commit 651b553

File tree

4 files changed

+3
-15
lines changed

4 files changed

+3
-15
lines changed

Runtime/Gamelogic/VisualScriptingEventNames.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public static class VisualScriptingEventNames
2121
public const string GleStartedEvent = "GleStartedEvent";
2222
public const string LampEvent = "LampEvent";
2323
public const string SwitchEvent = "SwitchEvent";
24-
public const string SwitchEnabledEvent = "SwitchEnabledEvent";
2524
public const string CoilEvent = "CoilEvent";
2625
}
2726
}

Runtime/Gamelogic/VisualScriptingGamelogicBridge.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ private static void OnSwitchChanged(object sender, SwitchEventArgs2 e)
7979
var args = new SwitchEventArgs2(e.Id, e.IsEnabled);
8080

8181
EventBus.Trigger(VisualScriptingEventNames.SwitchEvent, args);
82-
83-
if (e.IsEnabled) {
84-
EventBus.Trigger(VisualScriptingEventNames.SwitchEnabledEvent, args);
85-
}
8682
}
8783

8884
private static void OnCoilChanged(object sender, CoilEventArgs e)

Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public void OnInit(Player player, TableApi tableApi, BallManager ballManager)
6161
_player = player;
6262
BallManager = ballManager;
6363

64+
OnStarted?.Invoke(this, EventArgs.Empty);
6465
EventBus.Trigger(VisualScriptingEventNames.GleStartedEvent, EventArgs.Empty);
6566
}
6667

@@ -71,10 +72,6 @@ public void Switch(string id, bool isClosed)
7172
OnSwitchChanged?.Invoke(this, args);
7273

7374
EventBus.Trigger(VisualScriptingEventNames.SwitchEvent, args);
74-
75-
if (isClosed) {
76-
EventBus.Trigger(VisualScriptingEventNames.SwitchEnabledEvent, args);
77-
}
7875
}
7976

8077
public void SetCoil(string id, bool isEnabled)

Runtime/Nodes/Switches/SwitchEnabledEventUnit.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,17 @@ public class SwitchEnabledEventUnit : GleEventUnit<SwitchEventArgs2>
3131
protected override bool register => true;
3232

3333
// Adding an EventHook with the name of the event to the list of visual scripting events.
34-
public override EventHook GetHook(GraphReference reference)
35-
{
36-
return new EventHook(VisualScriptingEventNames.SwitchEnabledEvent);
37-
}
34+
public override EventHook GetHook(GraphReference reference) => new EventHook(VisualScriptingEventNames.SwitchEvent);
3835

3936
protected override void Definition()
4037
{
4138
base.Definition();
42-
4339
Id = ValueInput(nameof(Id), string.Empty);
4440
}
4541

4642
protected override bool ShouldTrigger(Flow flow, SwitchEventArgs2 args)
4743
{
48-
return flow.GetValue<string>(Id) == args.Id;
44+
return flow.GetValue<string>(Id) == args.Id && args.IsEnabled;
4945
}
5046
}
5147
}

0 commit comments

Comments
 (0)