Skip to content

Commit 837019a

Browse files
committed
Retrieve lamp value from GLE.
1 parent af253fd commit 837019a

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

Runtime/Nodes/Coils/SetCoilUnit.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,19 @@ protected override void Definition()
5050
Requirement(Id, InputTrigger);
5151
Succession(InputTrigger, OutputTrigger);
5252
}
53+
5354
private ControlOutput Process(Flow flow)
5455
{
55-
var gle = flow.stack.gameObject.GetComponentInParent<VisualScriptingGamelogicEngine>();
56-
57-
if (gle != null) {
58-
59-
var id = flow.GetValue<string>(Id);
60-
var isEnabled = flow.GetValue<bool>(IsEnabled);
61-
62-
gle.SetCoil(id, isEnabled);
63-
64-
} else {
56+
if (!AssertGle(flow)) {
6557
Debug.LogError("Cannot find GLE.");
58+
return OutputTrigger;
6659
}
6760

61+
var id = flow.GetValue<string>(Id);
62+
var isEnabled = flow.GetValue<bool>(IsEnabled);
63+
64+
Gle.SetCoil(id, isEnabled);
65+
6866
return OutputTrigger;
6967
}
7068
}

Runtime/Nodes/GleUnit.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ public abstract class GleUnit : Unit, IGleUnit
2929
{
3030
[DoNotSerialize]
3131
public List<string> Errors { get; } = new();
32+
33+
[DoNotSerialize]
34+
protected IGamelogicEngine Gle;
35+
36+
protected bool AssertGle(Flow flow)
37+
{
38+
if (Gle != null) {
39+
return true;
40+
}
41+
Gle = flow.stack.gameObject.GetComponentInParent<IGamelogicEngine>();
42+
return Gle == null;
43+
}
3244
}
3345

3446
public interface IGleUnit

Runtime/Nodes/Lamps/GetLampValueUnit.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

1717
using Unity.VisualScripting;
18+
using UnityEngine;
1819

1920
namespace VisualPinball.Unity.VisualScripting
2021
{
@@ -46,22 +47,22 @@ protected override void Definition()
4647

4748
private float GetValue(Flow flow)
4849
{
49-
if (_player == null) {
50-
_player = UnityEngine.Object.FindObjectOfType<Player>();
50+
if (!AssertGle(flow)) {
51+
Debug.LogError("Cannot find GLE.");
52+
return 0;
5153
}
5254

53-
var key = flow.GetValue<string>(Id);
54-
return _player.LampStatuses.ContainsKey(key) ? _player.LampStatuses[key] : 0;
55+
return Gle.GetLamp(flow.GetValue<string>(Id));
5556
}
5657

5758
private bool GetEnabled(Flow flow)
5859
{
59-
if (_player == null) {
60-
_player = flow.stack.self.GetComponentInParent<Player>();
60+
if (!AssertGle(flow)) {
61+
Debug.LogError("Cannot find GLE.");
62+
return false;
6163
}
6264

63-
var key = flow.GetValue<string>(Id);
64-
return _player.LampStatuses.ContainsKey(key) && (_player.LampStatuses[key] > 0);
65+
return Gle.GetLamp(flow.GetValue<string>(Id)) > 0;
6566
}
6667
}
6768
}

0 commit comments

Comments
 (0)