Optimization Part 2 (#6)

Authored-by: Dennis Ploeger <develop@dieploegers.de>
This commit is contained in:
Dennis Ploeger
2021-06-20 18:19:42 +02:00
committed by GitHub
parent 4e09f522ff
commit d5a0022b7b
18 changed files with 330 additions and 222 deletions

View File

@@ -1,3 +1,3 @@
source_md5="0167658bc4406f0d0fe437e0197c415a" source_md5="d7c036f59d6c4e0173f70e4eebbd2e05"
dest_md5="64b0613b3173e1e1c96dd18b6569e62d" dest_md5="413338b9673fcea9c377d96aa3045396"

View File

@@ -69,6 +69,9 @@ export(String) var trigger_out_verb = "trigger_out"
# If true, the player can interact with this item # If true, the player can interact with this item
export(bool) var is_interactive = true export(bool) var is_interactive = true
# Wether this item is movable
export(bool) var is_movable = false
# If true, player orients towards 'interaction_direction' as # If true, player orients towards 'interaction_direction' as
# player character arrives. # player character arrives.
export(bool) var player_orients_on_arrival = true export(bool) var player_orients_on_arrival = true
@@ -121,7 +124,7 @@ export(float) var v_speed_damp : float = 1.0
export(Script) var animations export(Script) var animations
# The movable subnode # The movable subnode
var movable: ESCMovable = null var _movable: ESCMovable = null
# Reference to the animation node (null if none was found) # Reference to the animation node (null if none was found)
var animation_sprite = null var animation_sprite = null
@@ -140,9 +143,6 @@ var inventory_item: ESCInventoryItem = null setget ,_get_inventory_item
# Add the movable node, connect signals, detect child nodes # Add the movable node, connect signals, detect child nodes
# and register this item # and register this item
func _ready(): func _ready():
movable = ESCMovable.new()
add_child(movable)
_detect_children() _detect_children()
@@ -152,6 +152,12 @@ func _ready():
# Register and connect all elements to Escoria backoffice. # Register and connect all elements to Escoria backoffice.
if not Engine.is_editor_hint(): if not Engine.is_editor_hint():
if is_movable:
_movable = ESCMovable.new()
add_child(_movable)
escoria.event_manager.connect("event_finished", self, "_update_terrain") escoria.event_manager.connect("event_finished", self, "_update_terrain")
escoria.object_manager.register_object( escoria.object_manager.register_object(
@@ -182,9 +188,9 @@ func _ready():
default_action_inventory = default_action default_action_inventory = default_action
# Perform a first terrain scaling if we have to. # Perform a first terrain scaling if we have to.
if !is_exit or dont_apply_terrain_scaling: if (!is_exit or dont_apply_terrain_scaling) and is_movable:
movable.last_scale = scale _movable.last_scale = scale
movable.update_terrain() _movable.update_terrain()
# Return the animation player node # Return the animation player node
@@ -272,7 +278,7 @@ func element_exited(body):
# #
# - target: Target item to teleport to # - target: Target item to teleport to
func teleport(target: Node) -> void: func teleport(target: Node) -> void:
movable.teleport(target) _movable.teleport(target)
# Use the movable node to make the item walk to the given position # Use the movable node to make the item walk to the given position
@@ -282,7 +288,7 @@ func teleport(target: Node) -> void:
# - pos: Position to walk to # - pos: Position to walk to
# - p_walk_context: Walk context to use # - p_walk_context: Walk context to use
func walk_to(pos : Vector2, p_walk_context: ESCWalkContext = null) -> void: func walk_to(pos : Vector2, p_walk_context: ESCWalkContext = null) -> void:
movable.walk_to(pos, p_walk_context) _movable.walk_to(pos, p_walk_context)
# Set the moving speed # Set the moving speed
@@ -292,6 +298,11 @@ func walk_to(pos : Vector2, p_walk_context: ESCWalkContext = null) -> void:
# - speed_value: Set the new speed # - speed_value: Set the new speed
func set_speed(speed_value : int) -> void: func set_speed(speed_value : int) -> void:
speed = speed_value speed = speed_value
# Check wether this item moved
func has_moved() -> bool:
return _movable.moved if is_movable else false
# Set the angle # Set the angle
@@ -300,21 +311,21 @@ func set_speed(speed_value : int) -> void:
# #
# Set the angle # Set the angle
func set_angle(deg : int, immediate = true): func set_angle(deg : int, immediate = true):
movable.set_angle(deg, immediate) _movable.set_angle(deg, immediate)
# Play the talking animation # Play the talking animation
func start_talking(): func start_talking():
if animation_sprite.is_playing(): if animation_sprite.is_playing():
animation_sprite.stop() animation_sprite.stop()
animation_sprite.play(animations.speaks[movable.last_dir][0]) animation_sprite.play(animations.speaks[_movable.last_dir][0])
# Stop playing the talking animation # Stop playing the talking animation
func stop_talking(): func stop_talking():
if animation_sprite.is_playing(): if animation_sprite.is_playing():
animation_sprite.stop() animation_sprite.stop()
animation_sprite.play(animations.idles[movable.last_dir][0]) animation_sprite.play(animations.idles[_movable.last_dir][0])
# Detect the child nodes and set respective references # Detect the child nodes and set respective references
@@ -336,7 +347,8 @@ func _detect_children() -> void:
# Upate the terrain when an event finished # Upate the terrain when an event finished
func _update_terrain(rc: int, event_name: String) -> void: func _update_terrain(rc: int, event_name: String) -> void:
movable.update_terrain(event_name) if is_movable:
_movable.update_terrain(event_name)
# Get inventory item from the inventory item scene # Get inventory item from the inventory item scene

View File

@@ -12,6 +12,11 @@ class_name ESCPlayer
export(NodePath) var camera_position_node export(NodePath) var camera_position_node
# A player is always movable
func _init():
is_movable = true
# Return the camera position if a camera_position_node exists or the # Return the camera position if a camera_position_node exists or the
# global position of the player # global position of the player
func get_camera_pos(): func get_camera_pos():

View File

@@ -92,23 +92,21 @@ func set_camera_limits(camera_limit_id : int = 0) -> void:
area.size = get_viewport().size area.size = get_viewport().size
escoria.logger.info("Setting camera limits from scene ", [area]) escoria.logger.info("Setting camera limits from scene ", [area])
limits = { limits = ESCCameraLimits.new(
"limit_left": area.position.x, area.position.x,
"limit_right": area.position.x + area.size.x, area.position.x + area.size.x,
"limit_top": area.position.y, area.position.y,
"limit_bottom": area.position.y + area.size.y, area.position.y + area.size.y
"set_default": true, )
}
else: else:
limits = { limits = ESCCameraLimits.new(
"limit_left": scene_camera_limits.position.x, scene_camera_limits.position.x,
"limit_right": scene_camera_limits.position.x + \ scene_camera_limits.position.x + \
scene_camera_limits.size.x, scene_camera_limits.size.x,
"limit_top": scene_camera_limits.position.y, scene_camera_limits.position.y,
"limit_bottom": scene_camera_limits.position.y + \ scene_camera_limits.position.y + \
scene_camera_limits.size.y + screen_ofs.y * 2, scene_camera_limits.size.y + screen_ofs.y * 2
"set_default": true, )
}
escoria.logger.info( escoria.logger.info(
"Setting camera limits from parameter ", "Setting camera limits from parameter ",
[scene_camera_limits] [scene_camera_limits]

View File

@@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=2] [gd_scene load_steps=2 format=2]
[ext_resource path="res://addons/escoria-core/game/scenes/camera_player/esccamera.gd" type="Script" id=1] [ext_resource path="res://addons/escoria-core/game/scenes/camera_player/esc_camera.gd" type="Script" id=1]
[node name="camera" type="Camera2D"] [node name="camera" type="Camera2D"]
current = true current = true

View File

@@ -1,67 +1,64 @@
# Camera handling
extends Camera2D extends Camera2D
class_name ESCCamera class_name ESCCamera
# Reference to the tween node for animating camera movements
onready var tween = $"tween" onready var tween = $"tween"
var default_limits = {} # This does not change once set # Target position of the camera
var target: Vector2 = Vector2()
var speed = 0.0 # The object to follow
# Target can be object or Vector2. See resove_target_pos() var follow_target: Node = null
var target
var target_pos : Vector2 # Target zoom of the camera
var zoom_target: Vector2
var zoom_time var zoom_time
var zoom_target
# This is needed to adjust dialog positions and such, see dialog_instance.gd # This is needed to adjust dialog positions and such, see dialog_instance.gd
var zoom_transform var zoom_transform
""" # Sets camera limits so it doesn't go out of the scene
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. # #### Parameters
- kwargs Dictionary (can be null) Limits to set. #
- limit_left int Left limit. # - limits: The limits to set
- limit_right int Right limit. func set_limits(limits: ESCCameraLimits):
- limit_top int Top limit. self.limit_left = limits.limit_left
- limit_bottom int Bottom limit. self.limit_right = limits.limit_right
- set_default bool (Facultative) If true, the given limits are save as default limits. self.limit_top = limits.limit_top
""" self.limit_bottom = limits.limit_bottom
func set_limits(kwargs=null):
if not kwargs:
kwargs = {
"limit_left": -10000,
"limit_right": 10000,
"limit_top": -10000,
"limit_bottom": 10000,
"set_default": false,
}
print_stack()
self.limit_left = kwargs["limit_left"]
self.limit_right = kwargs["limit_right"]
self.limit_top = kwargs["limit_top"]
self.limit_bottom = kwargs["limit_bottom"]
if "set_default" in kwargs and kwargs["set_default"] and not default_limits: func _resolve_target_and_zoom(p_target) -> void:
default_limits = kwargs target = Vector2()
zoom_target = Vector2()
follow_target = null
if p_target is Vector2:
target = p_target
elif p_target is Array:
var target_pos = Vector2()
func resolve_target_pos(): for obj in p_target:
if typeof(target) == TYPE_VECTOR2:
target_pos = target
elif typeof(target) == TYPE_ARRAY:
var count = 0
for obj in target:
target_pos += obj.get_camera_pos() target_pos += obj.get_camera_pos()
count += 1
# Let the error in if an empty array was passed (divzero) # Let the error in if an empty array was passed (divzero)
target_pos = target_pos / count target = target_pos / p_target.size()
elif p_target is Node and p_target.has_node("camera_pos") and \
p_target.get_node("camera_pos") is Camera2D:
target = p_target.get_node("camera_pos").global_position
zoom_target = p_target.get_node("camera_pos").zoom
elif p_target is Node and "is_movable" in p_target and p_target.is_movable:
follow_target = p_target
elif p_target.has_method("get_camera_pos"):
target = p_target.get_camera_pos()
else: else:
target_pos = target.get_camera_pos() target = p_target.global_position
return target_pos
func set_drag_margin_enabled(p_dm_h_enabled, p_dm_v_enabled): 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_h_enabled = p_dm_h_enabled
@@ -69,16 +66,19 @@ func set_drag_margin_enabled(p_dm_h_enabled, p_dm_v_enabled):
func set_target(p_target, p_speed : float = 0.0): func set_target(p_target, p_speed : float = 0.0):
speed = p_speed var speed = p_speed
target = p_target
_resolve_target_and_zoom(p_target)
resolve_target_pos()
if not follow_target == null:
target = follow_target.global_position
escoria.logger.info("Current camera position = " + str(self.global_position)) escoria.logger.info("Current camera position = " + str(self.global_position))
if speed == 0.0: if speed == 0.0:
self.global_position = target_pos self.global_position = target
else: else:
var time = self.global_position.distance_to(target_pos) / speed var time = self.global_position.distance_to(target) / speed
if tween.is_active(): if tween.is_active():
var tweenstat = String(tween.tell()) + "/" + String(tween.get_runtime()) var tweenstat = String(tween.tell()) + "/" + String(tween.get_runtime())
@@ -86,8 +86,15 @@ func set_target(p_target, p_speed : float = 0.0):
["Tween still active running camera_set_target: " + tweenstat]) ["Tween still active running camera_set_target: " + tweenstat])
tween.emit_signal("tween_completed") tween.emit_signal("tween_completed")
tween.interpolate_property(self, "global_position", self.global_position, tween.interpolate_property(
target_pos, time, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT) self,
"global_position",
self.global_position,
target,
time,
Tween.TRANS_LINEAR,
Tween.EASE_IN_OUT
)
tween.start() tween.start()
func set_camera_zoom(p_zoom_level, p_time): func set_camera_zoom(p_zoom_level, p_time):
@@ -116,38 +123,52 @@ func push(p_target, p_time, p_type):
var time = float(p_time) var time = float(p_time)
var type = "TRANS_" + p_type var type = "TRANS_" + p_type
target = p_target _resolve_target_and_zoom(p_target)
var camera_pos var push_target = null
var camera_pos_coords
if target.has_node("camera_pos"): if follow_target != null:
camera_pos = target.get_node("camera_pos") push_target = p_target.position
camera_pos_coords = camera_pos.global_position
else: else:
camera_pos_coords = target.global_position push_target = target
if time == 0: if time == 0:
self.global_position = camera_pos_coords self.global_position = push_target
if zoom_target != Vector2():
if camera_pos and camera_pos is Camera2D: self.zoom = zoom_target
self.zoom = camera_pos.zoom
else: else:
if tween.is_active(): if tween.is_active():
var tweenstat = String(tween.tell()) + "/" + String(tween.get_runtime()) var tweenstat = String(tween.tell()) + "/" + String(tween.get_runtime())
escoria.logger.report_warnings("camera", escoria.logger.report_warnings("camera",
["Tween still active running camera_push: " + tweenstat]) ["Tween still active running camera_push: " + tweenstat])
tween.emit_signal("tween_completed") tween.emit_signal("tween_completed", null, null)
if camera_pos and camera_pos is Camera2D: if zoom_target != Vector2():
tween.interpolate_property(self, "zoom", self.zoom, camera_pos.zoom, tween.interpolate_property(
time, tween.get(type), Tween.EASE_IN_OUT) self,
"zoom",
self.zoom,
zoom_target,
time,
tween.get(type),
Tween.EASE_IN_OUT
)
tween.interpolate_property(self, "global_position", self.global_position, tween.interpolate_property(
camera_pos_coords, time, tween.get(type), Tween.EASE_IN_OUT) self,
"global_position",
self.global_position,
push_target,
time,
tween.get(type),
Tween.EASE_IN_OUT
)
tween.start() tween.start()
func shift(p_x, p_y, p_time, p_type): func shift(p_x, p_y, p_time, p_type):
follow_target = null
var x = int(p_x) var x = int(p_x)
var y = int(p_y) var y = int(p_y)
var time = float(p_time) var time = float(p_time)
@@ -173,18 +194,11 @@ func target_reached():
func _process(_delta): func _process(_delta):
zoom_transform = self.get_canvas_transform() zoom_transform = self.get_canvas_transform()
if target and not tween.is_active(): if follow_target and not tween.is_active() and follow_target.has_moved():
if typeof(target) == TYPE_VECTOR2 or typeof(target) == TYPE_ARRAY: self.global_position = follow_target.global_position
self.global_position = resolve_target_pos()
elif "moved" in target and target.moved \
or "moved" in target.movable and target.movable.moved:
self.global_position = resolve_target_pos()
func _ready(): func _ready():
if not target: tween.connect("tween_all_completed", self, "target_reached")
target = Vector2(0, 0)
tween.connect("tween_completed", self, "target_reached")
escoria.object_manager.register_object( escoria.object_manager.register_object(
ESCObject.new( ESCObject.new(
self.name, self.name,

View File

@@ -0,0 +1,28 @@
# Describes a bounding box that limits the camera movement in the scene
extends Object
class_name ESCCameraLimits
# The left side of the bounding box
var limit_left: int = -10000
# The right side of the bounding box
var limit_right: int = 10000
# The top side of the bounding box
var limit_top: int = -10000
# The bottom side of the bounding box
var limit_bottom: int = 10000
func _init(
left: int,
right: int,
top: int,
bottom: int
):
limit_left = left
limit_right = right
limit_top = top
limit_bottom = bottom

View File

@@ -1,15 +1,23 @@
# A debug window which can run esc commands
extends WindowDialog extends WindowDialog
# Reference to the past actions display
onready var past_actions = $VBoxContainer/past_actions onready var past_actions = $VBoxContainer/past_actions
# Reference to the command input
onready var command = $VBoxContainer/command onready var command = $VBoxContainer/command
var last_event_done := true
# Run a command
#
# #### Parameters
#
# - p_command_str: Command to execute
func _on_command_text_entered(p_command_str : String): func _on_command_text_entered(p_command_str : String):
if p_command_str.empty(): if p_command_str.empty():
return return
last_event_done = false
command.text = "" command.text = ""
past_actions.text += "\n" past_actions.text += "\n"
past_actions.text += "# " + p_command_str past_actions.text += "# " + p_command_str
@@ -24,19 +32,13 @@ func _on_command_text_entered(p_command_str : String):
]) ])
if script: if script:
escoria.event_manager.run(script.events["debug"]) escoria.event_manager.queue_event(script.events["debug"])
var ret = yield(escoria.event_manager, "event_finished") var ret = yield(escoria.event_manager, "event_finished")
while ret[1] != "debug": while ret[1] != "debug":
ret = yield(escoria.event_manager, "event_finished") ret = yield(escoria.event_manager, "event_finished")
if not ret[0] == ESCExecution.RC_OK: past_actions.text += "Returned code: %d" % ret[0]
past_actions.text += "Returned code: %d" % ret[0]
func _on_event_done(event_name : String):
if event_name == "debug" and !last_event_done:
last_event_done = true
# past_actions.text += "\nDone.\n"
# Set the focus to the command
func _on_esc_prompt_popup_about_to_show(): func _on_esc_prompt_popup_about_to_show():
command.grab_focus() command.grab_focus()

View File

@@ -1,43 +1,38 @@
# Manages the inventory on the GUI connected to the inventory_ui_container
# variable
extends Control extends Control
class_name ESCInventory class_name ESCInventory
func get_class():
return "ESCInventory"
""" # Define the actual container node to add items as children of.
This script is set on the inventory UI scene's root node. # Should be a Container.
The scene MUST contain the 2 following nodes:
- one node named "ESCORIA_ALL_ITEMS" containing ALL ESCItems of the game. This is required
to be able to get the ESCInventoryItem for a given ESCItem.
- one Container node (under Control type) that will contain the inventory items.
It must be set in the "items_container" export variable.
"""
# Define the actual container node to add items as children of. Should be a Container.
export(NodePath) var inventory_ui_container export(NodePath) var inventory_ui_container
onready var all_items = $ESCORIA_ALL_ITEMS
var items_ids_in_inventory : Dictionary = {} # { item_id : TextureButton}
# A registry of inventory ESCInventoryItem nodes
var items_ids_in_inventory : Dictionary = {}
# Fill the items the player has from the start, do sanity checks and
# listen when a global has changed
func _ready(): func _ready():
# # For debugging scene only. These 2 lines should remain commented on normal run. if inventory_ui_container == null or inventory_ui_container.is_empty():
# if !Engine.is_editor_hint(): escoria.logger.report_errors(
# return self.get_path(),
["Items container is empty."]
)
return
for item_id in escoria.inventory_manager.items_in_inventory(): for item_id in escoria.inventory_manager.items_in_inventory():
call_deferred("add_new_item_by_id", item_id) call_deferred("add_new_item_by_id", item_id)
escoria.inventory = self escoria.inventory = self
if inventory_ui_container == null or inventory_ui_container.is_empty(): escoria.globals_manager.connect(
escoria.logger.report_errors(self.get_path(), ["Items container is empty."]) "global_changed", #
return self,
for c in get_node(inventory_ui_container).get_items(): "_on_escoria_global_changed"
items_ids_in_inventory[c.item_id] = c )
# c.connect("pressed", escoria.inputs_manager, "_on_inventory_item_pressed", [c.item_id])
escoria.globals_manager.connect("global_changed", self, "_on_escoria_global_changed")
# add item to Inventory UI using its id set in its scene # add item to Inventory UI using its id set in its scene
@@ -73,7 +68,6 @@ func add_new_item_by_id(item_id : String) -> void:
items_ids_in_inventory[item_id] = item_inventory_button items_ids_in_inventory[item_id] = item_inventory_button
get_node(inventory_ui_container).add_item(item_inventory_button) get_node(inventory_ui_container).add_item(item_inventory_button)
# Add the item to inventory
if not escoria.object_manager.has(item_id): if not escoria.object_manager.has(item_id):
escoria.object_manager.register_object( escoria.object_manager.register_object(
ESCObject.new( ESCObject.new(
@@ -82,40 +76,74 @@ func add_new_item_by_id(item_id : String) -> void:
), ),
true true
) )
item_inventory_button.visible = true item_inventory_button.visible = true
item_inventory_button.connect("mouse_left_inventory_item", item_inventory_button.connect(
escoria.inputs_manager, "_on_mouse_left_click_inventory_item") "mouse_left_inventory_item",
item_inventory_button.connect("mouse_double_left_inventory_item", escoria.inputs_manager,
escoria.inputs_manager, "_on_mouse_double_left_click_inventory_item") "_on_mouse_left_click_inventory_item"
item_inventory_button.connect("mouse_right_inventory_item", )
escoria.inputs_manager, "_on_mouse_right_click_inventory_item") item_inventory_button.connect(
"mouse_double_left_inventory_item",
escoria.inputs_manager,
"_on_mouse_double_left_click_inventory_item"
)
item_inventory_button.connect(
"mouse_right_inventory_item",
escoria.inputs_manager,
"_on_mouse_right_click_inventory_item"
)
item_inventory_button.connect("inventory_item_focused", item_inventory_button.connect(
escoria.inputs_manager, "_on_mouse_entered_inventory_item") "inventory_item_focused",
item_inventory_button.connect("inventory_item_unfocused", escoria.inputs_manager,
escoria.inputs_manager, "_on_mouse_exited_inventory_item") "_on_mouse_entered_inventory_item"
)
item_inventory_button.connect(
"inventory_item_unfocused",
escoria.inputs_manager,
"_on_mouse_exited_inventory_item"
)
# remove item fromInventory UI using its id set in its scene # remove item fromInventory UI using its id set in its scene
func remove_item_by_id(item_id : String) -> void: func remove_item_by_id(item_id : String) -> void:
if items_ids_in_inventory.has(item_id): if items_ids_in_inventory.has(item_id):
var item_inventory_button = items_ids_in_inventory[item_id] var item_inventory_button = items_ids_in_inventory[item_id]
item_inventory_button.disconnect("mouse_left_inventory_item", item_inventory_button.disconnect(
escoria.inputs_manager, "_on_mouse_left_click_inventory_item") "mouse_left_inventory_item",
item_inventory_button.disconnect("mouse_double_left_inventory_item", escoria.inputs_manager,
escoria.inputs_manager, "_on_mouse_double_left_click_inventory_item") "_on_mouse_left_click_inventory_item"
item_inventory_button.disconnect("mouse_right_inventory_item", )
escoria.inputs_manager, "_on_mouse_right_click_inventory_item") item_inventory_button.disconnect(
item_inventory_button.disconnect("inventory_item_focused", "mouse_double_left_inventory_item",
escoria.inputs_manager, "_on_mouse_entered_inventory_item") escoria.inputs_manager,
item_inventory_button.disconnect("inventory_item_unfocused", "_on_mouse_double_left_click_inventory_item"
escoria.inputs_manager, "_on_mouse_exited_inventory_item") )
item_inventory_button.disconnect(
"mouse_right_inventory_item",
escoria.inputs_manager,
"_on_mouse_right_click_inventory_item"
)
item_inventory_button.disconnect(
"inventory_item_focused",
escoria.inputs_manager,
"_on_mouse_entered_inventory_item"
)
item_inventory_button.disconnect(
"inventory_item_unfocused",
escoria.inputs_manager,
"_on_mouse_exited_inventory_item"
)
get_node(inventory_ui_container).remove_item(item_inventory_button) get_node(inventory_ui_container).remove_item(item_inventory_button)
item_inventory_button.queue_free() item_inventory_button.queue_free()
items_ids_in_inventory.erase(item_id) items_ids_in_inventory.erase(item_id)
# React to changes to inventory globals adding items or removing them
func _on_escoria_global_changed(global : String, old_value, new_value) -> void: func _on_escoria_global_changed(global : String, old_value, new_value) -> void:
if !global.begins_with("i/"): if !global.begins_with("i/"):
return return
@@ -126,4 +154,10 @@ func _on_escoria_global_changed(global : String, old_value, new_value) -> void:
else: else:
remove_item_by_id(item[0]) remove_item_by_id(item[0])
else: else:
escoria.logger.report_errors("inventory_ui.gd:_on_escoria_global_changed()", ["Global must contain 1 item name.", "(received: " + global + ")"]) escoria.logger.report_errors(
"inventory_ui.gd:_on_escoria_global_changed()",
[
"Global must contain only one item name.",
"(received: %s)" % global
]
)

View File

@@ -1,23 +1,28 @@
# Background music player
extends Control extends Control
class_name ESCBackgroundMusic class_name ESCBackgroundMusic
func get_class():
return "ESCBackgroundMusic"
onready var stream = $AudioStreamPlayer # Global id of the background music player
var state = "default" export var global_id: String = "bg_music"
export var global_id = "bg_music"
func game_cleared(): # The state of the music player. "default" or "off" disable music
set_state("off", true) # Any other state refers to a music stream that should be played
escoria.object_manager.register_object( var state: String = "default"
ESCObject.new(global_id, self),
true
)
func set_state(p_state, p_force = false): # Reference to the audio player
onready var stream: AudioStreamPlayer = $AudioStreamPlayer
# Set the state of this player
#
# #### Parameters
#
# - p_state: New state to use
# - p_force: Override the existing state even if the stream is still playing
func set_state(p_state: String, p_force: bool = false) -> void:
# If already playing this stream, keep playing, unless p_force # If already playing this stream, keep playing, unless p_force
if p_state == state and not p_force and stream.is_playing(): if p_state == state and not p_force and stream.is_playing():
return return
@@ -39,6 +44,8 @@ func set_state(p_state, p_force = false):
stream.volume_db = ProjectSettings.get_setting("escoria/sound/music_volume") stream.volume_db = ProjectSettings.get_setting("escoria/sound/music_volume")
stream.play() stream.play()
# Register to the object registry
func _ready(): func _ready():
escoria.object_manager.register_object( escoria.object_manager.register_object(
ESCObject.new(global_id, self), ESCObject.new(global_id, self),

View File

@@ -1,23 +1,28 @@
# Background sound player
extends Control extends Control
class_name ESCBackgroundSound class_name ESCBackgroundSound
func get_class():
return "ESCBackgroundSound"
onready var stream = $AudioStreamPlayer # Global id of the background sound player
var state = "default" export var global_id: String = "bg_sound"
export var global_id = "bg_sound"
func game_cleared(): # The state of the sound player. "default" or "off" disable sound
stream.stream = null # Any other state refers to a sound stream that should be played
escoria.object_manager.register_object( var state: String = "default"
ESCObject.new(global_id, self),
true
)
func set_state(p_state, p_force = false): # Reference to the audio player
onready var stream: AudioStreamPlayer = $AudioStreamPlayer
# Set the state of this player
#
# #### Parameters
#
# - p_state: New state to use
# - p_force: Override the existing state even if the stream is still playing
func set_state(p_state: String, p_force: bool = false):
# If already playing this stream, keep playing, unless p_force # If already playing this stream, keep playing, unless p_force
if p_state == state and not p_force and stream.is_playing(): if p_state == state and not p_force and stream.is_playing():
return return
@@ -40,6 +45,7 @@ func set_state(p_state, p_force = false):
stream.play() stream.play()
# Register to the object registry
func _ready(): func _ready():
escoria.object_manager.register_object( escoria.object_manager.register_object(
ESCObject.new(global_id, self), ESCObject.new(global_id, self),

View File

@@ -1,28 +1,41 @@
# A transition player for scene changes
# FIXME Add configuration to select a specific mask
extends ColorRect extends ColorRect
export(String, "fade_black", "fade_white", "transition_in", "transition_out") var transition_name
# Emitted when the transition was player
signal transition_done
# The name of the transition to play
export(
String,
"fade_black",
"fade_white",
"transition_in",
"transition_out"
) var transition_name: String
# Reference to the _AnimationPlayer_ node # Reference to the _AnimationPlayer_ node
onready var _anim_player := $AnimationPlayer onready var _anim_player := $AnimationPlayer
# Fade in when the scene is starting
signal transition_done
func _ready() -> void: func _ready() -> void:
# Plays the animation backward to fade in fade_in()
_anim_player.play_backwards(transition_name)
# Fade out the transition
func fade_out() -> void: func fade_out() -> void:
# Plays the Fade animation and wait until it finishes
_anim_player.play(transition_name) _anim_player.play(transition_name)
yield(_anim_player, "animation_finished") yield(_anim_player, "animation_finished")
emit_signal("transition_done") emit_signal("transition_done")
# Fade in the transition
func fade_in() -> void: func fade_in() -> void:
# Plays the Fade animation and wait until it finishes # Plays the Fade animation and wait until it finishes
_anim_player.play_backwards(transition_name) _anim_player.play_backwards(transition_name)
yield(_anim_player, "animation_finished") yield(_anim_player, "animation_finished")
emit_signal("transition_done") emit_signal("transition_done")

View File

@@ -4,4 +4,4 @@ name="Escoria"
description="A point'n'click framework within Godot Engine." description="A point'n'click framework within Godot Engine."
author="StraToN" author="StraToN"
version="1.0.0" version="1.0.0"
script="editor/plugin_escoria.gd" script="plugin.gd"

View File

@@ -8,25 +8,12 @@ const autoloads = {
"escoria": "res://addons/escoria-core/game/escoria.tscn", "escoria": "res://addons/escoria-core/game/escoria.tscn",
} }
# Custom types to generate outside of Classes
const custom_types = [
{
"type_name": "ESCItemsInventory",
"parent_type": "GridContainer",
"script_res": "res://addons/escoria-core/game/core-scripts/items_inventory.gd"
}
]
# Setup Escoria # Setup Escoria
func _enter_tree(): func _enter_tree():
for key in autoloads.keys(): for key in autoloads.keys():
add_autoload_singleton(key, autoloads[key]) add_autoload_singleton(key, autoloads[key])
for custom_type in custom_types:
add_custom_type(custom_type.type_name, custom_type.parent_type,
load(custom_type.script_res), null)
# Prepare settings # Prepare settings
set_escoria_main_settings() set_escoria_main_settings()
set_escoria_debug_settings() set_escoria_debug_settings()
@@ -251,7 +238,5 @@ func _exit_tree():
for key in autoloads.keys(): for key in autoloads.keys():
if ProjectSettings.has_setting(key): if ProjectSettings.has_setting(key):
remove_autoload_singleton(key) remove_autoload_singleton(key)
for custom_type in custom_types:
remove_custom_type(custom_type.type_name)

View File

@@ -6,8 +6,6 @@ camera_set_limits 2
camera_set_pos 500 150 150 camera_set_pos 500 150 150
wait 6 wait 6
camera_set_pos 1 1080 1000
wait 1
camera_set_limits 0 camera_set_limits 0
camera_set_target 0 player camera_set_target 0 player

BIN
icon.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@@ -107,7 +107,12 @@ _global_script_classes=[ {
"base": "Camera2D", "base": "Camera2D",
"class": "ESCCamera", "class": "ESCCamera",
"language": "GDScript", "language": "GDScript",
"path": "res://addons/escoria-core/game/scenes/camera_player/esccamera.gd" "path": "res://addons/escoria-core/game/scenes/camera_player/esc_camera.gd"
}, {
"base": "Object",
"class": "ESCCameraLimits",
"language": "GDScript",
"path": "res://addons/escoria-core/game/scenes/camera_player/esc_camera_limits.gd"
}, { }, {
"base": "ESCStatement", "base": "ESCStatement",
"class": "ESCCommand", "class": "ESCCommand",
@@ -445,6 +450,7 @@ _global_script_class_icons={
"ESCBackgroundSound": "", "ESCBackgroundSound": "",
"ESCBaseCommand": "", "ESCBaseCommand": "",
"ESCCamera": "", "ESCCamera": "",
"ESCCameraLimits": "",
"ESCCommand": "", "ESCCommand": "",
"ESCCommandArgumentDescriptor": "", "ESCCommandArgumentDescriptor": "",
"ESCCommandRegistry": "", "ESCCommandRegistry": "",