From 5cf250b295eed950279a1cfabf428bb0e55cf678 Mon Sep 17 00:00:00 2001 From: kziolkowski Date: Tue, 21 Oct 2025 12:39:17 +0200 Subject: [PATCH] :sparkles: Added randomizer class for certain types of EventResources --- .../Low Code/Randomizer/VariantRandomizer.cs | 54 +++++++++++++++++++ .../Randomizer/VariantRandomizer.cs.uid | 1 + 2 files changed, 55 insertions(+) create mode 100644 scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs create mode 100644 scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs.uid diff --git a/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs b/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs new file mode 100644 index 0000000..959fa1c --- /dev/null +++ b/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs @@ -0,0 +1,54 @@ +using System; +using Babushka.scripts.CSharp.Low_Code.Events; +using Godot; +using Microsoft.VisualBasic; + +namespace Babushka.scripts.CSharp.Low_Code.Randomizer; + +/// +/// A class to randomize the payload value of select types of s. +/// +public partial class VariantRandomizer : Node +{ + /// + /// The event resource to work on. + /// + [Export] public EventResource _eventResource; + + /// + /// Sets the payload of a randomizable event resource to a random value. + /// + public void RandomizeEventResource() + { + switch (_eventResource.Payload.VariantType) + { + case Variant.Type.Color: + _eventResource.Payload= GetRandomColor(); + break; + case Variant.Type.Int: + _eventResource.Payload= GetRandomInt(); + break; + case Variant.Type.Float: + _eventResource.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(); + } +} \ No newline at end of file diff --git a/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs.uid b/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs.uid new file mode 100644 index 0000000..ece8168 --- /dev/null +++ b/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs.uid @@ -0,0 +1 @@ +uid://co1b320qemg1i