update forge
This commit is contained in:
@@ -18,7 +18,7 @@ public class ForgeRandom : IRandom, IDisposable
|
||||
|
||||
public void NextBytes(byte[] buffer)
|
||||
{
|
||||
for (var i = 0; i < buffer.Length; i++)
|
||||
for (int i = 0; i < buffer.Length; i++)
|
||||
{
|
||||
buffer[i] = (byte)_randomNumberGenerator.RandiRange(0, 255);
|
||||
}
|
||||
@@ -26,13 +26,25 @@ public class ForgeRandom : IRandom, IDisposable
|
||||
|
||||
public void NextBytes(Span<byte> buffer)
|
||||
{
|
||||
for (var i = 0; i < buffer.Length; i++)
|
||||
for (int i = 0; i < buffer.Length; i++)
|
||||
{
|
||||
buffer[i] = (byte)_randomNumberGenerator.RandiRange(0, 255);
|
||||
}
|
||||
}
|
||||
|
||||
public double NextDouble()
|
||||
{
|
||||
double value;
|
||||
do
|
||||
{
|
||||
value = _randomNumberGenerator.Randf();
|
||||
}
|
||||
while (value >= 1.0d);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public double NextDoubleInclusive()
|
||||
{
|
||||
return _randomNumberGenerator.Randf();
|
||||
}
|
||||
@@ -52,12 +64,17 @@ public class ForgeRandom : IRandom, IDisposable
|
||||
return _randomNumberGenerator.RandiRange(minValue, maxValue - 1);
|
||||
}
|
||||
|
||||
public int NextIntInclusive(int minValue, int maxValue)
|
||||
{
|
||||
return _randomNumberGenerator.RandiRange(minValue, maxValue);
|
||||
}
|
||||
|
||||
public long NextInt64()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
var high = _randomNumberGenerator.Randi();
|
||||
var low = _randomNumberGenerator.Randi();
|
||||
uint high = _randomNumberGenerator.Randi();
|
||||
uint low = _randomNumberGenerator.Randi();
|
||||
return ((long)high << 32) | low;
|
||||
}
|
||||
}
|
||||
@@ -74,13 +91,47 @@ public class ForgeRandom : IRandom, IDisposable
|
||||
throw new ArgumentOutOfRangeException(nameof(minValue), "minValue must be less than maxValue.");
|
||||
}
|
||||
|
||||
var range = (ulong)(maxValue - minValue);
|
||||
var rand = (ulong)NextInt64();
|
||||
ulong range = (ulong)(maxValue - minValue);
|
||||
ulong rand = (ulong)NextInt64();
|
||||
|
||||
return (long)(rand % range) + minValue;
|
||||
}
|
||||
|
||||
public long NextInt64Inclusive(long minValue, long maxValue)
|
||||
{
|
||||
if (minValue > maxValue)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(minValue), "minValue must be less than or equal to maxValue.");
|
||||
}
|
||||
|
||||
if (minValue == maxValue)
|
||||
{
|
||||
return minValue;
|
||||
}
|
||||
|
||||
if (maxValue == long.MaxValue)
|
||||
{
|
||||
ulong inclusiveRange = (ulong)(maxValue - minValue) + 1UL;
|
||||
ulong rand = (ulong)NextInt64();
|
||||
return (long)(rand % inclusiveRange) + minValue;
|
||||
}
|
||||
|
||||
return NextInt64(minValue, maxValue + 1);
|
||||
}
|
||||
|
||||
public float NextSingle()
|
||||
{
|
||||
float value;
|
||||
do
|
||||
{
|
||||
value = _randomNumberGenerator.Randf();
|
||||
}
|
||||
while (value >= 1.0f);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public float NextSingleInclusive()
|
||||
{
|
||||
return _randomNumberGenerator.Randf();
|
||||
}
|
||||
|
||||
@@ -73,8 +73,8 @@ public static class StatescriptGraphBuilder
|
||||
continue;
|
||||
}
|
||||
|
||||
var outputPortIndex = connectionResource.OutputPort;
|
||||
var inputPortIndex = connectionResource.InputPort;
|
||||
int outputPortIndex = connectionResource.OutputPort;
|
||||
int inputPortIndex = connectionResource.InputPort;
|
||||
|
||||
if (outputPortIndex < 0 || outputPortIndex >= fromNode.OutputPorts.Length)
|
||||
{
|
||||
@@ -120,7 +120,7 @@ public static class StatescriptGraphBuilder
|
||||
if (variable.IsArray)
|
||||
{
|
||||
var initialValues = new Variant128[variable.InitialArrayValues.Count];
|
||||
for (var i = 0; i < variable.InitialArrayValues.Count; i++)
|
||||
for (int i = 0; i < variable.InitialArrayValues.Count; i++)
|
||||
{
|
||||
initialValues[i] = StatescriptVariableTypeConverter.GodotVariantToForge(
|
||||
variable.InitialArrayValues[i],
|
||||
@@ -167,7 +167,7 @@ public static class StatescriptGraphBuilder
|
||||
continue;
|
||||
}
|
||||
|
||||
var index = (byte)binding.PropertyIndex;
|
||||
byte index = (byte)binding.PropertyIndex;
|
||||
|
||||
if (binding.Direction == StatescriptPropertyDirection.Input)
|
||||
{
|
||||
@@ -251,11 +251,11 @@ public static class StatescriptGraphBuilder
|
||||
ConstructorInfo constructor = constructors.OrderByDescending(x => x.GetParameters().Length).First();
|
||||
ParameterInfo[] parameters = constructor.GetParameters();
|
||||
|
||||
var args = new object[parameters.Length];
|
||||
for (var i = 0; i < parameters.Length; i++)
|
||||
object[] args = new object[parameters.Length];
|
||||
for (int i = 0; i < parameters.Length; i++)
|
||||
{
|
||||
ParameterInfo param = parameters[i];
|
||||
var paramName = param.Name ?? string.Empty;
|
||||
string paramName = param.Name ?? string.Empty;
|
||||
|
||||
if (nodeResource.CustomData.TryGetValue(paramName, out GodotVariant value))
|
||||
{
|
||||
@@ -292,6 +292,20 @@ public static class StatescriptGraphBuilder
|
||||
|
||||
private static object ConvertParameter(GodotVariant value, Type targetType)
|
||||
{
|
||||
if (targetType.IsEnum)
|
||||
{
|
||||
if (value.VariantType == GodotVariant.Type.Int || value.VariantType == GodotVariant.Type.Float)
|
||||
{
|
||||
return Enum.ToObject(targetType, value.AsInt32());
|
||||
}
|
||||
|
||||
string enumText = value.AsString();
|
||||
if (!string.IsNullOrEmpty(enumText))
|
||||
{
|
||||
return Enum.Parse(targetType, enumText, ignoreCase: true);
|
||||
}
|
||||
}
|
||||
|
||||
if (targetType == typeof(StringKey))
|
||||
{
|
||||
return new StringKey(value.AsString());
|
||||
|
||||
83
addons/forge/core/statescript/nodes/action/DebugNode.cs
Normal file
83
addons/forge/core/statescript/nodes/action/DebugNode.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
// Copyright © Gamesmiths Guild.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Gamesmiths.Forge.Godot.Resources.Statescript;
|
||||
using Godot;
|
||||
|
||||
namespace Gamesmiths.Forge.Statescript.Nodes.Action;
|
||||
|
||||
/// <summary>
|
||||
/// Action node that resolves an input value of any supported type and prints it through
|
||||
/// <see cref="GD.Print(params Variant[])"/>.
|
||||
/// Useful for validating resolver chains while testing Statescript graphs in the editor.
|
||||
/// </summary>
|
||||
public sealed class DebugNode : ActionNode
|
||||
{
|
||||
private readonly StatescriptVariableType _valueType;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string Description => "Prints the resolved input value to the Godot console for debugging.";
|
||||
|
||||
public DebugNode(StatescriptVariableType valueType = StatescriptVariableType.Int)
|
||||
{
|
||||
_valueType = valueType;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void DefineParameters(
|
||||
List<InputProperty> inputProperties,
|
||||
List<OutputVariable> outputVariables)
|
||||
{
|
||||
inputProperties.Add(new InputProperty("Value", StatescriptVariableTypeConverter.ToSystemType(_valueType)));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected override void Execute(GraphContext graphContext)
|
||||
{
|
||||
if (!graphContext.TryResolveVariant(InputProperties[0].BoundName, out Variant128 value))
|
||||
{
|
||||
GD.Print("[Statescript Debug] <unresolved>");
|
||||
return;
|
||||
}
|
||||
|
||||
GD.Print("[Statescript Debug] ", FormatValue(value));
|
||||
}
|
||||
|
||||
private string FormatValue(Variant128 value)
|
||||
{
|
||||
return _valueType switch
|
||||
{
|
||||
StatescriptVariableType.Bool => value.AsBool().ToString(),
|
||||
StatescriptVariableType.Byte => value.AsByte().ToString(
|
||||
System.Globalization.CultureInfo.InvariantCulture),
|
||||
StatescriptVariableType.SByte => value.AsSByte().ToString(
|
||||
System.Globalization.CultureInfo.InvariantCulture),
|
||||
StatescriptVariableType.Char => value.AsChar().ToString(),
|
||||
StatescriptVariableType.Decimal => value.AsDecimal().ToString(
|
||||
System.Globalization.CultureInfo.InvariantCulture),
|
||||
StatescriptVariableType.Double => value.AsDouble().ToString(
|
||||
System.Globalization.CultureInfo.InvariantCulture),
|
||||
StatescriptVariableType.Float => value.AsFloat().ToString(
|
||||
System.Globalization.CultureInfo.InvariantCulture),
|
||||
StatescriptVariableType.Int => value.AsInt().ToString(
|
||||
System.Globalization.CultureInfo.InvariantCulture),
|
||||
StatescriptVariableType.UInt => value.AsUInt().ToString(
|
||||
System.Globalization.CultureInfo.InvariantCulture),
|
||||
StatescriptVariableType.Long => value.AsLong().ToString(
|
||||
System.Globalization.CultureInfo.InvariantCulture),
|
||||
StatescriptVariableType.ULong => value.AsULong().ToString(
|
||||
System.Globalization.CultureInfo.InvariantCulture),
|
||||
StatescriptVariableType.Short => value.AsShort().ToString(
|
||||
System.Globalization.CultureInfo.InvariantCulture),
|
||||
StatescriptVariableType.UShort => value.AsUShort().ToString(
|
||||
System.Globalization.CultureInfo.InvariantCulture),
|
||||
StatescriptVariableType.Vector2 => value.AsVector2().ToString(),
|
||||
StatescriptVariableType.Vector3 => value.AsVector3().ToString(),
|
||||
StatescriptVariableType.Vector4 => value.AsVector4().ToString(),
|
||||
StatescriptVariableType.Plane => value.AsPlane().ToString(),
|
||||
StatescriptVariableType.Quaternion => value.AsQuaternion().ToString(),
|
||||
_ => Convert.ToHexString(value.ToBytes()),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://byp7r8mspi3df
|
||||
Reference in New Issue
Block a user