Skip to content

Commit 68276b0

Browse files
committed
uvs: add SetLamp unit
1 parent bfcd1a4 commit 68276b0

File tree

9 files changed

+239
-2
lines changed

9 files changed

+239
-2
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 UnityEditor;
18+
using VisualPinball.Unity.VisualScripting;
19+
20+
namespace Editor.PropertyDrawers
21+
{
22+
[CustomPropertyDrawer(typeof(VisualScriptingLamp))]
23+
public class VisualScriptingLampPropertyDrawer : VisualScriptingDeviceItemPropertyDrawer
24+
{
25+
public override string NameName => nameof(VisualScriptingLamp.Name);
26+
public override string DescName => nameof(VisualScriptingLamp.Desc);
27+
}
28+
}

Editor/PropertyDrawers/VisualScriptingLampPropertyDrawer.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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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;
18+
using System.Collections.Generic;
19+
using System.Linq;
20+
using Unity.VisualScripting;
21+
22+
namespace VisualPinball.Unity.VisualScripting
23+
{
24+
[Widget(typeof(SetLampUnit))]
25+
public sealed class SetLampUnitWidget : GleUnitWidget<SetLampUnit>
26+
{
27+
private VariableNameInspector _lampIdInspector;
28+
private readonly Func<Metadata, VariableNameInspector> _setLampInspectorConstructor;
29+
30+
public SetLampUnitWidget(FlowCanvas canvas, SetLampUnit unit) : base(canvas, unit)
31+
{
32+
_setLampInspectorConstructor = meta => new VariableNameInspector(meta, GetNameSuggestions);
33+
}
34+
35+
public override Inspector GetPortInspector(IUnitPort port, Metadata meta)
36+
{
37+
if (port == unit.Id) {
38+
InspectorProvider.instance.Renew(ref _lampIdInspector, meta, _setLampInspectorConstructor);
39+
return _lampIdInspector;
40+
}
41+
42+
return base.GetPortInspector(port, meta);
43+
}
44+
45+
private IEnumerable<string> GetNameSuggestions()
46+
{
47+
if (!GameObjectAvailable) {
48+
return new List<string>();
49+
}
50+
var gle = Gle;
51+
return gle == null ? new List<string>() : gle.AvailableLamps.Select(lamp => lamp.Id).ToList();
52+
}
53+
}
54+
}

Editor/Widgets/SetLampUnitWidget.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: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 Unity.VisualScripting;
18+
using UnityEngine;
19+
20+
namespace VisualPinball.Unity.VisualScripting
21+
{
22+
[UnitTitle("Set Lamp")]
23+
[UnitCategory("Visual Pinball")]
24+
public class SetLampUnit : GleUnit
25+
{
26+
[DoNotSerialize]
27+
[PortLabelHidden]
28+
public ControlInput InputTrigger;
29+
30+
[DoNotSerialize]
31+
[PortLabelHidden]
32+
public ControlOutput OutputTrigger;
33+
34+
[DoNotSerialize]
35+
[PortLabel("Lamp ID")]
36+
public ValueInput Id { get; private set; }
37+
38+
[DoNotSerialize]
39+
[PortLabel("Value")]
40+
public ValueInput Value { get; private set; }
41+
42+
protected override void Definition()
43+
{
44+
InputTrigger = ControlInput(nameof(InputTrigger), Process);
45+
OutputTrigger = ControlOutput(nameof(OutputTrigger));
46+
47+
Id = ValueInput<string>(nameof(Id), string.Empty);
48+
Value = ValueInput<int>(nameof(Value), 0);
49+
50+
Requirement(Id, InputTrigger);
51+
Succession(InputTrigger, OutputTrigger);
52+
}
53+
private ControlOutput Process(Flow flow)
54+
{
55+
var gle = flow.stack.gameObject.GetComponentInParent<VisualScriptingGamelogicEngine>();
56+
57+
if (gle != null) {
58+
59+
var id = flow.GetValue<string>(Id);
60+
var value = flow.GetValue<int>(Value);
61+
62+
gle.SetLamp(id, value);
63+
64+
} else {
65+
Debug.LogError("Cannot find GLE.");
66+
}
67+
68+
return OutputTrigger;
69+
}
70+
71+
72+
}
73+
}

Runtime/Events/Nodes/SetLampUnit.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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ public class VisualScriptingGamelogicEngine : MonoBehaviour, IGamelogicEngine
3333
[Tooltip("The switches that are exposed in the Visual Scripting nodes.")]
3434
public VisualScriptingSwitch[] Switches;
3535
public VisualScriptingCoil[] Coils;
36-
public GamelogicEngineLamp[] Lamps;
36+
public VisualScriptingLamp[] Lamps;
3737
public GamelogicEngineWire[] Wires;
3838

3939
public GamelogicEngineSwitch[] AvailableSwitches => Switches.Select(sw => sw as GamelogicEngineSwitch).ToArray();
4040

41-
public GamelogicEngineLamp[] AvailableLamps => Lamps;
41+
public GamelogicEngineLamp[] AvailableLamps => Lamps.Select(lamp => lamp as GamelogicEngineLamp).ToArray();
4242

4343
public GamelogicEngineCoil[] AvailableCoils => Coils.Select(c => c as GamelogicEngineCoil).ToArray();
4444

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 InconsistentNaming
18+
19+
using System;
20+
using VisualPinball.Engine.Game.Engines;
21+
22+
namespace VisualPinball.Unity.VisualScripting
23+
{
24+
[Serializable]
25+
public class VisualScriptingLamp : GamelogicEngineLamp
26+
{
27+
public string Name;
28+
public string Desc;
29+
30+
public override string Id => Name;
31+
32+
public override string Description => Desc;
33+
34+
public VisualScriptingLamp() : base(string.Empty)
35+
{
36+
}
37+
}
38+
}

Runtime/Gamelogic/VisualScriptingLamp.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.

0 commit comments

Comments
 (0)