class_name Focus extends Camera2D # Transition to next slide and focus current slide signal ended @export_group("Tween caracteristics", "tween_") @export var tween_is_parallel: bool = false @export_group("Move", "move_") @export var move_duration: float = 1.0 @export var move_trans: Tween.TransitionType = Tween.TRANS_SINE @export var move_ease: Tween.EaseType = Tween.EASE_IN_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, scalar_scale: float) -> void: if tween: tween.kill() 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, "scope", target_scope, scope_duration).set_trans(scope_trans).set_ease(scope_ease) tween.tween_callback(end) func end(): ended.emit() 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)