Continued camera effects adding (zoom, shift)

Added trigger behaviour to ESCItem and removed ESCTriggerZone.
This commit is contained in:
Julian Murgia
2021-01-18 23:32:38 +01:00
parent ff56816205
commit 6890d927f5
24 changed files with 581 additions and 246 deletions

View File

@@ -25,8 +25,6 @@ func _enter_tree():
load("res://addons/escoria-core/game/core-scripts/escroom.gd"), null)
add_custom_type("ESCTerrain", "Navigation2D",
load("res://addons/escoria-core/game/core-scripts/escterrain.gd"), null)
add_custom_type("ESCTriggerZone", "Area2D",
load("res://addons/escoria-core/game/core-scripts/esctriggerzone.gd"), null)
set_escoria_main_settings()
set_escoria_debug_settings()
@@ -152,7 +150,6 @@ func _exit_tree():
remove_custom_type("ESCPlayer")
remove_custom_type("ESCRoom")
remove_custom_type("ESCTerrain")
remove_custom_type("ESCTriggerZone")
remove_autoloads()

View File

@@ -440,28 +440,19 @@ func register_object(name : String, val : Object, force : bool = false):
# Most objects have states/animations, but don't count on it
# if val.has_method("set_state"):
if val is ESCItem or val is ESCPlayer or val is ESCCharacter or val is ESCHotspot:
if val is ESCItem or val is ESCPlayer or val is ESCCharacter:
if name in states:
set_state(name, [states[name], true])
else:
set_state(name, [esctypes.OBJ_DEFAULT_STATE])
if val is ESCItem or val is ESCHotspot:
if val is ESCItem:
if val.is_interactive:
set_interactive(name, true)
# if val.has_method("set_active"):
# if name in actives:
# val.set_active(actives[name])
# if val.has_method("set_interactive"):
# if name in interactives:
# val.set_interactive(interactives[name])
if val.get("esc_script") != null and !val.get("esc_script").empty():
objects_events_table[name] = escoria.esc_compiler.load_esc_file(val.esc_script)
func get_object(name):
if !(name in objects):
@@ -588,11 +579,6 @@ func set_state(global_id : String, p_params : Array):
# animation_node = obj.get("animation")
if obj.get_animation_player() != null:
animation_node = obj.get_animation_player()
elif obj is ESCHotspot and obj.get_item_child_if_any() != null:
#if obj.get_item_child_if_any().get("animation") != null:
# animation_node = obj.get_item_child_if_any().animation
if obj.get_item_child_if_any().get_animation_player() != null:
animation_node = obj.get_item_child_if_any().get_animation_player()
if animation_node:
animation_node.stop()
@@ -614,7 +600,7 @@ func set_state(global_id : String, p_params : Array):
var animation = actual_animator.get_animation(p_params[0])
var animation_length = animation.length
animation_node.seek(animation_length)
print_debug("Item " + obj.global_id + " changed state to: " + p_params[0])
"""
When object is active, it is VISIBLE.

View File

@@ -156,10 +156,13 @@ camera_set_pos speed x y
Moves the camera to a position defined by "x" and "y", at the speed defined by
"speed" in pixels per second. If speed is 0, camera is teleported to the position.
"""
func camera_set_pos():
func camera_set_pos(command_params : Array):
# var speed = command_params[0]
# var x = command_params[1]
# var y = command_params[2]
# escoria.esc_runner.get_object("camera").set_pos(speed, x, y)
pass
"""
camera_set_target speed object [object2 object3 ...]
Configures the camera to follow 1 or more objects, using "speed" as speed limit.
@@ -180,8 +183,10 @@ the camera out, and smaller values zooms in, relative to the default value of 1.
An optional time in seconds controls how long it takes for the camera to zoom
into position.
"""
func camera_set_zoom():
pass
func camera_set_zoom(command_params : Array):
var zoom_level = command_params[0]
var speed = command_params[0] if command_params.size() > 1 else 0
escoria.esc_runner.get_object("camera").set_camera_zoom(zoom_level, speed)
"""
@@ -198,8 +203,12 @@ Shift camera by x and y pixels over time seconds.
- type is any of the Tween.TransitionType values without the prefix, eg. LINEAR,
QUART or CIRC; defaults to QUART.
"""
func camera_shift():
pass
func camera_shift(command_params : Array):
var x = command_params[0]
var y = command_params[1]
var time = command_params[2]
var type = command_params[3] if command_params.size() > 3 else "QUAD"
escoria.esc_runner.get_object("camera").shift(x, y, time, type)
"""

View File

@@ -20,10 +20,23 @@ var MovableScript = load("res://addons/escoria-core/game/core-scripts/behaviors/
export(String) var global_id
export(String, FILE, "*.esc") var esc_script
# If true, the ESC script may have an ":exit_scene" event to manage scene changes
export(bool) var is_exit
# is_trigger If true, object is considered as trigger. Allows using :trigger_in and
# :trigger_out verbs in ESC scripts.
export(bool) var is_trigger
export(String) var trigger_in_verb = "trigger_in"
export(String) var trigger_out_verb = "trigger_out"
# is_interactive : If true, object is not "focusable".
export(bool) var is_interactive = true
# player_orients_on_arrival : If true, player orients towards 'interaction_direction' as
# player character arrives.
export(bool) var player_orients_on_arrival = true
export(ESCPlayer.Directions) var interaction_direction
export(String) var tooltip_name
export(String) var default_action
@@ -97,6 +110,7 @@ var last_deg : int
var last_dir : int
func _ready():
assert(!global_id.empty())
# Adds movable behavior
Movable = Node.new()
@@ -120,11 +134,17 @@ func _ready():
if !Engine.is_editor_hint():
escoria.register_object(self)
connect("mouse_entered_item", escoria.inputs_manager, "_on_mouse_entered_item")
connect("mouse_exited_item", escoria.inputs_manager, "_on_mouse_exited_item")
connect("mouse_left_clicked_item", escoria.inputs_manager, "_on_mouse_left_clicked_item")
connect("mouse_double_left_clicked_item", escoria.inputs_manager, "_on_mouse_left_double_clicked_item")
connect("mouse_right_clicked_item", escoria.inputs_manager, "_on_mouse_right_clicked_item")
if !is_trigger:
connect("mouse_entered_item", escoria.inputs_manager, "_on_mouse_entered_item")
connect("mouse_exited_item", escoria.inputs_manager, "_on_mouse_exited_item")
connect("mouse_left_clicked_item", escoria.inputs_manager, "_on_mouse_left_clicked_item")
connect("mouse_double_left_clicked_item", escoria.inputs_manager, "_on_mouse_left_double_clicked_item")
connect("mouse_right_clicked_item", escoria.inputs_manager, "_on_mouse_right_clicked_item")
else:
connect("area_entered", self, "element_entered")
connect("area_exited", self, "element_exited")
connect("body_entered", self, "element_entered")
connect("body_exited", self, "element_exited")
if !is_exit:
last_scale = scale
@@ -184,12 +204,32 @@ func _on_mouse_exited():
################################################################################
# TRIGGER functions
func element_entered(body):
if body is ESCBackground or body.get_parent() is ESCBackground:
return
escoria.do("trigger_in", [global_id, body.global_id, trigger_in_verb])
func element_exited(body):
if body is ESCBackground or body.get_parent() is ESCBackground:
return
escoria.do("trigger_out", [global_id, body.global_id, trigger_out_verb])
################################################################################
# MOVING OBJECT functions
func teleport(target, angle : Object = null) -> void:
Movable.teleport(target, angle)
func walk_to(pos : Vector2, p_walk_context = null):
Movable.walk_to(pos, p_walk_context)
################################################################################
# TALKATIVE object functions
func start_talking():
# if animation_sprite.is_playing():

View File

@@ -2,30 +2,30 @@ tool
extends Area2D
class_name ESCTriggerZone
signal left_click_on_trigger
signal left_dblclick_on_trigger
signal right_click_on_trigger
signal mouse_enter_trigger
signal mouse_exit_trigger
func get_class():
return "ESCTriggerZone"
func mouse_enter():
emit_signal("mouse_enter_trigger", self)
func mouse_exit():
emit_signal("mouse_exit_trigger", self)
export(String) var global_id
export(String, FILE, "*.esc") var esc_script
func body_entered(body):
# if body is esc_type.PLAYER:
# if self.visible:
# run_event("enter")
pass
func body_exited(body):
# if body is esc_type.PLAYER:
# if self.visible:
# run_event("exit")
pass
func _ready():
assert(!global_id.empty())
escoria.register_object(self)
connect("area_entered", self, "element_entered")
connect("area_exited", self, "element_exited")
connect("body_entered", self, "element_entered")
connect("body_exited", self, "element_exited")
func element_entered(body):
if body is ESCBackground or body.get_parent() is ESCBackground:
return
escoria.do("trigger_in", [global_id, body.global_id])
func element_exited(body):
escoria.do("trigger_out", [global_id, body.global_id])

View File

@@ -87,7 +87,7 @@ func register_object(object : Object):
if object is ESCPlayer:
$esc_runner.register_object(object_id, object, true)
if object is ESCHotspot or object is Position2D:
if object is Position2D:
$esc_runner.register_object(object_id, object, true)
if object is ESCItem:
@@ -104,6 +104,9 @@ func register_object(object : Object):
if object is ESCInventory:
inventory = object
if object is ESCTriggerZone:
$esc_runner.register_object(object_id, object, true)
"""
@@ -154,17 +157,28 @@ func do(action : String, params : Array = []) -> void:
"item_left_click":
if params[0] is String:
printt("escoria.do : item_left_click on item ", params[0])
# call : ev_left_click_on_item()
ev_left_click_on_item($esc_runner.get_object(params[0]), params[1])
var item = $esc_runner.get_object(params[0])
ev_left_click_on_item(item, params[1])
"item_right_click":
if params[0] is String:
printt("escoria.do : item_right_click on item ", params[0])
# call : ev_left_click_on_item()
ev_left_click_on_item($esc_runner.get_object(params[0]), params[1], true)
"trigger_in":
var trigger_id = params[0]
var object_id = params[1]
var trigger_in_verb = params[2]
printt("escoria.do() : trigger_in ", trigger_id, " by ", object_id)
esc_runner.run_event(esc_runner.objects_events_table[trigger_id][trigger_in_verb])
"trigger_out":
var trigger_id = params[0]
var object_id = params[1]
var trigger_out_verb = params[2]
printt("escoria.do() : trigger_out ", trigger_id, " by ", object_id)
esc_runner.run_event(esc_runner.objects_events_table[trigger_id][trigger_out_verb])
_:
# $esc_runner.activate(action, params[0])
report_warnings("escoria.gd:do()", ["Action received:", action, "with params ", params])

