-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrameRandom.cs
More file actions
21 lines (18 loc) · 805 Bytes
/
Copy pathFrameRandom.cs
File metadata and controls
21 lines (18 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using Godot;
using MaxGodotFrame.Random;
namespace MaxGodotFrame;
/// <summary>Variant-safe API for C# and GDScript. State uses PackedByteArray, not unsigned Variants.</summary>
[GlobalClass]
public partial class FrameRandom : RefCounted
{
private readonly RandomStream stream = new(0);
public void Reseed(long seed) => stream.Reseed(unchecked((ulong)seed));
public int NextInt(int exclusiveMaximum) => stream.NextInt(exclusiveMaximum);
public byte[] ExportState() => stream.ExportState();
public string GetAlgorithm() => RandomStream.Algorithm;
public bool RestoreState(string algorithm, byte[] state)
{
try { stream.ImportState(algorithm, state); return true; }
catch (System.ArgumentException error) { GD.PushError(error.Message); return false; }
}
}