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