Skip to content

Commit 14e27dd

Browse files
jsm174freezy
authored andcommitted
misc: cleanup default value keys
1 parent 8adbca8 commit 14e27dd

17 files changed

+185
-130
lines changed

Editor/Descriptors/GetSwitchUnitDescriptor.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
// ReSharper disable UnusedType.Global
1818

19+
using System.Text.RegularExpressions;
1920
using Unity.VisualScripting;
2021
using VisualPinball.Unity.Editor;
2122
using IconSize = VisualPinball.Unity.Editor.IconSize;
@@ -40,13 +41,18 @@ protected override void DefinedPort(IUnitPort port, UnitPortDescription desc)
4041
{
4142
base.DefinedPort(port, desc);
4243

43-
switch (port.key) {
44-
case nameof(GetSwitchUnit.Ids):
45-
desc.summary = "The IDs of the switches for which to get the current status.";
46-
break;
47-
case nameof(GetSwitchUnit.IsEnabled):
48-
desc.summary = "Whether the switch is enabled.";
49-
break;
44+
if (port.key == nameof(GetSwitchUnit.IsEnabled)) {
45+
desc.summary = "Whether the switch is enabled.";
46+
}
47+
else {
48+
var match = new Regex("^(item)([0-9]+)$").Match(port.key);
49+
50+
if (match.Success) {
51+
var id = int.Parse(match.Groups[2].Value) + 1;
52+
53+
desc.label = $"Switch ID {id}";
54+
desc.summary = $"Switch ID {id} to check if enabled.";
55+
}
5056
}
5157
}
5258
}

Editor/Descriptors/PulseCoilUnitDescriptor.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
// ReSharper disable UnusedType.Global
1818

19+
using System.Text.RegularExpressions;
1920
using Unity.VisualScripting;
2021
using VisualPinball.Unity.Editor;
2122

@@ -43,13 +44,18 @@ protected override void DefinedPort(IUnitPort port, UnitPortDescription desc)
4344
{
4445
base.DefinedPort(port, desc);
4546

46-
switch (port.key) {
47-
case nameof(PulseCoilUnit.Ids):
48-
desc.summary = "The IDs of the coils to be pulsed.";
49-
break;
50-
case nameof(PulseCoilUnit.PulseDuration):
51-
desc.summary = "The time in milliseconds until the coils are disabled again.";
52-
break;
47+
if (port.key == nameof(PulseCoilUnit.PulseDuration)) {
48+
desc.summary = "The time in milliseconds until the coils are disabled again.";
49+
}
50+
else {
51+
var match = new Regex("^(item)([0-9]+)$").Match(port.key);
52+
53+
if (match.Success) {
54+
var id = int.Parse(match.Groups[2].Value) + 1;
55+
56+
desc.label = $"Coil ID {id}";
57+
desc.summary = $"Coil ID {id} of the coil to be pulsed.";
58+
}
5359
}
5460
}
5561
}

Editor/Descriptors/SetCoilUnitDescriptor.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
// ReSharper disable UnusedType.Global
1818

19+
using System.Text.RegularExpressions;
1920
using Unity.VisualScripting;
2021
using VisualPinball.Unity.Editor;
2122

@@ -43,13 +44,18 @@ protected override void DefinedPort(IUnitPort port, UnitPortDescription desc)
4344
{
4445
base.DefinedPort(port, desc);
4546

46-
switch (port.key) {
47-
case nameof(SetCoilUnit.Ids):
48-
desc.summary = "The IDs of the coils to be set.";
49-
break;
50-
case nameof(SetCoilUnit.IsEnabled):
51-
desc.summary = "The value to assign to the coils.";
52-
break;
47+
if (port.key == nameof(SetCoilUnit.IsEnabled)) {
48+
desc.summary = "The value to assign to the coils.";
49+
}
50+
else {
51+
var match = new Regex("^(item)([0-9]+)$").Match(port.key);
52+
53+
if (match.Success) {
54+
var id = int.Parse(match.Groups[2].Value) + 1;
55+
56+
desc.label = $"Coil ID {id}";
57+
desc.summary = $"Coil ID {id} of the coil to be set.";
58+
}
5359
}
5460
}
5561
}

