Skip to content

Commit

Permalink
Merge pull request #61 from 9thAzure/replacement_names
Browse files Browse the repository at this point in the history
Change `offset_position` to `offset` in `SimplePolygon2D`
  • Loading branch information
9thAzure committed Jun 3, 2024
2 parents c5b50e9 + 2f1b15a commit 91676a4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
2 changes: 2 additions & 0 deletions addons/complex_shape_creation/PropertyName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,18 @@ public Color Color
get => (Color)Instance.Get(PropertyName.Color);
set => Instance.Set(PropertyName.Color, value);
}
/// <summary>The offset position of the shape.</summary>
[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);
}
/// <summary>The offset position of the shape.</summary>
public Vector2 Offset
{
get => (Vector2)Instance.Get(PropertyName.Offset);
set => Instance.Set(PropertyName.Offset, value);
}
/// <summary>Position, relative to the node's parent.</summary>
public Vector2 Position
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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:
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_simple_polygon_2d.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down

0 comments on commit 91676a4

Please sign in to comment.