Parcourir la source

:beetle: Fix inverted zoom during tweens

Introduce a new attribute, scope, that is inverted zoom.
DricomDragon il y a 2 ans
Parent
commit
6bf3167032
2 fichiers modifiés avec 29 ajouts et 14 suppressions
  1. 27 13
      godot/projector/focus/Focus.gd
  2. 2 1
      godot/run/root.tscn

+ 27 - 13
godot/projector/focus/Focus.gd

@@ -13,27 +13,27 @@ signal ended
 @export var move_trans: Tween.TransitionType = Tween.TRANS_SINE
 @export var move_ease: Tween.EaseType = Tween.EASE_IN_OUT
 
-@export_group("Zoom", "zoom_")
-@export var zoom_duration: float = 1.0
-@export var zoom_trans: Tween.TransitionType = Tween.TRANS_SINE
-@export var zoom_closer_ease: Tween.EaseType = Tween.EASE_IN
-@export var zoom_wider_ease: Tween.EaseType = Tween.EASE_OUT
+@export_group("Scope", "scope_")
+@export var scope_duration: float = 1.0
+@export var scope_trans: Tween.TransitionType = Tween.TRANS_SINE
+@export var scope_closer_ease: Tween.EaseType = Tween.EASE_IN
+@export var scope_wider_ease: Tween.EaseType = Tween.EASE_OUT
 
 var tween: Tween
+var scope: Vector2 : get = get_scope, set = set_scope
 
 
-func focus_on(pos: Vector2, scope: float) -> void:
+func focus_on(pos: Vector2, scalar_scale: float) -> void:
 	if tween:
 		tween.kill()
 
-	var target_zoom = Vector2.ONE / scope
-	var is_wider = target_zoom.x < get_zoom().x
-	var min_zoom = target_zoom if is_wider else get_zoom()
-	var zoom_ease = zoom_wider_ease if is_wider else zoom_closer_ease
+	var target_scope = Vector2.ONE * scalar_scale
+	var is_wider = target_scope.x > get_scope().x
+	var scope_ease = scope_wider_ease if is_wider else scope_closer_ease
 
 	tween = create_tween().set_parallel(tween_is_parallel)
 	tween.tween_property(self, "position", pos, move_duration).set_trans(move_trans).set_ease(move_ease)
-	tween.tween_property(self, "zoom", target_zoom, zoom_duration).set_trans(zoom_trans).set_ease(zoom_ease)
+	tween.tween_property(self, "scope", target_scope, scope_duration).set_trans(scope_trans).set_ease(scope_ease)
 	tween.tween_callback(end)
 
 
@@ -41,5 +41,19 @@ func end():
 	ended.emit()
 
 
-func _on_show_new_focus(pos: Vector2, scope: float) -> void:
-	focus_on(pos, scope)
+func get_scope() -> Vector2:
+	return _invert_vector(get_zoom())
+
+
+func set_scope(new_scope: Vector2) -> void:
+	assert(new_scope.x > 0)
+	assert(new_scope.y > 0)
+	set_zoom(_invert_vector(new_scope))
+
+
+func _on_show_new_focus(pos: Vector2, scalar_scale: float) -> void:
+	focus_on(pos, scalar_scale)
+
+
+func _invert_vector(vec: Vector2) -> Vector2:
+	return Vector2(1.0 / vec.x, 1.0 / vec.y)

+ 2 - 1
godot/run/root.tscn

@@ -93,7 +93,8 @@ position = Vector2(8904, 4626)
 anchor_mode = 1
 zoom = Vector2(0.1, 0.1)
 tween_is_parallel = true
-zoom_trans = 10
+move_trans = 3
+scope_trans = 10
 
 [node name="Show" parent="Board" instance=ExtResource("2_cih7e")]
 start_slide = 50