Skip to content

Commit c52fa4d

Browse files
committed
Document and update light sequencer
1 parent 2d40ed4 commit c52fa4d

File tree

8 files changed

+163
-47
lines changed

8 files changed

+163
-47
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
// ReSharper disable UnusedType.Global
18+
19+
using Unity.VisualScripting;
20+
using VisualPinball.Unity.Editor;
21+
using IconSize = VisualPinball.Unity.Editor.IconSize;
22+
23+
namespace VisualPinball.Unity.VisualScripting.Editor
24+
{
25+
[Descriptor(typeof(SetLightSequenceUnit))]
26+
public class SetLightSequenceUnitDescriptor : UnitDescriptor<SetLightSequenceUnit>
27+
{
28+
public SetLightSequenceUnitDescriptor(SetLightSequenceUnit target) : base(target)
29+
{
30+
}
31+
32+
protected override string DefinedSummary()
33+
{
34+
return "This node sets the intensity of the lights at the next position within a light group. On each execution, the position increases by the number of steps. The number of lights set is the step number.\n\nExample: Four lights, A B C D, step size = 2. First run, lights A and B are set. Second run, lights C and D are set.";
35+
}
36+
37+
protected override EditorTexture DefinedIcon() => EditorTexture.Single(Unity.Editor.Icons.LampSequence);
38+
39+
protected override void DefinedPort(IUnitPort port, UnitPortDescription desc)
40+
{
41+
base.DefinedPort(port, desc);
42+
43+
switch (port.key) {
44+
case nameof(SetLightSequenceUnit.LightGroup):
45+
desc.summary = "The light group to cycle through.";
46+
break;
47+
48+
case nameof(SetLightSequenceUnit.Value):
49+
desc.summary = "The intensity to apply to the current step (0-1).";
50+
break;
51+
52+
case nameof(SetLightSequenceUnit.ColorChannel):
53+
desc.summary = "Which color channel to use. For non-RGB lights, use alpha.";
54+
break;
55+
56+
case nameof(SetLightSequenceUnit.Step):
57+
desc.summary = "How position is increased and to how many lights the intensity is applied to.";
58+
break;
59+
}
60+
}
61+
}
62+
}

Editor/Descriptors/SetLightSequenceUnitDescriptor.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.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
// ReSharper disable UnusedType.Global
18+
19+
using System;
20+
using Unity.VisualScripting;
21+
22+
namespace VisualPinball.Unity.VisualScripting.Editor
23+
{
24+
[Widget(typeof(SetLightSequenceUnit))]
25+
public sealed class SetLightSequenceUnitWidget : UnitWidget<SetLightSequenceUnit>
26+
{
27+
private ObjectPickerInspector<LightGroupComponent> _objectInspector;
28+
private readonly Func<Metadata, ObjectPickerInspector<LightGroupComponent>> _setObjectInspectorConstructor;
29+
30+
public SetLightSequenceUnitWidget(FlowCanvas canvas, SetLightSequenceUnit unit) : base(canvas, unit)
31+
{
32+
var tc = reference.gameObject.GetComponentInParent<TableComponent>();
33+
_setObjectInspectorConstructor = meta => new ObjectPickerInspector<LightGroupComponent>(meta, "Light Groups", tc);
34+
}
35+
36+
public override Inspector GetPortInspector(IUnitPort port, Metadata meta)
37+
{
38+
if (port == unit.LightGroup) {
39+
InspectorProvider.instance.Renew(ref _objectInspector, meta, _setObjectInspectorConstructor);
40+
return _objectInspector;
41+
}
42+
return base.GetPortInspector(port, meta);
43+
}
44+
}
45+
}

Editor/Widgets/SetLightSequenceUnitWidget.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/Nodes/Lamps/GetLampUnit.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ public class GetLampUnit : GleUnit
3636
[PortLabel("Is Enabled")]
3737
public ValueOutput IsEnabled { get; private set; }
3838

