Skip to content

Commit

Permalink
C#: Renames to follow .NET naming conventions
Browse files Browse the repository at this point in the history
Renamed C# types and members to use PascalCase and follow .NET naming conventions.
  • Loading branch information
raulsntos committed Jan 27, 2023
1 parent 4788cb3 commit a968e51
Show file tree
Hide file tree
Showing 60 changed files with 2,857 additions and 2,508 deletions.
2 changes: 1 addition & 1 deletion doc/classes/AABB.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
[/gdscript]
[csharp]
// position (-3, 2, 0), size (1, 1, 1)
var box = new AABB(new Vector3(-3, 2, 0), new Vector3(1, 1, 1));
var box = new Aabb(new Vector3(-3, 2, 0), new Vector3(1, 1, 1));
// position (-3, -1, 0), size (3, 4, 2), so we fit both the original AABB and Vector3(0, -1, 2)
var box2 = box.Expand(new Vector3(0, -1, 2));
[/csharp]
Expand Down
8 changes: 4 additions & 4 deletions doc/classes/AStarGrid2D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
[/gdscript]
[csharp]
AStarGrid2D astarGrid = new AStarGrid2D();
astarGrid.Size = new Vector2i(32, 32);
astarGrid.CellSize = new Vector2i(16, 16);
astarGrid.Size = new Vector2I(32, 32);
astarGrid.CellSize = new Vector2I(16, 16);
astarGrid.Update();
GD.Print(astarGrid.GetIdPath(Vector2i.Zero, new Vector2i(3, 4))); // prints (0, 0), (1, 1), (2, 2), (3, 3), (3, 4)
GD.Print(astarGrid.GetPointPath(Vector2i.Zero, new Vector2i(3, 4))); // prints (0, 0), (16, 16), (32, 32), (48, 48), (48, 64)
GD.Print(astarGrid.GetIdPath(Vector2I.Zero, new Vector2I(3, 4))); // prints (0, 0), (1, 1), (2, 2), (3, 3), (3, 4)
GD.Print(astarGrid.GetPointPath(Vector2I.Zero, new Vector2I(3, 4))); // prints (0, 0), (16, 16), (32, 32), (48, 48), (48, 64)
[/csharp]
[/codeblocks]
</description>
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/AnimationNodeStateMachineTransition.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
$animation_tree.set("parameters/conditions/idle", is_on_floor and (linear_velocity.x == 0))
[/gdscript]
[csharp]
GetNode&lt;AnimationTree&gt;("animation_tree").Set("parameters/conditions/idle", IsOnFloor &amp;&amp; (LinearVelocity.x == 0));
GetNode&lt;AnimationTree&gt;("animation_tree").Set("parameters/conditions/idle", IsOnFloor &amp;&amp; (LinearVelocity.X == 0));
[/csharp]
[/codeblocks]
</member>
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/Image.xml
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@
var img = new Image();
img.Create(imgWidth, imgHeight, false, Image.Format.Rgba8);

img.SetPixelv(new Vector2i(1, 2), Colors.Red); // Sets the color at (1, 2) to red.
img.SetPixelv(new Vector2I(1, 2), Colors.Red); // Sets the color at (1, 2) to red.
[/csharp]
[/codeblocks]
This is the same as [method set_pixel], but with a [Vector2i] argument instead of two integer arguments.
Expand Down
6 changes: 3 additions & 3 deletions doc/classes/Rect2i.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@
[/gdscript]
[csharp]
// position (-3, 2), size (1, 1)
var rect = new Rect2i(new Vector2i(-3, 2), new Vector2i(1, 1));
// position (-3, -1), size (3, 4), so we fit both rect and Vector2i(0, -1)
var rect2 = rect.Expand(new Vector2i(0, -1));
var rect = new Rect2I(new Vector2I(-3, 2), new Vector2I(1, 1));
// position (-3, -1), size (3, 4), so we fit both rect and Vector2I(0, -1)
var rect2 = rect.Expand(new Vector2I(0, -1));
[/csharp]
[/codeblocks]
</description>
Expand Down
8 changes: 4 additions & 4 deletions doc/classes/TextEdit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -770,12 +770,12 @@
var column_number = result.x
[/gdscript]
[csharp]
Vector2i result = Search("print", (uint)TextEdit.SearchFlags.WholeWords, 0, 0);
if (result.Length &gt; 0)
Vector2I result = Search("print", (uint)TextEdit.SearchFlags.WholeWords, 0, 0);
if (result.X != -1)
{
// Result found.
int lineNumber = result.y;
int columnNumber = result.x;
int lineNumber = result.Y;
int columnNumber = result.X;
}
[/csharp]
[/codeblocks]
Expand Down
62 changes: 34 additions & 28 deletions modules/mono/csharp_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include "mono_gd/gd_mono_cache.h"
#include "signal_awaiter_utils.h"
#include "utils/macros.h"
#include "utils/naming_utils.h"
#include "utils/string_utils.h"

