feat: Use wait parameter instead of immediate for turn_to and set_angle (#403)
Co-authored-by: Dennis Ploeger <develop@dieploegers.de>
This commit is contained in:
@@ -443,10 +443,8 @@ func _angle_is_between(
|
||||
# #### Parameters
|
||||
#
|
||||
# - deg int angle to set the character
|
||||
# - immediate
|
||||
# If true, direction is switched immediately. Else, successive
|
||||
# animations are used so that the character turns to target angle.
|
||||
func set_angle(deg: int, immediate = true) -> void:
|
||||
# - wait float Wait this amount of seconds until continuing with turning around
|
||||
func set_angle(deg: int, wait: float = 0.0) -> void:
|
||||
if deg < 0 or deg > 360:
|
||||
escoria.logger.report_errors(
|
||||
"movable.gd:set_angle()",
|
||||
@@ -454,37 +452,35 @@ func set_angle(deg: int, immediate = true) -> void:
|
||||
)
|
||||
moved = true
|
||||
|
||||
if immediate:
|
||||
last_dir = _get_dir_deg(deg, parent.animations)
|
||||
|
||||
# The character may have a state animation from before, which would be
|
||||
# resumed, so we immediately force the correct idle animation
|
||||
if parent.get_animation_player().get_animation() != \
|
||||
parent.animations.idles[last_dir].animation:
|
||||
parent.get_animation_player().play(
|
||||
parent.animations.idles[last_dir].animation
|
||||
)
|
||||
pose_scale = -1 if parent.animations.idles[last_dir].mirrored else 1
|
||||
else:
|
||||
var current_dir = last_dir
|
||||
var target_dir = _get_dir_deg(deg, parent.animations)
|
||||
|
||||
var way_to_turn = get_shortest_way_to_dir(current_dir, target_dir)
|
||||
var current_dir = last_dir
|
||||
var target_dir = _get_dir_deg(deg, parent.animations)
|
||||
|
||||
var dir = current_dir
|
||||
while dir != target_dir:
|
||||
dir += way_to_turn
|
||||
if dir >= parent.animations.dir_angles.size():
|
||||
dir = 0
|
||||
if dir < 0:
|
||||
dir = parent.animations.dir_angles.size() - 1
|
||||
|
||||
parent.get_animation_player().play(
|
||||
parent.animations.idles[dir].animation
|
||||
)
|
||||
yield(parent.get_animation_player(), "animation_finished")
|
||||
pose_scale = -1 if parent.animations.idles[dir].mirrored else 1
|
||||
var way_to_turn = get_shortest_way_to_dir(current_dir, target_dir)
|
||||
|
||||
var dir = current_dir
|
||||
while dir != target_dir:
|
||||
dir += way_to_turn
|
||||
if dir >= parent.animations.dir_angles.size():
|
||||
dir = 0
|
||||
if dir < 0:
|
||||
dir = parent.animations.dir_angles.size() - 1
|
||||
|
||||
parent.get_animation_player().play(
|
||||
parent.animations.idles[dir].animation
|
||||
)
|
||||
if wait > 0.0:
|
||||
yield(get_tree().create_timer(wait), "timeout")
|
||||
pose_scale = -1 if parent.animations.idles[dir].mirrored else 1
|
||||
|
||||
last_dir = _get_dir_deg(deg, parent.animations)
|
||||
|
||||
# The character may have a state animation from before, which would be
|
||||
# resumed, so we immediately force the correct idle animation
|
||||
if parent.get_animation_player().get_animation() != \
|
||||
parent.animations.idles[last_dir].animation:
|
||||
parent.get_animation_player().play(
|
||||
parent.animations.idles[last_dir].animation
|
||||
)
|
||||
update_terrain()
|
||||
|
||||
|
||||
@@ -493,17 +489,15 @@ func set_angle(deg: int, immediate = true) -> void:
|
||||
# #### Parameters
|
||||
#
|
||||
# - item_id id of the object to face.
|
||||
# - immediate
|
||||
# If true, direction is switched immediately. Else, successive
|
||||
# animations are used so that the character turns to target angle.
|
||||
func turn_to(item: Node, immediate = true) -> void:
|
||||
# - float Wait this amount of seconds until continuing with turning around
|
||||
func turn_to(item: Node, wait: float = 0.0) -> void:
|
||||
set_angle(
|
||||
wrapi(
|
||||
rad2deg(parent.get_position().angle_to_point(item.get_position())),
|
||||
0,
|
||||
360
|
||||
),
|
||||
immediate
|
||||
wait
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# `set_angle object degrees [immediate]`
|
||||
# `set_angle object degrees [wait]`
|
||||
#
|
||||
# Turns object to a degrees angle without animations. 0 sets object facing
|
||||
# forward, 90 sets it 90 degrees clockwise ("east") etc. When turning to the
|
||||
@@ -7,6 +7,9 @@
|
||||
# object must be player or interactive. degrees must be between [0, 360] or an
|
||||
# error is reported.
|
||||
#
|
||||
# The wait parameter sets how long to wait for each intermediate angle. It
|
||||
# defaults to 0, meaning the turnaround is immediate.
|
||||
#
|
||||
# @ESC
|
||||
extends ESCBaseCommand
|
||||
class_name SetAngleCommand
|
||||
@@ -16,8 +19,8 @@ class_name SetAngleCommand
|
||||
func configure() -> ESCCommandArgumentDescriptor:
|
||||
return ESCCommandArgumentDescriptor.new(
|
||||
2,
|
||||
[TYPE_STRING, TYPE_INT, TYPE_BOOL],
|
||||
[null, null, true]
|
||||
[TYPE_STRING, TYPE_INT, TYPE_REAL],
|
||||
[null, null, 0.0]
|
||||
)
|
||||
|
||||
|
||||
@@ -36,12 +39,13 @@ func validate(arguments: Array):
|
||||
|
||||
# Run the command
|
||||
func run(command_params: Array) -> int:
|
||||
var immediate = command_params[2]
|
||||
|
||||
# HACK Countering the fact that angle_to_point() function gives
|
||||
# angle against X axis not Y, we need to check direction using (angle-90°).
|
||||
# Since the ESC command already gives the right angle, we add 90.
|
||||
escoria.object_manager.get_object(command_params[0]).node\
|
||||
.set_angle(wrapi(int(command_params[1]) + 90, 0, 360), immediate)
|
||||
.set_angle(
|
||||
wrapi(int(command_params[1]) + 90, 0, 360),
|
||||
command_params[2]
|
||||
)
|
||||
return ESCExecution.RC_OK
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
# `turn_to object object_to_face [immediate]`
|
||||
# `turn_to object object_to_face [wait]`
|
||||
#
|
||||
# Turns object to face another object.
|
||||
#
|
||||
# Set immediate to true to show directly switch to the direction and not
|
||||
# show intermediate angles
|
||||
# The wait parameter sets how long to wait for each intermediate angle. It
|
||||
# defaults to 0, meaning the turnaround is immediate.
|
||||
#
|
||||
# @ESC
|
||||
extends ESCBaseCommand
|
||||
@@ -14,8 +14,8 @@ class_name TurnToCommand
|
||||
func configure() -> ESCCommandArgumentDescriptor:
|
||||
return ESCCommandArgumentDescriptor.new(
|
||||
2,
|
||||
[TYPE_STRING, TYPE_STRING, TYPE_BOOL],
|
||||
[null, null, false]
|
||||
[TYPE_STRING, TYPE_STRING, TYPE_REAL],
|
||||
[null, null, 0.0]
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -421,10 +421,9 @@ func get_sprite() -> Node:
|
||||
# #### Parameters
|
||||
#
|
||||
# - deg: The angle degree to set
|
||||
# - immediate: Set the angle immediately. If false will show intermediate
|
||||
# angles
|
||||
func set_angle(deg: int, immediate = true):
|
||||
_movable.set_angle(deg, immediate)
|
||||
# - wait: Wait this amount of seconds until continuing with turning around
|
||||
func set_angle(deg: int, wait: float = 0.0):
|
||||
_movable.set_angle(deg, wait)
|
||||
|
||||
|
||||
# Turn to face another object
|
||||
@@ -432,10 +431,9 @@ func set_angle(deg: int, immediate = true):
|
||||
# #### Parameters
|
||||
#
|
||||
# - deg: The angle degree to set
|
||||
# - immediate: Set the angle immediately. If false will show intermediate
|
||||
# angles
|
||||
func turn_to(object: Node, immediate = true):
|
||||
_movable.turn_to(object, immediate)
|
||||
# - float Wait this amount of seconds until continuing with turning around
|
||||
func turn_to(object: Node, wait: float = 0.0):
|
||||
_movable.turn_to(object, wait)
|
||||
|
||||
|
||||
# Play the talking animation
|
||||
|
||||
@@ -21,10 +21,10 @@ set_sound_state _music res://game/sfx/contemplation.ogg true
|
||||
wait 2
|
||||
walk_block player r1_destination_point2
|
||||
wait 2
|
||||
set_angle player 225 false
|
||||
set_angle player 225 0.2
|
||||
wait 2
|
||||
walk_block player r1_destination_point3
|
||||
wait 1
|
||||
turn_to player r1_r_exit false
|
||||
turn_to player r1_r_exit
|
||||
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
say player "Huh?"
|
||||
|
||||
turn_to player 180 true
|
||||
turn_to player slide_pos_1
|
||||
|
||||
say player "Nothing."
|
||||
|
||||
turn_to player 0
|
||||
turn_to player slide_pos_2 0.2
|
||||
|
||||
Reference in New Issue
Block a user