Skip to content

Commit c074957

Browse files
committed
Add table state.
1 parent 02196b5 commit c074957

File tree

52 files changed

+587
-232
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+587
-232
lines changed

Editor/Descriptors/PlayerVariableChangedEventUnitDescriptor.cs renamed to Editor/Descriptors/VariableChangedEventUnitDescriptor.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,31 @@ protected override void DefinedPort(IUnitPort port, UnitPortDescription desc)
4545
}
4646
}
4747
}
48+
49+
50+
[Descriptor(typeof(TableVariableChangedEventUnit))]
51+
public class TableVariableChangedEventUnitDescriptor : UnitDescriptor<TableVariableChangedEventUnit>
52+
{
53+
public TableVariableChangedEventUnitDescriptor(TableVariableChangedEventUnit target) : base(target)
54+
{
55+
}
56+
57+
protected override string DefinedSummary()
58+
{
59+
return "This event is emitted when a given table variable changes.";
60+
}
61+
62+
protected override EditorTexture DefinedIcon() => EditorTexture.Single(Unity.Editor.Icons.TableVariableEvent);
63+
64+
protected override void DefinedPort(IUnitPort port, UnitPortDescription desc)
65+
{
66+
base.DefinedPort(port, desc);
67+
68+
switch (port.key) {
69+
case nameof(TableVariableChangedEventUnit.Value):
70+
desc.summary = "The new value of the table variable.";
71+
break;
72+
}
73+
}
74+
}
4875
}

Editor/Descriptors/PlayerVariableIncreaseUnitDescriptor.cs.meta renamed to Editor/Descriptors/VariableChangedEventUnitDescriptor.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Descriptors/PlayerVariableGetUnitDescriptor.cs renamed to Editor/Descriptors/VariableGetUnitDescriptor.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,30 @@ protected override void DefinedPort(IUnitPort port, UnitPortDescription desc)
4545
}
4646
}
4747
}
48+
49+
[Descriptor(typeof(TableVariableGetUnit))]
50+
public class TableVariableGetUnitDescriptor : UnitDescriptor<TableVariableGetUnit>
51+
{
52+
public TableVariableGetUnitDescriptor(TableVariableGetUnit target) : base(target)
53+
{
54+
}
55+
56+
protected override string DefinedSummary()
57+
{
58+
return "This node retrieves the value of a given table variable.";
59+
}
60+
61+
protected override EditorTexture DefinedIcon() => EditorTexture.Single(Unity.Editor.Icons.TableVariable);
62+
63+
protected override void DefinedPort(IUnitPort port, UnitPortDescription desc)
64+
{
65+
base.DefinedPort(port, desc);
66+
67+
switch (port.key) {
68+
case nameof(TableVariableGetUnit.Value):
69+
desc.summary = "The current value of the table variable.";
70+
break;
71+
}
72+
}
73+
}
4874
}

Editor/Descriptors/PlayerVariableChangedEventUnitDescriptor.cs.meta renamed to Editor/Descriptors/VariableGetUnitDescriptor.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Descriptors/PlayerVariableIncreaseUnitDescriptor.cs renamed to Editor/Descriptors/VariableIncreaseUnitDescriptor.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,30 @@ protected override void DefinedPort(IUnitPort port, UnitPortDescription desc)
4545
}
4646
}
4747
}
48+
49+
[Descriptor(typeof(TableVariableIncreaseUnit))]
50+
public class TableVariableIncreaseUnitDescriptor : UnitDescriptor<TableVariableIncreaseUnit>
51+
{
52+
public TableVariableIncreaseUnitDescriptor(TableVariableIncreaseUnit target) : base(target)
53+
{
54+
}
55+
56+
protected override string DefinedSummary()
57+
{
58+
return "This node increases the value of a given table variable.\n\nTo decrease, use a negative value.";
59+
}
60+
61+
protected override EditorTexture DefinedIcon() => EditorTexture.Single(Unity.Editor.Icons.TableVariable);
62+
63+
protected override void DefinedPort(IUnitPort port, UnitPortDescription desc)
64+
{
65+
base.DefinedPort(port, desc);
66+
67+
switch (port.key) {
68+
case nameof(TableVariableIncreaseUnit.Value):
69+
desc.summary = "The value to add to the existing value.";
70+
break;
71+
}
72+
}
73+
}
4874
}

