Fix comments after converting docstrings

Some files were not converted properly, leaving the game in a broken state.
This commit is contained in:
Nathan Lovato 2020-01-11 15:58:11 +01:00
parent 865c7cefaa
commit dac4ff1bd7
3 changed files with 80 additions and 81 deletions

View file

@ -1,27 +1,26 @@
extends Node
# Globally accessible utils functionality
# extends Node
#
# Returns the direction in which the player is aiming with the stick
# static func get_aim_joystick_direction() -> Vector2:
# return get_aim_joystick_strength().normalized()
static func get_aim_joystick_direction() -> Vector2:
return get_aim_joystick_strength().normalized()
#
# Returns the strength of the XY input with the joystick used for aiming,
each axis being a value between 0 and 1
Adds a circular deadzone, as Godot's built-in system is per-axis,
creating a rectangular deadzone on the joystick
# static func get_aim_joystick_strength() -> Vector2:
# var deadzone_radius: = 0.5
# var input_strength: = Vector2(
# Input.get_action_strength("aim_right") - Input.get_action_strength("aim_left"),
# Input.get_action_strength("aim_down") - Input.get_action_strength("aim_up")
# )
# return input_strength if input_strength.length() > deadzone_radius else Vector2.ZERO
# each axis being a value between 0 and 1
# Adds a circular deadzone, as Godot's built-in system is per-axis,
# creating a rectangular deadzone on the joystick
static func get_aim_joystick_strength() -> Vector2:
var deadzone_radius: = 0.5
var input_strength: = Vector2(
Input.get_action_strength("aim_right") - Input.get_action_strength("aim_left"),
Input.get_action_strength("aim_down") - Input.get_action_strength("aim_up")
)
return input_strength if input_strength.length() > deadzone_radius else Vector2.ZERO
# Checks if two numbers are approximately equal
# static func is_equal_approx(a: float, b: float, cmp_epsilon: float = 1e-5) -> bool:
# var tolerance: = cmp_epsilon * abs(a)
# if tolerance < cmp_epsilon:
# tolerance = cmp_epsilon
# return abs(a - b) < tolerance
static func is_equal_approx(a: float, b: float, cmp_epsilon: float = 1e-5) -> bool:
var tolerance: = cmp_epsilon * abs(a)
if tolerance < cmp_epsilon:
tolerance = cmp_epsilon
return abs(a - b) < tolerance

View file

@ -16,16 +16,16 @@ func _physics_process(delta: float) -> void:
func update_position(velocity: Vector2 = Vector2.ZERO) -> void:
# Updates the camera rig's position based on the player's state and controller position
# if not is_active:
# return
if not is_active:
return
# # match Settings.controls:
match Settings.controls:
# # Settings.GAMEPAD:
# var joystick_strength: = Utils.get_aim_joystick_strength()
# camera.position = joystick_strength * offset
Settings.GAMEPAD:
var joystick_strength: = Utils.get_aim_joystick_strength()
camera.position = joystick_strength * offset
# # Settings.KBD_MOUSE, _:
# var mouse_position: = get_local_mouse_position()
# var distance_ratio: = clamp(mouse_position.length(), mouse_range.x, mouse_range.y) / mouse_range.y
# camera.position = distance_ratio * mouse_position.normalized() * offset
Settings.KBD_MOUSE, _:
var mouse_position: = get_local_mouse_position()
var distance_ratio: = clamp(mouse_position.length(), mouse_range.x, mouse_range.y) / mouse_range.y
camera.position = distance_ratio * mouse_position.normalized() * offset

View file

@ -2,67 +2,67 @@ tool
extends Area2D
# Detects and returns the best snapping target for the hook
#
# # onready var hooking_hint: Position2D = $HookingHint
# onready var ray_cast: RayCast2D = $RayCast2D
# # var target: HookTarget setget set_target
onready var hooking_hint: Position2D = $HookingHint
onready var ray_cast: RayCast2D = $RayCast2D
#
# # func _ready() -> void:
# if Engine.editor_hint:
# set_physics_process(false)
# ray_cast.set_as_toplevel(true)
var target: HookTarget setget set_target
func _ready() -> void:
if Engine.editor_hint:
set_physics_process(false)
ray_cast.set_as_toplevel(true)
func _physics_process(delta: float) -> void:
self.target = find_best_target()
#
# # func _physics_process(delta: float) -> void:
# self.target = find_best_target()
#
# Returns the closest target, skipping targets when there is an obstacle
between the player and the target.
# func find_best_target() -> HookTarget:
# var targets: = get_overlapping_areas()
# between the player and the target.
func find_best_target() -> HookTarget:
var targets: = get_overlapping_areas()
# # var closest_target: HookTarget = null
# var distance_to_closest: = 100000.0
# for t in targets:
# if not t.is_active:
# continue
var closest_target: HookTarget = null
var distance_to_closest: = 100000.0
for t in targets:
if not t.is_active:
continue
# # var distance: = global_position.distance_to(t.global_position)
# if distance > distance_to_closest:
# continue
var distance: = global_position.distance_to(t.global_position)
if distance > distance_to_closest:
continue
# # # Skip the target if there is a collider in the way
# ray_cast.global_position = global_position
# ray_cast.cast_to = t.global_position - global_position
# if ray_cast.is_colliding():
# continue
# Skip the target if there is a collider in the way
ray_cast.global_position = global_position
ray_cast.cast_to = t.global_position - global_position
if ray_cast.is_colliding():
continue
# # distance_to_closest = distance
# closest_target = t
# return closest_target
distance_to_closest = distance
closest_target = t
return closest_target
func has_target() -> bool:
return target != null
#
# # func has_target() -> bool:
# return target != null
#
# Returns the length of the hook, from the origin to the tip of the collision shape
Used to draw the hook's radius in the editor
# func calculate_length() -> float:
# var length: = -1.0
# for collider in [$CapsuleH, $CapsuleV]:
# if not collider:
# continue
# var capsule: CapsuleShape2D = collider.shape
# var capsule_length: float = collider.position.length() + capsule.height / 2 * sin(collider.rotation) + capsule.radius
# length = max(length, capsule_length)
# return length
# Used to draw the hook's radius in the editor
func calculate_length() -> float:
var length: = -1.0
for collider in [$CapsuleH, $CapsuleV]:
if not collider:
continue
var capsule: CapsuleShape2D = collider.shape
var capsule_length: float = collider.position.length() + capsule.height / 2 * sin(collider.rotation) + capsule.radius
length = max(length, capsule_length)
return length
#
# # func set_target(value: HookTarget) -> void:
# target = value
# hooking_hint.visible = target != null
# hooking_hint.global_position = target.global_position if target else hooking_hint.global_position
func set_target(value: HookTarget) -> void:
target = value
hooking_hint.visible = target != null
hooking_hint.global_position = target.global_position if target else hooking_hint.global_position