Optimization Part 2 (#6)
Authored-by: Dennis Ploeger <develop@dieploegers.de>
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
source_md5="0167658bc4406f0d0fe437e0197c415a"
|
||||
dest_md5="64b0613b3173e1e1c96dd18b6569e62d"
|
||||
source_md5="d7c036f59d6c4e0173f70e4eebbd2e05"
|
||||
dest_md5="413338b9673fcea9c377d96aa3045396"
|
||||
|
||||
|
||||
Binary file not shown.
@@ -69,6 +69,9 @@ export(String) var trigger_out_verb = "trigger_out"
|
||||
# If true, the player can interact with this item
|
||||
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
|
||||
# player character arrives.
|
||||
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
|
||||
|
||||
# The movable subnode
|
||||
var movable: ESCMovable = null
|
||||
var _movable: ESCMovable = null
|
||||
|
||||
# Reference to the animation node (null if none was found)
|
||||
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
|
||||
# and register this item
|
||||
func _ready():
|
||||
movable = ESCMovable.new()
|
||||
|
||||
add_child(movable)
|
||||
|
||||
_detect_children()
|
||||
|
||||
@@ -152,6 +152,12 @@ func _ready():
|
||||
|
||||
# Register and connect all elements to Escoria backoffice.
|
||||
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.object_manager.register_object(
|
||||
@@ -182,9 +188,9 @@ func _ready():
|
||||
default_action_inventory = default_action
|
||||
|
||||
# Perform a first terrain scaling if we have to.
|
||||
if !is_exit or dont_apply_terrain_scaling:
|
||||
movable.last_scale = scale
|
||||
movable.update_terrain()
|
||||
if (!is_exit or dont_apply_terrain_scaling) and is_movable:
|
||||
_movable.last_scale = scale
|
||||
_movable.update_terrain()
|
||||
|
||||
|
||||
# Return the animation player node
|
||||
@@ -272,7 +278,7 @@ func element_exited(body):
|
||||
#
|
||||
# - target: Target item to teleport to
|
||||
func teleport(target: Node) -> void:
|
||||
movable.teleport(target)
|
||||
_movable.teleport(target)
|
||||
|
||||
|
||||
# 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
|
||||
# - p_walk_context: Walk context to use
|
||||
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
|
||||
@@ -292,6 +298,11 @@ func walk_to(pos : Vector2, p_walk_context: ESCWalkContext = null) -> void:
|
||||
# - speed_value: Set the new speed
|
||||
func set_speed(speed_value : int) -> void:
|
||||
speed = speed_value
|
||||
|
||||
|
||||
# Check wether this item moved
|
||||
func has_moved() -> bool:
|
||||
return _movable.moved if is_movable else false
|
||||
|
||||
|
||||
# Set the angle
|
||||
@@ -300,21 +311,21 @@ func set_speed(speed_value : int) -> void:
|
||||
#
|
||||
# Set the angle
|
||||
func set_angle(deg : int, immediate = true):
|
||||
movable.set_angle(deg, immediate)
|
||||
_movable.set_angle(deg, immediate)
|
||||
|
||||
|
||||
# Play the talking animation
|
||||
func start_talking():
|
||||
if animation_sprite.is_playing():
|
||||
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
|
||||
func stop_talking():
|
||||
if animation_sprite.is_playing():
|
||||
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
|
||||
@@ -336,7 +347,8 @@ func _detect_children() -> void:
|
||||
|
||||
# Upate the terrain when an event finished
|
||||
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
|
||||
|
||||
@@ -12,6 +12,11 @@ class_name ESCPlayer
|
||||
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
|
||||
# global position of the player
|
||||
func get_camera_pos():
|
||||
|
||||
@@ -92,23 +92,21 @@ func set_camera_limits(camera_limit_id : int = 0) -> void:
|
||||
area.size = get_viewport().size
|
||||
|
||||
escoria.logger.info("Setting camera limits from scene ", [area])
|
||||
limits = {
|
||||
"limit_left": area.position.x,
|
||||
"limit_right": area.position.x + area.size.x,
|
||||
"limit_top": area.position.y,
|
||||
"limit_bottom": area.position.y + area.size.y,
|
||||
"set_default": true,
|
||||
}
|
||||
limits = ESCCameraLimits.new(
|
||||
area.position.x,
|
||||
area.position.x + area.size.x,
|
||||
area.position.y,
|
||||
area.position.y + area.size.y
|
||||
)
|
||||
else:
|
||||
limits = {
|
||||
"limit_left": scene_camera_limits.position.x,
|
||||
"limit_right": scene_camera_limits.position.x + \
|
||||
limits = ESCCameraLimits.new(
|
||||
scene_camera_limits.position.x,
|
||||
scene_camera_limits.position.x + \
|
||||
scene_camera_limits.size.x,
|
||||
"limit_top": scene_camera_limits.position.y,
|
||||
"limit_bottom": scene_camera_limits.position.y + \
|
||||
scene_camera_limits.size.y + screen_ofs.y * 2,
|
||||
"set_default": true,
|
||||
}
|
||||
scene_camera_limits.position.y,
|
||||
scene_camera_limits.position.y + \
|
||||
scene_camera_limits.size.y + screen_ofs.y * 2
|
||||
)
|
||||
escoria.logger.info(
|
||||
"Setting camera limits from parameter ",
|
||||
[scene_camera_limits]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[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"]
|
||||
current = true
|
||||
|
||||
@@ -1,67 +1,64 @@
|
||||
# Camera handling
|
||||
extends Camera2D
|
||||
class_name ESCCamera
|
||||
|
||||
|
||||
# Reference to the tween node for animating camera movements
|
||||
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
|
||||
# Target can be object or Vector2. See resove_target_pos()
|
||||
var target
|
||||
var target_pos : Vector2
|
||||
# The object to follow
|
||||
var follow_target: Node = null
|
||||
|
||||
# Target zoom of the camera
|
||||
var zoom_target: Vector2
|
||||
|
||||
var zoom_time
|
||||
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.
|
||||
- kwargs Dictionary (can be null) Limits to set.
|
||||
- limit_left int Left limit.
|
||||
- limit_right int Right limit.
|
||||
- limit_top int Top limit.
|
||||
- limit_bottom int Bottom limit.
|
||||
- set_default bool (Facultative) If true, the given limits are save as default limits.
|
||||
"""
|
||||
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()
|
||||
# Sets camera limits so it doesn't go out of the scene
|
||||
#
|
||||
# #### Parameters
|
||||
#
|
||||
# - limits: The limits to set
|
||||
func set_limits(limits: ESCCameraLimits):
|
||||
self.limit_left = limits.limit_left
|
||||
self.limit_right = limits.limit_right
|
||||
self.limit_top = limits.limit_top
|
||||
self.limit_bottom = limits.limit_bottom
|
||||
|
||||
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:
|
||||
default_limits = kwargs
|
||||
func _resolve_target_and_zoom(p_target) -> void:
|
||||
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():
|
||||
if typeof(target) == TYPE_VECTOR2:
|
||||
target_pos = target
|
||||
elif typeof(target) == TYPE_ARRAY:
|
||||
var count = 0
|
||||
|
||||
for obj in target:
|
||||
for obj in p_target:
|
||||
target_pos += obj.get_camera_pos()
|
||||
count += 1
|
||||
|
||||
# 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:
|
||||
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):
|
||||
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):
|
||||
speed = p_speed
|
||||
target = p_target
|
||||
|
||||
resolve_target_pos()
|
||||
var speed = p_speed
|
||||
|
||||
_resolve_target_and_zoom(p_target)
|
||||
|
||||
if not follow_target == null:
|
||||
target = follow_target.global_position
|
||||
|
||||
escoria.logger.info("Current camera position = " + str(self.global_position))
|
||||
|
||||
if speed == 0.0:
|
||||
self.global_position = target_pos
|
||||
self.global_position = target
|
||||
else:
|
||||
var time = self.global_position.distance_to(target_pos) / speed
|
||||
var time = self.global_position.distance_to(target) / speed
|
||||
|
||||
if tween.is_active():
|
||||
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.emit_signal("tween_completed")
|
||||
|
||||
tween.interpolate_property(self, "global_position", self.global_position,
|
||||
target_pos, time, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
|
||||
tween.interpolate_property(
|
||||
self,
|
||||
"global_position",
|
||||
self.global_position,
|
||||
target,
|
||||
time,
|
||||
Tween.TRANS_LINEAR,
|
||||
Tween.EASE_IN_OUT
|
||||
)
|
||||
tween.start()
|
||||
|
||||
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 type = "TRANS_" + p_type
|
||||
|
||||
target = p_target
|
||||
|
||||
var camera_pos
|
||||
var camera_pos_coords
|
||||
if target.has_node("camera_pos"):
|
||||
camera_pos = target.get_node("camera_pos")
|
||||
camera_pos_coords = camera_pos.global_position
|
||||
_resolve_target_and_zoom(p_target)
|
||||
|
||||
var push_target = null
|
||||
|
||||
if follow_target != null:
|
||||
push_target = p_target.position
|
||||
else:
|
||||
camera_pos_coords = target.global_position
|
||||
push_target = target
|
||||
|
||||
if time == 0:
|
||||
self.global_position = camera_pos_coords
|
||||
|
||||
if camera_pos and camera_pos is Camera2D:
|
||||
self.zoom = camera_pos.zoom
|
||||
self.global_position = push_target
|
||||
if zoom_target != Vector2():
|
||||
self.zoom = zoom_target
|
||||
else:
|
||||
if tween.is_active():
|
||||
var tweenstat = String(tween.tell()) + "/" + String(tween.get_runtime())
|
||||
escoria.logger.report_warnings("camera",
|
||||
["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:
|
||||
tween.interpolate_property(self, "zoom", self.zoom, camera_pos.zoom,
|
||||
time, tween.get(type), Tween.EASE_IN_OUT)
|
||||
if zoom_target != Vector2():
|
||||
tween.interpolate_property(
|
||||
self,
|
||||
"zoom",
|
||||
self.zoom,
|
||||
zoom_target,
|
||||
time,
|
||||
tween.get(type),
|
||||
Tween.EASE_IN_OUT
|
||||
)
|
||||
|
||||
tween.interpolate_property(self, "global_position", self.global_position,
|
||||
camera_pos_coords, time, tween.get(type), Tween.EASE_IN_OUT)
|
||||
tween.interpolate_property(
|
||||
self,
|
||||
"global_position",
|
||||
self.global_position,
|
||||
push_target,
|
||||
time,
|
||||
tween.get(type),
|
||||
Tween.EASE_IN_OUT
|
||||
)
|
||||
|
||||
tween.start()
|
||||
|
||||
|
||||
func shift(p_x, p_y, p_time, p_type):
|
||||
follow_target = null
|
||||
var x = int(p_x)
|
||||
var y = int(p_y)
|
||||
var time = float(p_time)
|
||||
@@ -173,18 +194,11 @@ func target_reached():
|
||||
func _process(_delta):
|
||||
zoom_transform = self.get_canvas_transform()
|
||||
|
||||
if target and not tween.is_active():
|
||||
if typeof(target) == TYPE_VECTOR2 or typeof(target) == TYPE_ARRAY:
|
||||
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()
|
||||
if follow_target and not tween.is_active() and follow_target.has_moved():
|
||||
self.global_position = follow_target.global_position
|
||||
|
||||
func _ready():
|
||||
if not target:
|
||||
target = Vector2(0, 0)
|
||||
|
||||
tween.connect("tween_completed", self, "target_reached")
|
||||
tween.connect("tween_all_completed", self, "target_reached")
|
||||
escoria.object_manager.register_object(
|
||||
ESCObject.new(
|
||||
self.name,
|
||||
@@ -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
|
||||
@@ -1,15 +1,23 @@
|
||||
# A debug window which can run esc commands
|
||||
extends WindowDialog
|
||||
|
||||
|
||||
# Reference to the past actions display
|
||||
onready var past_actions = $VBoxContainer/past_actions
|
||||
|
||||
# Reference to the command input
|
||||
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):
|
||||
if p_command_str.empty():
|
||||
return
|
||||
|
||||
last_event_done = false
|
||||
command.text = ""
|
||||
past_actions.text += "\n"
|
||||
past_actions.text += "# " + p_command_str
|
||||
@@ -24,19 +32,13 @@ func _on_command_text_entered(p_command_str : String):
|
||||
])
|
||||
|
||||
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")
|
||||
while ret[1] != "debug":
|
||||
ret = yield(escoria.event_manager, "event_finished")
|
||||
if not ret[0] == ESCExecution.RC_OK:
|
||||
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"
|
||||
past_actions.text += "Returned code: %d" % ret[0]
|
||||
|
||||
|
||||
# Set the focus to the command
|
||||
func _on_esc_prompt_popup_about_to_show():
|
||||
command.grab_focus()
|
||||
|
||||
@@ -1,43 +1,38 @@
|
||||
# Manages the inventory on the GUI connected to the inventory_ui_container
|
||||
# variable
|
||||
extends Control
|
||||
class_name ESCInventory
|
||||
|
||||
func get_class():
|
||||
return "ESCInventory"
|
||||
|
||||
"""
|
||||
This script is set on the inventory UI scene's root node.
|
||||
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.
|
||||
# Define the actual container node to add items as children of.
|
||||
# Should be a 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():
|
||||
# # For debugging scene only. These 2 lines should remain commented on normal run.
|
||||
# if !Engine.is_editor_hint():
|
||||
# return
|
||||
|
||||
if inventory_ui_container == null or inventory_ui_container.is_empty():
|
||||
escoria.logger.report_errors(
|
||||
self.get_path(),
|
||||
["Items container is empty."]
|
||||
)
|
||||
return
|
||||
|
||||
for item_id in escoria.inventory_manager.items_in_inventory():
|
||||
call_deferred("add_new_item_by_id", item_id)
|
||||
|
||||
escoria.inventory = self
|
||||
|
||||
if inventory_ui_container == null or inventory_ui_container.is_empty():
|
||||
escoria.logger.report_errors(self.get_path(), ["Items container is empty."])
|
||||
return
|
||||
for c in get_node(inventory_ui_container).get_items():
|
||||
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")
|
||||
escoria.globals_manager.connect(
|
||||
"global_changed", #
|
||||
self,
|
||||
"_on_escoria_global_changed"
|
||||
)
|
||||
|
||||
|
||||
# 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
|
||||
get_node(inventory_ui_container).add_item(item_inventory_button)
|
||||
|
||||
# Add the item to inventory
|
||||
if not escoria.object_manager.has(item_id):
|
||||
escoria.object_manager.register_object(
|
||||
ESCObject.new(
|
||||
@@ -82,40 +76,74 @@ func add_new_item_by_id(item_id : String) -> void:
|
||||
),
|
||||
true
|
||||
)
|
||||
|
||||
item_inventory_button.visible = true
|
||||
|
||||
item_inventory_button.connect("mouse_left_inventory_item",
|
||||
escoria.inputs_manager, "_on_mouse_left_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(
|
||||
"mouse_left_inventory_item",
|
||||
escoria.inputs_manager,
|
||||
"_on_mouse_left_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",
|
||||
escoria.inputs_manager, "_on_mouse_entered_inventory_item")
|
||||
item_inventory_button.connect("inventory_item_unfocused",
|
||||
escoria.inputs_manager, "_on_mouse_exited_inventory_item")
|
||||
item_inventory_button.connect(
|
||||
"inventory_item_focused",
|
||||
escoria.inputs_manager,
|
||||
"_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
|
||||
func remove_item_by_id(item_id : String) -> void:
|
||||
if items_ids_in_inventory.has(item_id):
|
||||
var item_inventory_button = items_ids_in_inventory[item_id]
|
||||
|
||||
item_inventory_button.disconnect("mouse_left_inventory_item",
|
||||
escoria.inputs_manager, "_on_mouse_left_click_inventory_item")
|
||||
item_inventory_button.disconnect("mouse_double_left_inventory_item",
|
||||
escoria.inputs_manager, "_on_mouse_double_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("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")
|
||||
item_inventory_button.disconnect(
|
||||
"mouse_left_inventory_item",
|
||||
escoria.inputs_manager,
|
||||
"_on_mouse_left_click_inventory_item"
|
||||
)
|
||||
item_inventory_button.disconnect(
|
||||
"mouse_double_left_inventory_item",
|
||||
escoria.inputs_manager,
|
||||
"_on_mouse_double_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(
|
||||
"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)
|
||||
item_inventory_button.queue_free()
|
||||
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:
|
||||
if !global.begins_with("i/"):
|
||||
return
|
||||
@@ -126,4 +154,10 @@ func _on_escoria_global_changed(global : String, old_value, new_value) -> void:
|
||||
else:
|
||||
remove_item_by_id(item[0])
|
||||
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
|
||||
]
|
||||
)
|
||||
|
||||
@@ -1,23 +1,28 @@
|
||||
# Background music player
|
||||
extends Control
|
||||
class_name ESCBackgroundMusic
|
||||
|
||||
func get_class():
|
||||
return "ESCBackgroundMusic"
|
||||
|
||||
onready var stream = $AudioStreamPlayer
|
||||
var state = "default"
|
||||
export var global_id = "bg_music"
|
||||
# Global id of the background music player
|
||||
export var global_id: String = "bg_music"
|
||||
|
||||
|
||||
func game_cleared():
|
||||
set_state("off", true)
|
||||
escoria.object_manager.register_object(
|
||||
ESCObject.new(global_id, self),
|
||||
true
|
||||
)
|
||||
# The state of the music player. "default" or "off" disable music
|
||||
# Any other state refers to a music stream that should be played
|
||||
var state: String = "default"
|
||||
|
||||
|
||||
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 p_state == state and not p_force and stream.is_playing():
|
||||
return
|
||||
@@ -39,6 +44,8 @@ func set_state(p_state, p_force = false):
|
||||
stream.volume_db = ProjectSettings.get_setting("escoria/sound/music_volume")
|
||||
stream.play()
|
||||
|
||||
|
||||
# Register to the object registry
|
||||
func _ready():
|
||||
escoria.object_manager.register_object(
|
||||
ESCObject.new(global_id, self),
|
||||
|
||||
@@ -1,23 +1,28 @@
|
||||
# Background sound player
|
||||
extends Control
|
||||
class_name ESCBackgroundSound
|
||||
|
||||
func get_class():
|
||||
return "ESCBackgroundSound"
|
||||
|
||||
onready var stream = $AudioStreamPlayer
|
||||
var state = "default"
|
||||
export var global_id = "bg_sound"
|
||||
# Global id of the background sound player
|
||||
export var global_id: String = "bg_sound"
|
||||
|
||||
|
||||
func game_cleared():
|
||||
stream.stream = null
|
||||
escoria.object_manager.register_object(
|
||||
ESCObject.new(global_id, self),
|
||||
true
|
||||
)
|
||||
# The state of the sound player. "default" or "off" disable sound
|
||||
# Any other state refers to a sound stream that should be played
|
||||
var state: String = "default"
|
||||
|
||||
|
||||
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 p_state == state and not p_force and stream.is_playing():
|
||||
return
|
||||
@@ -40,6 +45,7 @@ func set_state(p_state, p_force = false):
|
||||
stream.play()
|
||||
|
||||
|
||||
# Register to the object registry
|
||||
func _ready():
|
||||
escoria.object_manager.register_object(
|
||||
ESCObject.new(global_id, self),
|
||||
|
||||
@@ -1,28 +1,41 @@
|
||||
# A transition player for scene changes
|
||||
# FIXME Add configuration to select a specific mask
|
||||
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
|
||||
onready var _anim_player := $AnimationPlayer
|
||||
|
||||
|
||||
|
||||
signal transition_done
|
||||
|
||||
|
||||
# Fade in when the scene is starting
|
||||
func _ready() -> void:
|
||||
# Plays the animation backward to fade in
|
||||
_anim_player.play_backwards(transition_name)
|
||||
fade_in()
|
||||
|
||||
|
||||
# Fade out the transition
|
||||
func fade_out() -> void:
|
||||
# Plays the Fade animation and wait until it finishes
|
||||
_anim_player.play(transition_name)
|
||||
yield(_anim_player, "animation_finished")
|
||||
emit_signal("transition_done")
|
||||
|
||||
|
||||
# Fade in the transition
|
||||
func fade_in() -> void:
|
||||
# Plays the Fade animation and wait until it finishes
|
||||
_anim_player.play_backwards(transition_name)
|
||||
yield(_anim_player, "animation_finished")
|
||||
emit_signal("transition_done")
|
||||
|
||||
|
||||
@@ -4,4 +4,4 @@ name="Escoria"
|
||||
description="A point'n'click framework within Godot Engine."
|
||||
author="StraToN"
|
||||
version="1.0.0"
|
||||
script="editor/plugin_escoria.gd"
|
||||
script="plugin.gd"
|
||||
|
||||
@@ -8,25 +8,12 @@ const autoloads = {
|
||||
"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
|
||||
func _enter_tree():
|
||||
for key in autoloads.keys():
|
||||
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
|
||||
set_escoria_main_settings()
|
||||
set_escoria_debug_settings()
|
||||
@@ -251,7 +238,5 @@ func _exit_tree():
|
||||
for key in autoloads.keys():
|
||||
if ProjectSettings.has_setting(key):
|
||||
remove_autoload_singleton(key)
|
||||
for custom_type in custom_types:
|
||||
remove_custom_type(custom_type.type_name)
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@ camera_set_limits 2
|
||||
camera_set_pos 500 150 150
|
||||
wait 6
|
||||
|
||||
camera_set_pos 1 1080 1000
|
||||
wait 1
|
||||
camera_set_limits 0
|
||||
|
||||
camera_set_target 0 player
|
||||
|
||||
BIN
icon.png
BIN
icon.png
Binary file not shown.
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.5 KiB |
@@ -107,7 +107,12 @@ _global_script_classes=[ {
|
||||
"base": "Camera2D",
|
||||
"class": "ESCCamera",
|
||||
"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",
|
||||
"class": "ESCCommand",
|
||||
@@ -445,6 +450,7 @@ _global_script_class_icons={
|
||||
"ESCBackgroundSound": "",
|
||||
"ESCBaseCommand": "",
|
||||
"ESCCamera": "",
|
||||
"ESCCameraLimits": "",
|
||||
"ESCCommand": "",
|
||||
"ESCCommandArgumentDescriptor": "",
|
||||
"ESCCommandRegistry": "",
|
||||
|
||||
Reference in New Issue
Block a user