Editor/Descriptors/SwitchEnabledEventUnitDescriptor.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
// ReSharper disable UnusedType.Global
1818

19+
using System.Text.RegularExpressions;
1920
using Unity.VisualScripting;
2021

2122
namespace VisualPinball.Unity.VisualScripting.Editor
@@ -38,10 +39,13 @@ protected override void DefinedPort(IUnitPort port, UnitPortDescription desc)
3839
{
3940
base.DefinedPort(port, desc);
4041

41-
switch (port.key) {
42-
case nameof(SwitchEnabledEventUnit.Ids):
43-
desc.summary = "The IDs of the switches for which to look for enabled status.";
44-
break;
42+
var match = new Regex("^(item)([0-9]+)$").Match(port.key);
43+
44+
if (match.Success) {
45+
var id = int.Parse(match.Groups[2].Value) + 1;
46+
47+
desc.label = $"Switch ID {id}";
48+
desc.summary = $"Switch ID {id} to look for enabled status.";
4549
}
4650
}
4751
}

Editor/Descriptors/SwitchLampUnitDescriptor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ protected override void DefinedPort(IUnitPort port, UnitPortDescription desc)
4949
var match = new Regex("^(item)([0-9]+)$").Match(port.key);
5050

5151
if (match.Success) {
52-
var id = int.Parse(match.Groups[2].Value);
52+
var id = int.Parse(match.Groups[2].Value) + 1;
5353

5454
desc.label = $"Lamp ID {id}";
55-
desc.summary = "Lamp ID to enable if specified Value matches source Value, or disable if specified Value does not match source Value";
55+
desc.summary = $"Lamp ID {id} to enable if specified Value matches source Value, or disable if specified Value does not match source Value";
5656
}
5757
}
5858
}

