Fixed double click cause actions being executed twice on "arrived" signal.
Known bug: NPC movement broken ("arrived" not emitted?)
This commit is contained in:
@@ -28,7 +28,6 @@ var pose_scale : int
|
||||
|
||||
func _ready():
|
||||
parent.add_user_signal("arrived")
|
||||
last_scale = parent.scale
|
||||
|
||||
func _process(time):
|
||||
if Engine.is_editor_hint():
|
||||
@@ -122,11 +121,21 @@ func teleport(target, angle : Object = null) -> void:
|
||||
func walk_to(pos : Vector2, p_walk_context = null):
|
||||
if not parent.terrain:
|
||||
return walk_stop(parent.get_position())
|
||||
|
||||
if parent.interact_status == parent.INTERACT_STATES.INTERACT_WALKING:
|
||||
return
|
||||
if parent.interact_status == parent.INTERACT_STATES.INTERACT_STARTED:
|
||||
parent.interact_status = parent.INTERACT_STATES.INTERACT_WALKING
|
||||
|
||||
if parent.task == parent.PLAYER_TASKS.WALK:
|
||||
if walk_context.has("target_object") and p_walk_context.has("target_object"):
|
||||
if walk_context["target_object"] == p_walk_context["target_object"]:
|
||||
walk_context["fast"] = p_walk_context["fast"]
|
||||
return true
|
||||
elif walk_context.has("target") and p_walk_context.has("target"):
|
||||
if walk_context["target"] == p_walk_context["target"]:
|
||||
walk_context["fast"] = p_walk_context["fast"]
|
||||
return true
|
||||
else:
|
||||
# return false
|
||||
pass
|
||||
if parent.task == parent.PLAYER_TASKS.NONE:
|
||||
parent.task = parent.PLAYER_TASKS.WALK
|
||||
walk_path = parent.terrain.get_terrain_path(parent.get_position(), pos)
|
||||
walk_context = p_walk_context
|
||||
if walk_path.size() == 0:
|
||||
@@ -152,7 +161,7 @@ func walk(target_pos, p_speed, context = null):
|
||||
# PRIVATE FUNCTION
|
||||
func walk_stop(pos):
|
||||
parent.position = pos
|
||||
parent.interact_status = parent.INTERACT_STATES.INTERACT_NONE
|
||||
# parent.interact_status = parent.INTERACT_STATES.INTERACT_NONE
|
||||
walk_path = []
|
||||
|
||||
if parent.orig_speed:
|
||||
|
||||
@@ -71,19 +71,8 @@ var terrain : ESCTerrain
|
||||
# If the terrain node type is scalenodes
|
||||
var terrain_is_scalenodes : bool
|
||||
var check_maps = true
|
||||
var pose_scale : int
|
||||
var last_scale : Vector2
|
||||
var collision
|
||||
|
||||
# WALKING
|
||||
# State machine defining the current interact state of the player
|
||||
enum INTERACT_STATES {
|
||||
INTERACT_STARTED, #
|
||||
INTERACT_NONE, #
|
||||
INTERACT_WALKING # Player is walking
|
||||
}
|
||||
var interact_status # Current interact status, type INTERACT_STATES
|
||||
|
||||
export(int) var speed : int = 300
|
||||
export(float) var v_speed_damp : float = 1.0
|
||||
var orig_speed : float
|
||||
@@ -93,7 +82,7 @@ enum PLAYER_TASKS {
|
||||
WALK,
|
||||
SLIDE
|
||||
}
|
||||
var task # type PLAYER_TASKS
|
||||
onready var task = PLAYER_TASKS.NONE # type PLAYER_TASKS
|
||||
var params_queue : Array
|
||||
|
||||
|
||||
@@ -103,6 +92,7 @@ var size : Vector2
|
||||
var last_deg : int
|
||||
var last_dir : int
|
||||
|
||||
|
||||
func _ready():
|
||||
assert(!global_id.empty())
|
||||
|
||||
@@ -143,7 +133,7 @@ func _ready():
|
||||
connect("body_exited", self, "element_exited")
|
||||
|
||||
if !is_exit:
|
||||
last_scale = scale
|
||||
Movable.last_scale = scale
|
||||
Movable.update_terrain()
|
||||
|
||||
|
||||
@@ -153,7 +143,7 @@ func get_animation_player():
|
||||
if n is AnimationPlayer:
|
||||
animation_sprite = n
|
||||
return animation_sprite
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Initialize the interact_position attribute by searching for a Position2D
|
||||
@@ -180,7 +170,7 @@ func init_interact_position_with_node():
|
||||
|
||||
func manage_input(viewport : Viewport, event : InputEvent, shape_idx : int):
|
||||
if event is InputEventMouseButton:
|
||||
# var p = get_global_mouse_position()
|
||||
|
||||
if event.doubleclick:
|
||||
if event.button_index == BUTTON_LEFT:
|
||||
emit_signal("mouse_double_left_clicked_item", global_id, event)
|
||||
@@ -188,7 +178,7 @@ func manage_input(viewport : Viewport, event : InputEvent, shape_idx : int):
|
||||
if event.is_pressed():
|
||||
if event.button_index == BUTTON_LEFT:
|
||||
emit_signal("mouse_left_clicked_item", global_id, event)
|
||||
if event.button_index == BUTTON_RIGHT:
|
||||
elif event.button_index == BUTTON_RIGHT:
|
||||
emit_signal("mouse_right_clicked_item", global_id, event)
|
||||
|
||||
|
||||
|
||||
@@ -33,15 +33,7 @@ enum PLAYER_TASKS {
|
||||
WALK,
|
||||
SLIDE
|
||||
}
|
||||
var task # type PLAYER_TASKS
|
||||
|
||||
# State machine defining the current interact state of the player
|
||||
enum INTERACT_STATES {
|
||||
INTERACT_STARTED, #
|
||||
INTERACT_NONE, #
|
||||
INTERACT_WALKING # Player is walking
|
||||
}
|
||||
var interact_status # Current interact status, type INTERACT_STATES
|
||||
onready var task = PLAYER_TASKS.NONE # type PLAYER_TASKS
|
||||
|
||||
|
||||
enum Directions {
|
||||
@@ -126,8 +118,9 @@ func _ready():
|
||||
return
|
||||
|
||||
terrain = escoria.room_terrain
|
||||
Movable.last_scale = scale
|
||||
|
||||
set_process(true)
|
||||
# set_process(true)
|
||||
|
||||
|
||||
func _process(time):
|
||||
@@ -164,7 +157,7 @@ func teleport(target, angle : Object = null) -> void:
|
||||
|
||||
|
||||
func walk_to(pos : Vector2, p_walk_context = null):
|
||||
Movable.walk_to(pos, p_walk_context)
|
||||
return Movable.walk_to(pos, p_walk_context)
|
||||
|
||||
|
||||
func set_angle(deg : int, immediate = true):
|
||||
|
||||
@@ -134,7 +134,7 @@ func do(action : String, params : Array = []) -> void:
|
||||
var is_fast : bool = false
|
||||
if params.size() > 2 and params[2] == true:
|
||||
is_fast = true
|
||||
var walk_context = {"fast": is_fast}
|
||||
var walk_context = {"fast": is_fast, "target": target_position}
|
||||
moving_obj.walk_to(target_position, walk_context)
|
||||
|
||||
# Walk to object from its id
|
||||
@@ -237,15 +237,24 @@ func ev_left_click_on_item(obj, event, default_action = false):
|
||||
destination_position = event.position
|
||||
dont_interact = true
|
||||
|
||||
main.current_scene.player.walk_to(destination_position, walk_context)
|
||||
# Use esc_runner for this?
|
||||
var is_already_walking = main.current_scene.player.walk_to(destination_position, walk_context)
|
||||
|
||||
# Wait for the player to arrive before continuing with action.
|
||||
var context = yield(main.current_scene.player, "arrived")
|
||||
if context.target_object != walk_context.target_object:
|
||||
dont_interact = true
|
||||
printt("context arrived: ", context)
|
||||
if context.has("target_object") and walk_context.has("target_object"):
|
||||
if (context.target_object.global_id != walk_context.target_object.global_id) \
|
||||
or (context.target_object.global_id == walk_context.target_object.global_id and is_already_walking):
|
||||
dont_interact = true
|
||||
elif context.has("target") and walk_context.has("target"):
|
||||
if (context.target.global_id != walk_context.target.global_id) \
|
||||
or (context.target.global_id == walk_context.target.global_id and is_already_walking):
|
||||
dont_interact = true
|
||||
|
||||
# If no interaction should happen after player has arrived, leave immediately.
|
||||
if dont_interact:
|
||||
print("DONT INTERACT WAS TRUE")
|
||||
return
|
||||
|
||||
var player_global_pos = main.current_scene.player.global_position
|
||||
|
||||
Reference in New Issue
Block a user