feature/events #19

Merged
Jonathan merged 10 commits from feature/events into develop 2025-10-28 21:12:46 +01:00
3 changed files with 69 additions and 11 deletions
Showing only changes of commit ef56f79d5c - Show all commits
-8
View File
@@ -1,8 +0,0 @@
[gd_resource type="Resource" script_class="EventResource" load_steps=2 format=3 uid="uid://bgfxakxxfmoxs"]
[ext_resource type="Script" uid="uid://ci3t5mvnopntg" path="res://scripts/CSharp/Low Code/Events/EventResource.cs" id="1_jm77s"]
[resource]
script = ExtResource("1_jm77s")
_showLog = true
metadata/_custom_type_script = "uid://ci3t5mvnopntg"
@@ -1,4 +1,3 @@
using System;
using Godot;
using Godot.Collections;
@@ -23,6 +22,26 @@ public partial class EventListener : Node
/// The signal that is triggered when this listener is called by one of the <see cref="EventListener._eventResources"/>.
/// </summary>
[Signal] public delegate void EventRaisedEventHandler();
/// <summary>
/// The signal that is triggered when this listener is called by one of the <see cref="EventListener._eventResources"/>.
/// </summary>
[Signal] public delegate void EventRaisedWithPayloadEventHandler(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 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>
@@ -53,10 +72,24 @@ public partial class EventListener : Node
/// 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 Invoke()
public void EventInvoked(Variant payload)
{
if(_showLog)
GD.Print("Event Raised on: " + Name);
Outdated
Review

Debug logs bitte noch entfernen

Debug logs bitte noch entfernen
Outdated
Review

An sich stimme ich dir zu, aber diese habe ich mit Absicht drin gelassen und hinter einem bool versteckt, weil ich die Erfahrung gemacht habe, dass man diese Debugs relativ häufig braucht, wenn man mit Events und Variablen arbeitet.

An sich stimme ich dir zu, aber diese habe ich mit Absicht drin gelassen und hinter einem bool versteckt, weil ich die Erfahrung gemacht habe, dass man diese Debugs relativ häufig braucht, wenn man mit Events und Variablen arbeitet.
EmitSignal(SignalName.EventRaised);
EmitSignal(SignalName.EventRaisedWithPayload, payload);
}
/// <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);
kziolkowski marked this conversation as resolved Outdated
Outdated
Review

Debug logs bitte noch entfernen

Debug logs bitte noch entfernen
EmitSignal(SignalName.PayloadChanged, payload, oldPayload);
EmitSignal(SignalName.NewEventPayload, payload);
EmitSignal(SignalName.OldEventPayload, oldPayload);
}
}
@@ -14,6 +14,24 @@ public partial class EventResource : Resource
/// 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;
/// <summary>
/// Raise-Button Call with Editor Export for easier debugging.
@@ -56,7 +74,22 @@ public partial class EventResource : Resource
foreach (var eventListener in _eventListeners)
{
eventListener.Invoke();
eventListener.EventInvoked(_payload);
}
}
/// <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 _eventListeners)
{
eventListener.EventPayloadChanged(_payload, _lastPayload);
}
}
}