// Copyright © Gamesmiths Guild. using Gamesmiths.Forge.Core; using Gamesmiths.Forge.Statescript; using GodotPlane = Godot.Plane; using GodotQuaternion = Godot.Quaternion; using GodotVector2 = Godot.Vector2; using GodotVector3 = Godot.Vector3; using GodotVector4 = Godot.Vector4; using SysPlane = System.Numerics.Plane; using SysQuaternion = System.Numerics.Quaternion; using SysVector2 = System.Numerics.Vector2; using SysVector3 = System.Numerics.Vector3; using SysVector4 = System.Numerics.Vector4; namespace Gamesmiths.Forge.Godot.Core; /// /// Extension methods for that provide seamless support for Godot types. These methods /// automatically convert Godot math types (e.g., ) to their System.Numerics equivalents /// before storing them in the variable bag. /// /// /// Use these overloads in data binder delegates (e.g., when implementing /// ) to avoid manual Godot-to-System.Numerics /// conversions. /// public static class VariablesExtensions { /// /// Sets a variable from a value, converting it to . /// /// The variables bag. /// The name of the variable to set. /// The Godot Vector2 value to store. public static void SetGodotVar(this Variables variables, StringKey name, GodotVector2 value) { variables.SetVariant(name, new Variant128(new SysVector2(value.X, value.Y))); } /// /// Sets a variable from a value, converting it to . /// /// The variables bag. /// The name of the variable to set. /// The Godot Vector3 value to store. public static void SetGodotVar(this Variables variables, StringKey name, GodotVector3 value) { variables.SetVariant(name, new Variant128(new SysVector3(value.X, value.Y, value.Z))); } /// /// Sets a variable from a value, converting it to . /// /// The variables bag. /// The name of the variable to set. /// The Godot Vector4 value to store. public static void SetGodotVar(this Variables variables, StringKey name, GodotVector4 value) { variables.SetVariant(name, new Variant128(new SysVector4(value.X, value.Y, value.Z, value.W))); } /// /// Sets a variable from a value, converting it to . /// /// The variables bag. /// The name of the variable to set. /// The Godot Plane value to store. public static void SetGodotVar(this Variables variables, StringKey name, GodotPlane value) { variables.SetVariant( name, new Variant128(new SysPlane(value.Normal.X, value.Normal.Y, value.Normal.Z, value.D))); } /// /// Sets a variable from a value, converting it to . /// /// The variables bag. /// The name of the variable to set. /// The Godot Quaternion value to store. public static void SetGodotVar(this Variables variables, StringKey name, GodotQuaternion value) { variables.SetVariant(name, new Variant128(new SysQuaternion(value.X, value.Y, value.Z, value.W))); } }