Added randomizer class for certain types of EventResources

pull/19/head
kziolkowski 3 months ago
parent ef56f79d5c
commit 5cf250b295

@ -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;
/// <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 EventResource _eventResource;
/// <summary>
/// Sets the payload of a randomizable event resource to a random value.
/// </summary>
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();
}
}
Loading…
Cancel
Save