diff --git a/GlitchyEngine/src/Scripting/ScriptGlue.bf b/GlitchyEngine/src/Scripting/ScriptGlue.bf index ad2a040..55a2f69 100644 --- a/GlitchyEngine/src/Scripting/ScriptGlue.bf +++ b/GlitchyEngine/src/Scripting/ScriptGlue.bf @@ -260,6 +260,26 @@ static class ScriptGlue Box2D.Body.ApplyForceToCenter(rigidBody.[Friend]RuntimeBody, force, wakeUp); } + [RegisterCall("ScriptGlue::RigidBody2D_SetPosition")] + static void RigidBody2D_SetPosition(UUID entityId, ref float2 position) + { + Scene scene = ScriptEngine.Context; + Entity entity = scene.GetEntityByID(entityId); + + var rigidBody = entity.GetComponent(); + rigidBody.SetPosition(position); + } + + [RegisterCall("ScriptGlue::RigidBody2D_GetPosition")] + static void RigidBody2D_GetPosition(UUID entityId, ref float2 position) + { + Scene scene = ScriptEngine.Context; + Entity entity = scene.GetEntityByID(entityId); + + var rigidBody = entity.GetComponent(); + position = rigidBody.GetPosition(); + } + #endregion RigidBody2D #region Physics2D diff --git a/ScriptCore/Components/RigidBody2D.cs b/ScriptCore/Components/RigidBody2D.cs index 4b8c045..b4d831d 100644 --- a/ScriptCore/Components/RigidBody2D.cs +++ b/ScriptCore/Components/RigidBody2D.cs @@ -27,4 +27,20 @@ public class Rigidbody2D : Component { ScriptGlue.RigidBody2D_ApplyForceToCenter(Entity._uuid, force, wakeUp); } + + /// + /// Sets the position of the rigidbody. + /// + /// The position of the rigidbody. + public void SetPosition(float2 position) + { + ScriptGlue.RigidBody2D_SetPosition(Entity._uuid, position); + } + + public float2 GetPosition() + { + ScriptGlue.RigidBody2D_GetPosition(Entity._uuid, out float2 position); + + return position; + } } diff --git a/ScriptCore/ScriptGlue.cs b/ScriptCore/ScriptGlue.cs index 2d3b54e..9bf4e21 100644 --- a/ScriptCore/ScriptGlue.cs +++ b/ScriptCore/ScriptGlue.cs @@ -46,6 +46,12 @@ internal static class ScriptGlue [MethodImpl(MethodImplOptions.InternalCall)] internal static extern void RigidBody2D_ApplyForceToCenter(UUID entityId, in float2 force, bool wakeUp); + + [MethodImpl(MethodImplOptions.InternalCall)] + internal static extern void RigidBody2D_SetPosition(UUID entityId, in float2 position); + + [MethodImpl(MethodImplOptions.InternalCall)] + internal static extern void RigidBody2D_GetPosition(UUID entityId, out float2 position); #endregion RigidBody2D @@ -74,5 +80,4 @@ internal static class ScriptGlue internal static extern float4 modf_float4(float4 x, out float4 integerPart); #endregion - } diff --git a/ScriptCoreGenerator/VectorGenerator.cs b/ScriptCoreGenerator/VectorGenerator.cs index b43079a..521d231 100644 --- a/ScriptCoreGenerator/VectorGenerator.cs +++ b/ScriptCoreGenerator/VectorGenerator.cs @@ -66,6 +66,9 @@ public class VectorGenerator : ISourceGenerator builder.AppendLine(vector.Struct.GetParent().Usings.ToFullString()); builder.Append($$""" + // For "DebuggerBrowsable" and "DebuggerBrowsableState" + using System.Diagnostics; + namespace {{vector.Struct.GetNamespace()}}; public partial struct {{vector.VectorName}} @@ -102,15 +105,32 @@ public class VectorGenerator : ISourceGenerator GenerateCastOperator(cast, vector, toVectorDefinition, builder); } - + + GenerateToString(vector, builder); + GenerateSwizzle(vector, builder); - + builder.Append('}'); context.AddSource($"{vector.VectorName}.g.cs", builder.ToString()); } } + private void GenerateToString(VectorDefinition vector, StringBuilder builder) + { + builder.Append("public override string ToString() => $\"{{"); + + for (int i = 0; i < vector.ComponentCount; i++) + { + if (i > 0) + builder.Append(", "); + + builder.Append($"{ComponentNames[i]}: {{{ComponentNames[i]}}}"); + } + + builder.Append("}}\";\n\n"); + } + private void GenerateCastOperator(VectorCastSyntaxReceiver.VectorCast cast, VectorDefinition fromVector, VectorDefinition toVector, StringBuilder builder) { if (fromVector.ComponentCount != toVector.ComponentCount) @@ -592,7 +612,10 @@ public class VectorGenerator : ISourceGenerator //"""); // } + // DebuggerBrowsableState.Never to hide swizzle properties in debugger view + builder.Append($$""" + [DebuggerBrowsable(DebuggerBrowsableState.Never)] public {{vector.BaseName}}{{swizzleCount}} {{swizzleName}} { get => new({{swizzleConstructor}});