From edd97988da489b2a7a266fe95ae5a957cbdf51df Mon Sep 17 00:00:00 2001 From: Jason Millard Date: Tue, 23 Aug 2022 17:11:38 -0400 Subject: [PATCH 1/9] displays: add AddPointsDisplay and DisplayScoreEvent units --- .gitignore | 2 + .../AddPointsDisplayUnitDescriptor.cs | 50 ++++++++++++ .../AddPointsDisplayUnitDescriptor.cs.meta | 11 +++ .../DisplayScoreEventUnitDescriptor.cs | 30 ++++++++ .../DisplayScoreEventUnitDescriptor.cs.meta | 11 +++ .../Inspectors/DisplayDefinitionInspector.cs | 14 +++- Editor/Widgets/AddPointsDisplayUnitWidget.cs | 32 ++++++++ .../AddPointsDisplayUnitWidget.cs.meta | 11 +++ Editor/Widgets/DisplayScoreEventUnitWidget.cs | 32 ++++++++ .../DisplayScoreEventUnitWidget.cs.meta | 11 +++ Runtime/Display/DisplayDefinition.cs | 5 +- Runtime/Display/DisplayTypeFilterAttribute.cs | 34 +++++++++ .../DisplayTypeFilterAttribute.cs.meta | 11 +++ .../Gamelogic/VisualScriptingEventNames.cs | 1 + .../VisualScriptingGamelogicEngine.cs | 25 ++++-- Runtime/Nodes/Display/AddPointsDisplayUnit.cs | 76 +++++++++++++++++++ .../Display/AddPointsDisplayUnit.cs.meta | 11 +++ .../Nodes/Display/DisplayScoreEventUnit.cs | 61 +++++++++++++++ .../Display/DisplayScoreEventUnit.cs.meta | 11 +++ Runtime/Nodes/Display/UpdateDisplayUnit.cs | 14 ++-- Runtime/Nodes/Event/PinballEventUnit.cs | 2 +- 21 files changed, 434 insertions(+), 21 deletions(-) create mode 100644 Editor/Descriptors/AddPointsDisplayUnitDescriptor.cs create mode 100644 Editor/Descriptors/AddPointsDisplayUnitDescriptor.cs.meta create mode 100644 Editor/Descriptors/DisplayScoreEventUnitDescriptor.cs create mode 100644 Editor/Descriptors/DisplayScoreEventUnitDescriptor.cs.meta create mode 100644 Editor/Widgets/AddPointsDisplayUnitWidget.cs create mode 100644 Editor/Widgets/AddPointsDisplayUnitWidget.cs.meta create mode 100644 Editor/Widgets/DisplayScoreEventUnitWidget.cs create mode 100644 Editor/Widgets/DisplayScoreEventUnitWidget.cs.meta create mode 100644 Runtime/Display/DisplayTypeFilterAttribute.cs create mode 100644 Runtime/Display/DisplayTypeFilterAttribute.cs.meta create mode 100644 Runtime/Nodes/Display/AddPointsDisplayUnit.cs create mode 100644 Runtime/Nodes/Display/AddPointsDisplayUnit.cs.meta create mode 100644 Runtime/Nodes/Display/DisplayScoreEventUnit.cs create mode 100644 Runtime/Nodes/Display/DisplayScoreEventUnit.cs.meta diff --git a/.gitignore b/.gitignore index 0673581..01b8a8b 100644 --- a/.gitignore +++ b/.gitignore @@ -364,3 +364,5 @@ MigrationBackup/ # Vi swap files *.swp + +.DS_Store diff --git a/Editor/Descriptors/AddPointsDisplayUnitDescriptor.cs b/Editor/Descriptors/AddPointsDisplayUnitDescriptor.cs new file mode 100644 index 0000000..c9685e7 --- /dev/null +++ b/Editor/Descriptors/AddPointsDisplayUnitDescriptor.cs @@ -0,0 +1,50 @@ +// Visual Pinball Engine +// Copyright (C) 2022 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// ReSharper disable UnusedType.Global + +using Unity.VisualScripting; +using VisualPinball.Unity.Editor; +using IconSize = VisualPinball.Unity.Editor.IconSize; + +namespace VisualPinball.Unity.VisualScripting.Editor +{ + [Descriptor(typeof(AddPointsDisplayUnit))] + public class AddPointsDisplayUnitDescriptor : UnitDescriptor + { + public AddPointsDisplayUnitDescriptor(AddPointsDisplayUnit target) : base(target) + { + } + + protected override string DefinedSummary() + { + return "This node takes in a points value and sends it to the display connected through the given ID."; + } + + protected override EditorTexture DefinedIcon() => EditorTexture.Single(Unity.Editor.Icons.UpdateDisplay); + + protected override void DefinedPort(IUnitPort port, UnitPortDescription desc) + { + base.DefinedPort(port, desc); + + switch (port.key) { + case nameof(AddPointsDisplayUnit.Points): + desc.summary = "Sets the amount of points to add."; + break; + } + } + } +} diff --git a/Editor/Descriptors/AddPointsDisplayUnitDescriptor.cs.meta b/Editor/Descriptors/AddPointsDisplayUnitDescriptor.cs.meta new file mode 100644 index 0000000..772a663 --- /dev/null +++ b/Editor/Descriptors/AddPointsDisplayUnitDescriptor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 86d72589ba16542e28cd581ff3ffdaee +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Descriptors/DisplayScoreEventUnitDescriptor.cs b/Editor/Descriptors/DisplayScoreEventUnitDescriptor.cs new file mode 100644 index 0000000..821cfa6 --- /dev/null +++ b/Editor/Descriptors/DisplayScoreEventUnitDescriptor.cs @@ -0,0 +1,30 @@ +// Visual Pinball Engine +// Copyright (C) 2022 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// ReSharper disable UnusedType.Global + +using Unity.VisualScripting; + +namespace VisualPinball.Unity.VisualScripting.Editor +{ + [Descriptor(typeof(DisplayScoreEventUnit))] + public class DisplayScoreEventUnitDescriptor : UnitDescriptor + { + public DisplayScoreEventUnitDescriptor(DisplayScoreEventUnit target) : base(target) { } + + protected override EditorTexture DefinedIcon() => EditorTexture.Single(Unity.Editor.Icons.UpdateDisplay); + } +} diff --git a/Editor/Descriptors/DisplayScoreEventUnitDescriptor.cs.meta b/Editor/Descriptors/DisplayScoreEventUnitDescriptor.cs.meta new file mode 100644 index 0000000..63fb5a8 --- /dev/null +++ b/Editor/Descriptors/DisplayScoreEventUnitDescriptor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 488a45e0c4c684d31acbcae8570a26ee +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Inspectors/DisplayDefinitionInspector.cs b/Editor/Inspectors/DisplayDefinitionInspector.cs index a88e57c..8dfa9c5 100644 --- a/Editor/Inspectors/DisplayDefinitionInspector.cs +++ b/Editor/Inspectors/DisplayDefinitionInspector.cs @@ -37,9 +37,15 @@ protected override void OnGUI(Rect position, GUIContent label) ErrorMessage = "No displays defined."; } else { - var varNames = new List { "None" } - .Concat(gle.Displays.Select(d => d.Id)) - .ToArray(); + var varNames = new List { "None" }; + + if (metadata.HasAttribute()) { + varNames.AddRange(gle.Displays.Where(i => metadata.GetAttribute().types.Contains(i.Type)).Select(d => d.Id)); + } + else { + varNames.AddRange(gle.Displays.Select(d => d.Id)); + } + var currentDisplayDef = metadata.value as DisplayDefinition; var currentIndex = 0; if (currentDisplayDef != null) { @@ -47,7 +53,7 @@ protected override void OnGUI(Rect position, GUIContent label) currentIndex = displayDef != null ? Array.IndexOf(gle.Displays, displayDef) + 1 : 0; } - var newIndex = EditorGUI.Popup(position, currentIndex, varNames); + var newIndex = EditorGUI.Popup(position, currentIndex, varNames.ToArray()); metadata.RecordUndo(); metadata.value = newIndex == 0 ? null : gle.Displays[newIndex - 1]; ErrorMessage = null; diff --git a/Editor/Widgets/AddPointsDisplayUnitWidget.cs b/Editor/Widgets/AddPointsDisplayUnitWidget.cs new file mode 100644 index 0000000..4a8a675 --- /dev/null +++ b/Editor/Widgets/AddPointsDisplayUnitWidget.cs @@ -0,0 +1,32 @@ +// Visual Pinball Engine +// Copyright (C) 2022 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// ReSharper disable UnusedType.Global + +using System.Collections.Generic; +using System.Linq; +using Unity.VisualScripting; + +namespace VisualPinball.Unity.VisualScripting.Editor +{ + [Widget(typeof(AddPointsDisplayUnit))] + public sealed class AddPointsDisplayUnitWidget : GleUnitWidget + { + public AddPointsDisplayUnitWidget(FlowCanvas canvas, AddPointsDisplayUnit unit) : base(canvas, unit) + { + } + } +} diff --git a/Editor/Widgets/AddPointsDisplayUnitWidget.cs.meta b/Editor/Widgets/AddPointsDisplayUnitWidget.cs.meta new file mode 100644 index 0000000..d889b8e --- /dev/null +++ b/Editor/Widgets/AddPointsDisplayUnitWidget.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 55bb6cf38352b4ca5ae69e694064fa63 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Widgets/DisplayScoreEventUnitWidget.cs b/Editor/Widgets/DisplayScoreEventUnitWidget.cs new file mode 100644 index 0000000..41674fa --- /dev/null +++ b/Editor/Widgets/DisplayScoreEventUnitWidget.cs @@ -0,0 +1,32 @@ +// Visual Pinball Engine +// Copyright (C) 2022 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// ReSharper disable UnusedType.Global + +using System.Collections.Generic; +using System.Linq; +using Unity.VisualScripting; + +namespace VisualPinball.Unity.VisualScripting.Editor +{ + [Widget(typeof(DisplayScoreEventUnit))] + public sealed class DisplayScoreEventUnitWidget : GleUnitWidget + { + public DisplayScoreEventUnitWidget(FlowCanvas canvas, DisplayScoreEventUnit unit) : base(canvas, unit) + { + } + } +} diff --git a/Editor/Widgets/DisplayScoreEventUnitWidget.cs.meta b/Editor/Widgets/DisplayScoreEventUnitWidget.cs.meta new file mode 100644 index 0000000..34afd01 --- /dev/null +++ b/Editor/Widgets/DisplayScoreEventUnitWidget.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 23f7addcf01c442df9eb45dd7ac7f154 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Display/DisplayDefinition.cs b/Runtime/Display/DisplayDefinition.cs index 6fc5cce..e1dd38f 100644 --- a/Runtime/Display/DisplayDefinition.cs +++ b/Runtime/Display/DisplayDefinition.cs @@ -24,7 +24,8 @@ namespace VisualPinball.Unity.VisualScripting [Serializable] public class DisplayDefinition { - public string Id = "display0"; + public string Id = "display0"; + public DisplayType Type = DisplayType.DotMatrix; public int Width = 128; public int Height = 32; @@ -37,6 +38,6 @@ public bool Supports(DisplayFrameFormat format) return SupportedFormats != null && Array.IndexOf(SupportedFormats, format) >= 0; } - public DisplayConfig DisplayConfig => new(Id, Width, Height); + public DisplayConfig DisplayConfig => new(Id, Type, Width, Height); } } diff --git a/Runtime/Display/DisplayTypeFilterAttribute.cs b/Runtime/Display/DisplayTypeFilterAttribute.cs new file mode 100644 index 0000000..0e14322 --- /dev/null +++ b/Runtime/Display/DisplayTypeFilterAttribute.cs @@ -0,0 +1,34 @@ +// Visual Pinball Engine +// Copyright (C) 2022 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// ReSharper disable InconsistentNaming + +using System; +using System.Collections.Generic; + +namespace VisualPinball.Unity.VisualScripting +{ + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] + public class DisplayTypeFilterAttribute : Attribute + { + public DisplayTypeFilterAttribute(params DisplayType[] types) + { + this.types = types; + } + + public DisplayType[] types { get; private set; } + } +} diff --git a/Runtime/Display/DisplayTypeFilterAttribute.cs.meta b/Runtime/Display/DisplayTypeFilterAttribute.cs.meta new file mode 100644 index 0000000..5538b3b --- /dev/null +++ b/Runtime/Display/DisplayTypeFilterAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 06e47af885a744c228487dbc1894c16c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Gamelogic/VisualScriptingEventNames.cs b/Runtime/Gamelogic/VisualScriptingEventNames.cs index 461b07f..82831cc 100644 --- a/Runtime/Gamelogic/VisualScriptingEventNames.cs +++ b/Runtime/Gamelogic/VisualScriptingEventNames.cs @@ -22,6 +22,7 @@ public static class VisualScriptingEventNames public const string LampEvent = "LampEvent"; public const string SwitchEvent = "SwitchEvent"; public const string CoilEvent = "CoilEvent"; + public const string DisplayScoreEvent = "DisplayScoreEvent"; public const string CurrentPlayerChanged = "CurrentPlayerChanged"; public const string PlayerVariableChanged = "PlayerVariableChanged"; public const string TableVariableChanged = "TableVariableChanged"; diff --git a/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs b/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs index 0bcc49b..b9b62ff 100644 --- a/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs +++ b/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs @@ -64,7 +64,9 @@ public class VisualScriptingGamelogicEngine : MonoBehaviour, IGamelogicEngine, I public GamelogicEngineWire[] AvailableWires => Wires; public event EventHandler OnDisplaysRequested; - public event EventHandler OnDisplayFrame; + public event EventHandler OnDisplayUpdateFrame; + public event EventHandler OnDisplayAddPoints; + public event EventHandler OnLampChanged; public event EventHandler OnLampsChanged; public event EventHandler OnCoilChanged; @@ -87,11 +89,6 @@ public PlayerState CurrentPlayerState { } } - public void DisplayFrame(DisplayFrameData data) - { - OnDisplayFrame?.Invoke(this, data); - } - public void SetCurrentPlayer(int value, bool forceNotify = false) { if (!PlayerStates.ContainsKey(value)) { @@ -159,6 +156,21 @@ public void OnInit(Player player, TableApi tableApi, BallManager ballManager) EventBus.Trigger(VisualScriptingEventNames.GleStartedEvent, EventArgs.Empty); } + public void DisplayUpdateFrame(DisplayFrameData data) + { + OnDisplayUpdateFrame?.Invoke(this, data); + } + + public void DisplayAddPoints(DisplayAddPointsData data) + { + OnDisplayAddPoints?.Invoke(this, data); + } + + public void DisplayScoreEvent(string id, float score) + { + EventBus.Trigger(VisualScriptingEventNames.DisplayScoreEvent, new DisplayScoreEventArgs(id, score)); + } + public void Switch(string id, bool isClosed) { var args = new SwitchEventArgs2(id, isClosed); @@ -193,7 +205,6 @@ public bool GetCoil(string id) return _player.CoilStatuses.ContainsKey(id) && _player.CoilStatuses[id]; } - public void OnBeforeSerialize() { #if UNITY_EDITOR diff --git a/Runtime/Nodes/Display/AddPointsDisplayUnit.cs b/Runtime/Nodes/Display/AddPointsDisplayUnit.cs new file mode 100644 index 0000000..6a0ab65 --- /dev/null +++ b/Runtime/Nodes/Display/AddPointsDisplayUnit.cs @@ -0,0 +1,76 @@ +// Visual Pinball Engine +// Copyright (C) 2022 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using Unity.VisualScripting; +using UnityEngine; +using VisualPinball.Engine.Game.Engines; + +namespace VisualPinball.Unity.VisualScripting +{ + [UnitShortTitle("Add Points Display")] + [UnitTitle("Add Points Display")] + [UnitSurtitle("Gamelogic Engine")] + [UnitCategory("Visual Pinball")] + public class AddPointsDisplayUnit : GleUnit + { + [Serialize] + [Inspectable] + [UnitHeaderInspectable("ID")] + [DisplayTypeFilterAttribute(DisplayType.ScoreReel)] + public DisplayDefinition Display { get; private set; } + + [DoNotSerialize] + [PortLabelHidden] + public ControlInput InputTrigger; + + [DoNotSerialize] + [PortLabel("Points")] + public ValueInput Points { get; private set; } + + [DoNotSerialize] + [PortLabelHidden] + public ControlOutput OutputTrigger; + + protected override void Definition() + { + InputTrigger = ControlInput(nameof(InputTrigger), Process); + OutputTrigger = ControlOutput(nameof(OutputTrigger)); + + Points = ValueInput(nameof(Points)); + + Succession(InputTrigger, OutputTrigger); + } + + private ControlOutput Process(Flow flow) + { + if (!AssertVsGle(flow)) { + throw new InvalidOperationException("Cannot retrieve GLE from unit."); + } + + if (Display != null) { + var points = flow.GetValue(Points); + VsGle.DisplayAddPoints(new DisplayAddPointsData(Display.Id, points)); + } + + return OutputTrigger; + } + } +} diff --git a/Runtime/Nodes/Display/AddPointsDisplayUnit.cs.meta b/Runtime/Nodes/Display/AddPointsDisplayUnit.cs.meta new file mode 100644 index 0000000..d02b82c --- /dev/null +++ b/Runtime/Nodes/Display/AddPointsDisplayUnit.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 02b399ec8423241d3bac0d7a6804e698 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Nodes/Display/DisplayScoreEventUnit.cs b/Runtime/Nodes/Display/DisplayScoreEventUnit.cs new file mode 100644 index 0000000..616308c --- /dev/null +++ b/Runtime/Nodes/Display/DisplayScoreEventUnit.cs @@ -0,0 +1,61 @@ +// Visual Pinball Engine +// Copyright (C) 2022 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Collections.Generic; +using System.Collections.ObjectModel; +using Unity.VisualScripting; +using UnityEngine; + +namespace VisualPinball.Unity.VisualScripting +{ + [UnitTitle("On Display Score")] + [UnitSurtitle("Gamelogic Engine")] + [UnitCategory("Events\\Visual Pinball")] + public class DisplayScoreEventUnit : GleEventUnit + { + [Serialize] + [Inspectable] + [UnitHeaderInspectable("ID")] + [DisplayTypeFilterAttribute(DisplayType.ScoreReel)] + public DisplayDefinition Display { get; private set; } + + [DoNotSerialize] + [PortLabel("Score")] + public ValueOutput Score { get; private set; } + + [DoNotSerialize] + protected override bool register => true; + + public override EventHook GetHook(GraphReference reference) => new EventHook(VisualScriptingEventNames.DisplayScoreEvent); + + protected override void Definition() + { + base.Definition(); + + Score = ValueOutput(nameof(Score)); + } + + protected override bool ShouldTrigger(Flow flow, DisplayScoreEventArgs args) + { + return args.Id == Display.Id; + } + + protected override void AssignArguments(Flow flow, DisplayScoreEventArgs args) + { + flow.SetValue(Score, args.Score); + } + } +} diff --git a/Runtime/Nodes/Display/DisplayScoreEventUnit.cs.meta b/Runtime/Nodes/Display/DisplayScoreEventUnit.cs.meta new file mode 100644 index 0000000..95831a0 --- /dev/null +++ b/Runtime/Nodes/Display/DisplayScoreEventUnit.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 685f69a67823f424bb737f97b1d205a5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Nodes/Display/UpdateDisplayUnit.cs b/Runtime/Nodes/Display/UpdateDisplayUnit.cs index 3bc4cc2..344c364 100644 --- a/Runtime/Nodes/Display/UpdateDisplayUnit.cs +++ b/Runtime/Nodes/Display/UpdateDisplayUnit.cs @@ -105,42 +105,42 @@ private ControlOutput Process(Flow flow) if (Display != null) { if (Display.Supports(DisplayFrameFormat.Numeric) && NumericInput.hasValidConnection) { var numValue = flow.GetValue(NumericInput); - VsGle.DisplayFrame(new DisplayFrameData(Display.Id, DisplayFrameFormat.Numeric, BitConverter.GetBytes(numValue))); + VsGle.DisplayUpdateFrame(new DisplayFrameData(Display.Id, DisplayFrameFormat.Numeric, BitConverter.GetBytes(numValue))); } if (Display.Supports(DisplayFrameFormat.AlphaNumeric) && flow.IsLocal(TextInput)) { var strValue = flow.GetValue(TextInput); if (!string.IsNullOrEmpty(strValue)) { - VsGle.DisplayFrame(new DisplayFrameData(Display.Id, DisplayFrameFormat.AlphaNumeric, Encoding.UTF8.GetBytes(strValue))); + VsGle.DisplayUpdateFrame(new DisplayFrameData(Display.Id, DisplayFrameFormat.AlphaNumeric, Encoding.UTF8.GetBytes(strValue))); } } if (Display.Supports(DisplayFrameFormat.Segment) && SegmentInput.hasValidConnection) { var byteValue = flow.GetValue(SegmentInput); if (byteValue is { Length: > 0 }) { - VsGle.DisplayFrame(new DisplayFrameData(Display.Id, DisplayFrameFormat.Segment, byteValue)); + VsGle.DisplayUpdateFrame(new DisplayFrameData(Display.Id, DisplayFrameFormat.Segment, byteValue)); } } if (Display.Supports(DisplayFrameFormat.Dmd2) && Dmd2Input.hasValidConnection) { var byteValue = flow.GetValue(Dmd2Input); if (byteValue is { Length: > 0 }) { - VsGle.DisplayFrame(new DisplayFrameData(Display.Id, DisplayFrameFormat.Dmd2, byteValue)); + VsGle.DisplayUpdateFrame(new DisplayFrameData(Display.Id, DisplayFrameFormat.Dmd2, byteValue)); } } if (Display.Supports(DisplayFrameFormat.Dmd4) && Dmd4Input.hasValidConnection) { var byteValue = flow.GetValue(Dmd4Input); if (byteValue is { Length: > 0 }) { - VsGle.DisplayFrame(new DisplayFrameData(Display.Id, DisplayFrameFormat.Dmd4, byteValue)); + VsGle.DisplayUpdateFrame(new DisplayFrameData(Display.Id, DisplayFrameFormat.Dmd4, byteValue)); } } if (Display.Supports(DisplayFrameFormat.Dmd8) && Dmd8Input.hasValidConnection) { var byteValue = flow.GetValue(Dmd8Input); if (byteValue is { Length: > 0 }) { - VsGle.DisplayFrame(new DisplayFrameData(Display.Id, DisplayFrameFormat.Dmd8, byteValue)); + VsGle.DisplayUpdateFrame(new DisplayFrameData(Display.Id, DisplayFrameFormat.Dmd8, byteValue)); } } if (Display.Supports(DisplayFrameFormat.Dmd24) && Dmd24Input.hasValidConnection) { var byteValue = flow.GetValue(Dmd24Input); if (byteValue is { Length: > 0 }) { - VsGle.DisplayFrame(new DisplayFrameData(Display.Id, DisplayFrameFormat.Dmd24, byteValue)); + VsGle.DisplayUpdateFrame(new DisplayFrameData(Display.Id, DisplayFrameFormat.Dmd24, byteValue)); } } } diff --git a/Runtime/Nodes/Event/PinballEventUnit.cs b/Runtime/Nodes/Event/PinballEventUnit.cs index ac299c4..4952faa 100644 --- a/Runtime/Nodes/Event/PinballEventUnit.cs +++ b/Runtime/Nodes/Event/PinballEventUnit.cs @@ -61,7 +61,7 @@ protected override void Definition() protected override bool ShouldTrigger(Flow flow, PinballEventArgs args) { - return Event.Id.Equals(args.Id); + return Event != null && Event.Id.Equals(args.Id); } protected override void AssignArguments(Flow flow, PinballEventArgs args) From 7024256be7e19f6752bf025915fc127496c2374b Mon Sep 17 00:00:00 2001 From: Jason Millard Date: Fri, 26 Aug 2022 17:22:05 -0400 Subject: [PATCH 2/9] misc: added ClearDisplayUnit --- .../Descriptors/ClearDisplayUnitDescriptor.cs | 39 ++++++++++++ .../ClearDisplayUnitDescriptor.cs.meta | 11 ++++ Editor/Widgets/ClearDisplayUnitWidget.cs | 30 ++++++++++ Editor/Widgets/ClearDisplayUnitWidget.cs.meta | 11 ++++ .../VisualScriptingGamelogicEngine.cs | 10 +++- Runtime/Nodes/Display/ClearDisplayUnit.cs | 60 +++++++++++++++++++ .../Nodes/Display/ClearDisplayUnit.cs.meta | 11 ++++ .../Nodes/Display/DisplayScoreEventUnit.cs | 6 ++ 8 files changed, 176 insertions(+), 2 deletions(-) create mode 100644 Editor/Descriptors/ClearDisplayUnitDescriptor.cs create mode 100644 Editor/Descriptors/ClearDisplayUnitDescriptor.cs.meta create mode 100644 Editor/Widgets/ClearDisplayUnitWidget.cs create mode 100644 Editor/Widgets/ClearDisplayUnitWidget.cs.meta create mode 100644 Runtime/Nodes/Display/ClearDisplayUnit.cs create mode 100644 Runtime/Nodes/Display/ClearDisplayUnit.cs.meta diff --git a/Editor/Descriptors/ClearDisplayUnitDescriptor.cs b/Editor/Descriptors/ClearDisplayUnitDescriptor.cs new file mode 100644 index 0000000..1272f0d --- /dev/null +++ b/Editor/Descriptors/ClearDisplayUnitDescriptor.cs @@ -0,0 +1,39 @@ +// Visual Pinball Engine +// Copyright (C) 2022 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// ReSharper disable UnusedType.Global + +using Unity.VisualScripting; +using VisualPinball.Unity.Editor; +using IconSize = VisualPinball.Unity.Editor.IconSize; + +namespace VisualPinball.Unity.VisualScripting.Editor +{ + [Descriptor(typeof(ClearDisplayUnit))] + public class ClearDisplayUnitDescriptor : UnitDescriptor + { + public ClearDisplayUnitDescriptor(ClearDisplayUnit target) : base(target) + { + } + + protected override string DefinedSummary() + { + return "This node clears a display connected through the given ID."; + } + + protected override EditorTexture DefinedIcon() => EditorTexture.Single(Unity.Editor.Icons.UpdateDisplay); + } +} diff --git a/Editor/Descriptors/ClearDisplayUnitDescriptor.cs.meta b/Editor/Descriptors/ClearDisplayUnitDescriptor.cs.meta new file mode 100644 index 0000000..e788ef7 --- /dev/null +++ b/Editor/Descriptors/ClearDisplayUnitDescriptor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 86eda94feb9564ccf8c7a4dbe3079be7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Widgets/ClearDisplayUnitWidget.cs b/Editor/Widgets/ClearDisplayUnitWidget.cs new file mode 100644 index 0000000..4589824 --- /dev/null +++ b/Editor/Widgets/ClearDisplayUnitWidget.cs @@ -0,0 +1,30 @@ +// Visual Pinball Engine +// Copyright (C) 2022 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// ReSharper disable UnusedType.Global + +using Unity.VisualScripting; + +namespace VisualPinball.Unity.VisualScripting.Editor +{ + [Widget(typeof(ClearDisplayUnit))] + public sealed class ClearDisplayUnitWidget : GleUnitWidget + { + public ClearDisplayUnitWidget(FlowCanvas canvas, ClearDisplayUnit unit) : base(canvas, unit) + { + } + } +} diff --git a/Editor/Widgets/ClearDisplayUnitWidget.cs.meta b/Editor/Widgets/ClearDisplayUnitWidget.cs.meta new file mode 100644 index 0000000..fc4d182 --- /dev/null +++ b/Editor/Widgets/ClearDisplayUnitWidget.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a040226b549bc402d83800689d1ca891 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs b/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs index b9b62ff..f82b86a 100644 --- a/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs +++ b/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs @@ -64,6 +64,7 @@ public class VisualScriptingGamelogicEngine : MonoBehaviour, IGamelogicEngine, I public GamelogicEngineWire[] AvailableWires => Wires; public event EventHandler OnDisplaysRequested; + public event EventHandler OnDisplayClear; public event EventHandler OnDisplayUpdateFrame; public event EventHandler OnDisplayAddPoints; @@ -156,6 +157,11 @@ public void OnInit(Player player, TableApi tableApi, BallManager ballManager) EventBus.Trigger(VisualScriptingEventNames.GleStartedEvent, EventArgs.Empty); } + public void DisplayClear(DisplayClearData data) + { + OnDisplayClear?.Invoke(this, data); + } + public void DisplayUpdateFrame(DisplayFrameData data) { OnDisplayUpdateFrame?.Invoke(this, data); @@ -166,9 +172,9 @@ public void DisplayAddPoints(DisplayAddPointsData data) OnDisplayAddPoints?.Invoke(this, data); } - public void DisplayScoreEvent(string id, float score) + public void DisplayScoreEvent(string id, float points, float score) { - EventBus.Trigger(VisualScriptingEventNames.DisplayScoreEvent, new DisplayScoreEventArgs(id, score)); + EventBus.Trigger(VisualScriptingEventNames.DisplayScoreEvent, new DisplayScoreEventArgs(id, points, score)); } public void Switch(string id, bool isClosed) diff --git a/Runtime/Nodes/Display/ClearDisplayUnit.cs b/Runtime/Nodes/Display/ClearDisplayUnit.cs new file mode 100644 index 0000000..a009aa7 --- /dev/null +++ b/Runtime/Nodes/Display/ClearDisplayUnit.cs @@ -0,0 +1,60 @@ +// Visual Pinball Engine +// Copyright (C) 2022 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; +using System.Text; +using Unity.VisualScripting; + +namespace VisualPinball.Unity.VisualScripting +{ + [UnitTitle("Clear Display")] + [UnitSurtitle("Gamelogic Engine")] + [UnitCategory("Visual Pinball")] + public class ClearDisplayUnit : GleUnit + { + [Serialize, Inspectable, UnitHeaderInspectable("ID")] + public DisplayDefinition Display { get; private set; } + + [DoNotSerialize] + [PortLabelHidden] + public ControlInput InputTrigger; + + [DoNotSerialize] + [PortLabelHidden] + public ControlOutput OutputTrigger; + + protected override void Definition() + { + InputTrigger = ControlInput(nameof(InputTrigger), Process); + OutputTrigger = ControlOutput(nameof(OutputTrigger)); + + Succession(InputTrigger, OutputTrigger); + } + + private ControlOutput Process(Flow flow) + { + if (!AssertVsGle(flow)) { + throw new InvalidOperationException("Cannot retrieve GLE from unit."); + } + + if (Display != null) { + VsGle.DisplayClear(new DisplayClearData(Display.Id)); + } + + return OutputTrigger; + } + } +} diff --git a/Runtime/Nodes/Display/ClearDisplayUnit.cs.meta b/Runtime/Nodes/Display/ClearDisplayUnit.cs.meta new file mode 100644 index 0000000..177c850 --- /dev/null +++ b/Runtime/Nodes/Display/ClearDisplayUnit.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 15ec3d88570f643b3913dce96027e86a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Nodes/Display/DisplayScoreEventUnit.cs b/Runtime/Nodes/Display/DisplayScoreEventUnit.cs index 616308c..d1458c6 100644 --- a/Runtime/Nodes/Display/DisplayScoreEventUnit.cs +++ b/Runtime/Nodes/Display/DisplayScoreEventUnit.cs @@ -32,6 +32,10 @@ public class DisplayScoreEventUnit : GleEventUnit [DisplayTypeFilterAttribute(DisplayType.ScoreReel)] public DisplayDefinition Display { get; private set; } + [DoNotSerialize] + [PortLabel("Points")] + public ValueOutput Points { get; private set; } + [DoNotSerialize] [PortLabel("Score")] public ValueOutput Score { get; private set; } @@ -45,6 +49,7 @@ protected override void Definition() { base.Definition(); + Points = ValueOutput(nameof(Points)); Score = ValueOutput(nameof(Score)); } @@ -55,6 +60,7 @@ protected override bool ShouldTrigger(Flow flow, DisplayScoreEventArgs args) protected override void AssignArguments(Flow flow, DisplayScoreEventArgs args) { + flow.SetValue(Points, args.Points); flow.SetValue(Score, args.Score); } } From 47d8166476f156b4b176c9172703b06b2ecb63f9 Mon Sep 17 00:00:00 2001 From: Jason Millard Date: Sun, 28 Aug 2022 10:21:06 -0400 Subject: [PATCH 3/9] misc: remove DisplayAddPoints in favor of using UpdateFrame --- .../AddPointsDisplayUnitDescriptor.cs | 50 ------------ .../AddPointsDisplayUnitDescriptor.cs.meta | 11 --- Editor/Widgets/AddPointsDisplayUnitWidget.cs | 32 -------- .../AddPointsDisplayUnitWidget.cs.meta | 11 --- .../VisualScriptingGamelogicEngine.cs | 6 -- Runtime/Nodes/Display/AddPointsDisplayUnit.cs | 76 ------------------- .../Display/AddPointsDisplayUnit.cs.meta | 11 --- 7 files changed, 197 deletions(-) delete mode 100644 Editor/Descriptors/AddPointsDisplayUnitDescriptor.cs delete mode 100644 Editor/Descriptors/AddPointsDisplayUnitDescriptor.cs.meta delete mode 100644 Editor/Widgets/AddPointsDisplayUnitWidget.cs delete mode 100644 Editor/Widgets/AddPointsDisplayUnitWidget.cs.meta delete mode 100644 Runtime/Nodes/Display/AddPointsDisplayUnit.cs delete mode 100644 Runtime/Nodes/Display/AddPointsDisplayUnit.cs.meta diff --git a/Editor/Descriptors/AddPointsDisplayUnitDescriptor.cs b/Editor/Descriptors/AddPointsDisplayUnitDescriptor.cs deleted file mode 100644 index c9685e7..0000000 --- a/Editor/Descriptors/AddPointsDisplayUnitDescriptor.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Visual Pinball Engine -// Copyright (C) 2022 freezy and VPE Team -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// ReSharper disable UnusedType.Global - -using Unity.VisualScripting; -using VisualPinball.Unity.Editor; -using IconSize = VisualPinball.Unity.Editor.IconSize; - -namespace VisualPinball.Unity.VisualScripting.Editor -{ - [Descriptor(typeof(AddPointsDisplayUnit))] - public class AddPointsDisplayUnitDescriptor : UnitDescriptor - { - public AddPointsDisplayUnitDescriptor(AddPointsDisplayUnit target) : base(target) - { - } - - protected override string DefinedSummary() - { - return "This node takes in a points value and sends it to the display connected through the given ID."; - } - - protected override EditorTexture DefinedIcon() => EditorTexture.Single(Unity.Editor.Icons.UpdateDisplay); - - protected override void DefinedPort(IUnitPort port, UnitPortDescription desc) - { - base.DefinedPort(port, desc); - - switch (port.key) { - case nameof(AddPointsDisplayUnit.Points): - desc.summary = "Sets the amount of points to add."; - break; - } - } - } -} diff --git a/Editor/Descriptors/AddPointsDisplayUnitDescriptor.cs.meta b/Editor/Descriptors/AddPointsDisplayUnitDescriptor.cs.meta deleted file mode 100644 index 772a663..0000000 --- a/Editor/Descriptors/AddPointsDisplayUnitDescriptor.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 86d72589ba16542e28cd581ff3ffdaee -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/Widgets/AddPointsDisplayUnitWidget.cs b/Editor/Widgets/AddPointsDisplayUnitWidget.cs deleted file mode 100644 index 4a8a675..0000000 --- a/Editor/Widgets/AddPointsDisplayUnitWidget.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Visual Pinball Engine -// Copyright (C) 2022 freezy and VPE Team -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// ReSharper disable UnusedType.Global - -using System.Collections.Generic; -using System.Linq; -using Unity.VisualScripting; - -namespace VisualPinball.Unity.VisualScripting.Editor -{ - [Widget(typeof(AddPointsDisplayUnit))] - public sealed class AddPointsDisplayUnitWidget : GleUnitWidget - { - public AddPointsDisplayUnitWidget(FlowCanvas canvas, AddPointsDisplayUnit unit) : base(canvas, unit) - { - } - } -} diff --git a/Editor/Widgets/AddPointsDisplayUnitWidget.cs.meta b/Editor/Widgets/AddPointsDisplayUnitWidget.cs.meta deleted file mode 100644 index d889b8e..0000000 --- a/Editor/Widgets/AddPointsDisplayUnitWidget.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 55bb6cf38352b4ca5ae69e694064fa63 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs b/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs index f82b86a..faf1efb 100644 --- a/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs +++ b/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs @@ -66,7 +66,6 @@ public class VisualScriptingGamelogicEngine : MonoBehaviour, IGamelogicEngine, I public event EventHandler OnDisplaysRequested; public event EventHandler OnDisplayClear; public event EventHandler OnDisplayUpdateFrame; - public event EventHandler OnDisplayAddPoints; public event EventHandler OnLampChanged; public event EventHandler OnLampsChanged; @@ -167,11 +166,6 @@ public void DisplayUpdateFrame(DisplayFrameData data) OnDisplayUpdateFrame?.Invoke(this, data); } - public void DisplayAddPoints(DisplayAddPointsData data) - { - OnDisplayAddPoints?.Invoke(this, data); - } - public void DisplayScoreEvent(string id, float points, float score) { EventBus.Trigger(VisualScriptingEventNames.DisplayScoreEvent, new DisplayScoreEventArgs(id, points, score)); diff --git a/Runtime/Nodes/Display/AddPointsDisplayUnit.cs b/Runtime/Nodes/Display/AddPointsDisplayUnit.cs deleted file mode 100644 index 6a0ab65..0000000 --- a/Runtime/Nodes/Display/AddPointsDisplayUnit.cs +++ /dev/null @@ -1,76 +0,0 @@ -// Visual Pinball Engine -// Copyright (C) 2022 freezy and VPE Team -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using Unity.VisualScripting; -using UnityEngine; -using VisualPinball.Engine.Game.Engines; - -namespace VisualPinball.Unity.VisualScripting -{ - [UnitShortTitle("Add Points Display")] - [UnitTitle("Add Points Display")] - [UnitSurtitle("Gamelogic Engine")] - [UnitCategory("Visual Pinball")] - public class AddPointsDisplayUnit : GleUnit - { - [Serialize] - [Inspectable] - [UnitHeaderInspectable("ID")] - [DisplayTypeFilterAttribute(DisplayType.ScoreReel)] - public DisplayDefinition Display { get; private set; } - - [DoNotSerialize] - [PortLabelHidden] - public ControlInput InputTrigger; - - [DoNotSerialize] - [PortLabel("Points")] - public ValueInput Points { get; private set; } - - [DoNotSerialize] - [PortLabelHidden] - public ControlOutput OutputTrigger; - - protected override void Definition() - { - InputTrigger = ControlInput(nameof(InputTrigger), Process); - OutputTrigger = ControlOutput(nameof(OutputTrigger)); - - Points = ValueInput(nameof(Points)); - - Succession(InputTrigger, OutputTrigger); - } - - private ControlOutput Process(Flow flow) - { - if (!AssertVsGle(flow)) { - throw new InvalidOperationException("Cannot retrieve GLE from unit."); - } - - if (Display != null) { - var points = flow.GetValue(Points); - VsGle.DisplayAddPoints(new DisplayAddPointsData(Display.Id, points)); - } - - return OutputTrigger; - } - } -} diff --git a/Runtime/Nodes/Display/AddPointsDisplayUnit.cs.meta b/Runtime/Nodes/Display/AddPointsDisplayUnit.cs.meta deleted file mode 100644 index d02b82c..0000000 --- a/Runtime/Nodes/Display/AddPointsDisplayUnit.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 02b399ec8423241d3bac0d7a6804e698 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: From bc378498cb7cca4b5faaf780cdd7b1b73690ac57 Mon Sep 17 00:00:00 2001 From: Jason Millard Date: Sun, 28 Aug 2022 13:50:00 -0400 Subject: [PATCH 4/9] misc: rename DisplayScoreEvent to DisplayUpdateEvent. Remove DisplayType. Cleanup --- ...cs => DisplayUpdateEventUnitDescriptor.cs} | 18 +++++++-- .../DisplayUpdateEventUnitDescriptor.cs.meta | 2 +- .../UpdateDisplayUnitDescriptor.cs | 2 - .../Inspectors/DisplayDefinitionInspector.cs | 13 ++----- .../DisplayScoreEventUnitWidget.cs.meta | 11 ------ ...get.cs => DisplayUpdateEventUnitWidget.cs} | 8 ++-- .../DisplayUpdateEventUnitWidget.cs.meta} | 2 +- Runtime/Display/DisplayDefinition.cs | 5 +-- Runtime/Display/DisplayTypeFilterAttribute.cs | 34 ----------------- .../Gamelogic/VisualScriptingEventNames.cs | 2 +- .../VisualScriptingGamelogicEngine.cs | 4 +- ...EventUnit.cs => DisplayUpdateEventUnit.cs} | 37 ++++++++++--------- ...cs.meta => DisplayUpdateEventUnit.cs.meta} | 2 +- 13 files changed, 50 insertions(+), 90 deletions(-) rename Editor/Descriptors/{DisplayScoreEventUnitDescriptor.cs => DisplayUpdateEventUnitDescriptor.cs} (63%) rename Runtime/Display/DisplayTypeFilterAttribute.cs.meta => Editor/Descriptors/DisplayUpdateEventUnitDescriptor.cs.meta (83%) delete mode 100644 Editor/Widgets/DisplayScoreEventUnitWidget.cs.meta rename Editor/Widgets/{DisplayScoreEventUnitWidget.cs => DisplayUpdateEventUnitWidget.cs} (72%) rename Editor/{Descriptors/DisplayScoreEventUnitDescriptor.cs.meta => Widgets/DisplayUpdateEventUnitWidget.cs.meta} (83%) delete mode 100644 Runtime/Display/DisplayTypeFilterAttribute.cs rename Runtime/Nodes/Display/{DisplayScoreEventUnit.cs => DisplayUpdateEventUnit.cs} (58%) rename Runtime/Nodes/Display/{DisplayScoreEventUnit.cs.meta => DisplayUpdateEventUnit.cs.meta} (83%) diff --git a/Editor/Descriptors/DisplayScoreEventUnitDescriptor.cs b/Editor/Descriptors/DisplayUpdateEventUnitDescriptor.cs similarity index 63% rename from Editor/Descriptors/DisplayScoreEventUnitDescriptor.cs rename to Editor/Descriptors/DisplayUpdateEventUnitDescriptor.cs index 821cfa6..bcc23df 100644 --- a/Editor/Descriptors/DisplayScoreEventUnitDescriptor.cs +++ b/Editor/Descriptors/DisplayUpdateEventUnitDescriptor.cs @@ -20,11 +20,23 @@ namespace VisualPinball.Unity.VisualScripting.Editor { - [Descriptor(typeof(DisplayScoreEventUnit))] - public class DisplayScoreEventUnitDescriptor : UnitDescriptor + [Descriptor(typeof(DisplayUpdateEventUnit))] + public class DisplayUpdateEventUnitDescriptor : UnitDescriptor { - public DisplayScoreEventUnitDescriptor(DisplayScoreEventUnit target) : base(target) { } + public DisplayUpdateEventUnitDescriptor(DisplayUpdateEventUnit target) : base(target) { } protected override EditorTexture DefinedIcon() => EditorTexture.Single(Unity.Editor.Icons.UpdateDisplay); + + protected override void DefinedPort(IUnitPort port, UnitPortDescription desc) + { + base.DefinedPort(port, desc); + + switch (port.key) + { + case nameof(DisplayUpdateEventUnit.NumericOutput): + desc.summary = "The numerical value of the display update."; + break; + } + } } } diff --git a/Runtime/Display/DisplayTypeFilterAttribute.cs.meta b/Editor/Descriptors/DisplayUpdateEventUnitDescriptor.cs.meta similarity index 83% rename from Runtime/Display/DisplayTypeFilterAttribute.cs.meta rename to Editor/Descriptors/DisplayUpdateEventUnitDescriptor.cs.meta index 5538b3b..3a605ec 100644 --- a/Runtime/Display/DisplayTypeFilterAttribute.cs.meta +++ b/Editor/Descriptors/DisplayUpdateEventUnitDescriptor.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 06e47af885a744c228487dbc1894c16c +guid: 399a09248e20e417d9032b7db6901408 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Editor/Descriptors/UpdateDisplayUnitDescriptor.cs b/Editor/Descriptors/UpdateDisplayUnitDescriptor.cs index 34bf0da..d4eedfc 100644 --- a/Editor/Descriptors/UpdateDisplayUnitDescriptor.cs +++ b/Editor/Descriptors/UpdateDisplayUnitDescriptor.cs @@ -17,8 +17,6 @@ // ReSharper disable UnusedType.Global using Unity.VisualScripting; -using VisualPinball.Unity.Editor; -using IconSize = VisualPinball.Unity.Editor.IconSize; namespace VisualPinball.Unity.VisualScripting.Editor { diff --git a/Editor/Inspectors/DisplayDefinitionInspector.cs b/Editor/Inspectors/DisplayDefinitionInspector.cs index 8dfa9c5..6f9cc63 100644 --- a/Editor/Inspectors/DisplayDefinitionInspector.cs +++ b/Editor/Inspectors/DisplayDefinitionInspector.cs @@ -37,14 +37,9 @@ protected override void OnGUI(Rect position, GUIContent label) ErrorMessage = "No displays defined."; } else { - var varNames = new List { "None" }; - - if (metadata.HasAttribute()) { - varNames.AddRange(gle.Displays.Where(i => metadata.GetAttribute().types.Contains(i.Type)).Select(d => d.Id)); - } - else { - varNames.AddRange(gle.Displays.Select(d => d.Id)); - } + var varNames = new List { "None" } + .Concat(gle.Displays.Select(d => d.Id)) + .ToArray(); var currentDisplayDef = metadata.value as DisplayDefinition; var currentIndex = 0; @@ -53,7 +48,7 @@ protected override void OnGUI(Rect position, GUIContent label) currentIndex = displayDef != null ? Array.IndexOf(gle.Displays, displayDef) + 1 : 0; } - var newIndex = EditorGUI.Popup(position, currentIndex, varNames.ToArray()); + var newIndex = EditorGUI.Popup(position, currentIndex, varNames); metadata.RecordUndo(); metadata.value = newIndex == 0 ? null : gle.Displays[newIndex - 1]; ErrorMessage = null; diff --git a/Editor/Widgets/DisplayScoreEventUnitWidget.cs.meta b/Editor/Widgets/DisplayScoreEventUnitWidget.cs.meta deleted file mode 100644 index 34afd01..0000000 --- a/Editor/Widgets/DisplayScoreEventUnitWidget.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 23f7addcf01c442df9eb45dd7ac7f154 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/Widgets/DisplayScoreEventUnitWidget.cs b/Editor/Widgets/DisplayUpdateEventUnitWidget.cs similarity index 72% rename from Editor/Widgets/DisplayScoreEventUnitWidget.cs rename to Editor/Widgets/DisplayUpdateEventUnitWidget.cs index 41674fa..74267df 100644 --- a/Editor/Widgets/DisplayScoreEventUnitWidget.cs +++ b/Editor/Widgets/DisplayUpdateEventUnitWidget.cs @@ -16,16 +16,14 @@ // ReSharper disable UnusedType.Global -using System.Collections.Generic; -using System.Linq; using Unity.VisualScripting; namespace VisualPinball.Unity.VisualScripting.Editor { - [Widget(typeof(DisplayScoreEventUnit))] - public sealed class DisplayScoreEventUnitWidget : GleUnitWidget + [Widget(typeof(DisplayUpdateEventUnit))] + public sealed class DisplayUpdateEventUnitWidget : GleUnitWidget { - public DisplayScoreEventUnitWidget(FlowCanvas canvas, DisplayScoreEventUnit unit) : base(canvas, unit) + public DisplayUpdateEventUnitWidget(FlowCanvas canvas, DisplayUpdateEventUnit unit) : base(canvas, unit) { } } diff --git a/Editor/Descriptors/DisplayScoreEventUnitDescriptor.cs.meta b/Editor/Widgets/DisplayUpdateEventUnitWidget.cs.meta similarity index 83% rename from Editor/Descriptors/DisplayScoreEventUnitDescriptor.cs.meta rename to Editor/Widgets/DisplayUpdateEventUnitWidget.cs.meta index 63fb5a8..1634202 100644 --- a/Editor/Descriptors/DisplayScoreEventUnitDescriptor.cs.meta +++ b/Editor/Widgets/DisplayUpdateEventUnitWidget.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 488a45e0c4c684d31acbcae8570a26ee +guid: 23997501720e84b8ebc9d1d149e4537d MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Display/DisplayDefinition.cs b/Runtime/Display/DisplayDefinition.cs index e1dd38f..6fc5cce 100644 --- a/Runtime/Display/DisplayDefinition.cs +++ b/Runtime/Display/DisplayDefinition.cs @@ -24,8 +24,7 @@ namespace VisualPinball.Unity.VisualScripting [Serializable] public class DisplayDefinition { - public string Id = "display0"; - public DisplayType Type = DisplayType.DotMatrix; + public string Id = "display0"; public int Width = 128; public int Height = 32; @@ -38,6 +37,6 @@ public bool Supports(DisplayFrameFormat format) return SupportedFormats != null && Array.IndexOf(SupportedFormats, format) >= 0; } - public DisplayConfig DisplayConfig => new(Id, Type, Width, Height); + public DisplayConfig DisplayConfig => new(Id, Width, Height); } } diff --git a/Runtime/Display/DisplayTypeFilterAttribute.cs b/Runtime/Display/DisplayTypeFilterAttribute.cs deleted file mode 100644 index 0e14322..0000000 --- a/Runtime/Display/DisplayTypeFilterAttribute.cs +++ /dev/null @@ -1,34 +0,0 @@ -// Visual Pinball Engine -// Copyright (C) 2022 freezy and VPE Team -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// ReSharper disable InconsistentNaming - -using System; -using System.Collections.Generic; - -namespace VisualPinball.Unity.VisualScripting -{ - [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] - public class DisplayTypeFilterAttribute : Attribute - { - public DisplayTypeFilterAttribute(params DisplayType[] types) - { - this.types = types; - } - - public DisplayType[] types { get; private set; } - } -} diff --git a/Runtime/Gamelogic/VisualScriptingEventNames.cs b/Runtime/Gamelogic/VisualScriptingEventNames.cs index 82831cc..4f4eeb6 100644 --- a/Runtime/Gamelogic/VisualScriptingEventNames.cs +++ b/Runtime/Gamelogic/VisualScriptingEventNames.cs @@ -22,7 +22,7 @@ public static class VisualScriptingEventNames public const string LampEvent = "LampEvent"; public const string SwitchEvent = "SwitchEvent"; public const string CoilEvent = "CoilEvent"; - public const string DisplayScoreEvent = "DisplayScoreEvent"; + public const string DisplayUpdateEvent = "DisplayUpdateEvent"; public const string CurrentPlayerChanged = "CurrentPlayerChanged"; public const string PlayerVariableChanged = "PlayerVariableChanged"; public const string TableVariableChanged = "TableVariableChanged"; diff --git a/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs b/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs index faf1efb..c71bb42 100644 --- a/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs +++ b/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs @@ -166,9 +166,9 @@ public void DisplayUpdateFrame(DisplayFrameData data) OnDisplayUpdateFrame?.Invoke(this, data); } - public void DisplayScoreEvent(string id, float points, float score) + public void DisplayUpdateEvent(DisplayFrameData data) { - EventBus.Trigger(VisualScriptingEventNames.DisplayScoreEvent, new DisplayScoreEventArgs(id, points, score)); + EventBus.Trigger(VisualScriptingEventNames.DisplayUpdateEvent, new DisplayUpdateEventArgs(data)); } public void Switch(string id, bool isClosed) diff --git a/Runtime/Nodes/Display/DisplayScoreEventUnit.cs b/Runtime/Nodes/Display/DisplayUpdateEventUnit.cs similarity index 58% rename from Runtime/Nodes/Display/DisplayScoreEventUnit.cs rename to Runtime/Nodes/Display/DisplayUpdateEventUnit.cs index d1458c6..3eb5e2d 100644 --- a/Runtime/Nodes/Display/DisplayScoreEventUnit.cs +++ b/Runtime/Nodes/Display/DisplayUpdateEventUnit.cs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using Unity.VisualScripting; @@ -21,47 +22,49 @@ namespace VisualPinball.Unity.VisualScripting { - [UnitTitle("On Display Score")] + [UnitTitle("On Display Update")] [UnitSurtitle("Gamelogic Engine")] [UnitCategory("Events\\Visual Pinball")] - public class DisplayScoreEventUnit : GleEventUnit + public class DisplayUpdateEventUnit : GleEventUnit { [Serialize] [Inspectable] [UnitHeaderInspectable("ID")] - [DisplayTypeFilterAttribute(DisplayType.ScoreReel)] public DisplayDefinition Display { get; private set; } [DoNotSerialize] - [PortLabel("Points")] - public ValueOutput Points { get; private set; } - - [DoNotSerialize] - [PortLabel("Score")] - public ValueOutput Score { get; private set; } + [PortLabel("Numeric")] + public ValueOutput NumericOutput { get; private set; } [DoNotSerialize] protected override bool register => true; - public override EventHook GetHook(GraphReference reference) => new EventHook(VisualScriptingEventNames.DisplayScoreEvent); + public override EventHook GetHook(GraphReference reference) => new EventHook(VisualScriptingEventNames.DisplayUpdateEvent); protected override void Definition() { base.Definition(); - Points = ValueOutput(nameof(Points)); - Score = ValueOutput(nameof(Score)); + if (Display != null) { + if (Display.Supports(DisplayFrameFormat.Numeric)) + { + NumericOutput = ValueOutput(nameof(NumericOutput)); + } + } } - protected override bool ShouldTrigger(Flow flow, DisplayScoreEventArgs args) + protected override bool ShouldTrigger(Flow flow, DisplayUpdateEventArgs args) { - return args.Id == Display.Id; + return Display != null && Display.Id == args.DisplayFrameData.Id; } - protected override void AssignArguments(Flow flow, DisplayScoreEventArgs args) + protected override void AssignArguments(Flow flow, DisplayUpdateEventArgs args) { - flow.SetValue(Points, args.Points); - flow.SetValue(Score, args.Score); + if (Display.Supports(DisplayFrameFormat.Numeric)) { + if (args.DisplayFrameData.Format == DisplayFrameFormat.Numeric) { + flow.SetValue(NumericOutput, BitConverter.ToSingle(args.DisplayFrameData.Data)); + } + } } } } diff --git a/Runtime/Nodes/Display/DisplayScoreEventUnit.cs.meta b/Runtime/Nodes/Display/DisplayUpdateEventUnit.cs.meta similarity index 83% rename from Runtime/Nodes/Display/DisplayScoreEventUnit.cs.meta rename to Runtime/Nodes/Display/DisplayUpdateEventUnit.cs.meta index 95831a0..e6dd9b4 100644 --- a/Runtime/Nodes/Display/DisplayScoreEventUnit.cs.meta +++ b/Runtime/Nodes/Display/DisplayUpdateEventUnit.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 685f69a67823f424bb737f97b1d205a5 +guid: dfa19398c5fa3430696dd8f19ab85051 MonoImporter: externalObjects: {} serializedVersion: 2 From 8c0246a53d7e0e0640c60f1fb4155f87ef5ba459 Mon Sep 17 00:00:00 2001 From: Jason Millard Date: Sun, 28 Aug 2022 14:39:52 -0400 Subject: [PATCH 5/9] misc: cleanup to match PinballEventUnity's ShouldTrigger --- Runtime/Nodes/Display/DisplayUpdateEventUnit.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/Nodes/Display/DisplayUpdateEventUnit.cs b/Runtime/Nodes/Display/DisplayUpdateEventUnit.cs index 3eb5e2d..6b2b1fc 100644 --- a/Runtime/Nodes/Display/DisplayUpdateEventUnit.cs +++ b/Runtime/Nodes/Display/DisplayUpdateEventUnit.cs @@ -55,7 +55,7 @@ protected override void Definition() protected override bool ShouldTrigger(Flow flow, DisplayUpdateEventArgs args) { - return Display != null && Display.Id == args.DisplayFrameData.Id; + return Display != null && Display.Id.Equals(args.DisplayFrameData.Id); } protected override void AssignArguments(Flow flow, DisplayUpdateEventArgs args) From d38b6516e811903d104bba6ce97ce8526c99082b Mon Sep 17 00:00:00 2001 From: Jason Millard Date: Sun, 28 Aug 2022 19:35:42 -0400 Subject: [PATCH 6/9] misc: add alphanumeric support to DisplayUpdateEvent. Add DisplayUpdateEvent icon --- .../DisplayUpdateEventUnitDescriptor.cs | 5 ++++- .../Nodes/Display/DisplayUpdateEventUnit.cs | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Editor/Descriptors/DisplayUpdateEventUnitDescriptor.cs b/Editor/Descriptors/DisplayUpdateEventUnitDescriptor.cs index bcc23df..cc3bf5d 100644 --- a/Editor/Descriptors/DisplayUpdateEventUnitDescriptor.cs +++ b/Editor/Descriptors/DisplayUpdateEventUnitDescriptor.cs @@ -25,7 +25,7 @@ public class DisplayUpdateEventUnitDescriptor : UnitDescriptor EditorTexture.Single(Unity.Editor.Icons.UpdateDisplay); + protected override EditorTexture DefinedIcon() => EditorTexture.Single(Unity.Editor.Icons.DisplayUpdateEvent); protected override void DefinedPort(IUnitPort port, UnitPortDescription desc) { @@ -36,6 +36,9 @@ protected override void DefinedPort(IUnitPort port, UnitPortDescription desc) case nameof(DisplayUpdateEventUnit.NumericOutput): desc.summary = "The numerical value of the display update."; break; + case nameof(DisplayUpdateEventUnit.TextOutput): + desc.summary = "The text value of the display update."; + break; } } } diff --git a/Runtime/Nodes/Display/DisplayUpdateEventUnit.cs b/Runtime/Nodes/Display/DisplayUpdateEventUnit.cs index 6b2b1fc..fda737b 100644 --- a/Runtime/Nodes/Display/DisplayUpdateEventUnit.cs +++ b/Runtime/Nodes/Display/DisplayUpdateEventUnit.cs @@ -17,6 +17,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Text; using Unity.VisualScripting; using UnityEngine; @@ -36,6 +37,10 @@ public class DisplayUpdateEventUnit : GleEventUnit [PortLabel("Numeric")] public ValueOutput NumericOutput { get; private set; } + [DoNotSerialize] + [PortLabel("Text")] + public ValueOutput TextOutput { get; private set; } + [DoNotSerialize] protected override bool register => true; @@ -46,10 +51,13 @@ protected override void Definition() base.Definition(); if (Display != null) { - if (Display.Supports(DisplayFrameFormat.Numeric)) - { + if (Display.Supports(DisplayFrameFormat.Numeric)) { NumericOutput = ValueOutput(nameof(NumericOutput)); } + + if (Display.Supports(DisplayFrameFormat.AlphaNumeric)) { + TextOutput = ValueOutput(nameof(TextOutput)); + } } } @@ -65,6 +73,12 @@ protected override void AssignArguments(Flow flow, DisplayUpdateEventArgs args) flow.SetValue(NumericOutput, BitConverter.ToSingle(args.DisplayFrameData.Data)); } } + + if (Display.Supports(DisplayFrameFormat.AlphaNumeric)) { + if (args.DisplayFrameData.Format == DisplayFrameFormat.AlphaNumeric) { + flow.SetValue(TextOutput, Encoding.UTF8.GetString(args.DisplayFrameData.Data)); + } + } } } } From 3a1be8388de433dccb4310846a2f5ba3b17d6b75 Mon Sep 17 00:00:00 2001 From: Jason Millard Date: Mon, 29 Aug 2022 22:39:04 -0400 Subject: [PATCH 7/9] misc: address code review comments. --- Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs | 6 +++--- Runtime/Nodes/Display/ClearDisplayUnit.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs b/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs index c71bb42..eeca908 100644 --- a/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs +++ b/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs @@ -64,7 +64,7 @@ public class VisualScriptingGamelogicEngine : MonoBehaviour, IGamelogicEngine, I public GamelogicEngineWire[] AvailableWires => Wires; public event EventHandler OnDisplaysRequested; - public event EventHandler OnDisplayClear; + public event EventHandler OnDisplayClear; public event EventHandler OnDisplayUpdateFrame; public event EventHandler OnLampChanged; @@ -156,9 +156,9 @@ public void OnInit(Player player, TableApi tableApi, BallManager ballManager) EventBus.Trigger(VisualScriptingEventNames.GleStartedEvent, EventArgs.Empty); } - public void DisplayClear(DisplayClearData data) + public void DisplayClear(string id) { - OnDisplayClear?.Invoke(this, data); + OnDisplayClear?.Invoke(this, id); } public void DisplayUpdateFrame(DisplayFrameData data) diff --git a/Runtime/Nodes/Display/ClearDisplayUnit.cs b/Runtime/Nodes/Display/ClearDisplayUnit.cs index a009aa7..52e6c39 100644 --- a/Runtime/Nodes/Display/ClearDisplayUnit.cs +++ b/Runtime/Nodes/Display/ClearDisplayUnit.cs @@ -51,7 +51,7 @@ private ControlOutput Process(Flow flow) } if (Display != null) { - VsGle.DisplayClear(new DisplayClearData(Display.Id)); + VsGle.DisplayClear(Display.Id); } return OutputTrigger; From 4efa0911d1a179a9fee82a305a362deef38aa53c Mon Sep 17 00:00:00 2001 From: Jason Millard Date: Tue, 30 Aug 2022 11:51:43 -0400 Subject: [PATCH 8/9] misc: More cleanup. Replace DisplayUpdateEvent with DisplayEvent. --- ...scriptor.cs => DisplayEventUnitDescriptor.cs} | 16 ++++++++-------- .../DisplayEventUnitDescriptor.cs.meta | 2 +- ...ntUnitWidget.cs => DisplayEventUnitWidget.cs} | 6 +++--- .../DisplayEventUnitWidget.cs.meta} | 2 +- Runtime/Gamelogic/VisualScriptingEventNames.cs | 2 +- .../Gamelogic/VisualScriptingGamelogicEngine.cs | 11 ++++++----- ...layUpdateEventUnit.cs => DisplayEventUnit.cs} | 10 +++++----- .../Nodes/Display/DisplayEventUnit.cs.meta | 2 +- 8 files changed, 26 insertions(+), 25 deletions(-) rename Editor/Descriptors/{DisplayUpdateEventUnitDescriptor.cs => DisplayEventUnitDescriptor.cs} (66%) rename Runtime/Nodes/Display/DisplayUpdateEventUnit.cs.meta => Editor/Descriptors/DisplayEventUnitDescriptor.cs.meta (83%) rename Editor/Widgets/{DisplayUpdateEventUnitWidget.cs => DisplayEventUnitWidget.cs} (76%) rename Editor/{Descriptors/DisplayUpdateEventUnitDescriptor.cs.meta => Widgets/DisplayEventUnitWidget.cs.meta} (83%) rename Runtime/Nodes/Display/{DisplayUpdateEventUnit.cs => DisplayEventUnit.cs} (84%) rename Editor/Widgets/DisplayUpdateEventUnitWidget.cs.meta => Runtime/Nodes/Display/DisplayEventUnit.cs.meta (83%) diff --git a/Editor/Descriptors/DisplayUpdateEventUnitDescriptor.cs b/Editor/Descriptors/DisplayEventUnitDescriptor.cs similarity index 66% rename from Editor/Descriptors/DisplayUpdateEventUnitDescriptor.cs rename to Editor/Descriptors/DisplayEventUnitDescriptor.cs index cc3bf5d..a7206fd 100644 --- a/Editor/Descriptors/DisplayUpdateEventUnitDescriptor.cs +++ b/Editor/Descriptors/DisplayEventUnitDescriptor.cs @@ -20,12 +20,12 @@ namespace VisualPinball.Unity.VisualScripting.Editor { - [Descriptor(typeof(DisplayUpdateEventUnit))] - public class DisplayUpdateEventUnitDescriptor : UnitDescriptor + [Descriptor(typeof(DisplayEventUnit))] + public class DisplayEventUnitDescriptor : UnitDescriptor { - public DisplayUpdateEventUnitDescriptor(DisplayUpdateEventUnit target) : base(target) { } + public DisplayEventUnitDescriptor(DisplayEventUnit target) : base(target) { } - protected override EditorTexture DefinedIcon() => EditorTexture.Single(Unity.Editor.Icons.DisplayUpdateEvent); + protected override EditorTexture DefinedIcon() => EditorTexture.Single(Unity.Editor.Icons.DisplayEvent); protected override void DefinedPort(IUnitPort port, UnitPortDescription desc) { @@ -33,11 +33,11 @@ protected override void DefinedPort(IUnitPort port, UnitPortDescription desc) switch (port.key) { - case nameof(DisplayUpdateEventUnit.NumericOutput): - desc.summary = "The numerical value of the display update."; + case nameof(DisplayEventUnit.NumericOutput): + desc.summary = "The numerical value of the display event."; break; - case nameof(DisplayUpdateEventUnit.TextOutput): - desc.summary = "The text value of the display update."; + case nameof(DisplayEventUnit.TextOutput): + desc.summary = "The text value of the display event."; break; } } diff --git a/Runtime/Nodes/Display/DisplayUpdateEventUnit.cs.meta b/Editor/Descriptors/DisplayEventUnitDescriptor.cs.meta similarity index 83% rename from Runtime/Nodes/Display/DisplayUpdateEventUnit.cs.meta rename to Editor/Descriptors/DisplayEventUnitDescriptor.cs.meta index e6dd9b4..088f0b3 100644 --- a/Runtime/Nodes/Display/DisplayUpdateEventUnit.cs.meta +++ b/Editor/Descriptors/DisplayEventUnitDescriptor.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: dfa19398c5fa3430696dd8f19ab85051 +guid: 60c0acc9f3d294135be71b5edc285b47 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Editor/Widgets/DisplayUpdateEventUnitWidget.cs b/Editor/Widgets/DisplayEventUnitWidget.cs similarity index 76% rename from Editor/Widgets/DisplayUpdateEventUnitWidget.cs rename to Editor/Widgets/DisplayEventUnitWidget.cs index 74267df..f0dd158 100644 --- a/Editor/Widgets/DisplayUpdateEventUnitWidget.cs +++ b/Editor/Widgets/DisplayEventUnitWidget.cs @@ -20,10 +20,10 @@ namespace VisualPinball.Unity.VisualScripting.Editor { - [Widget(typeof(DisplayUpdateEventUnit))] - public sealed class DisplayUpdateEventUnitWidget : GleUnitWidget + [Widget(typeof(DisplayEventUnit))] + public sealed class DisplayEventUnitWidget : GleUnitWidget { - public DisplayUpdateEventUnitWidget(FlowCanvas canvas, DisplayUpdateEventUnit unit) : base(canvas, unit) + public DisplayEventUnitWidget(FlowCanvas canvas, DisplayEventUnit unit) : base(canvas, unit) { } } diff --git a/Editor/Descriptors/DisplayUpdateEventUnitDescriptor.cs.meta b/Editor/Widgets/DisplayEventUnitWidget.cs.meta similarity index 83% rename from Editor/Descriptors/DisplayUpdateEventUnitDescriptor.cs.meta rename to Editor/Widgets/DisplayEventUnitWidget.cs.meta index 3a605ec..62d2850 100644 --- a/Editor/Descriptors/DisplayUpdateEventUnitDescriptor.cs.meta +++ b/Editor/Widgets/DisplayEventUnitWidget.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 399a09248e20e417d9032b7db6901408 +guid: 71c5c16c4dcbd449195a1195a75602f6 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Gamelogic/VisualScriptingEventNames.cs b/Runtime/Gamelogic/VisualScriptingEventNames.cs index 4f4eeb6..a003713 100644 --- a/Runtime/Gamelogic/VisualScriptingEventNames.cs +++ b/Runtime/Gamelogic/VisualScriptingEventNames.cs @@ -22,7 +22,7 @@ public static class VisualScriptingEventNames public const string LampEvent = "LampEvent"; public const string SwitchEvent = "SwitchEvent"; public const string CoilEvent = "CoilEvent"; - public const string DisplayUpdateEvent = "DisplayUpdateEvent"; + public const string DisplayEvent = "DisplayEvent"; public const string CurrentPlayerChanged = "CurrentPlayerChanged"; public const string PlayerVariableChanged = "PlayerVariableChanged"; public const string TableVariableChanged = "TableVariableChanged"; diff --git a/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs b/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs index eeca908..2a645c9 100644 --- a/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs +++ b/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs @@ -66,6 +66,7 @@ public class VisualScriptingGamelogicEngine : MonoBehaviour, IGamelogicEngine, I public event EventHandler OnDisplaysRequested; public event EventHandler OnDisplayClear; public event EventHandler OnDisplayUpdateFrame; + public event EventHandler OnDisplayUpdated; public event EventHandler OnLampChanged; public event EventHandler OnLampsChanged; @@ -166,11 +167,6 @@ public void DisplayUpdateFrame(DisplayFrameData data) OnDisplayUpdateFrame?.Invoke(this, data); } - public void DisplayUpdateEvent(DisplayFrameData data) - { - EventBus.Trigger(VisualScriptingEventNames.DisplayUpdateEvent, new DisplayUpdateEventArgs(data)); - } - public void Switch(string id, bool isClosed) { var args = new SwitchEventArgs2(id, isClosed); @@ -190,6 +186,11 @@ public void SetLamp(string id, float value, bool isCoil = false, LampSource sour OnLampChanged?.Invoke(this, new LampEventArgs(id, value, isCoil, source)); } + public void SetDisplay(DisplayFrameData data) + { + EventBus.Trigger(VisualScriptingEventNames.DisplayEvent, new DisplayEventArgs(data)); + } + public LampState GetLamp(string id) { return _player.LampStatuses.ContainsKey(id) ? _player.LampStatuses[id] : LampState.Default; diff --git a/Runtime/Nodes/Display/DisplayUpdateEventUnit.cs b/Runtime/Nodes/Display/DisplayEventUnit.cs similarity index 84% rename from Runtime/Nodes/Display/DisplayUpdateEventUnit.cs rename to Runtime/Nodes/Display/DisplayEventUnit.cs index fda737b..a139da4 100644 --- a/Runtime/Nodes/Display/DisplayUpdateEventUnit.cs +++ b/Runtime/Nodes/Display/DisplayEventUnit.cs @@ -23,10 +23,10 @@ namespace VisualPinball.Unity.VisualScripting { - [UnitTitle("On Display Update")] + [UnitTitle("On Display Changed")] [UnitSurtitle("Gamelogic Engine")] [UnitCategory("Events\\Visual Pinball")] - public class DisplayUpdateEventUnit : GleEventUnit + public class DisplayEventUnit : GleEventUnit { [Serialize] [Inspectable] @@ -44,7 +44,7 @@ public class DisplayUpdateEventUnit : GleEventUnit [DoNotSerialize] protected override bool register => true; - public override EventHook GetHook(GraphReference reference) => new EventHook(VisualScriptingEventNames.DisplayUpdateEvent); + public override EventHook GetHook(GraphReference reference) => new EventHook(VisualScriptingEventNames.DisplayEvent); protected override void Definition() { @@ -61,12 +61,12 @@ protected override void Definition() } } - protected override bool ShouldTrigger(Flow flow, DisplayUpdateEventArgs args) + protected override bool ShouldTrigger(Flow flow, DisplayEventArgs args) { return Display != null && Display.Id.Equals(args.DisplayFrameData.Id); } - protected override void AssignArguments(Flow flow, DisplayUpdateEventArgs args) + protected override void AssignArguments(Flow flow, DisplayEventArgs args) { if (Display.Supports(DisplayFrameFormat.Numeric)) { if (args.DisplayFrameData.Format == DisplayFrameFormat.Numeric) { diff --git a/Editor/Widgets/DisplayUpdateEventUnitWidget.cs.meta b/Runtime/Nodes/Display/DisplayEventUnit.cs.meta similarity index 83% rename from Editor/Widgets/DisplayUpdateEventUnitWidget.cs.meta rename to Runtime/Nodes/Display/DisplayEventUnit.cs.meta index 1634202..c7579a2 100644 --- a/Editor/Widgets/DisplayUpdateEventUnitWidget.cs.meta +++ b/Runtime/Nodes/Display/DisplayEventUnit.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 23997501720e84b8ebc9d1d149e4537d +guid: 3b573073ca33b4faa8898ea67c052243 MonoImporter: externalObjects: {} serializedVersion: 2 From 3d21e4ec5c94ce5087716f713cdb126207632f9f Mon Sep 17 00:00:00 2001 From: freezy Date: Fri, 2 Sep 2022 23:27:17 +0200 Subject: [PATCH 9/9] refactor: Update naming from main. --- Runtime/Gamelogic/VisualScriptingEventNames.cs | 2 +- Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs | 4 ++-- Runtime/Nodes/Display/DisplayEventUnit.cs | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Runtime/Gamelogic/VisualScriptingEventNames.cs b/Runtime/Gamelogic/VisualScriptingEventNames.cs index a003713..7b59c6d 100644 --- a/Runtime/Gamelogic/VisualScriptingEventNames.cs +++ b/Runtime/Gamelogic/VisualScriptingEventNames.cs @@ -22,7 +22,7 @@ public static class VisualScriptingEventNames public const string LampEvent = "LampEvent"; public const string SwitchEvent = "SwitchEvent"; public const string CoilEvent = "CoilEvent"; - public const string DisplayEvent = "DisplayEvent"; + public const string DisplayChangedEvent = "DisplayChangedEvent"; public const string CurrentPlayerChanged = "CurrentPlayerChanged"; public const string PlayerVariableChanged = "PlayerVariableChanged"; public const string TableVariableChanged = "TableVariableChanged"; diff --git a/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs b/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs index 2a645c9..6fc794b 100644 --- a/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs +++ b/Runtime/Gamelogic/VisualScriptingGamelogicEngine.cs @@ -186,9 +186,9 @@ public void SetLamp(string id, float value, bool isCoil = false, LampSource sour OnLampChanged?.Invoke(this, new LampEventArgs(id, value, isCoil, source)); } - public void SetDisplay(DisplayFrameData data) + public void DisplayChanged(DisplayFrameData data) { - EventBus.Trigger(VisualScriptingEventNames.DisplayEvent, new DisplayEventArgs(data)); + EventBus.Trigger(VisualScriptingEventNames.DisplayChangedEvent, new DisplayChangedEventArgs(data)); } public LampState GetLamp(string id) diff --git a/Runtime/Nodes/Display/DisplayEventUnit.cs b/Runtime/Nodes/Display/DisplayEventUnit.cs index a139da4..00b5945 100644 --- a/Runtime/Nodes/Display/DisplayEventUnit.cs +++ b/Runtime/Nodes/Display/DisplayEventUnit.cs @@ -26,7 +26,7 @@ namespace VisualPinball.Unity.VisualScripting [UnitTitle("On Display Changed")] [UnitSurtitle("Gamelogic Engine")] [UnitCategory("Events\\Visual Pinball")] - public class DisplayEventUnit : GleEventUnit + public class DisplayEventUnit : GleEventUnit { [Serialize] [Inspectable] @@ -44,7 +44,7 @@ public class DisplayEventUnit : GleEventUnit [DoNotSerialize] protected override bool register => true; - public override EventHook GetHook(GraphReference reference) => new EventHook(VisualScriptingEventNames.DisplayEvent); + public override EventHook GetHook(GraphReference reference) => new(VisualScriptingEventNames.DisplayChangedEvent); protected override void Definition() { @@ -61,12 +61,12 @@ protected override void Definition() } } - protected override bool ShouldTrigger(Flow flow, DisplayEventArgs args) + protected override bool ShouldTrigger(Flow flow, DisplayChangedEventArgs args) { return Display != null && Display.Id.Equals(args.DisplayFrameData.Id); } - protected override void AssignArguments(Flow flow, DisplayEventArgs args) + protected override void AssignArguments(Flow flow, DisplayChangedEventArgs args) { if (Display.Supports(DisplayFrameFormat.Numeric)) { if (args.DisplayFrameData.Format == DisplayFrameFormat.Numeric) {