Skip to content

Commit 868908e

Browse files
committed
api: Lamp values now always between 0 and 1.
1 parent a87ef59 commit 868908e

File tree

7 files changed

+77
-15
lines changed

7 files changed

+77
-15
lines changed

Editor/Descriptors/GetLampUnitDescriptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected override void DefinedPort(IUnitPort port, UnitPortDescription desc)
4545
desc.summary = "The ID of the lamp for which the intensity is returned.";
4646
break;
4747
case nameof(GetLampUnit.Value):
48-
desc.summary = "The intensity of the lamp.";
48+
desc.summary = "The intensity of the lamp (0-1).";
4949
break;
5050
case nameof(GetLampUnit.IsEnabled):
5151
desc.summary = "Whether the intensity is larger than 0.";

Editor/Descriptors/LampEventUnitDescriptor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected override void DefinedPort(IUnitPort port, UnitPortDescription desc)
4343
desc.summary = "The ID of the lamp that changed its intensity.";
4444
break;
4545
case nameof(LampEventUnit.Value):
46-
desc.summary = "The new intensity of the lamp (0-255).";
46+
desc.summary = "The new intensity of the lamp (0-1).";
4747
break;
4848
case nameof(LampEventUnit.IsEnabled):
4949
desc.summary = "Whether the intensity is larger than 0.";
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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(SetLampUnit))]
26+
public class SetLampUnitDescriptor : UnitDescriptor<SetLampUnit>
27+
{
28+
public SetLampUnitDescriptor(SetLampUnit target) : base(target)
29+
{
30+
}
31+
32+
protected override string DefinedSummary()
33+
{
34+
return "This node assigns a given value to a lamp defined by its mapped ID. This will also trigger the lamp changed event and update the internal status.";
35+
}
36+
37+
protected override EditorTexture DefinedIcon() => EditorTexture.Single(Unity.Editor.Icons.Light(IconSize.Large, IconColor.Orange));
38+
39+
protected override void DefinedPort(IUnitPort port, UnitPortDescription desc)
40+
{
41+
base.DefinedPort(port, desc);
42+
43+
switch (port.key) {
44+
case nameof(SetLampUnit.Id):
45+
desc.summary = "The ID of the lamp for which the intensity is returned.";
46+
break;
47+
case nameof(SetLampUnit.Value):
48+
desc.summary = "The intensity of the lamp (0-1).";
49+
break;
50+
}
51+
}
52+
}
53+
}

Editor/Descriptors/SetLampUnitDescriptor.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/Gamelogic/VisualScriptingGamelogicEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void SetCoil(string id, bool isEnabled)
7171
OnCoilChanged?.Invoke(this, new CoilEventArgs(id, isEnabled));
7272
}
7373

74-
public void SetLamp(string id, int value, bool isCoil = false, LampSource source = LampSource.Lamp)
74+
public void SetLamp(string id, float value, bool isCoil = false, LampSource source = LampSource.Lamp)
7575
{
7676
OnLampChanged?.Invoke(this, new LampEventArgs(id, value, isCoil, source));
7777
}

Runtime/Nodes/Lamps/LampEventUnit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected override void Definition()
4747

4848
Id = ValueInput(nameof(Id), string.Empty);
4949

50-
Value = ValueOutput<int>(nameof(Value));
50+
Value = ValueOutput<float>(nameof(Value));
5151
IsEnabled = ValueOutput<bool>(nameof(IsEnabled));
5252
}
5353

Runtime/Nodes/Lamps/SetLampUnit.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
namespace VisualPinball.Unity.VisualScripting
2121
{
22-
[UnitTitle("Set Lamp")]
22+
[UnitTitle("Set Lamp Value")]
2323
[UnitCategory("Visual Pinball")]
2424
public class SetLampUnit : GleUnit
2525
{
@@ -45,27 +45,25 @@ protected override void Definition()
4545
OutputTrigger = ControlOutput(nameof(OutputTrigger));
4646

4747
Id = ValueInput<string>(nameof(Id), string.Empty);
48-
Value = ValueInput<int>(nameof(Value), 0);
48+
Value = ValueInput<float>(nameof(Value), 0f);
4949

5050
Requirement(Id, InputTrigger);
5151
Succession(InputTrigger, OutputTrigger);
5252
}
5353

5454
private ControlOutput Process(Flow flow)
5555
{
56-
var gle = flow.stack.gameObject.GetComponentInParent<VisualScriptingGamelogicEngine>();
5756

58-
if (gle != null) {
59-
60-
var id = flow.GetValue<string>(Id);
61-
var value = flow.GetValue<int>(Value);
62-
63-
gle.SetLamp(id, value);
64-
65-
} else {
57+
if (!AssertGle(flow)) {
6658
Debug.LogError("Cannot find GLE.");
59+
return OutputTrigger;
6760
}
6861

62+
var id = flow.GetValue<string>(Id);
63+
var value = flow.GetValue<float>(Value);
64+
65+
Gle.SetLamp(id, value);
66+
6967
return OutputTrigger;
7068
}
7169
}

0 commit comments

Comments
 (0)