# Conflicts: # addons/dialogic/vesna_style.tres # dialog/NPC_narrative.tres # scenes/Babushka_scene_indoor_vesnas_room.tscnpull/21/head
commit
1f13f3ea51
@ -0,0 +1,7 @@
|
|||||||
|
[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_yg3mc"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("1_yg3mc")
|
||||||
|
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,8 @@
|
|||||||
|
[gd_resource type="Resource" script_class="VariableResource" load_steps=2 format=3 uid="uid://c6iw30ydc0qa0"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://dtvx2cakx0bey" path="res://scripts/CSharp/Low Code/Variables/VariableResource.cs" id="1_sbnhb"]
|
||||||
|
|
||||||
|
[resource]
|
||||||
|
script = ExtResource("1_sbnhb")
|
||||||
|
Payload = 0
|
||||||
|
metadata/_custom_type_script = "uid://dtvx2cakx0bey"
|
||||||
@ -0,0 +1,101 @@
|
|||||||
|
[gd_scene load_steps=10 format=3 uid="uid://6n3p3psmxovj"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://pqemey80frcq" path="res://scripts/CSharp/Low Code/Variables/VariableListener.cs" id="1_4h3ry"]
|
||||||
|
[ext_resource type="Script" uid="uid://bc6uaaxsx5k5p" path="res://scripts/CSharp/Low Code/Events/EventListener.cs" id="1_w5ykc"]
|
||||||
|
[ext_resource type="Resource" uid="uid://dpnre2bn041jm" path="res://resources/low code/test/var_ColorTestValue.tres" id="2_bj4kf"]
|
||||||
|
[ext_resource type="Script" uid="uid://b5dotkx17gvxg" path="res://scripts/CSharp/Low Code/Events/EventRaiser.cs" id="3_bj4kf"]
|
||||||
|
[ext_resource type="Resource" uid="uid://boijwlxmth68v" path="res://resources/low code/test/event_textLabelClicked.tres" id="5_4h3ry"]
|
||||||
|
[ext_resource type="Script" uid="uid://co1b320qemg1i" path="res://scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs" id="5_nm8dh"]
|
||||||
|
[ext_resource type="Script" uid="uid://dco37q6ddm8kv" path="res://scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantToString.cs" id="7_nm8dh"]
|
||||||
|
[ext_resource type="Resource" uid="uid://c6iw30ydc0qa0" path="res://resources/low code/test/var_Counter.tres" id="9_44nfx"]
|
||||||
|
[ext_resource type="Script" uid="uid://d1y23ytkt1w2j" path="res://scripts/CSharp/Low Code/Variables/VariantValueChanger/VariantIncrementor.cs" id="10_p6d2q"]
|
||||||
|
|
||||||
|
[node name="EventTest" type="Node2D"]
|
||||||
|
|
||||||
|
[node name="Control" type="Control" parent="."]
|
||||||
|
layout_mode = 3
|
||||||
|
anchors_preset = 0
|
||||||
|
offset_top = -1.0
|
||||||
|
offset_right = 513.0
|
||||||
|
offset_bottom = 329.0
|
||||||
|
|
||||||
|
[node name="ColorRect" type="ColorRect" parent="Control"]
|
||||||
|
layout_mode = 0
|
||||||
|
offset_right = 178.0
|
||||||
|
offset_bottom = 145.0
|
||||||
|
script = ExtResource("1_4h3ry")
|
||||||
|
_variableResources = Array[Object]([ExtResource("2_bj4kf")])
|
||||||
|
|
||||||
|
[node name="ChangeColorButton" type="Button" parent="Control"]
|
||||||
|
layout_mode = 0
|
||||||
|
offset_top = 148.0
|
||||||
|
offset_right = 112.0
|
||||||
|
offset_bottom = 179.0
|
||||||
|
text = "Change Color
|
||||||
|
"
|
||||||
|
script = ExtResource("5_nm8dh")
|
||||||
|
_variableResource = ExtResource("2_bj4kf")
|
||||||
|
|
||||||
|
[node name="LabelTextEventButton" type="Button" parent="Control"]
|
||||||
|
layout_mode = 0
|
||||||
|
offset_left = 194.0
|
||||||
|
offset_top = 148.0
|
||||||
|
offset_right = 351.0
|
||||||
|
offset_bottom = 179.0
|
||||||
|
text = "Show Event Text
|
||||||
|
"
|
||||||
|
script = ExtResource("3_bj4kf")
|
||||||
|
_eventResources = Array[Object]([ExtResource("5_4h3ry")])
|
||||||
|
|
||||||
|
[node name="TestLabel" type="Label" parent="Control"]
|
||||||
|
visible = false
|
||||||
|
layout_mode = 0
|
||||||
|
offset_left = 237.0
|
||||||
|
offset_top = 54.0
|
||||||
|
offset_right = 277.0
|
||||||
|
offset_bottom = 77.0
|
||||||
|
text = "[Dieser Text erscheint,
|
||||||
|
wenn das Event richtig
|
||||||
|
verknüpft ist]"
|
||||||
|
script = ExtResource("1_w5ykc")
|
||||||
|
_eventResources = Array[Object]([ExtResource("5_4h3ry")])
|
||||||
|
|
||||||
|
[node name="LabelTextEventButton2" type="Button" parent="Control"]
|
||||||
|
layout_mode = 0
|
||||||
|
offset_left = 361.0
|
||||||
|
offset_top = 148.0
|
||||||
|
offset_right = 518.0
|
||||||
|
offset_bottom = 179.0
|
||||||
|
text = "get current number
|
||||||
|
"
|
||||||
|
|
||||||
|
[node name="TestLabel2" type="Label" parent="Control"]
|
||||||
|
layout_mode = 0
|
||||||
|
offset_left = 432.0
|
||||||
|
offset_top = 117.0
|
||||||
|
offset_right = 472.0
|
||||||
|
offset_bottom = 166.0
|
||||||
|
text = "0
|
||||||
|
"
|
||||||
|
script = ExtResource("7_nm8dh")
|
||||||
|
_resource = ExtResource("9_44nfx")
|
||||||
|
|
||||||
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
|
position = Vector2(239, 110)
|
||||||
|
zoom = Vector2(3.4, 3.4)
|
||||||
|
|
||||||
|
[node name="Timer" type="Timer" parent="."]
|
||||||
|
wait_time = 0.5
|
||||||
|
autostart = true
|
||||||
|
|
||||||
|
[node name="CountLoop" type="Node" parent="Timer"]
|
||||||
|
script = ExtResource("10_p6d2q")
|
||||||
|
_resource = ExtResource("9_44nfx")
|
||||||
|
|
||||||
|
[connection signal="NewEventPayload" from="Control/ColorRect" to="Control/ColorRect" method="set_color"]
|
||||||
|
[connection signal="pressed" from="Control/ChangeColorButton" to="Control/ChangeColorButton" method="RandomizeEventResource"]
|
||||||
|
[connection signal="pressed" from="Control/LabelTextEventButton" to="Control/LabelTextEventButton" method="RaiseEvents"]
|
||||||
|
[connection signal="EventRaised" from="Control/TestLabel" to="Control/TestLabel" method="show"]
|
||||||
|
[connection signal="pressed" from="Control/LabelTextEventButton2" to="Control/TestLabel2" method="ConvertToString"]
|
||||||
|
[connection signal="PayloadAsString" from="Control/TestLabel2" to="Control/TestLabel2" method="set_text"]
|
||||||
|
[connection signal="timeout" from="Timer" to="Timer/CountLoop" method="Increment"]
|
||||||
@ -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
|
||||||
Loading…
Reference in new issue