mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Added ToString-Method for Vectors
This commit is contained in:
@@ -20,6 +20,8 @@ struct VectorAttribute<T, ComponentCount> : Attribute, IComptimeTypeApply where
|
||||
GenerateEqualityOperators(type);
|
||||
|
||||
GenerateArrayAccess(type);
|
||||
|
||||
GenerateToString(type);
|
||||
}
|
||||
|
||||
[Comptime]
|
||||
@@ -311,6 +313,30 @@ struct VectorAttribute<T, ComponentCount> : 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)]
|
||||
|
||||
Reference in New Issue
Block a user