From 4957f3c0337a3c3331e00784eec36a94c3a3e428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Sun, 3 Nov 2024 19:09:28 +0100 Subject: [PATCH] Added ToString-Method for Vectors --- GlitchyEngine/src/Math/VectorAttribute.bf | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/GlitchyEngine/src/Math/VectorAttribute.bf b/GlitchyEngine/src/Math/VectorAttribute.bf index aad3d54..93c2524 100644 --- a/GlitchyEngine/src/Math/VectorAttribute.bf +++ b/GlitchyEngine/src/Math/VectorAttribute.bf @@ -20,6 +20,8 @@ struct VectorAttribute : Attribute, IComptimeTypeApply where GenerateEqualityOperators(type); GenerateArrayAccess(type); + + GenerateToString(type); } [Comptime] @@ -311,6 +313,30 @@ struct VectorAttribute : Attribute, IComptimeTypeApply where Compiler.EmitTypeBody(type, arrayAccess); } + + [Comptime] + private static void GenerateToString(Type type) + { + String string = scope String(); + + for (int i < ComponentCount) + { + if (i != 0) + string.Append(", "); + + string.AppendF($"{{{ComponentNames[i]}}}"); + } + + String func = scope $""" + public void ToString(System.String buffer) + {{ + buffer.AppendF($"({string})"); + }} + + """; + + Compiler.EmitTypeBody(type, func); + } } [AttributeUsage(.Struct | .Class)]