|
14 | 14 | // You should have received a copy of the GNU General Public License |
15 | 15 | // along with this program. If not, see <https://www.gnu.org/licenses/>. |
16 | 16 |
|
| 17 | +// ReSharper disable UnusedType.Global |
| 18 | + |
17 | 19 | using System; |
18 | 20 | using System.Collections.Generic; |
| 21 | +using System.Linq; |
19 | 22 | using Unity.VisualScripting; |
20 | 23 | using VisualPinball.Unity; |
21 | 24 |
|
22 | 25 | namespace VisualPinball.Unity.VisualScripting.Editor |
23 | 26 | { |
24 | 27 | [Widget(typeof(GetLampValueUnit))] |
25 | | - public sealed class GetLampValueUnitWidget : UnitWidget<GetLampValueUnit> |
| 28 | + public sealed class GetLampValueUnitWidget : GleUnitWidget<GetLampValueUnit> |
26 | 29 | { |
27 | 30 | public GetLampValueUnitWidget(FlowCanvas canvas, GetLampValueUnit unit) : base(canvas, unit) |
28 | 31 | { |
29 | | - lampIdInspectorConstructor = (metadata) => new VariableNameInspector(metadata, GetNameSuggestions); |
| 32 | + _lampIdInspectorConstructor = meta => new VariableNameInspector(meta, GetNameSuggestions); |
30 | 33 | } |
31 | 34 |
|
32 | 35 | protected override NodeColorMix baseColor => NodeColorMix.TealReadable; |
33 | 36 |
|
34 | | - private VariableNameInspector lampIdInspector; |
35 | | - private Func<Metadata, VariableNameInspector> lampIdInspectorConstructor; |
| 37 | + private VariableNameInspector _lampIdInspector; |
| 38 | + private readonly Func<Metadata, VariableNameInspector> _lampIdInspectorConstructor; |
36 | 39 |
|
37 | | - public override Inspector GetPortInspector(IUnitPort port, Metadata metadata) |
| 40 | + public override Inspector GetPortInspector(IUnitPort port, Metadata meta) |
38 | 41 | { |
39 | | - if (port == unit.id) { |
40 | | - InspectorProvider.instance.Renew(ref lampIdInspector, metadata, lampIdInspectorConstructor); |
| 42 | + if (port == unit.Id) { |
| 43 | + InspectorProvider.instance.Renew(ref _lampIdInspector, meta, _lampIdInspectorConstructor); |
41 | 44 |
|
42 | | - return lampIdInspector; |
| 45 | + return _lampIdInspector; |
43 | 46 | } |
44 | 47 |
|
45 | | - return base.GetPortInspector(port, metadata); |
| 48 | + return base.GetPortInspector(port, meta); |
46 | 49 | } |
47 | 50 |
|
48 | 51 | private IEnumerable<string> GetNameSuggestions() |
49 | 52 | { |
50 | | - var list = new List<string>(); |
51 | | - |
52 | | - var tableComponent = TableSelector.Instance.SelectedTable; |
53 | | - |
54 | | - if (tableComponent != null) { |
55 | | - var gle = tableComponent.gameObject.GetComponent<IGamelogicEngine>(); |
56 | | - |
57 | | - if (gle != null) { |
58 | | - foreach (var lamp in gle.AvailableLamps) { |
59 | | - list.Add(lamp.Id); |
60 | | - } |
61 | | - } |
| 53 | + if (!GameObjectAvailable) { |
| 54 | + return new List<string>(); |
62 | 55 | } |
63 | | - |
64 | | - return list; |
| 56 | + var gle = Gle; |
| 57 | + return gle == null ? new List<string>() : gle.AvailableLamps.Select(lamp => lamp.Id).ToList(); |
65 | 58 | } |
66 | 59 | } |
67 | 60 | } |
0 commit comments