Skip to content

Commit 5bb7d81

Browse files
committed
nodes: rework LampGroup* to SetLight*. Rework the use of apis
1 parent 8f614aa commit 5bb7d81

File tree

11 files changed

+171
-210
lines changed

11 files changed

+171
-210
lines changed

Editor/Descriptors/LampEventUnitDescriptor.cs

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

Editor/Widgets/GetLampValueUnitWidget.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ public GetLampValueUnitWidget(FlowCanvas canvas, GetLampValueUnit unit) : base(c
2020

2121
public override Inspector GetPortInspector(IUnitPort port, Metadata metadata)
2222
{
23-
if (port == unit.id)
24-
{
25-
// This feels so hacky. The real holy grail here would be to support attribute decorators like Unity does.
23+
if (port == unit.id) {
2624
InspectorProvider.instance.Renew(ref lampIdInspector, metadata, lampIdInspectorConstructor);
2725

2826
return lampIdInspector;
@@ -33,18 +31,15 @@ public override Inspector GetPortInspector(IUnitPort port, Metadata metadata)
3331

3432
private IEnumerable<string> GetNameSuggestions()
3533
{
36-
List<string> list = new List<string>();
34+
var list = new List<string>();
3735

3836
var tableComponent = TableSelector.Instance.SelectedTable;
3937

40-
if (tableComponent != null)
41-
{
38+
if (tableComponent != null) {
4239
var gle = tableComponent.gameObject.GetComponent<IGamelogicEngine>();
4340

44-
if (gle != null)
45-
{
46-
foreach (var lamp in gle.AvailableLamps)
47-
{
41+
if (gle != null) {
42+
foreach (var lamp in gle.AvailableLamps) {
4843
list.Add(lamp.Id);
4944
}
5045
}

Editor/Widgets/LampEventUnitWidget.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ public LampEventUnitWidget(FlowCanvas canvas, LampEventUnit unit) : base(canvas,
2020

2121
public override Inspector GetPortInspector(IUnitPort port, Metadata metadata)
2222
{
23-
if (port == unit.id)
24-
{
25-
// This feels so hacky. The real holy grail here would be to support attribute decorators like Unity does.
23+
if (port == unit.id) {
2624
InspectorProvider.instance.Renew(ref lampIdInspector, metadata, lampIdInspectorConstructor);
2725

2826
return lampIdInspector;
@@ -33,18 +31,15 @@ public override Inspector GetPortInspector(IUnitPort port, Metadata metadata)
3331

3432
private IEnumerable<string> GetNameSuggestions()
3533
{
36-
List<string> list = new List<string>();
34+
var list = new List<string>();
3735

3836
var tableComponent = TableSelector.Instance.SelectedTable;
3937

40-
if (tableComponent != null)
41-
{
38+
if (tableComponent != null) {
4239
var gle = tableComponent.gameObject.GetComponent<IGamelogicEngine>();
4340

44-
if (gle != null)
45-
{
46-
foreach (var lamp in gle.AvailableLamps)
47-
{
41+
if (gle != null) {
42+
foreach (var lamp in gle.AvailableLamps) {
4843
list.Add(lamp.Id);
4944
}
5045
}

Runtime/Events/Nodes/LampEventUnit.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ public sealed class LampEventUnit : EventUnit<LampEventArgs>
1111
public ValueInput id { get; private set; }
1212

1313
[DoNotSerialize]
14+
[PortLabelHidden]
1415
public ValueOutput value { get; private set; }
1516

1617
[DoNotSerialize]
18+
[PortLabelHidden]
1719
public ValueOutput enabled { get; private set; }
1820

1921
protected override bool register => true;

Runtime/Lamps/Nodes/LampGroupSequenceUnit.cs

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

Runtime/Lamps/Nodes/LampGroupSequenceUnit.cs.meta

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

Runtime/Lamps/Nodes/LampGroupUnit.cs

Lines changed: 0 additions & 91 deletions
This file was deleted.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Unity.VisualScripting;
5+
using UnityEngine;
6+
using VisualPinball.Engine.Math;
7+
8+
namespace VisualPinball.Unity.VisualScripting
9+
{
10+
[UnitTitle("Set Light Sequence")]
11+
[UnitCategory("Visual Pinball")]
12+
public class SetLightSequenceUnit : Unit
13+
{
14+
[DoNotSerialize]
15+
[PortLabelHidden]
16+
public ControlInput enter { get; private set; }
17+
18+
[DoNotSerialize]
19+
[PortLabelHidden]
20+
public ValueInput gameObjects;
21+
22+
[DoNotSerialize]
23+
[PortLabelHidden]
24+
public ValueInput value;
25+
26+
[DoNotSerialize]
27+
[PortLabelHidden]
28+
public ValueInput colorChannel;
29+
30+
[DoNotSerialize]
31+
public ValueInput step;
32+
33+
[DoNotSerialize]
34+
[PortLabelHidden]
35+
public ControlOutput exit { get; private set; }
36+
37+
private Player _player;
38+
private int _currentIndex = 0;
39+
40+
protected override void Definition()
41+
{
42+
enter = ControlInput(nameof(enter), Process);
43+
44+
gameObjects = ValueInput<List<GameObject>>(nameof(gameObjects));
45+
46+
value = ValueInput<float>(nameof(value), 0);
47+
colorChannel = ValueInput(nameof(colorChannel), ColorChannel.Alpha);
48+
step = ValueInput<int>(nameof(step), 1);
49+
50+
exit = ControlOutput(nameof(exit));
51+
}
52+
53+
private ControlOutput Process(Flow flow)
54+
{
55+
if (_player == null) {
56+
_player = UnityEngine.Object.FindObjectOfType<Player>();
57+
}
58+
59+
var valueRaw = flow.GetValue<float>(value);
60+
var colorChannelRaw = flow.GetValue<ColorChannel>(colorChannel);
61+
var stepRaw = flow.GetValue<int>(step);
62+
63+
var lights = new List<ILampDeviceComponent>();
64+
65+
foreach (var go in flow.GetValue<List<GameObject>>(gameObjects)) {
66+
if (go != null) {
67+
foreach (var lamp in go.GetComponentsInChildren<ILampDeviceComponent>()) {
68+
if (lamp is LightGroupComponent) {
69+
lights.AddRange(((LightGroupComponent)lamp).Lights);
70+
}
71+
else {
72+
lights.Add(lamp);
73+
}
74+
}
75+
}
76+
}
77+
78+
for (var index = 0; index < lights.Count(); index++) {
79+
_player.Lamp(lights[index]).OnLamp(
80+
(index >= (_currentIndex * stepRaw) && index < ((_currentIndex + 1) * stepRaw)) ? valueRaw : 0,
81+
colorChannelRaw);
82+
}
83+
84+
if (++_currentIndex >= lights.Count() / stepRaw) {
85+
_currentIndex = 0;
86+
}
87+
88+
return exit;
89+
}
90+
}
91+
}

Runtime/Lamps/Nodes/LampGroupUnit.cs.meta renamed to Runtime/Lamps/Nodes/SetLightSequenceUnit.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)