parent
080ebaae47
commit
c96e6da78e
@ -1,9 +0,0 @@
|
|||||||
[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://dc7e13hq47uma"]
|
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Low Code/Events/EventResource.cs" id="1_ufwo5"]
|
|
||||||
|
|
||||||
[resource]
|
|
||||||
script = ExtResource("1_ufwo5")
|
|
||||||
_showLog = true
|
|
||||||
Payload = Color(0.84002423, 0.44197178, 0.5653889, 1)
|
|
||||||
metadata/_custom_type_script = "uid://ci3t5mvnopntg"
|
|
||||||
@ -1,9 +1,7 @@
|
|||||||
[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://bgfxakxxfmoxs"]
|
[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://bfw1dfd0r8avr"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Low Code/Events/EventResource.cs" id="1_dd3u7"]
|
[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Low Code/Events/EventResource.cs" id="1_yg3mc"]
|
||||||
|
|
||||||
[resource]
|
[resource]
|
||||||
script = ExtResource("1_dd3u7")
|
script = ExtResource("1_yg3mc")
|
||||||
_showLog = true
|
|
||||||
Payload = "This is a test."
|
|
||||||
metadata/_custom_type_script = "uid://ci3t5mvnopntg"
|
metadata/_custom_type_script = "uid://ci3t5mvnopntg"
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://boijwlxmth68v"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Low Code/Events/EventResource.cs" id="1_vfqv2"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("1_vfqv2")
|
||||||
|
metadata/_custom_type_script = "uid://ci3t5mvnopntg"
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
[gd_resource type="Resource" script_class="VariableResource" load_steps=2 format=3 uid="uid://dpnre2bn041jm"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://dtvx2cakx0bey" path="res://scripts/CSharp/Low Code/Variables/VariableResource.cs" id="1_h8big"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("1_h8big")
|
||||||
|
Payload = Color(0, 0, 0, 1)
|
||||||
|
metadata/_custom_type_script = "uid://dtvx2cakx0bey"
|
||||||
@ -0,0 +1,69 @@
|
|||||||
|
using Godot;
|
||||||
|
using Godot.Collections;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.Low_Code.Variables;
|
||||||
|
|
||||||
|
public partial class VariableListener : Node
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The event resource to listen to.
|
||||||
|
/// </summary>
|
||||||
|
[Export] private Array<VariableResource> _variableResources;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Log to console when this event is being raised.
|
||||||
|
/// </summary>
|
||||||
|
[Export] private bool _showLog;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A signal that is triggered when the payload of one of the <see cref="EventListener._eventResources"/> changed.
|
||||||
|
/// </summary>
|
||||||
|
[Signal] public delegate void PayloadChangedEventHandler(Variant payload, Variant oldPayload);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A signal that is triggered when the payload of one of the <see cref="EventListener._eventResources"/> changed.
|
||||||
|
/// </summary>
|
||||||
|
[Signal] public delegate void NewEventPayloadEventHandler(Variant payload);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A signal that is triggered when the payload of one of the <see cref="EventListener._eventResources"/> changed.
|
||||||
|
/// </summary>
|
||||||
|
[Signal] public delegate void OldEventPayloadEventHandler(Variant oldPayload);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Subscribes to all <see cref="EventResource"/>s present in the <see cref="_eventResources"/> array.
|
||||||
|
/// <inheritdoc cref="Node._EnterTree"/>
|
||||||
|
/// </summary>
|
||||||
|
public override void _EnterTree()
|
||||||
|
{
|
||||||
|
foreach (var resource in _variableResources)
|
||||||
|
{
|
||||||
|
resource.RegisterListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Unsubscribes from all <see cref="EventResource"/>s present in the <see cref="_eventResources"/> array.
|
||||||
|
/// <inheritdoc cref="Node._ExitTree"/>
|
||||||
|
/// </summary>
|
||||||
|
public override void _ExitTree()
|
||||||
|
{
|
||||||
|
foreach (var variableResource in _variableResources)
|
||||||
|
{
|
||||||
|
variableResource.UnregisterListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called by a <see cref="EventResource"/>s from the <see cref="_eventResources"/> array.
|
||||||
|
/// Propagates the event by emitting <see cref="EventRaised"/> signal.
|
||||||
|
/// </summary>
|
||||||
|
public void EventPayloadChanged(Variant payload, Variant oldPayload)
|
||||||
|
{
|
||||||
|
if(_showLog)
|
||||||
|
GD.Print($"Calling Event Payload Changed Signals on: " + Name);
|
||||||
|
EmitSignal(SignalName.PayloadChanged, payload, oldPayload);
|
||||||
|
EmitSignal(SignalName.NewEventPayload, payload);
|
||||||
|
EmitSignal(SignalName.OldEventPayload, oldPayload);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
uid://pqemey80frcq
|
||||||
@ -0,0 +1,69 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Babushka.scripts.CSharp.Low_Code.Variables;
|
||||||
|
|
||||||
|
[GlobalClass]
|
||||||
|
public partial class VariableResource : Resource
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Log into console when this event resource is adding or removing listeners, and when it's raised.
|
||||||
|
/// </summary>
|
||||||
|
[Export] private bool _showLog;
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
public Variant Payload
|
||||||
|
{
|
||||||
|
get { return _payload; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (!_payload.Equals(value))
|
||||||
|
{
|
||||||
|
_lastPayload = _payload;
|
||||||
|
_payload = value;
|
||||||
|
ValueChangeHandler();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Variant _payload;
|
||||||
|
private Variant _lastPayload;
|
||||||
|
|
||||||
|
private List<VariableListener> _varListeners = new ();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds an EventListener to the calling list for this event.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="listener"></param>
|
||||||
|
public void RegisterListener(VariableListener listener)
|
||||||
|
{
|
||||||
|
if(_showLog)
|
||||||
|
GD.Print("Registering listener " + listener);
|
||||||
|
_varListeners.Add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes an Eventlistener from the calling list for this event.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="listener"></param>
|
||||||
|
public void UnregisterListener(VariableListener listener)
|
||||||
|
{
|
||||||
|
if(_showLog)
|
||||||
|
GD.Print("Unregistering listener " + listener);
|
||||||
|
_varListeners.Remove(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when the Payload value changed.
|
||||||
|
/// </summary>
|
||||||
|
public void ValueChangeHandler()
|
||||||
|
{
|
||||||
|
if(_showLog)
|
||||||
|
GD.Print($"Event payload changed from {_lastPayload} to {_payload} on event resource: " + ResourcePath.GetFile().TrimSuffix(".tres"));
|
||||||
|
|
||||||
|
foreach (var eventListener in _varListeners)
|
||||||
|
{
|
||||||
|
eventListener.EventPayloadChanged(_payload, _lastPayload);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
uid://dtvx2cakx0bey
|
||||||
Loading…
Reference in new issue