From e5cdb5c79d4f1cfd8857dee4801101ad114a6966 Mon Sep 17 00:00:00 2001 From: 9thAzure Date: Mon, 3 Jun 2024 11:28:49 -0700 Subject: [PATCH] forgot offset_position in SimplePolygon2D --- addons/complex_shape_creation/PropertyName.cs | 2 ++ .../simple_polygon_2d/SimplePolygon2D.cs | 8 +++++- .../simple_polygon_2d/simple_polygon_2d.gd | 26 ++++++++++++------- tests/unit_tests/test_simple_polygon_2d.gd | 2 +- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/addons/complex_shape_creation/PropertyName.cs b/addons/complex_shape_creation/PropertyName.cs index efb3a29..ffa76e1 100644 --- a/addons/complex_shape_creation/PropertyName.cs +++ b/addons/complex_shape_creation/PropertyName.cs @@ -10,7 +10,9 @@ public static class PropertyName public static readonly StringName OffsetRotationDegrees = new("offset_rotation_degrees"); public static readonly StringName OffsetRotation = new("offset_rotation"); public static readonly StringName Color = new("color"); + [Obsolete("Property name has been replaced, use 'Offset' instead.", false)] public static readonly StringName OffsetPosition = new("offset_position"); + public static readonly StringName Offset = new("offset"); public static readonly StringName Width = new("width"); public static readonly StringName DrawnArcDegrees = new("drawn_arc_degrees"); public static readonly StringName DrawnArc = new("drawn_arc"); diff --git a/addons/complex_shape_creation/simple_polygon_2d/SimplePolygon2D.cs b/addons/complex_shape_creation/simple_polygon_2d/SimplePolygon2D.cs index fda5968..5bc0021 100644 --- a/addons/complex_shape_creation/simple_polygon_2d/SimplePolygon2D.cs +++ b/addons/complex_shape_creation/simple_polygon_2d/SimplePolygon2D.cs @@ -52,12 +52,18 @@ public Color Color get => (Color)Instance.Get(PropertyName.Color); set => Instance.Set(PropertyName.Color, value); } - /// The offset position of the shape. + [Obsolete("Property name has been replaced, use 'Offset' instead.", false)] public Vector2 OffsetPosition { get => (Vector2)Instance.Get(PropertyName.OffsetPosition); set => Instance.Set(PropertyName.OffsetPosition, value); } + /// The offset position of the shape. + public Vector2 Offset + { + get => (Vector2)Instance.Get(PropertyName.Offset); + set => Instance.Set(PropertyName.Offset, value); + } /// Position, relative to the node's parent. public Vector2 Position { diff --git a/addons/complex_shape_creation/simple_polygon_2d/simple_polygon_2d.gd b/addons/complex_shape_creation/simple_polygon_2d/simple_polygon_2d.gd index 7acc80b..06239c0 100644 --- a/addons/complex_shape_creation/simple_polygon_2d/simple_polygon_2d.gd +++ b/addons/complex_shape_creation/simple_polygon_2d/simple_polygon_2d.gd @@ -52,11 +52,19 @@ var color : Color = Color.WHITE: color = value queue_redraw() -## The offset position of the shape. +## see [member offset] +## @deprecated @export -var offset_position : Vector2 = Vector2.ZERO: +var offset_position := Vector2.ZERO: + set(value): + offset = value + get: + return offset + +## The offset position of the shape. +var offset : Vector2 = Vector2.ZERO: set(value): - offset_position = value + offset = value queue_redraw() ## A method for consistency across other nodes. [b]Equivalent to [method CanvasItem.queue_redraw].[/b] @@ -69,24 +77,24 @@ func regenerate() -> void: func _draw() -> void: if (vertices_count == 1): - draw_circle(offset_position, size, color) + draw_circle(offset, size, color) return if (vertices_count == 2): if offset_rotation == 0: - draw_line(Vector2.UP * size + offset_position, Vector2.DOWN * size + offset_position, color) + draw_line(Vector2.UP * size + offset, Vector2.DOWN * size + offset, color) return var point1 := Vector2(sin(offset_rotation), -cos(offset_rotation)) * size - draw_line(point1 + offset_position, -point1 + offset_position, color) + draw_line(point1 + offset, -point1 + offset, color) return if (vertices_count == 4 && offset_rotation == 0): const sqrt_two_over_two := 0.707106781 - draw_rect(Rect2(offset_position - Vector2.ONE * sqrt_two_over_two * size, Vector2.ONE * sqrt_two_over_two * size * 2), color) + draw_rect(Rect2(offset - Vector2.ONE * sqrt_two_over_two * size, Vector2.ONE * sqrt_two_over_two * size * 2), color) return - draw_colored_polygon(get_shape_vertices(vertices_count, size, offset_rotation, offset_position), color) + draw_colored_polygon(get_shape_vertices(vertices_count, size, offset_rotation, offset), color) func _init(vertices_count : int = 1, size := 10.0, offset_rotation := 0.0, color := Color.WHITE, offset_position := Vector2.ZERO): if vertices_count != 1: @@ -98,7 +106,7 @@ func _init(vertices_count : int = 1, size := 10.0, offset_rotation := 0.0, color if color != Color.WHITE: self.color = color if offset_position != Vector2.ZERO: - self.offset_position = offset_position + self.offset = offset_position static var _circle := get_shape_vertices(32) diff --git a/tests/unit_tests/test_simple_polygon_2d.gd b/tests/unit_tests/test_simple_polygon_2d.gd index 7f8da9a..67a4c94 100644 --- a/tests/unit_tests/test_simple_polygon_2d.gd +++ b/tests/unit_tests/test_simple_polygon_2d.gd @@ -9,7 +9,7 @@ func test_init__filled__variables_assigned(): assert_eq(shape.size, 5.0, "Property 'size'.") assert_eq(shape.offset_rotation, 1.0, "Property 'offset_rotation'.") assert_eq(shape.color, Color.RED, "Property 'color'.") - assert_eq(shape.offset_position, Vector2.ONE, "Property 'offset_position'.") + assert_eq(shape.offset, Vector2.ONE, "Property 'offset'.") shape.queue_free() var param2 := [[2], [5], [8], [32], [100]]