Editor/Descriptors/PlayerVariableSetUnitDescriptor.cs.meta renamed to Editor/Descriptors/VariableIncreaseUnitDescriptor.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Descriptors/PlayerVariableSetUnitDescriptor.cs renamed to Editor/Descriptors/VariableSetUnitDescriptor.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,30 @@ protected override void DefinedPort(IUnitPort port, UnitPortDescription desc)
4545
}
4646
}
4747
}
48+
49+
[Descriptor(typeof(TableVariableSetUnit))]
50+
public class TableVariableSetUnitDescriptor : UnitDescriptor<TableVariableSetUnit>
51+
{
52+
public TableVariableSetUnitDescriptor(TableVariableSetUnit target) : base(target)
53+
{
54+
}
55+
56+
protected override string DefinedSummary()
57+
{
58+
return "This node sets the value of a given table variable.";
59+
}
60+
61+
protected override EditorTexture DefinedIcon() => EditorTexture.Single(Unity.Editor.Icons.TableVariable);
62+
63+
protected override void DefinedPort(IUnitPort port, UnitPortDescription desc)
64+
{
65+
base.DefinedPort(port, desc);
66+
67+
switch (port.key) {
68+
case nameof(TableVariableSetUnit.Value):
69+
desc.summary = "The new value of the table variable.";
70+
break;
71+
}
72+
}
73+
}
4874
}

Editor/Descriptors/PlayerVariableGetUnitDescriptor.cs.meta renamed to Editor/Descriptors/VariableSetUnitDescriptor.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Inspectors/PlayerVariableDefinitionInspector.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

Editor/Inspectors/PlayerVariableDefinitionInspector.cs renamed to Editor/Inspectors/VariableDefinitionInspector.cs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,56 @@
2222

2323
namespace VisualPinball.Unity.VisualScripting.Editor
2424
{
25-
2625
[Inspector(typeof(PlayerVariableDefinition))]
27-
public class PlayerVariableDefinitionInspector : GleInspector
26+
public class PlayerVariableDefinitionInspector : VariableDefinitionInspector
27+
{
28+
public PlayerVariableDefinitionInspector(Metadata metadata) : base(metadata)
29+
{
30+
}
31+
32+
protected override List<VariableDefinition> VariableDefinition(VisualScriptingGamelogicEngine gle)
33+
{
34+
return gle.PlayerVariableDefinitions.Select(s => s as VariableDefinition).ToList();
35+
}
36+
}
37+
38+
[Inspector(typeof(TableVariableDefinition))]
39+
public class TableVariableDefinitionInspector : VariableDefinitionInspector
2840
{
29-
public PlayerVariableDefinitionInspector(Metadata metadata) : base(metadata) { }
41+
public TableVariableDefinitionInspector(Metadata metadata) : base(metadata)
42+
{
43+
}
44+
45+
protected override List<VariableDefinition> VariableDefinition(VisualScriptingGamelogicEngine gle)
46+
{
47+
return gle.TableVariableDefinitions.Select(s => s as VariableDefinition).ToList();
48+
}
49+
}
50+
51+
public abstract class VariableDefinitionInspector : GleInspector
52+
{
53+
protected abstract List<VariableDefinition> VariableDefinition(VisualScriptingGamelogicEngine gle);
54+
55+
public VariableDefinitionInspector(Metadata metadata) : base(metadata) { }
3056

3157
protected override void OnGUI(Rect position, GUIContent label)
3258
{
3359
// can't get this from the flow
3460
var gle = Gle;
3561
if (gle != null) {
36-
var varDefinitions = gle.PlayerVariableDefinitions;
62+
var varDefinitions = VariableDefinition(gle);
3763
if (varDefinitions == null || varDefinitions.Count(p => !string.IsNullOrEmpty(p.Name)) == 0) {
3864
ErrorMessage = "No variables defined.";
3965

4066
} else {
4167
var varNames = new List<string> { "None" }
4268
.Concat(varDefinitions.Select(d => d.Name))
4369
.ToArray();
44-
var currentVarDef = metadata.value as PlayerVariableDefinition;
70+
var currentVarDef = metadata.value as VariableDefinition;
4571
var currentIndex = 0;
4672
if (currentVarDef != null) {
47-
var playerVarDef = varDefinitions.FirstOrDefault(p => p.Id == currentVarDef!.Id);
48-
currentIndex = playerVarDef != null ? varDefinitions.IndexOf(playerVarDef) + 1 : 0;
73+
var stateVarDef = varDefinitions.FirstOrDefault(p => p.Id == currentVarDef!.Id);
74+
currentIndex = stateVarDef != null ? varDefinitions.IndexOf(stateVarDef) + 1 : 0;
4975
}
5076

5177
var newIndex = EditorGUI.Popup(position, currentIndex, varNames);

0 commit comments

Comments
 (0)