Skip to content

Commit 15698f2

Browse files
committed
Abstract the analyzer stuff.
1 parent 5b538ca commit 15698f2

File tree

5 files changed

+51
-21
lines changed

5 files changed

+51
-21
lines changed

Editor/GleUnitAnalyzer.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
using System.Collections.Generic;
22
using Unity.VisualScripting;
3+
using VisualPinball.Unity;
34
using VisualPinball.Unity.VisualScripting;
45

56
namespace Editor
67
{
8+
79
[Analyser(typeof(SwitchEventUnit))]
8-
public class GleUnitAnalyser : UnitAnalyser<SwitchEventUnit>
10+
public class SwitchEventUnitAnalyzer : GleUnitAnalyser<SwitchEventArgs>
11+
{
12+
public SwitchEventUnitAnalyzer(GraphReference reference, SwitchEventUnit target) : base(reference, target)
13+
{
14+
}
15+
}
16+
17+
public abstract class GleUnitAnalyser<TArgs> : UnitAnalyser<GleEventUnit<TArgs>>
918
{
10-
public GleUnitAnalyser(GraphReference reference, SwitchEventUnit target) : base(reference, target) { }
19+
protected GleUnitAnalyser(GraphReference reference, GleEventUnit<TArgs> target) : base(reference, target) { }
1120

1221
protected override IEnumerable<Warning> Warnings()
1322
{
14-
foreach (var baseWarning in base.Warnings())
15-
{
23+
foreach (var baseWarning in base.Warnings()) {
1624
yield return baseWarning;
1725
}
1826

Editor/Widgets/SwitchEventUnitWidget.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ namespace VisualPinball.Unity.VisualScripting
2424
[Widget(typeof(SwitchEventUnit))]
2525
public sealed class SwitchEventUnitWidget : UnitWidget<SwitchEventUnit>
2626
{
27-
2827
protected override NodeColorMix baseColor => GleAvailable ? NodeColorMix.TealReadable : new NodeColorMix { red = 1f, green = 0f, blue = 0f };
2928
private bool GameObjectAvailable => reference != null && reference.gameObject != null;
3029
private bool GleAvailable => GameObjectAvailable && Gle != null;
@@ -63,7 +62,6 @@ private IEnumerable<string> GetNameSuggestions()
6362
}
6463
var gle = Gle;
6564
return gle == null ? new List<string>() : gle.AvailableSwitches.Select(lamp => lamp.Id).ToList();
66-
6765
}
6866
}
6967
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Visual Pinball Engine
2+
// Copyright (C) 2021 freezy and VPE Team
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
using System.Collections.Generic;
18+
using Unity.VisualScripting;
19+
20+
namespace VisualPinball.Unity.VisualScripting
21+
{
22+
public abstract class GleEventUnit<TArgs> : EventUnit<TArgs>
23+
{
24+
[DoNotSerialize]
25+
public readonly List<string> Errors = new();
26+
}
27+
}

Runtime/Events/Nodes/GleEventUnit.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Events/Nodes/SwitchEventUnit.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@
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-
using System;
18-
using System.Collections.Generic;
1917
using Unity.VisualScripting;
20-
using UnityEngine;
2118

2219
namespace VisualPinball.Unity.VisualScripting
2320
{
2421
[UnitTitle("On Switch Changed")]
2522
[UnitCategory("Events\\Visual Pinball")]
26-
public class SwitchEventUnit : EventUnit<SwitchEventArgs>
23+
public class SwitchEventUnit : GleEventUnit<SwitchEventArgs>
2724
{
2825
[DoNotSerialize]
2926
[PortLabel("Switch ID")]
@@ -33,11 +30,6 @@ public class SwitchEventUnit : EventUnit<SwitchEventArgs>
3330
[PortLabel("Is Enabled")]
3431
public ValueOutput enabled { get; private set; }
3532

36-
public VisualScriptingGamelogicEngine gle { get; private set; }
37-
38-
[DoNotSerialize]
39-
public readonly List<string> Errors = new();
40-
4133
protected override bool register => true;
4234

4335
// Adding an EventHook with the name of the event to the list of visual scripting events.
@@ -54,12 +46,6 @@ protected override void Definition()
5446
enabled = ValueOutput<bool>(nameof(enabled));
5547
}
5648

57-
public override void Instantiate(GraphReference instance)
58-
{
59-
base.Instantiate(instance);
60-
Debug.Log("Switch event instantiated.");
61-
}
62-
6349
protected override void AssignArguments(Flow flow, SwitchEventArgs args)
6450
{
6551
flow.SetValue(enabled, args.IsEnabled);

0 commit comments

Comments
 (0)