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():
|
func _ready():
|
||||||
parent.add_user_signal("arrived")
|
parent.add_user_signal("arrived")
|
||||||
last_scale = parent.scale
|
|
||||||
|
|
||||||
func _process(time):
|
func _process(time):
|
||||||
if Engine.is_editor_hint():
|
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):
|
func walk_to(pos : Vector2, p_walk_context = null):
|
||||||
if not parent.terrain:
|
if not parent.terrain:
|
||||||
return walk_stop(parent.get_position())
|
return walk_stop(parent.get_position())
|
||||||
|
|
||||||
if parent.interact_status == parent.INTERACT_STATES.INTERACT_WALKING:
|
if parent.task == parent.PLAYER_TASKS.WALK:
|
||||||
return
|
if walk_context.has("target_object") and p_walk_context.has("target_object"):
|
||||||
if parent.interact_status == parent.INTERACT_STATES.INTERACT_STARTED:
|
if walk_context["target_object"] == p_walk_context["target_object"]:
|
||||||
parent.interact_status = parent.INTERACT_STATES.INTERACT_WALKING
|
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_path = parent.terrain.get_terrain_path(parent.get_position(), pos)
|
||||||
walk_context = p_walk_context
|
walk_context = p_walk_context
|
||||||
if walk_path.size() == 0:
|
if walk_path.size() == 0:
|
||||||
@@ -152,7 +161,7 @@ func walk(target_pos, p_speed, context = null):
|
|||||||
# PRIVATE FUNCTION
|
# PRIVATE FUNCTION
|
||||||
func walk_stop(pos):
|
func walk_stop(pos):
|
||||||
parent.position = pos
|
parent.position = pos
|
||||||
parent.interact_status = parent.INTERACT_STATES.INTERACT_NONE
|
# parent.interact_status = parent.INTERACT_STATES.INTERACT_NONE
|
||||||
walk_path = []
|
walk_path = []
|
||||||
|
|
||||||
if parent.orig_speed:
|
if parent.orig_speed:
|
||||||
|
|||||||
@@ -71,19 +71,8 @@ var terrain : ESCTerrain
|
|||||||
# If the terrain node type is scalenodes
|
# If the terrain node type is scalenodes
|
||||||
var terrain_is_scalenodes : bool
|
var terrain_is_scalenodes : bool
|
||||||
var check_maps = true
|
var check_maps = true
|
||||||
var pose_scale : int
|
|
||||||
var last_scale : Vector2
|
|
||||||
var collision
|
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(int) var speed : int = 300
|
||||||
export(float) var v_speed_damp : float = 1.0
|
export(float) var v_speed_damp : float = 1.0
|
||||||
var orig_speed : float
|
var orig_speed : float
|
||||||
@@ -93,7 +82,7 @@ enum PLAYER_TASKS {
|
|||||||
WALK,
|
WALK,
|
||||||
SLIDE
|
SLIDE
|
||||||
}
|
}
|
||||||
var task # type PLAYER_TASKS
|
onready var task = PLAYER_TASKS.NONE # type PLAYER_TASKS
|
||||||
var params_queue : Array
|
var params_queue : Array
|
||||||
|
|
||||||
|
|
||||||
@@ -103,6 +92,7 @@ var size : Vector2
|
|||||||
var last_deg : int
|
var last_deg : int
|
||||||
var last_dir : int
|
var last_dir : int
|
||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
assert(!global_id.empty())
|
assert(!global_id.empty())
|
||||||
|
|
||||||
@@ -143,7 +133,7 @@ func _ready():
|
|||||||
connect("body_exited", self, "element_exited")
|
connect("body_exited", self, "element_exited")
|
||||||
|
|
||||||
if !is_exit:
|
if !is_exit:
|
||||||
last_scale = scale
|
Movable.last_scale = scale
|
||||||
Movable.update_terrain()
|
Movable.update_terrain()
|
||||||
|
|
||||||
|
|
||||||
@@ -153,7 +143,7 @@ func get_animation_player():
|
|||||||
if n is AnimationPlayer:
|
if n is AnimationPlayer:
|
||||||
animation_sprite = n
|
animation_sprite = n
|
||||||
return animation_sprite
|
return animation_sprite
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Initialize the interact_position attribute by searching for a Position2D
|
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):
|
func manage_input(viewport : Viewport, event : InputEvent, shape_idx : int):
|
||||||
if event is InputEventMouseButton:
|
if event is InputEventMouseButton:
|
||||||
# var p = get_global_mouse_position()
|
|
||||||
if event.doubleclick:
|
if event.doubleclick:
|
||||||
if event.button_index == BUTTON_LEFT:
|
if event.button_index == BUTTON_LEFT:
|
||||||
emit_signal("mouse_double_left_clicked_item", global_id, event)
|
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.is_pressed():
|
||||||
if event.button_index == BUTTON_LEFT:
|
if event.button_index == BUTTON_LEFT:
|
||||||
emit_signal("mouse_left_clicked_item", global_id, event)
|
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)
|
emit_signal("mouse_right_clicked_item", global_id, event)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -33,15 +33,7 @@ enum PLAYER_TASKS {
|
|||||||
WALK,
|
WALK,
|
||||||
SLIDE
|
SLIDE
|
||||||
}
|
}
|
||||||
var task # type PLAYER_TASKS
|
onready var task = PLAYER_TASKS.NONE # 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
|
|
||||||
|
|
||||||
|
|
||||||
enum Directions {
|
enum Directions {
|
||||||
@@ -126,8 +118,9 @@ func _ready():
|
|||||||
return
|
return
|
||||||
|
|
||||||
terrain = escoria.room_terrain
|
terrain = escoria.room_terrain
|
||||||
|
Movable.last_scale = scale
|
||||||
|
|
||||||
set_process(true)
|
# set_process(true)
|
||||||
|
|
||||||
|
|
||||||
func _process(time):
|
func _process(time):
|
||||||
@@ -164,7 +157,7 @@ func teleport(target, angle : Object = null) -> void:
|
|||||||
|
|
||||||
|
|
||||||
func walk_to(pos : Vector2, p_walk_context = null):
|
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):
|
func set_angle(deg : int, immediate = true):
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ func do(action : String, params : Array = []) -> void:
|
|||||||
var is_fast : bool = false
|
var is_fast : bool = false
|
||||||
if params.size() > 2 and params[2] == true:
|
if params.size() > 2 and params[2] == true:
|
||||||
is_fast = 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)
|
moving_obj.walk_to(target_position, walk_context)
|
||||||
|
|
||||||
# Walk to object from its id
|
# 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
|
destination_position = event.position
|
||||||
dont_interact = true
|
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.
|
# Wait for the player to arrive before continuing with action.
|
||||||
var context = yield(main.current_scene.player, "arrived")
|
var context = yield(main.current_scene.player, "arrived")
|
||||||
if context.target_object != walk_context.target_object:
|
printt("context arrived: ", context)
|
||||||
dont_interact = true
|
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 no interaction should happen after player has arrived, leave immediately.
|
||||||
if dont_interact:
|
if dont_interact:
|
||||||
|
print("DONT INTERACT WAS TRUE")
|
||||||
return
|
return
|
||||||
|
|
||||||
var player_global_pos = main.current_scene.player.global_position
|
var player_global_pos = main.current_scene.player.global_position
|
||||||
|
|||||||
@@ -373,6 +373,10 @@ __meta__ = {
|
|||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[node name="Line2D" type="Line2D" parent="Hotspots/trigger_left"]
|
||||||
|
points = PoolVector2Array( 718.237, 1756.04, 724.544, 1950.34, 815.761, 1947.51, 801.579, 1756.32, 719.359, 1756.32 )
|
||||||
|
width = 2.0
|
||||||
|
|
||||||
[node name="trigger_right" type="Area2D" parent="Hotspots"]
|
[node name="trigger_right" type="Area2D" parent="Hotspots"]
|
||||||
position = Vector2( 220, 0 )
|
position = Vector2( 220, 0 )
|
||||||
script = ExtResource( 7 )
|
script = ExtResource( 7 )
|
||||||
@@ -402,6 +406,10 @@ __meta__ = {
|
|||||||
"_edit_use_anchors_": false
|
"_edit_use_anchors_": false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[node name="Line2D" type="Line2D" parent="Hotspots/trigger_right"]
|
||||||
|
points = PoolVector2Array( 1089.37, 1757.17, 1097.85, 1949.99, 1187.37, 1947.87, 1174.21, 1755.79, 1090.78, 1756.18 )
|
||||||
|
width = 2.0
|
||||||
|
|
||||||
[node name="light_left" type="Area2D" parent="Hotspots"]
|
[node name="light_left" type="Area2D" parent="Hotspots"]
|
||||||
position = Vector2( 412, 0 )
|
position = Vector2( 412, 0 )
|
||||||
script = ExtResource( 7 )
|
script = ExtResource( 7 )
|
||||||
|
|||||||
@@ -159,6 +159,7 @@ interact_positions = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Hotspots/m_door"]
|
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Hotspots/m_door"]
|
||||||
|
visible = false
|
||||||
polygon = PoolVector2Array( 557.522, 348.813, 551.222, 42.6524, 743.99, 43.9123, 750.289, 345.033 )
|
polygon = PoolVector2Array( 557.522, 348.813, 551.222, 42.6524, 743.99, 43.9123, 750.289, 345.033 )
|
||||||
|
|
||||||
[node name="Position2D" type="Position2D" parent="Hotspots/m_door"]
|
[node name="Position2D" type="Position2D" parent="Hotspots/m_door"]
|
||||||
|
|||||||
@@ -16,11 +16,11 @@
|
|||||||
#change_scene res://game/rooms/room5/room5.tscn
|
#change_scene res://game/rooms/room5/room5.tscn
|
||||||
|
|
||||||
# 6/ character room
|
# 6/ character room
|
||||||
#change_scene res://game/rooms/room6/room6.tscn
|
change_scene res://game/rooms/room6/room6.tscn
|
||||||
|
|
||||||
# 7/ long room with camera shift to object 2 if look on object 1
|
# 7/ long room with camera shift to object 2 if look on object 1
|
||||||
# and stairs with camera shift too
|
# and stairs with camera shift too
|
||||||
change_scene res://game/rooms/room7/room7.tscn
|
#change_scene res://game/rooms/room7/room7.tscn
|
||||||
|
|
||||||
# 8/ puzzle in superposed scene
|
# 8/ puzzle in superposed scene
|
||||||
#change_scene res://game/rooms/room8/room8.tscn
|
#change_scene res://game/rooms/room8/room8.tscn
|
||||||
|
|||||||
Reference in New Issue
Block a user