#define CACHED_STRING_NAME(m_var) (CSharpLanguage::get_singleton()->get_string_names().m_var)
Expand Down Expand Up @@ -333,7 +334,7 @@ void CSharpLanguage::get_string_delimiters(List<String> *p_delimiters) const {
}

static String get_base_class_name(const String &p_base_class_name, const String p_class_name) {
String base_class = p_base_class_name;
String base_class = pascal_to_pascal_case(p_base_class_name);
if (p_class_name == base_class) {
base_class = "Godot." + base_class;
}
Expand Down Expand Up @@ -394,13 +395,18 @@ bool CSharpLanguage::supports_builtin_mode() const {
}

#ifdef TOOLS_ENABLED
struct VariantCsName {
Variant::Type variant_type;
const String cs_type;
};

static String variant_type_to_managed_name(const String &p_var_type_name) {
if (p_var_type_name.is_empty()) {
return "Variant";
}

if (ClassDB::class_exists(p_var_type_name)) {
return p_var_type_name;
return pascal_to_pascal_case(p_var_type_name);
}

if (p_var_type_name == Variant::get_type_name(Variant::OBJECT)) {
Expand Down Expand Up @@ -459,34 +465,34 @@ static String variant_type_to_managed_name(const String &p_var_type_name) {
return "Signal";
}

Variant::Type var_types[] = {
Variant::BOOL,
Variant::INT,
Variant::VECTOR2,
Variant::VECTOR2I,
Variant::RECT2,
Variant::RECT2I,
Variant::VECTOR3,
Variant::VECTOR3I,
Variant::TRANSFORM2D,
Variant::VECTOR4,
Variant::VECTOR4I,
Variant::PLANE,
Variant::QUATERNION,
Variant::AABB,
Variant::BASIS,
Variant::TRANSFORM3D,
Variant::PROJECTION,
Variant::COLOR,
Variant::STRING_NAME,
Variant::NODE_PATH,
Variant::RID,
Variant::CALLABLE
const VariantCsName var_types[] = {
{ Variant::BOOL, "bool" },
{ Variant::INT, "long" },
{ Variant::VECTOR2, "Vector2" },
{ Variant::VECTOR2I, "Vector2I" },
{ Variant::RECT2, "Rect2" },
{ Variant::RECT2I, "Rect2I" },
{ Variant::VECTOR3, "Vector3" },
{ Variant::VECTOR3I, "Vector3I" },
{ Variant::TRANSFORM2D, "Transform2D" },
{ Variant::VECTOR4, "Vector4" },
{ Variant::VECTOR4I, "Vector4I" },
{ Variant::PLANE, "Plane" },
{ Variant::QUATERNION, "Quaternion" },
{ Variant::AABB, "Aabb" },
{ Variant::BASIS, "Basis" },
{ Variant::TRANSFORM3D, "Transform3D" },
{ Variant::PROJECTION, "Projection" },
{ Variant::COLOR, "Color" },
{ Variant::STRING_NAME, "StringName" },
{ Variant::NODE_PATH, "NodePath" },
{ Variant::RID, "Rid" },
{ Variant::CALLABLE, "Callable" },
};

for (unsigned int i = 0; i < sizeof(var_types) / sizeof(Variant::Type); i++) {
if (p_var_type_name == Variant::get_type_name(var_types[i])) {
return p_var_type_name;
for (unsigned int i = 0; i < sizeof(var_types) / sizeof(VariantCsName); i++) {
if (p_var_type_name == Variant::get_type_name(var_types[i].variant_type)) {
return var_types[i].cs_type;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ public partial class ExportedFields : Godot.Object

// Godot structs
[Export] private Vector2 field_Vector2 = new(10f, 10f);
[Export] private Vector2i field_Vector2i = Vector2i.Up;
[Export] private Vector2I field_Vector2I = Vector2I.Up;
[Export] private Rect2 field_Rect2 = new(new Vector2(10f, 10f), new Vector2(10f, 10f));
[Export] private Rect2i field_Rect2i = new(new Vector2i(10, 10), new Vector2i(10, 10));
[Export] private Rect2I field_Rect2I = new(new Vector2I(10, 10), new Vector2I(10, 10));
[Export] private Transform2D field_Transform2D = Transform2D.Identity;
[Export] private Vector3 field_Vector3 = new(10f, 10f, 10f);
[Export] private Vector3i field_Vector3i = Vector3i.Back;
[Export] private Vector3I field_Vector3I = Vector3I.Back;
[Export] private Basis field_Basis = new Basis(Quaternion.Identity);
[Export] private Quaternion field_Quaternion = new Quaternion(Basis.Identity);
[Export] private Transform3D field_Transform3D = Transform3D.Identity;
[Export] private Vector4 field_Vector4 = new(10f, 10f, 10f, 10f);
[Export] private Vector4i field_Vector4i = Vector4i.One;
[Export] private Vector4I field_Vector4I = Vector4I.One;
[Export] private Projection field_Projection = Projection.Identity;
[Export] private AABB field_AABB = new AABB(10f, 10f, 10f, new Vector3(1f, 1f, 1f));
[Export] private Aabb field_Aabb = new Aabb(10f, 10f, 10f, new Vector3(1f, 1f, 1f));
[Export] private Color field_Color = Colors.Aquamarine;
[Export] private Plane field_Plane = Plane.PlaneXZ;
[Export] private Callable field_Callable = new Callable(Engine.GetMainLoop(), "_process");
Expand Down Expand Up @@ -83,7 +83,7 @@ enum MyFlagsEnum
[Export] private Godot.Object[] field_GodotObjectOrDerivedArray = { null };
[Export] private StringName[] field_StringNameArray = { "foo", "bar" };
[Export] private NodePath[] field_NodePathArray = { "foo", "bar" };
[Export] private RID[] field_RIDArray = { default, default, default };
[Export] private Rid[] field_RidArray = { default, default, default };
// Note we use Array and not System.Array. This tests the generated namespace qualification.
[Export] private Int32[] field_empty_Int32Array = Array.Empty<Int32>();
// Note we use List and not System.Collections.Generic.
Expand All @@ -97,7 +97,7 @@ enum MyFlagsEnum
[Export] private Godot.Texture field_GodotResourceTexture;
[Export] private StringName field_StringName = new StringName("foo");
[Export] private NodePath field_NodePath = new NodePath("foo");
[Export] private RID field_RID;
[Export] private Rid field_Rid;

[Export]
private Godot.Collections.Dictionary field_GodotDictionary =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,19 @@ public String LamdaProperty_String

// Godot structs
[Export] private Vector2 property_Vector2 { get; set; } = new(10f, 10f);
[Export] private Vector2i property_Vector2i { get; set; } = Vector2i.Up;
[Export] private Vector2I property_Vector2I { get; set; } = Vector2I.Up;
[Export] private Rect2 property_Rect2 { get; set; } = new(new Vector2(10f, 10f), new Vector2(10f, 10f));
[Export] private Rect2i property_Rect2i { get; set; } = new(new Vector2i(10, 10), new Vector2i(10, 10));
[Export] private Rect2I property_Rect2I { get; set; } = new(new Vector2I(10, 10), new Vector2I(10, 10));
[Export] private Transform2D property_Transform2D { get; set; } = Transform2D.Identity;
[Export] private Vector3 property_Vector3 { get; set; } = new(10f, 10f, 10f);
[Export] private Vector3i property_Vector3i { get; set; } = Vector3i.Back;
[Export] private Vector3I property_Vector3I { get; set; } = Vector3I.Back;
[Export] private Basis property_Basis { get; set; } = new Basis(Quaternion.Identity);
[Export] private Quaternion property_Quaternion { get; set; } = new Quaternion(Basis.Identity);
[Export] private Transform3D property_Transform3D { get; set; } = Transform3D.Identity;
[Export] private Vector4 property_Vector4 { get; set; } = new(10f, 10f, 10f, 10f);
[Export] private Vector4i property_Vector4i { get; set; } = Vector4i.One;
[Export] private Vector4I property_Vector4I { get; set; } = Vector4I.One;
[Export] private Projection property_Projection { get; set; } = Projection.Identity;
[Export] private AABB property_AABB { get; set; } = new AABB(10f, 10f, 10f, new Vector3(1f, 1f, 1f));
[Export] private Aabb property_Aabb { get; set; } = new Aabb(10f, 10f, 10f, new Vector3(1f, 1f, 1f));
[Export] private Color property_Color { get; set; } = Colors.Aquamarine;
[Export] private Plane property_Plane { get; set; } = Plane.PlaneXZ;
[Export] private Callable property_Callable { get; set; } = new Callable(Engine.GetMainLoop(), "_process");
Expand Down Expand Up @@ -171,7 +171,7 @@ enum MyFlagsEnum
[Export] private Godot.Object[] property_GodotObjectOrDerivedArray { get; set; } = { null };
[Export] private StringName[] field_StringNameArray { get; set; } = { "foo", "bar" };
[Export] private NodePath[] field_NodePathArray { get; set; } = { "foo", "bar" };
[Export] private RID[] field_RIDArray { get; set; } = { default, default, default };
[Export] private Rid[] field_RidArray { get; set; } = { default, default, default };

// Variant
[Export] private Variant property_Variant { get; set; } = "foo";
Expand All @@ -181,7 +181,7 @@ enum MyFlagsEnum
[Export] private Godot.Texture property_GodotResourceTexture { get; set; }
[Export] private StringName property_StringName { get; set; } = new StringName("foo");
[Export] private NodePath property_NodePath { get; set; } = new NodePath("foo");
[Export] private RID property_RID { get; set; }
[Export] private Rid property_Rid { get; set; }

[Export]
private Godot.Collections.Dictionary property_GodotDictionary { get; set; } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static class GodotClasses
public const string ExportSubgroupAttr = "Godot.ExportSubgroupAttribute";
public const string SignalAttr = "Godot.SignalAttribute";
public const string MustBeVariantAttr = "Godot.MustBeVariantAttribute";
public const string GodotClassNameAttr = "Godot.GodotClassName";
public const string GodotClassNameAttr = "Godot.GodotClassNameAttribute";
public const string SystemFlagsAttr = "System.FlagsAttribute";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ internal enum VariantType
Float = 3,
String = 4,
Vector2 = 5,
Vector2i = 6,
Vector2I = 6,
Rect2 = 7,
Rect2i = 8,
Rect2I = 8,
Vector3 = 9,
Vector3i = 10,
Transform2d = 11,
Vector3I = 10,
Transform2D = 11,
Vector4 = 12,
Vector4i = 13,
Vector4I = 13,
Plane = 14,
Quaternion = 15,
Aabb = 16,
Basis = 17,
Transform3d = 18,
Transform3D = 18,
Projection = 19,
Color = 20,
StringName = 21,
Expand Down Expand Up @@ -56,12 +56,12 @@ internal enum PropertyHint
ExpEasing = 4,
Link = 5,
Flags = 6,
Layers2dRender = 7,
Layers2dPhysics = 8,
Layers2dNavigation = 9,
Layers3dRender = 10,
Layers3dPhysics = 11,
Layers3dNavigation = 12,
Layers2DRender = 7,
Layers2DPhysics = 8,
Layers2DNavigation = 9,
Layers3DRender = 10,
Layers3DPhysics = 11,
Layers3DNavigation = 12,
File = 13,
Dir = 14,
GlobalFile = 15,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ public enum MarshalType

// Godot structs
Vector2,
Vector2i,
Vector2I,
Rect2,
Rect2i,
Rect2I,
Transform2D,
Vector3,
Vector3i,
Vector3I,
Basis,
Quaternion,
Transform3D,
Vector4,
Vector4i,
Vector4I,
Projection,
AABB,
Aabb,
Color,
Plane,
Callable,
Expand All @@ -55,7 +55,7 @@ public enum MarshalType
GodotObjectOrDerivedArray,
SystemArrayOfStringName,
SystemArrayOfNodePath,
SystemArrayOfRID,
SystemArrayOfRid,

// Variant
Variant,
Expand All @@ -64,7 +64,7 @@ public enum MarshalType
GodotObjectOrDerived,
StringName,
NodePath,
RID,
Rid,
GodotDictionary,
GodotArray,
GodotGenericDictionary,
Expand Down

0 comments on commit a968e51

Please sign in to comment.