Re-implemented turn_to command (#390)
* Re-implemented turn_to command Fixes #385 Fixed a bug in esc_movable blocking player_orients_on_arrival for ESCLocation nodes * docs: Automatic update of API docs * Fixes Co-authored-by: StraToN <StraToN@users.noreply.github.com>
This commit is contained in:
@@ -267,10 +267,9 @@ func walk_stop(pos: Vector2) -> void:
|
||||
|
||||
# If we're heading to an object and reached its interaction position,
|
||||
# orient towards the defined interaction direction set on the object
|
||||
# (if any)
|
||||
# (if any), can be ESCItem or ESCLocation
|
||||
if walk_context.target_object and \
|
||||
walk_context.target_object.node.player_orients_on_arrival and \
|
||||
walk_context.target_object.interactive:
|
||||
walk_context.target_object.node.player_orients_on_arrival:
|
||||
var orientation = walk_context.target_object.node.interaction_direction
|
||||
last_dir = orientation
|
||||
parent.get_animation_player().play(
|
||||
@@ -488,6 +487,25 @@ func set_angle(deg: int, immediate = true) -> void:
|
||||
update_terrain()
|
||||
|
||||
|
||||
# Turns the character to face another item or character.
|
||||
#
|
||||
# #### 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:
|
||||
set_angle(
|
||||
wrapi(
|
||||
rad2deg(parent.get_position().angle_to_point(item.get_position())),
|
||||
0,
|
||||
360
|
||||
),
|
||||
immediate
|
||||
)
|
||||
|
||||
|
||||
# Returns the angle that corresponds to the current direction of the object.
|
||||
func _get_angle() -> int:
|
||||
return parent.animations.dir_angles[last_dir].angle_start
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
# `turn_to object degrees [immediate]`
|
||||
# `turn_to object object_to_face [immediate]`
|
||||
#
|
||||
# Turns object to a degrees angle with a directions animation.
|
||||
#
|
||||
# 0 sets object facing forward, 90 sets it 90 degrees clockwise ("east") etc.
|
||||
# When turning to the destination angle, animations are played if they're
|
||||
# defined in animations. object must be player or interactive. degrees must
|
||||
# be between [0, 360] or an error is reported.
|
||||
# Turns object to face another object.
|
||||
#
|
||||
# Set immediate to true to show directly switch to the direction and not
|
||||
# show intermediate angles
|
||||
@@ -19,7 +14,7 @@ class_name TurnToCommand
|
||||
func configure() -> ESCCommandArgumentDescriptor:
|
||||
return ESCCommandArgumentDescriptor.new(
|
||||
2,
|
||||
[TYPE_STRING, TYPE_INT, TYPE_BOOL],
|
||||
[TYPE_STRING, TYPE_STRING, TYPE_BOOL],
|
||||
[null, null, false]
|
||||
)
|
||||
|
||||
@@ -34,11 +29,11 @@ func validate(arguments: Array):
|
||||
]
|
||||
)
|
||||
return false
|
||||
if arguments[1] < 0 or arguments[1] > 360:
|
||||
if not escoria.object_manager.objects.has(arguments[1]):
|
||||
escoria.logger.report_errors(
|
||||
"turn_to: invalid degrees",
|
||||
"turn_to: invalid target object",
|
||||
[
|
||||
"Degree %d not between 0 and 360" % arguments[1]
|
||||
"Object with global id %s not found" % arguments[1]
|
||||
]
|
||||
)
|
||||
return false
|
||||
@@ -48,8 +43,8 @@ func validate(arguments: Array):
|
||||
# Run the command
|
||||
func run(command_params: Array) -> int:
|
||||
(escoria.object_manager.get_object(command_params[0]).node as ESCItem)\
|
||||
.set_angle(
|
||||
command_params[1],
|
||||
.turn_to(
|
||||
escoria.object_manager.get_object(command_params[1]).node,
|
||||
command_params[2]
|
||||
)
|
||||
return ESCExecution.RC_OK
|
||||
|
||||
@@ -41,8 +41,8 @@ func perform_walk(
|
||||
target_position = destination.node.interact_position
|
||||
|
||||
var walk_context = ESCWalkContext.new(
|
||||
destination.node,
|
||||
Vector2(),
|
||||
destination,
|
||||
target_position,
|
||||
is_fast,
|
||||
true
|
||||
)
|
||||
|
||||
@@ -231,6 +231,7 @@ func get_interact_position() -> Vector2:
|
||||
for c in get_children():
|
||||
if c is Position2D:
|
||||
if c.get_owner() == self:
|
||||
interact_position = global_position
|
||||
continue
|
||||
interact_position = c.global_position
|
||||
|
||||
@@ -360,7 +361,18 @@ func get_sprite() -> Node:
|
||||
# angles
|
||||
func set_angle(deg: int, immediate = true):
|
||||
_movable.set_angle(deg, immediate)
|
||||
|
||||
|
||||
|
||||
# Turn to face another object
|
||||
#
|
||||
# #### 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)
|
||||
|
||||
|
||||
# Play the talking animation
|
||||
func start_talking():
|
||||
|
||||
@@ -67,6 +67,7 @@ func add_new_item_by_id(item_id: String) -> void:
|
||||
var item_inventory_button = (
|
||||
escoria.object_manager.get_object(item_id).node as ESCItem
|
||||
).inventory_item.duplicate()
|
||||
item_inventory_button.global_id = item_id
|
||||
items_ids_in_inventory[item_id] = item_inventory_button
|
||||
get_node(inventory_ui_container).add_item(item_inventory_button)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user