Skip to content

Commit deaa5b4

Browse files
committed
Add get player ID node.
1 parent 4ab2e21 commit deaa5b4

File tree

6 files changed

+171
-0
lines changed

6 files changed

+171
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Visual Pinball Engine
2+
// Copyright (C) 2022 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(GetPlayerIdUnit))]
26+
public class GetPlayerIdUnitDescriptor : UnitDescriptor<GetPlayerIdUnit>
27+
{
28+
public GetPlayerIdUnitDescriptor(GetPlayerIdUnit target) : base(target)
29+
{
30+
}
31+
32+
protected override string DefinedSummary()
33+
{
34+
return "This node returns either the first, the last, or the current player ID.";
35+
}
36+
37+
protected override EditorTexture DefinedIcon() => EditorTexture.Single(Unity.Editor.Icons.PlayerVariable);
38+
39+
protected override void DefinedPort(IUnitPort port, UnitPortDescription desc)
40+
{
41+
base.DefinedPort(port, desc);
42+
43+
switch (port.key) {
44+
case nameof(GetPlayerIdUnit.PlayerId):
45+
desc.summary = "The player ID as configured in the node header.";
46+
break;
47+
}
48+
}
49+
}
50+
}

Editor/Descriptors/GetPlayerIdUnitDescriptor.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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Visual Pinball Engine
2+
// Copyright (C) 2022 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+
21+
namespace VisualPinball.Unity.VisualScripting.Editor
22+
{
23+
[Widget(typeof(GetPlayerIdUnit))]
24+
public sealed class GetPlayerIdWidget : GleUnitWidget<GetPlayerIdUnit>
25+
{
26+
public GetPlayerIdWidget(FlowCanvas canvas, GetPlayerIdUnit unit) : base(canvas, unit)
27+
{
28+
}
29+
}
30+
}

Editor/Widgets/GetPlayerIdWidget.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: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Visual Pinball Engine
2+
// Copyright (C) 2022 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.Linq;
19+
using Unity.VisualScripting;
20+
21+
namespace VisualPinball.Unity.VisualScripting
22+
{
23+
[UnitTitle("Get Player ID")]
24+
[UnitSurtitle("Player State")]
25+
[UnitCategory("Visual Pinball/Variables")]
26+
public class GetPlayerIdUnit : GleUnit
27+
{
28+
[Serialize, Inspectable, UnitHeaderInspectable]
29+
public WhichPlayer Which { get; set; }
30+
31+
[DoNotSerialize, PortLabel("Player ID"), Inspectable]
32+
public ValueOutput PlayerId { get; private set; }
33+
34+
protected override void Definition()
35+
{
36+
PlayerId = ValueOutput(nameof(PlayerId), GetPlayerId);
37+
}
38+
39+
private int GetPlayerId(Flow flow)
40+
{
41+
if (!AssertVsGle(flow)) {
42+
throw new InvalidOperationException("Cannot retrieve GLE from unit.");
43+
}
44+
45+
return Which switch {
46+
WhichPlayer.First => VsGle.PlayerStates.Keys.Min(),
47+
WhichPlayer.Last => VsGle.PlayerStates.Keys.Max(),
48+
WhichPlayer.Current => VsGle.CurrentPlayerState.Id,
49+
_ => throw new ArgumentOutOfRangeException()
50+
};
51+
}
52+
}
53+
54+
public enum WhichPlayer
55+
{
56+
Current, First, Last
57+
}
58+
}

Runtime/Nodes/PlayerState/GetPlayerIdUnit.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)