View File

@@ -82,9 +82,7 @@ func set_current_scene(p_scene, run_events=true):
if "setup" in escoria.esc_runner.game:
escoria.esc_runner.run_event(escoria.esc_runner.game["setup"])
yield(escoria.esc_runner, "event_done")
# Because 1) changing a scene and 2) having a scene become ready
# both call `set_current_scene`, we don't want to duplicate thing
if not escoria.esc_runner.running_event:
escoria.esc_runner.run_game()
@@ -179,3 +177,5 @@ func check_game_scene_methods():
assert(current_scene.game.has_method("inventory_item_focused"))
assert(current_scene.game.has_method("inventory_item_unfocused"))
assert(current_scene.game.has_method("mousewheel_action"))

View File

@@ -15,6 +15,7 @@ var zoom_target
# This is needed to adjust dialog positions and such, see dialog_instance.gd
var zoom_transform
"""
Sets camera limits so it doesn't go out of the scene. If kwargs is null, default
limits are used. See Camera2D limits for more details.
@@ -65,6 +66,7 @@ func set_drag_margin_enabled(p_dm_h_enabled, p_dm_v_enabled):
self.drag_margin_h_enabled = p_dm_h_enabled
self.drag_margin_v_enabled = p_dm_v_enabled
func set_target(p_target, p_speed : float = 0.0):
speed = p_speed
target = p_target
@@ -157,16 +159,15 @@ func shift(p_x, p_y, p_time, p_type):
escoria.report_warnings("camera",
["Tween still active running camera_shift: " + tweenstat])
tween.emit_signal("tween_completed")
tween.interpolate_property(self, "global_position", self.global_position,
new_pos, time, tween.get(type), Tween.EASE_IN_OUT)
new_pos, float(time), tween.get(type), Tween.EASE_IN_OUT)
tween.start()
func target_reached(_obj=null, _key=null):
func target_reached():
tween.stop_all()
func _process(_delta):
zoom_transform = self.get_canvas_transform()

View File

@@ -13,14 +13,13 @@ var waiting_for_target2 = false
func _ready():
escoria.esc_runner.connect("action_changed", self, "on_action_selected")
escoria.inputs_manager.connect("element_focused", self, "on_element_focused")
func on_action_selected() -> void:
current_action = escoria.esc_runner.current_action
update_tooltip_text()
func on_element_focused(element_id : String) -> void:
func element_focused(element_id : String) -> void:
printt("action_target_tooltip.gd:on_element_focused()", "Element focused: ", element_id)
if element_id == "":