Editor/Widgets/GetSwitchUnitWidget.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ public GetSwitchUnitWidget(FlowCanvas canvas, GetSwitchUnit unit) : base(canvas,
3535

3636
public override Inspector GetPortInspector(IUnitPort port, Metadata meta)
3737
{
38-
if (_switchIdInspectorConstructorList.Count() < unit.idCount) {
39-
for (var index = 0; index < unit.idCount - _switchIdInspectorConstructorList.Count(); index++) {
38+
if (_switchIdInspectorConstructorList.Count() < unit.itemCount) {
39+
for (var index = 0; index < unit.itemCount - _switchIdInspectorConstructorList.Count(); index++) {
4040
_switchIdInspectorConstructorList.Add(meta => new VariableNameInspector(meta, GetNameSuggestions));
4141
}
4242
}
4343

44-
for (var index = 0; index < unit.idCount; index++) {
45-
if (unit.Ids[index] == port) {
44+
for (var index = 0; index < unit.itemCount; index++) {
45+
if (unit.Items[index] == port) {
4646
VariableNameInspector switchIdInspector = new VariableNameInspector(meta, GetNameSuggestions);
4747
InspectorProvider.instance.Renew(ref switchIdInspector, meta, _switchIdInspectorConstructorList[index]);
4848

Editor/Widgets/PulseCoilUnitWidget.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ public PulseCoilUnitWidget(FlowCanvas canvas, PulseCoilUnit unit) : base(canvas,
3535

3636
public override Inspector GetPortInspector(IUnitPort port, Metadata meta)
3737
{
38-
if (_coilIdInspectorConstructorList.Count() < unit.idCount) {
39-
for (var index = 0; index < unit.idCount - _coilIdInspectorConstructorList.Count(); index++) {
38+
if (_coilIdInspectorConstructorList.Count() < unit.itemCount) {
39+
for (var index = 0; index < unit.itemCount - _coilIdInspectorConstructorList.Count(); index++) {
4040
_coilIdInspectorConstructorList.Add(meta => new VariableNameInspector(meta, GetNameSuggestions));
4141
}
4242
}
4343

44-
for (var index = 0; index < unit.idCount; index++) {
45-
if (unit.Ids[index] == port) {
44+
for (var index = 0; index < unit.itemCount; index++) {
45+
if (unit.Items[index] == port) {
4646
VariableNameInspector coilIdInspector = new VariableNameInspector(meta, GetNameSuggestions);
4747
InspectorProvider.instance.Renew(ref coilIdInspector, meta, _coilIdInspectorConstructorList[index]);
4848

Editor/Widgets/SetCoilUnitWidget.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ public SetCoilUnitWidget(FlowCanvas canvas, SetCoilUnit unit) : base(canvas, uni
3535

3636
public override Inspector GetPortInspector(IUnitPort port, Metadata meta)
3737
{
38-
if (_coilIdInspectorConstructorList.Count() < unit.idCount) {
39-
for (var index = 0; index < unit.idCount - _coilIdInspectorConstructorList.Count(); index++) {
38+
if (_coilIdInspectorConstructorList.Count() < unit.itemCount) {
39+
for (var index = 0; index < unit.itemCount - _coilIdInspectorConstructorList.Count(); index++) {
4040
_coilIdInspectorConstructorList.Add(meta => new VariableNameInspector(meta, GetNameSuggestions));
4141
}
4242
}
4343

44-
for (var index = 0; index < unit.idCount; index++) {
45-
if (unit.Ids[index] == port) {
44+
for (var index = 0; index < unit.itemCount; index++) {
45+
if (unit.Items[index] == port) {
4646
VariableNameInspector coilIdInspector = new VariableNameInspector(meta, GetNameSuggestions);
4747
InspectorProvider.instance.Renew(ref coilIdInspector, meta, _coilIdInspectorConstructorList[index]);
4848

Editor/Widgets/SwitchEnabledEventUnitWidget.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ public SwitchEnabledEventUnitWidget(FlowCanvas canvas, SwitchEnabledEventUnit un
3535

3636
public override Inspector GetPortInspector(IUnitPort port, Metadata meta)
3737
{
38-
if (_switchIdInspectorConstructorList.Count() < unit.idCount) {
39-
for (var index = 0; index < unit.idCount - _switchIdInspectorConstructorList.Count(); index++) {
38+
if (_switchIdInspectorConstructorList.Count() < unit.itemCount) {
39+
for (var index = 0; index < unit.itemCount - _switchIdInspectorConstructorList.Count(); index++) {
4040
_switchIdInspectorConstructorList.Add(meta => new VariableNameInspector(meta, GetNameSuggestions));
4141
}
4242
}
4343

44-
for (var index = 0; index < unit.idCount; index++) {
45-
if (unit.Ids[index] == port) {
44+
for (var index = 0; index < unit.itemCount; index++) {
45+
if (unit.Items[index] == port) {
4646
VariableNameInspector switchIdInspector = new VariableNameInspector(meta, GetNameSuggestions);
4747
InspectorProvider.instance.Renew(ref switchIdInspector, meta, _switchIdInspectorConstructorList[index]);
4848

Editor/Widgets/SwitchLampUnitWidget.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ public SwitchLampUnitWidget(FlowCanvas canvas, SwitchLampUnit unit) : base(canva
3535

3636
public override Inspector GetPortInspector(IUnitPort port, Metadata meta)
3737
{
38-
if (_lampIdInspectorConstructorList.Count() < unit.idCount) {
39-
for (var index = 0; index < unit.idCount - _lampIdInspectorConstructorList.Count(); index++) {
38+
if (_lampIdInspectorConstructorList.Count() < unit.itemCount) {
39+
for (var index = 0; index < unit.itemCount - _lampIdInspectorConstructorList.Count(); index++) {
4040
_lampIdInspectorConstructorList.Add(meta => new LampIdValueInspector(meta, GetNameSuggestions));
4141
}
4242
}
4343

44-
for (var index = 0; index < unit.idCount; index++) {
44+
for (var index = 0; index < unit.itemCount; index++) {
4545
if (unit.Items[index] == port) {
4646
LampIdValueInspector lampIdInspector = new LampIdValueInspector(meta, GetNameSuggestions);
4747
InspectorProvider.instance.Renew(ref lampIdInspector, meta, _lampIdInspectorConstructorList[index]);

0 commit comments

Comments
 (0)