mirror of
https://github.com/Relintai/broken_seals.git
synced 2025-01-29 02:29:18 +01:00
Emit changed events properly in sd shapes.
This commit is contained in:
parent
1e57dba26e
commit
5d0c999103
@ -3,36 +3,35 @@ extends MMNode
|
|||||||
|
|
||||||
var points : PoolVector2Array = [Vector2(0.2, 0.2), Vector2(0.7, 0.4), Vector2(0.4, 0.7)]
|
var points : PoolVector2Array = [Vector2(0.2, 0.2), Vector2(0.7, 0.4), Vector2(0.4, 0.7)]
|
||||||
|
|
||||||
func to_string() -> String:
|
|
||||||
var rv = PoolStringArray()
|
|
||||||
for p in points:
|
|
||||||
rv.append("("+str(p.x)+","+str(p.y)+")")
|
|
||||||
return rv.join(",")
|
|
||||||
|
|
||||||
func clear() -> void:
|
func clear() -> void:
|
||||||
points.resize(0)
|
points.resize(0)
|
||||||
|
|
||||||
set_dirty(true)
|
_polygon_changed()
|
||||||
|
|
||||||
func add_point(x : float, y : float, closed : bool = true) -> void:
|
func add_point(x : float, y : float, closed : bool = true) -> void:
|
||||||
var p : Vector2 = Vector2(x, y)
|
var p : Vector2 = Vector2(x, y)
|
||||||
var points_count = points.size()
|
var points_count = points.size()
|
||||||
|
|
||||||
if points_count < 3:
|
if points_count < 3:
|
||||||
points.append(p)
|
points.append(p)
|
||||||
|
_polygon_changed()
|
||||||
return
|
return
|
||||||
|
|
||||||
var min_length : float = (p-Geometry.get_closest_point_to_segment_2d(p, points[0], points[points_count-1])).length()
|
var min_length : float = (p-Geometry.get_closest_point_to_segment_2d(p, points[0], points[points_count-1])).length()
|
||||||
var insert_point = 0
|
var insert_point = 0
|
||||||
|
|
||||||
for i in points_count-1:
|
for i in points_count-1:
|
||||||
var length = (p - Geometry.get_closest_point_to_segment_2d(p, points[i], points[i+1])).length()
|
var length = (p - Geometry.get_closest_point_to_segment_2d(p, points[i], points[i+1])).length()
|
||||||
if length < min_length:
|
if length < min_length:
|
||||||
min_length = length
|
min_length = length
|
||||||
insert_point = i+1
|
insert_point = i+1
|
||||||
|
|
||||||
if !closed and insert_point == 0 and (points[0]-p).length() > (points[points_count-1]-p).length():
|
if !closed and insert_point == 0 and (points[0]-p).length() > (points[points_count-1]-p).length():
|
||||||
insert_point = points_count
|
insert_point = points_count
|
||||||
|
|
||||||
points.insert(insert_point, p)
|
points.insert(insert_point, p)
|
||||||
|
|
||||||
set_dirty(true)
|
_polygon_changed()
|
||||||
|
|
||||||
func remove_point(index : int) -> bool:
|
func remove_point(index : int) -> bool:
|
||||||
var s = points.size()
|
var s = points.size()
|
||||||
@ -40,7 +39,8 @@ func remove_point(index : int) -> bool:
|
|||||||
return false
|
return false
|
||||||
else:
|
else:
|
||||||
points.remove(index)
|
points.remove(index)
|
||||||
set_dirty(true)
|
_polygon_changed()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
func get_point_count() -> int:
|
func get_point_count() -> int:
|
||||||
@ -51,32 +51,21 @@ func get_point(i : int) -> Vector2:
|
|||||||
|
|
||||||
func set_point(i : int, v : Vector2) -> void:
|
func set_point(i : int, v : Vector2) -> void:
|
||||||
points[i] = v
|
points[i] = v
|
||||||
set_dirty(true)
|
|
||||||
|
_polygon_changed()
|
||||||
|
|
||||||
func set_points(v : PoolVector2Array) -> void:
|
func set_points(v : PoolVector2Array) -> void:
|
||||||
points = v
|
points = v
|
||||||
set_dirty(true)
|
|
||||||
|
|
||||||
func get_shader() -> String:
|
_polygon_changed()
|
||||||
var elements : PoolStringArray = PoolStringArray()
|
|
||||||
|
func _polygon_changed() -> void:
|
||||||
|
emit_changed()
|
||||||
|
|
||||||
|
|
||||||
|
func to_string() -> String:
|
||||||
|
var rv = PoolStringArray()
|
||||||
for p in points:
|
for p in points:
|
||||||
elements.append("vec2(%.9f, %.9f)" % [p.x, p.y])
|
rv.append("("+str(p.x)+","+str(p.y)+")")
|
||||||
return "{"+elements.join(", ")+"}"
|
|
||||||
|
|
||||||
func serialize() -> Dictionary:
|
return rv.join(",")
|
||||||
var rv = []
|
|
||||||
for p in points:
|
|
||||||
rv.append({ x=p.x, y=p.y })
|
|
||||||
return { type="Polygon", points=rv }
|
|
||||||
|
|
||||||
func deserialize(v) -> void:
|
|
||||||
clear()
|
|
||||||
if typeof(v) == TYPE_DICTIONARY and v.has("type") and v.type == "Polygon":
|
|
||||||
for p in v.points:
|
|
||||||
points.push_back(Vector2(p.x, p.y))
|
|
||||||
elif typeof(v) == TYPE_OBJECT and v.get_script() == get_script():
|
|
||||||
clear()
|
|
||||||
for p in v.points:
|
|
||||||
points.push_back(Vector2(p.x, p.y))
|
|
||||||
else:
|
|
||||||
print("Cannot deserialize polygon")
|
|
||||||
|
@ -37,6 +37,7 @@ func get_angle() -> Vector2:
|
|||||||
func set_angle(val : Vector2) -> void:
|
func set_angle(val : Vector2) -> void:
|
||||||
angle = val
|
angle = val
|
||||||
|
|
||||||
|
emit_changed()
|
||||||
output.emit_changed()
|
output.emit_changed()
|
||||||
|
|
||||||
#radius
|
#radius
|
||||||
@ -46,6 +47,7 @@ func get_radius() -> float:
|
|||||||
func set_radius(val : float) -> void:
|
func set_radius(val : float) -> void:
|
||||||
radius = val
|
radius = val
|
||||||
|
|
||||||
|
emit_changed()
|
||||||
output.emit_changed()
|
output.emit_changed()
|
||||||
|
|
||||||
#width
|
#width
|
||||||
@ -55,4 +57,5 @@ func get_width() -> float:
|
|||||||
func set_width(val : float) -> void:
|
func set_width(val : float) -> void:
|
||||||
width = val
|
width = val
|
||||||
|
|
||||||
|
emit_changed()
|
||||||
output.emit_changed()
|
output.emit_changed()
|
||||||
|
@ -35,6 +35,7 @@ func get_center() -> Vector2:
|
|||||||
func set_center(val : Vector2) -> void:
|
func set_center(val : Vector2) -> void:
|
||||||
center = val
|
center = val
|
||||||
|
|
||||||
|
emit_changed()
|
||||||
output.emit_changed()
|
output.emit_changed()
|
||||||
|
|
||||||
#size
|
#size
|
||||||
@ -44,4 +45,5 @@ func get_size() -> Vector2:
|
|||||||
func set_size(val : Vector2) -> void:
|
func set_size(val : Vector2) -> void:
|
||||||
size = val
|
size = val
|
||||||
|
|
||||||
|
emit_changed()
|
||||||
output.emit_changed()
|
output.emit_changed()
|
||||||
|
@ -35,6 +35,7 @@ func get_center() -> Vector2:
|
|||||||
func set_center(val : Vector2) -> void:
|
func set_center(val : Vector2) -> void:
|
||||||
center = val
|
center = val
|
||||||
|
|
||||||
|
emit_changed()
|
||||||
output.emit_changed()
|
output.emit_changed()
|
||||||
|
|
||||||
#radius
|
#radius
|
||||||
@ -44,4 +45,5 @@ func get_radius() -> float:
|
|||||||
func set_radius(val : float) -> void:
|
func set_radius(val : float) -> void:
|
||||||
radius = val
|
radius = val
|
||||||
|
|
||||||
|
emit_changed()
|
||||||
output.emit_changed()
|
output.emit_changed()
|
||||||
|
@ -24,3 +24,6 @@ func _register_methods(mm_graph_node) -> void:
|
|||||||
func get_property_value(uv : Vector2) -> float:
|
func get_property_value(uv : Vector2) -> float:
|
||||||
return SDF2D.sdPolygon(uv, points)
|
return SDF2D.sdPolygon(uv, points)
|
||||||
|
|
||||||
|
func _polygon_changed() -> void:
|
||||||
|
emit_changed()
|
||||||
|
output.emit_changed()
|
||||||
|
@ -35,6 +35,7 @@ func get_center() -> Vector2:
|
|||||||
func set_center(val : Vector2) -> void:
|
func set_center(val : Vector2) -> void:
|
||||||
center = val
|
center = val
|
||||||
|
|
||||||
|
emit_changed()
|
||||||
output.emit_changed()
|
output.emit_changed()
|
||||||
|
|
||||||
#size
|
#size
|
||||||
@ -44,4 +45,5 @@ func get_size() -> Vector2:
|
|||||||
func set_size(val : Vector2) -> void:
|
func set_size(val : Vector2) -> void:
|
||||||
size = val
|
size = val
|
||||||
|
|
||||||
|
emit_changed()
|
||||||
output.emit_changed()
|
output.emit_changed()
|
||||||
|
@ -45,6 +45,7 @@ func _draw():
|
|||||||
|
|
||||||
draw_rect(Rect2(draw_offset, draw_size), axes_color, false)
|
draw_rect(Rect2(draw_offset, draw_size), axes_color, false)
|
||||||
var tp : Vector2 = transform_point(polygon.points[polygon.points.size()-1 if closed else 0])
|
var tp : Vector2 = transform_point(polygon.points[polygon.points.size()-1 if closed else 0])
|
||||||
|
|
||||||
for p in polygon.points:
|
for p in polygon.points:
|
||||||
var tnp = transform_point(p)
|
var tnp = transform_point(p)
|
||||||
draw_line(tp, tnp, curve_color)
|
draw_line(tp, tnp, curve_color)
|
||||||
|
Loading…
Reference in New Issue
Block a user