Browse Source

:tada: Remove the use of signal

Auto-detect nearby focus.
DricomDragon 1 year ago
parent
commit
4712e32040

+ 3 - 3
README.md

@@ -18,7 +18,7 @@ Leverage the Godot scene system by providing a custom Slide node to use as root
 
 
 A custom Camera2D node named Focus handles transitions, tweening position and scale. Transition can be customized via the Focus node.
 A custom Camera2D node named Focus handles transitions, tweening position and scale. Transition can be customized via the Focus node.
 
 
-Don't forget to connect the Show node signal to the Focus node.
+The Focus is auto-detected by the Show node, and must rely at the same level in your scene tree.
 
 
 ### React to input : next, skip, previous, home slide
 ### React to input : next, skip, previous, home slide
 
 
@@ -50,9 +50,9 @@ Create your main global scene.
 
 
 Instantiate the Focus node, playing the role of a custom Camera2D.
 Instantiate the Focus node, playing the role of a custom Camera2D.
 
 
-#### 4. Instantiate a Show and link its signal to the Focus
+#### 4. Instantiate a Show
 
 
-Instantiate the Show node, and use the node inspector to link the `new_focus` signal to the Focus node.
+Instantiate the Show node, that must be next to the Focus node that will be auto-detected.
 
 
 #### 5. Create your own Slides by creating Scene based on Slide node
 #### 5. Create your own Slides by creating Scene based on Slide node
 
 

+ 0 - 4
godot/addons/slide_show/projector/focus/Focus.gd

@@ -83,7 +83,3 @@ func _invert_vector(vec: Vector2) -> Vector2:
 	assert(vec.x > 0)
 	assert(vec.x > 0)
 	assert(vec.y > 0)
 	assert(vec.y > 0)
 	return Vector2(1.0 / vec.x, 1.0 / vec.y)
 	return Vector2(1.0 / vec.x, 1.0 / vec.y)
-
-
-func _on_show_new_focus(pos: Vector2, scalar_scale: float, trans: Transit) -> void:
-	focus_on(pos, scalar_scale, trans)

+ 3 - 3
godot/addons/slide_show/projector/show/Show.gd

@@ -3,8 +3,6 @@ extends Node2D
 # Manage slide cycling
 # Manage slide cycling
 
 
 
 
-signal new_focus(pos: Vector2, scale: float, trans: Focus.Transit)
-
 const VOID_SLIDE_ID := -1
 const VOID_SLIDE_ID := -1
 
 
 @export_group("Slide management")
 @export_group("Slide management")
@@ -20,6 +18,7 @@ const VOID_SLIDE_ID := -1
 var current_id := VOID_SLIDE_ID
 var current_id := VOID_SLIDE_ID
 var current_slide: Slide
 var current_slide: Slide
 
 
+@onready var focus: Focus = $"../Focus"
 @onready var slides: Array = get_children()
 @onready var slides: Array = get_children()
 
 
 
 
@@ -60,7 +59,7 @@ func next_slide_at(next_id: int, trans: Focus.Transit) -> void:
 
 
 func _focus_slide(id: int, trans: Focus.Transit) -> Slide:
 func _focus_slide(id: int, trans: Focus.Transit) -> Slide:
 	var slide: Slide = slides[id]
 	var slide: Slide = slides[id]
-	new_focus.emit(slide.get_center(), slide.get_scale().x, trans)
+	focus.focus_on(slide.get_center(), slide.get_scale().x, trans)
 	return slide
 	return slide
 
 
 
 
@@ -91,6 +90,7 @@ func _enforce() -> void:
 
 
 
 
 func _enforce_parameters() -> void:
 func _enforce_parameters() -> void:
+	assert(focus, "A Focus node must be next to the Show node")
 	assert(start_slide >= 0,
 	assert(start_slide >= 0,
 		"Negative index is not supported for start_slide")
 		"Negative index is not supported for start_slide")
 	assert(start_slide < slides.size(),
 	assert(start_slide < slides.size(),

+ 0 - 2
godot/example/example_slide_show.tscn

@@ -28,5 +28,3 @@ scale = Vector2(0.8, 0.8)
 position = Vector2(644, 436)
 position = Vector2(644, 436)
 scale = Vector2(0.2, 0.2)
 scale = Vector2(0.2, 0.2)
 always_visible = true
 always_visible = true
-
-[connection signal="new_focus" from="Show" to="Focus" method="_on_show_new_focus"]