From cc45ad22b74a358fd55c3c66a0586eb4290c010b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=83zvan=20C=2E=20R=C4=83dulescu?= Date: Thu, 4 Dec 2025 12:41:58 +0200 Subject: [PATCH 1/7] Simplify & fix `AntialiasedRegularPolygon2D` angle - Generate the AA texture with `generate_antialiased_texture.gd` as a binary resource and save it to disk instead of in-memory. Stops Godot from complaining that the scene file is too large. - Simplify code by reusing classes. - Other defaults and shuffle code around. For example we usually rewrite `_ready()`, so instead of remembering to call `super()`, moved all relevant property assignments to `_init()` instead. - Made the `Line2D` an internal node. - Rename regular polygon 2D `angle_degrees` to `arc`. - Fix issue with `arc` not spanning the correct angle. - Other export QoL like `arc` showing in degrees, but value being radians, etc. --- .gitignore | 3 + .../antialiased_line2d/antialiased_line2d.gd | 22 ----- .../antialiased_line2d/antialiased_line_2d.gd | 9 ++ .../antialiased_line_2d.gd.uid | 1 + ...sed_line2d.svg => antialiased_line_2d.svg} | 0 .../antialiased_line_2d.svg.import | 43 +++++++++ .../antialiased_polygon2d.gd | 55 ------------ .../antialiased_polygon_2d.gd | 62 +++++++++++++ .../antialiased_polygon_2d.gd.uid | 1 + ...lygon2d.svg => antialiased_polygon_2d.svg} | 0 ...port => antialiased_polygon_2d.svg.import} | 12 ++- .../antialiased_regular_polygon2d.gd | 82 ------------------ .../antialiased_regular_polygon_2d.gd | 47 ++++++++++ .../antialiased_regular_polygon_2d.gd.uid | 1 + ...svg => antialiased_regular_polygon_2d.svg} | 0 ...antialiased_regular_polygon_2d.svg.import} | 12 ++- .../antialiased_texture.res | Bin 0 -> 175234 bytes ...ure.gd => generate_antialiased_texture.gd} | 25 +++--- .../generate_antialiased_texture.gd.uid | 1 + addons/antialiased_line2d/plugin.gd | 12 +-- addons/antialiased_line2d/plugin.gd.uid | 1 + dev_2d.tscn | 11 +++ icon.png | Bin 1882 -> 0 bytes ...iased_line2d.svg.import => icon.svg.import | 16 ++-- project.godot | 31 +++++++ 25 files changed, 259 insertions(+), 188 deletions(-) create mode 100644 .gitignore delete mode 100644 addons/antialiased_line2d/antialiased_line2d.gd create mode 100644 addons/antialiased_line2d/antialiased_line_2d.gd create mode 100644 addons/antialiased_line2d/antialiased_line_2d.gd.uid rename addons/antialiased_line2d/{antialiased_line2d.svg => antialiased_line_2d.svg} (100%) create mode 100644 addons/antialiased_line2d/antialiased_line_2d.svg.import delete mode 100644 addons/antialiased_line2d/antialiased_polygon2d.gd create mode 100644 addons/antialiased_line2d/antialiased_polygon_2d.gd create mode 100644 addons/antialiased_line2d/antialiased_polygon_2d.gd.uid rename addons/antialiased_line2d/{antialiased_polygon2d.svg => antialiased_polygon_2d.svg} (100%) rename addons/antialiased_line2d/{antialiased_polygon2d.svg.import => antialiased_polygon_2d.svg.import} (65%) delete mode 100644 addons/antialiased_line2d/antialiased_regular_polygon2d.gd create mode 100644 addons/antialiased_line2d/antialiased_regular_polygon_2d.gd create mode 100644 addons/antialiased_line2d/antialiased_regular_polygon_2d.gd.uid rename addons/antialiased_line2d/{antialiased_regular_polygon2d.svg => antialiased_regular_polygon_2d.svg} (100%) rename addons/antialiased_line2d/{antialiased_regular_polygon2d.svg.import => antialiased_regular_polygon_2d.svg.import} (64%) create mode 100644 addons/antialiased_line2d/antialiased_texture.res rename addons/antialiased_line2d/{texture.gd => generate_antialiased_texture.gd} (66%) create mode 100644 addons/antialiased_line2d/generate_antialiased_texture.gd.uid create mode 100644 addons/antialiased_line2d/plugin.gd.uid create mode 100644 dev_2d.tscn delete mode 100644 icon.png rename addons/antialiased_line2d/antialiased_line2d.svg.import => icon.svg.import (60%) create mode 100644 project.godot diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0af181c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# Godot 4+ specific ignores +.godot/ +/android/ diff --git a/addons/antialiased_line2d/antialiased_line2d.gd b/addons/antialiased_line2d/antialiased_line2d.gd deleted file mode 100644 index bd30427..0000000 --- a/addons/antialiased_line2d/antialiased_line2d.gd +++ /dev/null @@ -1,22 +0,0 @@ -@tool -@icon("antialiased_line2d.svg") -class_name AntialiasedLine2D -extends Line2D - - -func _ready() -> void: - texture = AntialiasedLine2DTexture.texture - texture_mode = Line2D.LINE_TEXTURE_TILE - texture_filter = TextureFilter.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC - - -static func construct_closed_line(p_polygon: PackedVector2Array) -> PackedVector2Array: - var end_point: Vector2 = p_polygon[p_polygon.size() - 1] - var distance: float = end_point.distance_to(p_polygon[0]) # distance to start point - var bridge_point: Vector2 = end_point.move_toward(p_polygon[0], distance * 0.5) - # Close the polygon drawn by the line by adding superimposed bridge points between the start and end points. - var polygon_line := p_polygon - polygon_line.push_back(bridge_point) - polygon_line.insert(0, bridge_point) - - return polygon_line diff --git a/addons/antialiased_line2d/antialiased_line_2d.gd b/addons/antialiased_line2d/antialiased_line_2d.gd new file mode 100644 index 0000000..e83dba2 --- /dev/null +++ b/addons/antialiased_line2d/antialiased_line_2d.gd @@ -0,0 +1,9 @@ +@tool +@icon("antialiased_line_2d.svg") +class_name AntialiasedLine2D +extends Line2D + +func _init() -> void: + texture = preload("antialiased_texture.res") + texture_mode = Line2D.LINE_TEXTURE_TILE + texture_filter = TextureFilter.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC diff --git a/addons/antialiased_line2d/antialiased_line_2d.gd.uid b/addons/antialiased_line2d/antialiased_line_2d.gd.uid new file mode 100644 index 0000000..c4bca11 --- /dev/null +++ b/addons/antialiased_line2d/antialiased_line_2d.gd.uid @@ -0,0 +1 @@ +uid://dn534defa6rgl diff --git a/addons/antialiased_line2d/antialiased_line2d.svg b/addons/antialiased_line2d/antialiased_line_2d.svg similarity index 100% rename from addons/antialiased_line2d/antialiased_line2d.svg rename to addons/antialiased_line2d/antialiased_line_2d.svg diff --git a/addons/antialiased_line2d/antialiased_line_2d.svg.import b/addons/antialiased_line2d/antialiased_line_2d.svg.import new file mode 100644 index 0000000..c0ccd78 --- /dev/null +++ b/addons/antialiased_line2d/antialiased_line_2d.svg.import @@ -0,0 +1,43 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://guodfckewtpv" +path="res://.godot/imported/antialiased_line_2d.svg-e464e33122bc77a73cfbb4456f98b08b.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/antialiased_line2d/antialiased_line_2d.svg" +dest_files=["res://.godot/imported/antialiased_line_2d.svg-e464e33122bc77a73cfbb4456f98b08b.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/addons/antialiased_line2d/antialiased_polygon2d.gd b/addons/antialiased_line2d/antialiased_polygon2d.gd deleted file mode 100644 index 038adca..0000000 --- a/addons/antialiased_line2d/antialiased_polygon2d.gd +++ /dev/null @@ -1,55 +0,0 @@ -# This is a convenience node that automatically synchronizes an AntialiasedLine2D -# with a Polygon2D. -@tool -@icon("antialiased_polygon2d.svg") -class_name AntialiasedPolygon2D -extends Polygon2D - -@export var stroke_color := Color(0.4, 0.5, 1.0): set = set_stroke_color -@export_range(0.0, 1000.0) var stroke_width:float = 10.0: set = set_stroke_width -@export var stroke_joint_mode:Line2D.LineJointMode = Line2D.LINE_JOINT_SHARP: set = set_stroke_joint_mode -@export_range(0.0, 1000.0) var stroke_sharp_limit:float = 2.0: set = set_stroke_sharp_limit -@export_range(1, 32) var stroke_round_precision: int = 8: set = set_stroke_round_precision - -var line_2d := Line2D.new() - - -func _ready() -> void: - line_2d.texture = AntialiasedLine2DTexture.texture - line_2d.texture_mode = Line2D.LINE_TEXTURE_TILE - line_2d.texture_filter = TextureFilter.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC - if polygon.size() >= 1: - line_2d.points = AntialiasedLine2D.construct_closed_line(polygon) - add_child(line_2d) - - -func _set(property: StringName, value: Variant) -> bool: - if property == &"polygon": - line_2d.points = AntialiasedLine2D.construct_closed_line(polygon) - - return false - - -func set_stroke_color(p_stroke_color: Color) -> void: - stroke_color = p_stroke_color - line_2d.default_color = stroke_color - - -func set_stroke_width(p_stroke_width: float) -> void: - stroke_width = p_stroke_width - line_2d.width = stroke_width - - -func set_stroke_joint_mode(p_stroke_joint_mode: Line2D.LineJointMode) -> void: - stroke_joint_mode = p_stroke_joint_mode - line_2d.joint_mode = stroke_joint_mode - - -func set_stroke_sharp_limit(p_stroke_sharp_limit: float) -> void: - stroke_sharp_limit = p_stroke_sharp_limit - line_2d.sharp_limit = stroke_sharp_limit - - -func set_stroke_round_precision(p_stroke_round_precision: int) -> void: - stroke_round_precision = p_stroke_round_precision - line_2d.round_precision = stroke_round_precision diff --git a/addons/antialiased_line2d/antialiased_polygon_2d.gd b/addons/antialiased_line2d/antialiased_polygon_2d.gd new file mode 100644 index 0000000..f1d11ae --- /dev/null +++ b/addons/antialiased_line2d/antialiased_polygon_2d.gd @@ -0,0 +1,62 @@ +# This is a convenience node that automatically synchronizes an AntialiasedLine2D +# with a Polygon2D. +@tool +@icon("antialiased_polygon2d.svg") +class_name AntialiasedPolygon2D +extends Polygon2D + +@export var stroke_color := Color.BLACK: + set = set_stroke_color +@export_range(0.0, 1000.0) var stroke_width: float = 10.0: + set = set_stroke_width +@export var stroke_joint_mode: Line2D.LineJointMode = Line2D.LINE_JOINT_SHARP: + set = set_stroke_joint_mode +@export_range(0.0, 1000.0) var stroke_sharp_limit: float = 2.0: + set = set_stroke_sharp_limit +@export_range(1, 32) var stroke_round_precision: int = 8: + set = set_stroke_round_precision + +var antialiased_line_2d := AntialiasedLine2D.new() + + +func _init() -> void: + antialiased_line_2d.closed = true + add_child(antialiased_line_2d, INTERNAL_MODE_FRONT) + antialiased_line_2d.owner = self + + stroke_color = stroke_color + stroke_width = stroke_width + stroke_joint_mode = stroke_joint_mode + stroke_sharp_limit = stroke_sharp_limit + stroke_round_precision = stroke_round_precision + + +func _set(property: StringName, value: Variant) -> bool: + if property == &"polygon": + antialiased_line_2d.points = polygon + return false + + +func set_stroke_color(p_stroke_color: Color) -> void: + stroke_color = p_stroke_color + antialiased_line_2d.default_color = stroke_color + + +func set_stroke_width(p_stroke_width: float) -> void: + stroke_width = p_stroke_width + antialiased_line_2d.width = stroke_width + + +func set_stroke_joint_mode(p_stroke_joint_mode: Line2D.LineJointMode) -> void: + stroke_joint_mode = p_stroke_joint_mode + antialiased_line_2d.joint_mode = stroke_joint_mode + + +func set_stroke_sharp_limit(p_stroke_sharp_limit: float) -> void: + stroke_sharp_limit = p_stroke_sharp_limit + antialiased_line_2d.sharp_limit = stroke_sharp_limit + + +func set_stroke_round_precision(p_stroke_round_precision: int) -> void: + stroke_round_precision = p_stroke_round_precision + antialiased_line_2d.round_precision = stroke_round_precision diff --git a/addons/antialiased_line2d/antialiased_polygon_2d.gd.uid b/addons/antialiased_line2d/antialiased_polygon_2d.gd.uid new file mode 100644 index 0000000..d9c8502 --- /dev/null +++ b/addons/antialiased_line2d/antialiased_polygon_2d.gd.uid @@ -0,0 +1 @@ +uid://cffrqtfahnwmy diff --git a/addons/antialiased_line2d/antialiased_polygon2d.svg b/addons/antialiased_line2d/antialiased_polygon_2d.svg similarity index 100% rename from addons/antialiased_line2d/antialiased_polygon2d.svg rename to addons/antialiased_line2d/antialiased_polygon_2d.svg diff --git a/addons/antialiased_line2d/antialiased_polygon2d.svg.import b/addons/antialiased_line2d/antialiased_polygon_2d.svg.import similarity index 65% rename from addons/antialiased_line2d/antialiased_polygon2d.svg.import rename to addons/antialiased_line2d/antialiased_polygon_2d.svg.import index 49414e5..3e2cfd9 100644 --- a/addons/antialiased_line2d/antialiased_polygon2d.svg.import +++ b/addons/antialiased_line2d/antialiased_polygon_2d.svg.import @@ -3,21 +3,23 @@ importer="texture" type="CompressedTexture2D" uid="uid://bkfc7y0qnfi4a" -path="res://.godot/imported/antialiased_polygon2d.svg-d9d32c42c22022e4f4053cee124a07c0.ctex" +path="res://.godot/imported/antialiased_polygon_2d.svg-551511e1467fb80a5d4a598652644318.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://addons/antialiased_line2d/antialiased_polygon2d.svg" -dest_files=["res://.godot/imported/antialiased_polygon2d.svg-d9d32c42c22022e4f4053cee124a07c0.ctex"] +source_file="res://addons/antialiased_line2d/antialiased_polygon_2d.svg" +dest_files=["res://.godot/imported/antialiased_polygon_2d.svg-551511e1467fb80a5d4a598652644318.ctex"] [params] compress/mode=0 compress/high_quality=false compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 @@ -25,6 +27,10 @@ mipmaps/generate=false mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 process/fix_alpha_border=true process/premult_alpha=false process/normal_map_invert_y=false diff --git a/addons/antialiased_line2d/antialiased_regular_polygon2d.gd b/addons/antialiased_line2d/antialiased_regular_polygon2d.gd deleted file mode 100644 index 02c49f8..0000000 --- a/addons/antialiased_line2d/antialiased_regular_polygon2d.gd +++ /dev/null @@ -1,82 +0,0 @@ -# This is a convenience node that automatically synchronizes an AntialiasedLine2D -# with a Polygon2D, while also generating a regular Polygon2D shape (hexagon, octagon, …). -@tool -@icon("antialiased_regular_polygon2d.svg") -class_name AntialiasedRegularPolygon2D -extends Polygon2D - -@export var size := Vector2(64, 64): set = set_size -@export_range(3, 128) var sides: int = 32: set = set_sides -@export_range(0.0, 360.0) var angle_degrees: float = 360: set = set_angle_degrees -@export var stroke_color := Color(0.4, 0.5, 1.0): set = set_stroke_color -@export_range(0.0, 1000.0) var stroke_width:float = 10.0: set = set_stroke_width -@export var stroke_joint_mode:Line2D.LineJointMode = Line2D.LINE_JOINT_SHARP: set = set_stroke_joint_mode -@export_range(0.0, 1000.0) var stroke_sharp_limit:float = 2.0: set = set_stroke_sharp_limit -@export_range(1, 32) var stroke_round_precision: int = 8: set = set_stroke_round_precision - -var line_2d := Line2D.new() - - -func _ready() -> void: - line_2d.texture = AntialiasedLine2DTexture.texture - line_2d.texture_mode = Line2D.LINE_TEXTURE_TILE - line_2d.texture_filter = TextureFilter.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC - update_points() - add_child(line_2d) - - -func _set(property: StringName, value: Variant) -> bool: - if property == &"polygon": - line_2d.points = AntialiasedLine2D.construct_closed_line(value) - - return false - - -func update_points() -> void: - var points := PackedVector2Array() - for side in sides: - points.push_back(Vector2(0, -1).rotated(side / float(sides) * deg_to_rad(angle_degrees)) * size * 0.5) - if not is_equal_approx(angle_degrees, 360.0): - points.push_back(Vector2.ZERO) - polygon = points - # Force an update of the Line2D here to prevent it from getting out of sync. - line_2d.points = AntialiasedLine2D.construct_closed_line(polygon) - - -func set_size(p_size: Vector2) -> void: - size = p_size - update_points() - - -func set_sides(p_sides: int) -> void: - sides = p_sides - update_points() - - -func set_angle_degrees(p_angle_degrees: float) -> void: - angle_degrees = p_angle_degrees - update_points() - - -func set_stroke_color(p_stroke_color: Color) -> void: - stroke_color = p_stroke_color - line_2d.default_color = stroke_color - -func set_stroke_width(p_stroke_width: float) -> void: - stroke_width = p_stroke_width - line_2d.width = stroke_width - - -func set_stroke_joint_mode(p_stroke_joint_mode: Line2D.LineJointMode) -> void: - stroke_joint_mode = p_stroke_joint_mode - line_2d.joint_mode = stroke_joint_mode - - -func set_stroke_sharp_limit(p_stroke_sharp_limit: float) -> void: - stroke_sharp_limit = p_stroke_sharp_limit - line_2d.sharp_limit = stroke_sharp_limit - - -func set_stroke_round_precision(p_stroke_round_precision: int) -> void: - stroke_round_precision = p_stroke_round_precision - line_2d.round_precision = stroke_round_precision diff --git a/addons/antialiased_line2d/antialiased_regular_polygon_2d.gd b/addons/antialiased_line2d/antialiased_regular_polygon_2d.gd new file mode 100644 index 0000000..aff7613 --- /dev/null +++ b/addons/antialiased_line2d/antialiased_regular_polygon_2d.gd @@ -0,0 +1,47 @@ +# This is a convenience node that automatically synchronizes an AntialiasedLine2D +# with a Polygon2D, while also generating a regular Polygon2D shape (hexagon, octagon, …). +@tool +@icon("antialiased_regular_polygon2d.svg") +class_name AntialiasedRegularPolygon2D +extends AntialiasedPolygon2D + +@export_custom(PROPERTY_HINT_LINK, "suffix:px") var size := Vector2(64.0, 64.0): + set = set_size +@export_range(3, 128, 1, "or_greater") var sides := 32: + set = set_sides +@export_range(0.0, 360.0, 0.01, "radians_as_degrees", "prefer_slider") var arc := TAU: + set = set_arc + + +func _init() -> void: + super() + _update_points() + + +func _update_points() -> void: + var points := PackedVector2Array() + var half_size := size * 0.5 + for side in sides: + points.push_back(Vector2.RIGHT.rotated(side / float(sides) * arc) * half_size) + + if not is_equal_approx(arc, TAU): + points.push_back(Vector2.RIGHT.rotated(arc) * half_size) + points.push_back(Vector2.ZERO) + + polygon = points + antialiased_line_2d.points = polygon + + +func set_size(p_size: Vector2) -> void: + size = p_size + _update_points() + + +func set_sides(p_sides: int) -> void: + sides = p_sides + _update_points() + + +func set_arc(p_arc: float) -> void: + arc = p_arc + _update_points() diff --git a/addons/antialiased_line2d/antialiased_regular_polygon_2d.gd.uid b/addons/antialiased_line2d/antialiased_regular_polygon_2d.gd.uid new file mode 100644 index 0000000..53eb65c --- /dev/null +++ b/addons/antialiased_line2d/antialiased_regular_polygon_2d.gd.uid @@ -0,0 +1 @@ +uid://do0g7nebwevll diff --git a/addons/antialiased_line2d/antialiased_regular_polygon2d.svg b/addons/antialiased_line2d/antialiased_regular_polygon_2d.svg similarity index 100% rename from addons/antialiased_line2d/antialiased_regular_polygon2d.svg rename to addons/antialiased_line2d/antialiased_regular_polygon_2d.svg diff --git a/addons/antialiased_line2d/antialiased_regular_polygon2d.svg.import b/addons/antialiased_line2d/antialiased_regular_polygon_2d.svg.import similarity index 64% rename from addons/antialiased_line2d/antialiased_regular_polygon2d.svg.import rename to addons/antialiased_line2d/antialiased_regular_polygon_2d.svg.import index c958857..d387caf 100644 --- a/addons/antialiased_line2d/antialiased_regular_polygon2d.svg.import +++ b/addons/antialiased_line2d/antialiased_regular_polygon_2d.svg.import @@ -3,21 +3,23 @@ importer="texture" type="CompressedTexture2D" uid="uid://cypudkhnexspo" -path="res://.godot/imported/antialiased_regular_polygon2d.svg-90c0efb58c0991f1567ca6f17fea2cda.ctex" +path="res://.godot/imported/antialiased_regular_polygon_2d.svg-e5fe8971a84cb7ee564c075edcb739d4.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://addons/antialiased_line2d/antialiased_regular_polygon2d.svg" -dest_files=["res://.godot/imported/antialiased_regular_polygon2d.svg-90c0efb58c0991f1567ca6f17fea2cda.ctex"] +source_file="res://addons/antialiased_line2d/antialiased_regular_polygon_2d.svg" +dest_files=["res://.godot/imported/antialiased_regular_polygon_2d.svg-e5fe8971a84cb7ee564c075edcb739d4.ctex"] [params] compress/mode=0 compress/high_quality=false compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 @@ -25,6 +27,10 @@ mipmaps/generate=false mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 process/fix_alpha_border=true process/premult_alpha=false process/normal_map_invert_y=false diff --git a/addons/antialiased_line2d/antialiased_texture.res b/addons/antialiased_line2d/antialiased_texture.res new file mode 100644 index 0000000000000000000000000000000000000000..034dfea955685e52d2f425538f88eab3ba84210d GIT binary patch literal 175234 zcmeI*!A=uF7y#g*fD#fsc_4c5?gfv;o8d&_#lpQ=%Fs4;X|vr%jy{KvKztwH!dIv> zYb#Pi(hv_ozuo-V=|8hG|9sn~haTEKX&;68v6ZgR=CPNq$7Rurr}3(uR&hQggw53Y zv3s%oE&hD_C%HmnJB`^-QN_tOy74lG7k~F%7G(_ij`N}}!t>Oa zbgRL*Zps_vvQjF9R*IJ?nyKC&95e-Y;^6FEFYIjO5h1)zajSp6q0Vr6c=kDb`kp8G zz3=AsX40H{l_HmrBddHFoY(zk`yox8v$?K*9Q6A2Kk186RTgzKYB!DgI4wU6$Nl24 z$?T*|IT)A4c+#wvD_yMAZ1_z|Twk}s%(>nIGY0_z1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkKcNg&Le1lCtz>Eqxf0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0tD7pV157j{$cEVZQpn{PJjRb0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pkPfFln{0e{nDxTECuo(gb2oNCfNCfWx&Ar;4kAy*)cL=QZly64e zG0lHV->h`IwY{S>*KkHz5jN&Dy* DVDfqo literal 0 HcmV?d00001 diff --git a/addons/antialiased_line2d/texture.gd b/addons/antialiased_line2d/generate_antialiased_texture.gd similarity index 66% rename from addons/antialiased_line2d/texture.gd rename to addons/antialiased_line2d/generate_antialiased_texture.gd index b3973c6..cddad12 100644 --- a/addons/antialiased_line2d/texture.gd +++ b/addons/antialiased_line2d/generate_antialiased_texture.gd @@ -1,22 +1,19 @@ @tool -extends Node +extends EditorScript # Generates the antialiased Line2D texture that will be used by the various nodes. # We do this in a singleton to perform this generation once at load, rather than once # for every AntialiasedLine2D node. This generation can take several dozen milliseconds, # so it would cause stuttering if performed during gameplay. -var texture: ImageTexture = null - - -func _ready() -> void: +func _run() -> void: # Generate a texture with custom mipmaps (1-pixel feather on the top and bottom sides). - # The texture must be square for mipmaps to work correctly. The texture's in-memory size is still - # pretty low (less than 200 KB), so this should not cause any performance problems. + # The texture must be square for mipmaps to work correctly. The texture's in-memory size + # is still pretty low (less than 200 KB), so this should not cause any performance problems. var data := PackedByteArray() - for mipmap in [256, 128, 64, 32, 16, 8, 4, 2, 1]: - for y in mipmap: - for x in mipmap: + for mipmap: int in [256, 128, 64, 32, 16, 8, 4, 2, 1]: + for y: int in range(mipmap): + for x: int in range(mipmap): # White. If you need a different color for the Line2D, change the `default_color` property. data.push_back(255) @@ -42,5 +39,9 @@ func _ready() -> void: # Average of 0 and 255 (there is only one pixel). data.push_back(128) - var image = Image.create_from_data(256, 256, true, Image.FORMAT_LA8, data) - texture = ImageTexture.create_from_image(image) + var image := Image.create_from_data(256, 256, true, Image.FORMAT_LA8, data) + var texture := ImageTexture.create_from_image(image) + + # Saving it binary significantly reduces the size of scenes using these addon nodes. It also + # stops Godot complaining that the scenes are too large. + ResourceSaver.save(texture, "res://addons/antialiased_line2d/antialiased_texture.res") diff --git a/addons/antialiased_line2d/generate_antialiased_texture.gd.uid b/addons/antialiased_line2d/generate_antialiased_texture.gd.uid new file mode 100644 index 0000000..3211245 --- /dev/null +++ b/addons/antialiased_line2d/generate_antialiased_texture.gd.uid @@ -0,0 +1 @@ +uid://bmweaw7b725v0 diff --git a/addons/antialiased_line2d/plugin.gd b/addons/antialiased_line2d/plugin.gd index e5e9dab..7b6b371 100644 --- a/addons/antialiased_line2d/plugin.gd +++ b/addons/antialiased_line2d/plugin.gd @@ -2,9 +2,9 @@ extends EditorPlugin -func _enter_tree() -> void: - add_autoload_singleton("AntialiasedLine2DTexture", "res://addons/antialiased_line2d/texture.gd") - - -func _exit_tree() -> void: - remove_autoload_singleton("AntialiasedLine2DTexture") +#func _enter_tree() -> void: + #add_autoload_singleton("AntialiasedLine2DTexture", "res://addons/antialiased_line2d/antialiased_line_2d_texture.gd") +# +# +#func _exit_tree() -> void: + #remove_autoload_singleton("AntialiasedLine2DTexture") diff --git a/addons/antialiased_line2d/plugin.gd.uid b/addons/antialiased_line2d/plugin.gd.uid new file mode 100644 index 0000000..448c44c --- /dev/null +++ b/addons/antialiased_line2d/plugin.gd.uid @@ -0,0 +1 @@ +uid://bc54m2bgeinam diff --git a/dev_2d.tscn b/dev_2d.tscn new file mode 100644 index 0000000..161cb7a --- /dev/null +++ b/dev_2d.tscn @@ -0,0 +1,11 @@ +[gd_scene load_steps=2 format=3 uid="uid://dj2evvyq4bs4d"] + +[ext_resource type="Script" uid="uid://do0g7nebwevll" path="res://addons/antialiased_line2d/antialiased_regular_polygon_2d.gd" id="1_0dtyr"] + +[node name="Dev2D" type="Node2D" unique_id=156282689] + +[node name="AntialiasedRegularPolygon2D" type="Polygon2D" parent="." unique_id=1545685098] +polygon = PackedVector2Array(32, 0, 24.513422, 20.569202, 5.556743, 31.513847, -16.000002, 27.712812, -30.070164, 10.944647, -30.070164, -10.944645, -15.999997, -27.712814, 5.5567408, -31.513847, 24.513418, -20.569208) +script = ExtResource("1_0dtyr") +sides = 9 +metadata/_custom_type_script = "uid://do0g7nebwevll" diff --git a/icon.png b/icon.png deleted file mode 100644 index 6518f380720ee6818f796c0f010b63233a9da36f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1882 zcmXX`3sh5A7Cn!IKp_gwwO(;7 zXSW#75 zHeH=uS0|gTm7!VJ(577l2sbtwYGrx^YUDGBBQ?_Aj34y%vgtY`l80}7w;Y+S;yNlC^+qDSF$Q8AY!6EZt>yz*_4$I*2cn;bNu_ug?>TRll89dKs+;kyVWP^kzc@r7S;7& zn-h)g8`nkuy?DdVxko!U`JVb>f7Lzwlh&b;lbpm0V{^SbMUphbmE6=|2P@B!Z@=*l z44UrsHN`?kM2iLzw>+lI_eadR$=*!R?D5~NjZPLq@1lo8e)^;TdbsrYpg+0sVD{(o z(dY&yiT*TtA5{HNffcp)K;(&ZsIo%%KEk^XhbV3jw4_t;Aw)~ahu~DYAH-#li6>Ny zHOB##Xf5+}pi9T5KSvJ76Y)m6cf2;|tN2w=D`Pn4FhPxZhLH^*SlL&~{x6kls6R@!0$L~kG zE0b1kW+OR0yB%?g?))=V4D=HQ)qUIqZ%j%RWAuZKm)Pbkea3o`9TD{>iVu8sfOcom zejz3F8-@?wB5;o;l3q*QVRDfjl!@CrjyAO$KDsrvYNqYwc&5V6ly&4`G*D0 z-kgWF!P>(UlOH{O8pj~d+j?7Sw#|9_R?sY_y}(p!xV}(&f%e_L_i(KVq zrgQAXc6-47G~3dtqivf?lpn}XyE zXZZ9GIAoHS5K@L%2Tj@-JNROf(v>&-Q!FJ6oJ|~#rHccw<6%Tf3EP^;U-wlvo=HeO z2dF0+Xco|KmcSdu#?;s-tkkFCd@XMZwG z6J5Mb&}n0qn2K|AJVgKg-YWKm&$`iwqaisi-Mn{*n3;C&fy9z+{Th67wQsUo%-x-yq^q$J~xz8X!R+BN(7dGryYzMKo&)%JmfdMUOLV5RJgSM=mI; zA=0lB(=hh~Tx4g0+sBI}CBL6Rg#Kr z)q4S2v__jCm@{)zOEjdo7Js@p4 zlcb$DtlM?%y`>cdgV^_op;~ Date: Thu, 4 Dec 2025 12:57:18 +0200 Subject: [PATCH 2/7] fix: update stroke using `draw` signal instead of `_set()` fix #12 by updating stroke using `draw` signal instead of handling updates in `_set()` --- addons/antialiased_line2d/antialiased_polygon_2d.gd | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/addons/antialiased_line2d/antialiased_polygon_2d.gd b/addons/antialiased_line2d/antialiased_polygon_2d.gd index f1d11ae..7ea5b54 100644 --- a/addons/antialiased_line2d/antialiased_polygon_2d.gd +++ b/addons/antialiased_line2d/antialiased_polygon_2d.gd @@ -20,6 +20,8 @@ var antialiased_line_2d := AntialiasedLine2D.new() func _init() -> void: + draw.connect(func() -> void: antialiased_line_2d.points = polygon) + antialiased_line_2d.closed = true add_child(antialiased_line_2d, INTERNAL_MODE_FRONT) antialiased_line_2d.owner = self @@ -31,12 +33,6 @@ func _init() -> void: stroke_round_precision = stroke_round_precision -func _set(property: StringName, value: Variant) -> bool: - if property == &"polygon": - antialiased_line_2d.points = polygon - return false - - func set_stroke_color(p_stroke_color: Color) -> void: stroke_color = p_stroke_color antialiased_line_2d.default_color = stroke_color From 4b96bed9cdbef00fea7e9fea9b72a97cad67c10d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=83zvan=20C=2E=20R=C4=83dulescu?= Date: Thu, 4 Dec 2025 13:15:45 +0200 Subject: [PATCH 3/7] Make a demo scene --- demo_2d.tscn | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ dev_2d.tscn | 11 ----------- 2 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 demo_2d.tscn delete mode 100644 dev_2d.tscn diff --git a/demo_2d.tscn b/demo_2d.tscn new file mode 100644 index 0000000..912edb2 --- /dev/null +++ b/demo_2d.tscn @@ -0,0 +1,49 @@ +[gd_scene load_steps=7 format=3 uid="uid://dj2evvyq4bs4d"] + +[ext_resource type="Texture2D" uid="uid://bkcr36hllehnr" path="res://addons/antialiased_line2d/antialiased_texture.res" id="1_itky3"] +[ext_resource type="Script" uid="uid://do0g7nebwevll" path="res://addons/antialiased_line2d/antialiased_regular_polygon_2d.gd" id="1_ppfrx"] +[ext_resource type="Script" uid="uid://dn534defa6rgl" path="res://addons/antialiased_line2d/antialiased_line_2d.gd" id="2_0d3o8"] +[ext_resource type="Script" uid="uid://cffrqtfahnwmy" path="res://addons/antialiased_line2d/antialiased_polygon_2d.gd" id="3_ywlda"] + +[sub_resource type="Curve" id="Curve_lbxes"] +_data = [Vector2(0, 0.21329296), 0.0, -0.5499946, 0, 0, Vector2(1, 1), 0.0, 0.0, 0, 0] +point_count = 2 + +[sub_resource type="Gradient" id="Gradient_mwmwj"] +colors = PackedColorArray(0.8936984, 0.5757751, 0, 1, 1, 0.40018785, 1, 1) + +[node name="Demo2D" type="Node2D" unique_id=156282689] + +[node name="AntialiasedLine2D" type="Line2D" parent="." unique_id=1129113876] +texture_filter = 6 +position = Vector2(234, 304) +points = PackedVector2Array(-79, -165, 134, -59, -106, 146, 126, 225) +width = 30.0 +width_curve = SubResource("Curve_lbxes") +gradient = SubResource("Gradient_mwmwj") +texture = ExtResource("1_itky3") +texture_mode = 1 +script = ExtResource("2_0d3o8") +metadata/_custom_type_script = "uid://dn534defa6rgl" + +[node name="AntialiasedPolygon2D" type="Polygon2D" parent="." unique_id=1315508753] +position = Vector2(616, 360) +color = Color(0.4445356, 0.6073561, 1, 1) +polygon = PackedVector2Array(-88, -179, 102, -164, 87, -26, 177, 54, -124, 166, -67, -62) +script = ExtResource("3_ywlda") +stroke_color = Color(0.8694817, 0.9994655, 0.5256372, 1) +stroke_width = 30.0 +stroke_joint_mode = 2 +metadata/_custom_type_script = "uid://cffrqtfahnwmy" + +[node name="AntialiasedRegularPolygon2D" type="Polygon2D" parent="." unique_id=924601883] +position = Vector2(948, 307) +color = Color(1, 0.37254903, 0.16078432, 1) +polygon = PackedVector2Array(100, 0, 98.66433, 16.289547, 94.69301, 32.143948, 88.19213, 47.13967, 79.335335, 60.876144, 68.35923, 72.986404, 55.557026, 83.14696, 41.270706, 91.08638, 25.881907, 96.59258, 9.801713, 99.51847, -6.5403166, 99.7859, -22.707632, 97.387695, -38.26834, 92.387955, -52.80678, 84.92021, -65.93458, 75.18399, -77.30105, 63.439327, -86.60254, 50.000008, -93.59059, 35.224995, -98.07853, 19.509031, -99.94646, 3.2719169, -99.144485, -13.052626, -95.69404, -29.028467, -89.68727, -44.228878, -81.28467, -58.24777, -70.710686, -70.71067, -58.24778, -81.28466, -44.22887, -89.68728, -29.028454, -95.69404, -13.052639, -99.144485, 3.2719028, -99.94646, 19.50904, -98.07852, 35.22503, -93.59058, 49.999992, -86.60255, 0, 0) +script = ExtResource("1_ppfrx") +size = Vector2(200, 200) +arc = 5.235987755982989 +stroke_color = Color(0.14464921, 0.116794996, 0.29650894, 1) +stroke_width = 32.0 +stroke_joint_mode = 1 +metadata/_custom_type_script = "uid://do0g7nebwevll" diff --git a/dev_2d.tscn b/dev_2d.tscn deleted file mode 100644 index 161cb7a..0000000 --- a/dev_2d.tscn +++ /dev/null @@ -1,11 +0,0 @@ -[gd_scene load_steps=2 format=3 uid="uid://dj2evvyq4bs4d"] - -[ext_resource type="Script" uid="uid://do0g7nebwevll" path="res://addons/antialiased_line2d/antialiased_regular_polygon_2d.gd" id="1_0dtyr"] - -[node name="Dev2D" type="Node2D" unique_id=156282689] - -[node name="AntialiasedRegularPolygon2D" type="Polygon2D" parent="." unique_id=1545685098] -polygon = PackedVector2Array(32, 0, 24.513422, 20.569202, 5.556743, 31.513847, -16.000002, 27.712812, -30.070164, 10.944647, -30.070164, -10.944645, -15.999997, -27.712814, 5.5567408, -31.513847, 24.513418, -20.569208) -script = ExtResource("1_0dtyr") -sides = 9 -metadata/_custom_type_script = "uid://do0g7nebwevll" From 767629b4698d7dac3cb09fc3528252edbc2710db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=83zvan=20C=2E=20R=C4=83dulescu?= Date: Thu, 4 Dec 2025 23:10:15 +0200 Subject: [PATCH 4/7] Extract utility regular polygon build function --- .../antialiased_regular_polygon_2d.gd | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/addons/antialiased_line2d/antialiased_regular_polygon_2d.gd b/addons/antialiased_line2d/antialiased_regular_polygon_2d.gd index aff7613..7305254 100644 --- a/addons/antialiased_line2d/antialiased_regular_polygon_2d.gd +++ b/addons/antialiased_line2d/antialiased_regular_polygon_2d.gd @@ -15,20 +15,13 @@ extends AntialiasedPolygon2D func _init() -> void: super() + for connection: Dictionary in draw.get_connections(): + draw.disconnect(connection.callable) _update_points() func _update_points() -> void: - var points := PackedVector2Array() - var half_size := size * 0.5 - for side in sides: - points.push_back(Vector2.RIGHT.rotated(side / float(sides) * arc) * half_size) - - if not is_equal_approx(arc, TAU): - points.push_back(Vector2.RIGHT.rotated(arc) * half_size) - points.push_back(Vector2.ZERO) - - polygon = points + polygon = build_polygon(size, sides, arc) antialiased_line_2d.points = polygon @@ -45,3 +38,16 @@ func set_sides(p_sides: int) -> void: func set_arc(p_arc: float) -> void: arc = p_arc _update_points() + + +static func build_polygon(size: Vector2, sides := 32, arc := TAU, has_point_at_origin := true) -> PackedVector2Array: + var result := PackedVector2Array() + var half_size := size * 0.5 + for side: int in range(sides): + result.push_back(Vector2.RIGHT.rotated(side / float(sides) * arc) * half_size) + + if not is_equal_approx(arc, TAU): + result.push_back(Vector2.RIGHT.rotated(arc) * half_size) + if has_point_at_origin: + result.push_back(Vector2.ZERO) + return result From e51f8259133c0e95aa687ec2dbde89c85858d506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=83zvan=20C=2E=20R=C4=83dulescu?= Date: Fri, 5 Dec 2025 16:45:29 +0200 Subject: [PATCH 5/7] Extend `arc` to `[-TAU, TAU]` range since in code we can use both positive and negative angles --- addons/antialiased_line2d/antialiased_regular_polygon_2d.gd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/antialiased_line2d/antialiased_regular_polygon_2d.gd b/addons/antialiased_line2d/antialiased_regular_polygon_2d.gd index 7305254..dfe6d4a 100644 --- a/addons/antialiased_line2d/antialiased_regular_polygon_2d.gd +++ b/addons/antialiased_line2d/antialiased_regular_polygon_2d.gd @@ -9,7 +9,7 @@ extends AntialiasedPolygon2D set = set_size @export_range(3, 128, 1, "or_greater") var sides := 32: set = set_sides -@export_range(0.0, 360.0, 0.01, "radians_as_degrees", "prefer_slider") var arc := TAU: +@export_range(-360, 360.0, 0.01, "radians_as_degrees", "prefer_slider") var arc := TAU: set = set_arc @@ -36,7 +36,7 @@ func set_sides(p_sides: int) -> void: func set_arc(p_arc: float) -> void: - arc = p_arc + arc = clampf(p_arc, -TAU, TAU) _update_points() @@ -46,7 +46,7 @@ static func build_polygon(size: Vector2, sides := 32, arc := TAU, has_point_at_o for side: int in range(sides): result.push_back(Vector2.RIGHT.rotated(side / float(sides) * arc) * half_size) - if not is_equal_approx(arc, TAU): + if not is_equal_approx(absf(arc), TAU): result.push_back(Vector2.RIGHT.rotated(arc) * half_size) if has_point_at_origin: result.push_back(Vector2.ZERO) From 9c28465ed753bcd625330c5ef042a8572490564d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=83zvan=20C=2E=20R=C4=83dulescu?= Date: Mon, 15 Dec 2025 14:34:17 +0200 Subject: [PATCH 6/7] fix: incorrect `add_child()` call --- addons/antialiased_line2d/antialiased_polygon_2d.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/antialiased_line2d/antialiased_polygon_2d.gd b/addons/antialiased_line2d/antialiased_polygon_2d.gd index 7ea5b54..20d71cf 100644 --- a/addons/antialiased_line2d/antialiased_polygon_2d.gd +++ b/addons/antialiased_line2d/antialiased_polygon_2d.gd @@ -23,7 +23,7 @@ func _init() -> void: draw.connect(func() -> void: antialiased_line_2d.points = polygon) antialiased_line_2d.closed = true - add_child(antialiased_line_2d, INTERNAL_MODE_FRONT) + add_child(antialiased_line_2d, false, INTERNAL_MODE_FRONT) antialiased_line_2d.owner = self stroke_color = stroke_color From 92f2259ed84dcd03529c838ab3342d627c6166b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=83zvan=20C=2E=20R=C4=83dulescu?= Date: Fri, 23 Jan 2026 12:35:23 +0200 Subject: [PATCH 7/7] fix: cleanup & `AntialiasedLine2D` revert defaults Since `_is_instantiated` is only updated propertly in `_ready()` I reverted all scripts to using `_ready()` instead of `_init()` to be symetrical and not have `AntialiasedLine2D` the only odd one with potentially both `_init()` & `_ready()` or just `_ready()`. - removed commented out code from `plug.gd` - removed top-level files - added `AntialiasedLine2D` revert defaults for built-in `texture`, `texture_mode` & `texture_filter` properties --- .../antialiased_line2d/antialiased_line_2d.gd | 28 ++++++++++- .../antialiased_polygon_2d.gd | 6 +-- .../antialiased_regular_polygon_2d.gd | 4 +- addons/antialiased_line2d/plugin.gd | 8 --- demo_2d.tscn | 49 ------------------- icon.svg | 1 - icon.svg.import | 43 ---------------- project.godot | 31 ------------ 8 files changed, 31 insertions(+), 139 deletions(-) delete mode 100644 demo_2d.tscn delete mode 100644 icon.svg delete mode 100644 icon.svg.import delete mode 100644 project.godot diff --git a/addons/antialiased_line2d/antialiased_line_2d.gd b/addons/antialiased_line2d/antialiased_line_2d.gd index e83dba2..4c14c2b 100644 --- a/addons/antialiased_line2d/antialiased_line_2d.gd +++ b/addons/antialiased_line2d/antialiased_line_2d.gd @@ -3,7 +3,31 @@ class_name AntialiasedLine2D extends Line2D -func _init() -> void: - texture = preload("antialiased_texture.res") +const TEXTURE = preload("antialiased_texture.res") + +@export_storage var _is_instantiated := false + + +func _ready() -> void: + if _is_instantiated: + return + + texture = TEXTURE texture_mode = Line2D.LINE_TEXTURE_TILE texture_filter = TextureFilter.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC + + _is_instantiated = true + + +func _property_can_revert(property: StringName) -> bool: + return property in [&"texture", &"texture_mode", &"texture_filter"] + + +func _property_get_revert(property: StringName) -> Variant: + if property == &"texture": + return TEXTURE + elif property == &"texture_mode": + return Line2D.LINE_TEXTURE_TILE + elif property == &"texture_filter": + return TextureFilter.TEXTURE_FILTER_LINEAR_WITH_MIPMAPS_ANISOTROPIC + return null diff --git a/addons/antialiased_line2d/antialiased_polygon_2d.gd b/addons/antialiased_line2d/antialiased_polygon_2d.gd index 20d71cf..ad2e7af 100644 --- a/addons/antialiased_line2d/antialiased_polygon_2d.gd +++ b/addons/antialiased_line2d/antialiased_polygon_2d.gd @@ -1,7 +1,7 @@ # This is a convenience node that automatically synchronizes an AntialiasedLine2D # with a Polygon2D. @tool -@icon("antialiased_polygon2d.svg") +@icon("antialiased_polygon_2d.svg") class_name AntialiasedPolygon2D extends Polygon2D @@ -19,11 +19,11 @@ extends Polygon2D var antialiased_line_2d := AntialiasedLine2D.new() -func _init() -> void: +func _ready() -> void: draw.connect(func() -> void: antialiased_line_2d.points = polygon) antialiased_line_2d.closed = true - add_child(antialiased_line_2d, false, INTERNAL_MODE_FRONT) + add_child(antialiased_line_2d, false, Node.INTERNAL_MODE_FRONT) antialiased_line_2d.owner = self stroke_color = stroke_color diff --git a/addons/antialiased_line2d/antialiased_regular_polygon_2d.gd b/addons/antialiased_line2d/antialiased_regular_polygon_2d.gd index dfe6d4a..dd7391d 100644 --- a/addons/antialiased_line2d/antialiased_regular_polygon_2d.gd +++ b/addons/antialiased_line2d/antialiased_regular_polygon_2d.gd @@ -1,7 +1,7 @@ # This is a convenience node that automatically synchronizes an AntialiasedLine2D # with a Polygon2D, while also generating a regular Polygon2D shape (hexagon, octagon, …). @tool -@icon("antialiased_regular_polygon2d.svg") +@icon("antialiased_regular_polygon_2d.svg") class_name AntialiasedRegularPolygon2D extends AntialiasedPolygon2D @@ -13,7 +13,7 @@ extends AntialiasedPolygon2D set = set_arc -func _init() -> void: +func _ready() -> void: super() for connection: Dictionary in draw.get_connections(): draw.disconnect(connection.callable) diff --git a/addons/antialiased_line2d/plugin.gd b/addons/antialiased_line2d/plugin.gd index 7b6b371..5af87f6 100644 --- a/addons/antialiased_line2d/plugin.gd +++ b/addons/antialiased_line2d/plugin.gd @@ -1,10 +1,2 @@ @tool extends EditorPlugin - - -#func _enter_tree() -> void: - #add_autoload_singleton("AntialiasedLine2DTexture", "res://addons/antialiased_line2d/antialiased_line_2d_texture.gd") -# -# -#func _exit_tree() -> void: - #remove_autoload_singleton("AntialiasedLine2DTexture") diff --git a/demo_2d.tscn b/demo_2d.tscn deleted file mode 100644 index 912edb2..0000000 --- a/demo_2d.tscn +++ /dev/null @@ -1,49 +0,0 @@ -[gd_scene load_steps=7 format=3 uid="uid://dj2evvyq4bs4d"] - -[ext_resource type="Texture2D" uid="uid://bkcr36hllehnr" path="res://addons/antialiased_line2d/antialiased_texture.res" id="1_itky3"] -[ext_resource type="Script" uid="uid://do0g7nebwevll" path="res://addons/antialiased_line2d/antialiased_regular_polygon_2d.gd" id="1_ppfrx"] -[ext_resource type="Script" uid="uid://dn534defa6rgl" path="res://addons/antialiased_line2d/antialiased_line_2d.gd" id="2_0d3o8"] -[ext_resource type="Script" uid="uid://cffrqtfahnwmy" path="res://addons/antialiased_line2d/antialiased_polygon_2d.gd" id="3_ywlda"] - -[sub_resource type="Curve" id="Curve_lbxes"] -_data = [Vector2(0, 0.21329296), 0.0, -0.5499946, 0, 0, Vector2(1, 1), 0.0, 0.0, 0, 0] -point_count = 2 - -[sub_resource type="Gradient" id="Gradient_mwmwj"] -colors = PackedColorArray(0.8936984, 0.5757751, 0, 1, 1, 0.40018785, 1, 1) - -[node name="Demo2D" type="Node2D" unique_id=156282689] - -[node name="AntialiasedLine2D" type="Line2D" parent="." unique_id=1129113876] -texture_filter = 6 -position = Vector2(234, 304) -points = PackedVector2Array(-79, -165, 134, -59, -106, 146, 126, 225) -width = 30.0 -width_curve = SubResource("Curve_lbxes") -gradient = SubResource("Gradient_mwmwj") -texture = ExtResource("1_itky3") -texture_mode = 1 -script = ExtResource("2_0d3o8") -metadata/_custom_type_script = "uid://dn534defa6rgl" - -[node name="AntialiasedPolygon2D" type="Polygon2D" parent="." unique_id=1315508753] -position = Vector2(616, 360) -color = Color(0.4445356, 0.6073561, 1, 1) -polygon = PackedVector2Array(-88, -179, 102, -164, 87, -26, 177, 54, -124, 166, -67, -62) -script = ExtResource("3_ywlda") -stroke_color = Color(0.8694817, 0.9994655, 0.5256372, 1) -stroke_width = 30.0 -stroke_joint_mode = 2 -metadata/_custom_type_script = "uid://cffrqtfahnwmy" - -[node name="AntialiasedRegularPolygon2D" type="Polygon2D" parent="." unique_id=924601883] -position = Vector2(948, 307) -color = Color(1, 0.37254903, 0.16078432, 1) -polygon = PackedVector2Array(100, 0, 98.66433, 16.289547, 94.69301, 32.143948, 88.19213, 47.13967, 79.335335, 60.876144, 68.35923, 72.986404, 55.557026, 83.14696, 41.270706, 91.08638, 25.881907, 96.59258, 9.801713, 99.51847, -6.5403166, 99.7859, -22.707632, 97.387695, -38.26834, 92.387955, -52.80678, 84.92021, -65.93458, 75.18399, -77.30105, 63.439327, -86.60254, 50.000008, -93.59059, 35.224995, -98.07853, 19.509031, -99.94646, 3.2719169, -99.144485, -13.052626, -95.69404, -29.028467, -89.68727, -44.228878, -81.28467, -58.24777, -70.710686, -70.71067, -58.24778, -81.28466, -44.22887, -89.68728, -29.028454, -95.69404, -13.052639, -99.144485, 3.2719028, -99.94646, 19.50904, -98.07852, 35.22503, -93.59058, 49.999992, -86.60255, 0, 0) -script = ExtResource("1_ppfrx") -size = Vector2(200, 200) -arc = 5.235987755982989 -stroke_color = Color(0.14464921, 0.116794996, 0.29650894, 1) -stroke_width = 32.0 -stroke_joint_mode = 1 -metadata/_custom_type_script = "uid://do0g7nebwevll" diff --git a/icon.svg b/icon.svg deleted file mode 100644 index b26c807..0000000 --- a/icon.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/icon.svg.import b/icon.svg.import deleted file mode 100644 index 552862c..0000000 --- a/icon.svg.import +++ /dev/null @@ -1,43 +0,0 @@ -[remap] - -importer="texture" -type="CompressedTexture2D" -uid="uid://dv6ixieiuexcr" -path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://icon.svg" -dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"] - -[params] - -compress/mode=0 -compress/high_quality=false -compress/lossy_quality=0.7 -compress/uastc_level=0 -compress/rdo_quality_loss=0.0 -compress/hdr_compression=1 -compress/normal_map=0 -compress/channel_pack=0 -mipmaps/generate=false -mipmaps/limit=-1 -roughness/mode=0 -roughness/src_normal="" -process/channel_remap/red=0 -process/channel_remap/green=1 -process/channel_remap/blue=2 -process/channel_remap/alpha=3 -process/fix_alpha_border=true -process/premult_alpha=false -process/normal_map_invert_y=false -process/hdr_as_srgb=false -process/hdr_clamp_exposure=false -process/size_limit=0 -detect_3d/compress_to=1 -svg/scale=4.0 -editor/scale_with_editor_scale=false -editor/convert_colors_with_editor_theme=false diff --git a/project.godot b/project.godot deleted file mode 100644 index e8829a2..0000000 --- a/project.godot +++ /dev/null @@ -1,31 +0,0 @@ -; Engine configuration file. -; It's best edited using the editor UI and not directly, -; since the parameters that go here are not all obvious. -; -; Format: -; [section] ; section goes between [] -; param=value ; assign values to parameters - -config_version=5 - -[application] - -config/name="Antialiased Line2D" -config/features=PackedStringArray("4.6", "Forward Plus") -config/icon="uid://dv6ixieiuexcr" - -[dotnet] - -project/assembly_name="tmp" - -[editor_plugins] - -enabled=PackedStringArray("res://addons/antialiased_line2d/plugin.cfg") - -[physics] - -3d/physics_engine="Jolt Physics" - -[rendering] - -rendering_device/driver.windows="d3d12"