Просмотр исходного кода

:sparkles: Make the code more logical and legible

- Specify local var types
- Rename methods
DricomDragon 2 лет назад
Родитель
Сommit
58020ee275
3 измененных файлов с 17 добавлено и 16 удалено
  1. 4 4
      godot/projector/focus/Focus.gd
  2. 10 9
      godot/projector/show/Show.gd
  3. 3 3
      godot/projector/slide/Slide.gd

+ 4 - 4
godot/projector/focus/Focus.gd

@@ -52,8 +52,6 @@ func get_scope() -> Vector2:
 
 
 func set_scope(new_scope: Vector2) -> void:
-	assert(new_scope.x > 0)
-	assert(new_scope.y > 0)
 	set_zoom(_invert_vector(new_scope))
 
 
@@ -67,8 +65,8 @@ func _beam_to_focus() -> void:
 func _smooth_transit_to_focus() -> void:
 	_abort_ongoing_transit()
 
-	var is_wider = target_scope.x > get_scope().x
-	var scope_ease = scope_wider_ease if is_wider else scope_closer_ease
+	var is_wider: bool = target_scope.x > get_scope().x
+	var scope_ease: Tween.EaseType = scope_wider_ease if is_wider else scope_closer_ease
 
 	tween = create_tween().set_parallel(tween_is_parallel)
 	tween.tween_property(self, "position", target_pos, move_duration).set_trans(move_trans).set_ease(move_ease)
@@ -82,6 +80,8 @@ func _abort_ongoing_transit() -> void:
 
 
 func _invert_vector(vec: Vector2) -> Vector2:
+	assert(vec.x > 0)
+	assert(vec.y > 0)
 	return Vector2(1.0 / vec.x, 1.0 / vec.y)
 
 

+ 10 - 9
godot/projector/show/Show.gd

@@ -38,15 +38,14 @@ func next_slide(trans: Focus.Transit) -> void:
 
 
 func next_slide_at(next_id: int, trans: Focus.Transit) -> void:
-	_disconnect_current_slide()
+	_disable_current_slide()
 	current_id = next_id
 	current_slide = _focus_slide(current_id, trans)
-	_connect_current_slide()
+	_enable_current_slide()
 
 
 func _focus_slide(id: int, trans: Focus.Transit) -> Slide:
 	var slide: Slide = slides[id]
-	slide.focus()
 	new_focus.emit(slide.get_center(), slide.get_scale().x, trans)
 	return slide
 
@@ -56,13 +55,14 @@ func _hide_every_slide() -> void:
 		slide.gently_hide()
 
 
-func _disconnect_current_slide() -> void:
+func _disable_current_slide() -> void:
 	if current_slide != null:
-		current_slide.remove_focus()
+		current_slide.disable()
 		current_slide.finished.disconnect(_on_current_slide_finished)
 
 
-func _connect_current_slide() -> void:
+func _enable_current_slide() -> void:
+	current_slide.enable()
 	current_slide.finished.connect(_on_current_slide_finished)
 
 
@@ -119,11 +119,12 @@ func _unhandled_input(event: InputEvent) -> void:
 
 
 func _focus_nearest_slide_from(target_pos: Vector2) -> void:
-	var next_id = _search_nearest_slide_from(target_pos)
+	var next_slide = _search_nearest_slide_from(target_pos)
+	var next_id = slides.find(next_slide)
 	next_slide_at(next_id, Focus.Transit.SMOOTH)
 
 
-func _search_nearest_slide_from(target_pos: Vector2) -> int:
+func _search_nearest_slide_from(target_pos: Vector2) -> Slide:
 	var nearest_slide = current_slide
 	var shortest_distance = target_pos.distance_squared_to(nearest_slide.get_center())
 	for current_slide in slides:
@@ -132,7 +133,7 @@ func _search_nearest_slide_from(target_pos: Vector2) -> int:
 			nearest_slide = current_slide
 			shortest_distance = current_distance
 
-	return slides.find(nearest_slide)
+	return nearest_slide
 
 
 func _on_current_slide_finished() -> void:

+ 3 - 3
godot/projector/slide/Slide.gd

@@ -13,14 +13,14 @@ var center_offset: Vector2
 
 func _ready() -> void:
 	center_offset = _compute_center_offset()
-	remove_focus()
+	disable()
 
 
-func remove_focus() -> void:
+func disable() -> void:
 	set_process_unhandled_key_input(false)
 
 
-func focus() -> void:
+func enable() -> void:
 	set_visible(true)
 	set_process_unhandled_key_input(true)