39-
private Player _player;
40-
4139
protected override void Definition()
4240
{
4341
Id = ValueInput(nameof(Id), string.Empty);

Runtime/Nodes/Lamps/SetLampUnit.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ namespace VisualPinball.Unity.VisualScripting
2323
[UnitTitle("Set Lamp (ID, Value)")]
2424
[UnitSurtitle("Gamelogic Engine")]
2525
[UnitCategory("Visual Pinball")]
26-
[UnitOrder(0)]
2726
public class SetLampUnit : GleUnit
2827
{
2928
[DoNotSerialize]

Runtime/Nodes/Lamps/SetLightSequenceUnit.cs

Lines changed: 33 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,91 +14,82 @@
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.Collections.Generic;
1817
using Unity.VisualScripting;
1918
using UnityEngine;
2019
using VisualPinball.Engine.Math;
2120

2221
namespace VisualPinball.Unity.VisualScripting
2322
{
2423
[UnitTitle("Set Light Sequence")]
24+
[UnitSurtitle("Scene")]
2525
[UnitCategory("Visual Pinball")]
26-
public class SetLightSequenceUnit : Unit
26+
public class SetLightSequenceUnit : GleUnit
2727
{
2828
[DoNotSerialize]
2929
[PortLabelHidden]
30-
public ControlInput enter { get; private set; }
30+
public ControlInput InputTrigger;
3131

3232
[DoNotSerialize]
3333
[PortLabelHidden]
34-
public ValueInput gameObjects;
34+
public ControlOutput OutputTrigger;
3535

3636
[DoNotSerialize]
37-
[PortLabelHidden]
38-
public ValueInput value;
37+
[PortLabel("Light Group")]
38+
public ValueInput LightGroup;
3939

4040
[DoNotSerialize]
41-
[PortLabelHidden]
42-
public ValueInput colorChannel;
41+
[PortLabel("Intensity")]
42+
public ValueInput Value;
4343

4444
[DoNotSerialize]
45-
public ValueInput step;
45+
[PortLabel("Color Channel")]
46+
public ValueInput ColorChannel;
4647

4748
[DoNotSerialize]
48-
[PortLabelHidden]
49-
public ControlOutput exit { get; private set; }
49+
[PortLabel("Step")]
50+
public ValueInput Step;
5051

51-
private Player _player;
52-
private int _currentIndex = 0;
52+
private int _currentIndex;
5353

5454
protected override void Definition()
5555
{
56-
enter = ControlInput(nameof(enter), Process);
56+
InputTrigger = ControlInput(nameof(InputTrigger), Process);
57+
OutputTrigger = ControlOutput(nameof(OutputTrigger));
5758

58-
gameObjects = ValueInput<List<GameObject>>(nameof(gameObjects));
59+
LightGroup = ValueInput<LightGroupComponent>(nameof(LightGroup));
5960

60-
value = ValueInput<float>(nameof(value), 0);
61-
colorChannel = ValueInput(nameof(colorChannel), ColorChannel.Alpha);
62-
step = ValueInput<int>(nameof(step), 1);
61+
Value = ValueInput<float>(nameof(Value), 0);
62+
ColorChannel = ValueInput(nameof(ColorChannel), Engine.Math.ColorChannel.Alpha);
63+
Step = ValueInput<int>(nameof(Step), 1);
6364

64-
exit = ControlOutput(nameof(exit));
65+
Requirement(Lights, InputTrigger);
66+
Requirement(Value, InputTrigger);
67+
Succession(InputTrigger, OutputTrigger);
6568
}
6669

6770
private ControlOutput Process(Flow flow)
6871
{
69-
if (_player == null) {
70-
_player = Object.FindObjectOfType<Player>();
72+
if (!AssertPlayer(flow)) {
73+
Debug.LogError("Cannot find player.");
74+
return OutputTrigger;
7175
}
7276

73-
var valueRaw = flow.GetValue<float>(value);
74-
var colorChannelRaw = flow.GetValue<ColorChannel>(colorChannel);
75-
var stepRaw = flow.GetValue<int>(step);
76-
77-
var lights = new List<ILampDeviceComponent>();
78-
79-
foreach (var go in flow.GetValue<List<GameObject>>(gameObjects)) {
80-
if (go != null) {
81-
foreach (var lamp in go.GetComponentsInChildren<ILampDeviceComponent>()) {
82-
if (lamp is LightGroupComponent lightGroup) {
83-
lights.AddRange(lightGroup.Lights);
84-
} else {
85-
lights.Add(lamp);
86-
}
87-
}
88-
}
89-
}
77+
var valueRaw = flow.GetValue<float>(Value);
78+
var colorChannelRaw = flow.GetValue<ColorChannel>(ColorChannel);
79+
var stepRaw = flow.GetValue<int>(Step);
80+
var lamps = flow.GetValue<LightGroupComponent>(LightGroup).Lights;
9081

91-
for (var index = 0; index < lights.Count; index++) {
92-
_player.Lamp(lights[index]).OnLamp(
82+
for (var index = 0; index < lamps.Count; index++) {
83+
Player.Lamp(lamps[index]).OnLamp(
9384
index >= _currentIndex * stepRaw && index < (_currentIndex + 1) * stepRaw ? valueRaw : 0,
9485
colorChannelRaw);
9586
}
9687

97-
if (++_currentIndex >= lights.Count / stepRaw) {
88+
if (++_currentIndex >= lamps.Count / stepRaw) {
9889
_currentIndex = 0;
9990
}
10091

101-
return exit;
92+
return OutputTrigger;
10293
}
10394
}
10495
}

Runtime/Nodes/Lamps/SetLightUnit.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ namespace VisualPinball.Unity.VisualScripting
2424
[UnitShortTitle("Set Lamp")]
2525
[UnitSurtitle("Scene")]
2626
[UnitCategory("Visual Pinball")]
27-
[UnitOrder(1)]
2827
public class SetLightUnit : GleUnit
2928
{
3029
[DoNotSerialize]
@@ -40,7 +39,7 @@ public class SetLightUnit : GleUnit
4039
public ValueInput LampComponent;
4140

4241
[DoNotSerialize]
43-
[PortLabel("Value")]
42+
[PortLabel("Intensity")]
4443
public ValueInput Value;
4544

4645
[DoNotSerialize]

0 commit comments

Comments
 (0)