You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Babushka/scripts/CSharp/Low Code/Randomizer/VariantRandomizer.cs

55 lines
1.5 KiB

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();
}
}