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.
54 lines
1.4 KiB
54 lines
1.4 KiB
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();
|
|
}
|
|
} |