Merge branch 'develop' into feature/detection_cross

# Conflicts:
#	addons/dialogic/vesna_style.tres
#	dialog/NPC_narrative.tres
#	scenes/Babushka_scene_indoor_vesnas_room.tscn
This commit is contained in:
2025-10-29 14:01:55 +01:00
29 changed files with 593 additions and 43 deletions
@@ -0,0 +1,62 @@
using Godot;
using Godot.Collections;
namespace Babushka.scripts.CSharp.Low_Code.Events;
/// <summary>
/// Listens to an <see cref="EventResource"/> as long as this node is in the tree (i.e., during playtime).
/// </summary>
public partial class EventListener : Node
{
/// <summary>
/// The event resource to listen to.
/// </summary>
[Export] private Array<EventResource> _eventResources;
/// <summary>
/// Log to console when this event is being raised.
/// </summary>
[Export] private bool _showLog;
/// <summary>
/// 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>
/// 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 eventRes in _eventResources)
{
eventRes.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 eventRes in _eventResources)
{
eventRes.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 EventInvoked()
{
if(_showLog)
GD.Print("Event Raised on: " + Name);
EmitSignal(SignalName.EventRaised);
}
}
@@ -0,0 +1 @@
uid://bc6uaaxsx5k5p
@@ -0,0 +1,26 @@
using Godot;
using Godot.Collections;
namespace Babushka.scripts.CSharp.Low_Code.Events;
/// <summary>
/// Raises one or more <see cref="EventResource"/>s from the scene.
/// </summary>
public partial class EventRaiser : Node
{
/// <summary>
/// The <see cref="EventResource"/>s to call
/// </summary>
[Export] Array<EventResource> _eventResources;
/// <summary>
/// Raises all <see cref="EventResource"/>s present in <see cref="_eventResources"/>.
/// </summary>
public void RaiseEvents()
{
foreach (var eventRes in _eventResources)
{
eventRes.Raise();
}
}
}
@@ -0,0 +1 @@
uid://b5dotkx17gvxg
@@ -0,0 +1,65 @@
using System.Collections.Generic;
using Godot;
namespace Babushka.scripts.CSharp.Low_Code.Events;
/// <summary>
/// Represents an event in the project space.
/// Can be called by <see cref="EventRaiser"/> and subscribed to by <see cref="EventListener"/>.
/// </summary>
[GlobalClass] [Tool]
public partial class EventResource : Resource
{
/// <summary>
/// Log into console when this event resource is adding or removing listeners, and when it's raised.
/// </summary>
[Export] private bool _showLog;
/// <summary>
/// Raise-Button Call with Editor Export for easier debugging.
/// Beware: This will only work with custom event listeners that register at edit-time.
/// Standard <see cref="EventListeners"/> register and deregister during playtime.
/// </summary>
[ExportToolButton("Raise")] Callable _raiseAction => Callable.From(Raise);
private List<EventListener> _eventListeners = new ();
/// <summary>
/// Adds an EventListener to the calling list for this event.
/// </summary>
/// <param name="listener"></param>
public void RegisterListener(EventListener listener)
{
if(_showLog)
GD.Print("Registering listener " + listener);
_eventListeners.Add(listener);
}
/// <summary>
/// Removes an Eventlistener from the calling list for this event.
/// </summary>
/// <param name="listener"></param>
public void UnregisterListener(EventListener listener)
{
if(_showLog)
GD.Print("Unregistering listener " + listener);
_eventListeners.Remove(listener);
}
/// <summary>
/// Raises this event on all current listeners.
/// </summary>
public void Raise()
{
if(_showLog)
GD.Print("Raising event: " + ResourcePath.GetFile().TrimSuffix(".tres"));
foreach (var eventListener in _eventListeners)
{
eventListener.EventInvoked();
}
}
}
@@ -0,0 +1 @@
uid://ci3t5mvnopntg
@@ -0,0 +1,55 @@
using System;
using Babushka.scripts.CSharp.Low_Code.Events;
using Babushka.scripts.CSharp.Low_Code.Variables;
using Godot;
namespace Babushka.scripts.CSharp.Low_Code.Randomizer;
/// <summary>
/// A class to randomize the payload value of select types of <see cref="EventResource"/>s.
/// </summary>
public partial class VariantRandomizer : Node
{
/// <summary>
/// The event resource to work on.
/// </summary>
[Export] public VariableResource _variableResource;
/// <summary>
/// Sets the payload of a randomizable event resource to a random value.
/// </summary>
public void RandomizeEventResource()
{
switch (_variableResource.Payload.VariantType)
{
case Variant.Type.Color:
_variableResource.Payload= GetRandomColor();
break;
case Variant.Type.Int:
_variableResource.Payload= GetRandomInt();
break;
case Variant.Type.Float:
_variableResource.Payload= GetRandomFloat();
break;
}
}
private Color GetRandomColor()
{
Random rand = new Random();
return new Color(rand.NextSingle(), rand.NextSingle(), rand.NextSingle(), 1.0f);
}
private int GetRandomInt()
{
Random rand = new Random();
return rand.Next();
}
private float GetRandomFloat()
{
Random rand = new Random();
return rand.NextSingle();
}
}
@@ -0,0 +1 @@
uid://co1b320qemg1i
@@ -0,0 +1,30 @@
using Godot;
namespace Babushka.scripts.CSharp.Low_Code.Variables;
/// <summary>
/// An active getter component for calling the payload value of a <see cref="VariableResource"/>.
/// </summary>
public partial class VariableGetter : Node
{
/// <summary>
/// The event resource to listen to.
/// </summary>
[Export] private VariableResource _variableResource;
/// <summary>
/// A signal that is triggered when the payload of one of the <see cref="VariableResource"/> is called.
/// </summary>
[Signal] public delegate void GetPayloadEventHandler(Variant payload);
/// <summary>
/// Gets the Variant payload of a VariableResource on demand.
/// </summary>
/// <returns></returns>
public Variant Get()
{
Variant payload = _variableResource.Payload;
EmitSignal(SignalName.GetPayload, payload);
return payload;
}
}
@@ -0,0 +1 @@
uid://34okoih6wkmu
@@ -0,0 +1,72 @@
using Godot;
using Godot.Collections;
namespace Babushka.scripts.CSharp.Low_Code.Variables;
/// <summary>
/// A passive Node that listens to valuechange-events on a <see cref="VariableResource"/>.
/// </summary>
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,76 @@
using System.Collections.Generic;
using Godot;
namespace Babushka.scripts.CSharp.Low_Code.Variables;
/// <summary>
/// A <see cref="Variant"/> value wrapper resource used to store state values and notify ingame scripts.
/// </summary>
[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;
/// <summary>
/// Public property that manages the access to the payload.
/// Triggers the ValueChange-function when set to a new value.
/// </summary>
[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
@@ -0,0 +1,22 @@
using Godot;
namespace Babushka.scripts.CSharp.Low_Code.Variables.VariantValueChanger;
public partial class VariantIncrementor : Node
{
[Export] private VariableResource _resource;
public void Increment()
{
int integerValue = _resource.Payload.AsInt32();
integerValue++;
_resource.Payload = integerValue;
}
public void Decrement()
{
int integerValue = _resource.Payload.AsInt32();
integerValue--;
_resource.Payload = integerValue;
}
}
@@ -0,0 +1 @@
uid://d1y23ytkt1w2j
@@ -0,0 +1,16 @@
using Godot;
namespace Babushka.scripts.CSharp.Low_Code.Variables.VariantValueChanger;
public partial class VariantToString : Node
{
[Export] private VariableResource _resource;
[Signal] public delegate void PayloadAsStringEventHandler(string payloadAsString);
public void ConvertToString()
{
EmitSignal(SignalName.PayloadAsString, _resource.Payload.AsString());
}
}
@@ -0,0 +1 @@
uid://dco37q6ddm8kv