diff --git a/addons b/addons new file mode 120000 index 00000000..473b8cc6 --- /dev/null +++ b/addons @@ -0,0 +1 @@ +../escoria-demo-game/addons/ \ No newline at end of file diff --git a/addons/escoria-core/_test/test_esc_compiler.gd b/addons/escoria-core/_test/test_esc_compiler.gd deleted file mode 100644 index f2453740..00000000 --- a/addons/escoria-core/_test/test_esc_compiler.gd +++ /dev/null @@ -1,300 +0,0 @@ -extends Control - - -func _test_basic() -> bool: - var esc = """ -:test -# first group -> - say player "Test" - # Second group - > [test] - say player "Test2 BLANK" - say player "Test3" [test2] - # Third group - > - - say player "Test4" -# Fourth group -> - say player "Test5" - say player "Test 6" - say player TEST:"Test 7" - """ - var script = escoria.esc_compiler.compile(esc.split("\n")) - - var subject = script - assert(subject is ESCScript) - - subject = script.events.keys() - assert(subject.size() == 1) - assert(subject[0] == "test") - - subject = script.events["test"].statements - assert(subject.size() == 2) - - subject = script.events["test"].statements[0] - assert(subject is ESCGroup) - assert(subject.statements.size() == 4) - - subject = script.events["test"].statements[0].statements[0] - assert(subject is ESCCommand) - assert(subject.name == "say") - assert(subject.parameters.size() == 2) - assert(subject.parameters[0] == "player") - assert(subject.parameters[1] == '"Test"') - - subject = script.events["test"].statements[0].statements[1] - assert(subject is ESCGroup) - assert(subject.conditions.size() == 1) - assert(subject.conditions[0] is ESCCondition) - assert(subject.conditions[0].flag == "test") - - subject = script.events["test"].statements[0].statements[1].statements[0] - assert(subject is ESCCommand) - assert(subject.name == "say") - assert(subject.parameters.size() == 2) - assert(subject.parameters[0] == "player") - assert(subject.parameters[1] == '"Test2 BLANK"') - - subject = script.events["test"].statements[0].statements[2] - assert(subject is ESCCommand) - assert(subject.name == "say") - assert(subject.parameters.size() == 2) - assert(subject.parameters[0] == "player") - assert(subject.parameters[1] == '"Test3"') - assert(subject.conditions.size() == 1) - assert(subject.conditions[0].flag == "test2") - - subject = script.events["test"].statements[0].statements[3] - assert(subject is ESCGroup) - assert(subject.statements.size() == 1) - - subject = script.events["test"].statements[1] - assert(subject is ESCGroup) - assert(subject.statements.size() == 3) - - subject = script.events["test"].statements[1].statements[1] - assert(subject is ESCCommand) - assert(subject.name == "say") - assert(subject.parameters[1] == '"Test 6"') - - subject = script.events["test"].statements[1].statements[2] - assert(subject is ESCCommand) - assert(subject.name == "say") - assert(subject.parameters[1] == "TEST:\"Test 7\"") - - return true - - -func _test_conditions() -> bool: - var esc = """ -:test -say player "Test" [flag] -say player "Test" [flag1,flag2] -say player "Test" [!flag] -say player "Test" [i/flag] -say player "Test" [i/flag,flag] -say player "Test" [i/flag,flag,!flag2] -say player "Test" [eq flag 3] -say player "Test" [eq flag 3,gt flag 5] -say player "Test" [!eq flag 3] - """ - var script = escoria.esc_compiler.compile(esc.split("\n")) - - var subject = script.events["test"].statements[0] - assert(subject is ESCCommand) - assert(subject.conditions.size() == 1) - - subject = script.events["test"].statements[0].conditions[0] - assert(subject.flag == "flag") - assert(not subject.negated) - assert(not subject.inventory) - assert(subject.comparison == ESCCondition.COMPARISON_NONE) - - subject = script.events["test"].statements[1].conditions - assert(subject.size() == 2) - assert(subject[0].flag == "flag1") - assert(subject[1].flag == "flag2") - - subject = script.events["test"].statements[2].conditions - assert(subject.size() == 1) - assert(subject[0].flag == "flag") - assert(subject[0].negated) - - subject = script.events["test"].statements[3].conditions - assert(subject.size() == 1) - assert(subject[0].flag == "flag") - assert(subject[0].inventory) - - subject = script.events["test"].statements[4].conditions - assert(subject.size() == 2) - assert(subject[0].flag == "flag") - assert(subject[0].inventory) - assert(subject[1].flag == "flag") - assert(not subject[1].inventory) - - subject = script.events["test"].statements[5].conditions - assert(subject.size() == 3) - assert(subject[0].flag == "flag") - assert(subject[0].inventory) - assert(subject[1].flag == "flag") - assert(not subject[1].inventory) - assert(subject[2].flag == "flag2") - assert(not subject[2].inventory) - assert(subject[2].negated) - - subject = script.events["test"].statements[6].conditions - assert(subject.size() == 1) - assert(subject[0].flag == "flag") - assert(subject[0].comparison == ESCCondition.COMPARISON_EQ) - assert(subject[0].comparison_value == 3) - - subject = script.events["test"].statements[7].conditions - assert(subject.size() == 2) - assert(subject[0].flag == "flag") - assert(subject[0].comparison == ESCCondition.COMPARISON_EQ) - assert(subject[0].comparison_value == 3) - assert(subject[1].flag == "flag") - assert(subject[1].comparison == ESCCondition.COMPARISON_GT) - assert(subject[1].comparison_value == 5) - - subject = script.events["test"].statements[8].conditions - assert(subject.size() == 1) - assert(subject[0].flag == "flag") - assert(subject[0].comparison == ESCCondition.COMPARISON_EQ) - assert(subject[0].comparison_value == 3) - assert(subject[0].negated) - - return true - - -func _test_event_flags() -> bool: - var esc = """ -:test | TK -:test2 | TK NO_TT -:test3 | TK NO_TT NO_UI - """ - var script = escoria.esc_compiler.compile(esc.split("\n")) - - var subject = script.events - assert(subject.keys().size() == 3) - assert("test" in subject.keys()) - assert("test2" in subject.keys()) - assert("test3" in subject.keys()) - - subject = script.events["test"] - assert(subject.name == "test") - assert(subject.flags & ESCEvent.FLAG_TK != 0) - assert(subject.flags & ESCEvent.FLAG_NO_TT == 0) - - subject = script.events["test2"] - assert(subject.name == "test2") - assert(subject.flags & ESCEvent.FLAG_TK != 0) - assert(subject.flags & ESCEvent.FLAG_NO_TT != 0) - - subject = script.events["test3"] - assert(subject.name == "test3") - assert(subject.flags & ESCEvent.FLAG_TK != 0) - assert(subject.flags & ESCEvent.FLAG_NO_TT != 0) - assert(subject.flags & ESCEvent.FLAG_NO_UI != 0) - - return true - - -func _test_dialog() -> bool: - var esc = """ -:test -? - - "Option 1" - say player "test" - say player "testb" - say player "testb?" - - "Option 2" [flag] - say player "test2" - ? - - "Suboption 1" - say player "test21" - - "Suboption 2" - say player "test22" - ! - - "Option 3" - > - say player "test3" - - TEST:"Option 4" - say player "test4" -! - """ - var script = escoria.esc_compiler.compile(esc.split("\n")) - - var subject = script.events["test"].statements - assert(subject.size() == 1) - - assert(subject[0] is ESCDialog) - assert(subject[0].options.size() == 4) - - subject = script.events["test"].statements[0].options[0] - assert(subject is ESCDialogOption) - assert(subject.option == "Option 1") - - subject = script.events["test"].statements[0].options[0].statements - assert(subject.size() == 3) - assert(subject[0] is ESCCommand) - assert(subject[0].name == "say") - assert(subject[0].parameters.size() == 2) - assert(subject[1] is ESCCommand) - assert(subject[1].name == "say") - assert(subject[1].parameters.size() == 2) - assert(subject[1].parameters[1] == '"testb"') - assert(subject[2] is ESCCommand) - assert(subject[2].name == "say") - assert(subject[2].parameters.size() == 2) - assert(subject[2].parameters[1] == '"testb?"') - - subject = script.events["test"].statements[0].options[1] - assert(subject is ESCDialogOption) - assert(subject.option == "Option 2") - assert(subject.conditions.size() == 1) - assert(subject.conditions[0].flag == "flag") - - subject = script.events["test"].statements[0].options[1].statements - assert(subject.size() == 2) - assert(subject[0] is ESCCommand) - assert(subject[0].name == "say") - assert(subject[0].parameters.size() == 2) - - assert(subject[1] is ESCDialog) - assert(subject[1].options.size() == 2) - - subject = script.events["test"].statements[0].options[2] - assert(subject is ESCDialogOption) - assert(subject.option == "Option 3") - - subject = script.events["test"].statements[0].options[2].statements - assert(subject.size() == 1) - assert(subject[0] is ESCGroup) - assert(subject[0].statements.size() == 1) - assert(subject[0].statements[0] is ESCCommand) - assert(subject[0].statements[0].parameters.size() == 2) - - subject = script.events["test"].statements[0].options[3] - assert(subject is ESCDialogOption) - assert(subject.option == "TEST") - - return true - - -func _on_BasicFunctionality_pressed(): - $VBoxContainer/VBoxContainer/BasicFunctionality.pressed = self._test_basic() - - -func _on_Conditions_pressed(): - $VBoxContainer/VBoxContainer/Conditions.pressed = self._test_conditions() - - -func _on_EventFlags_pressed(): - $VBoxContainer/VBoxContainer/EventFlags.pressed = self._test_event_flags() - - -func _on_Dialog_pressed(): - $VBoxContainer/VBoxContainer/Dialog.pressed = self._test_dialog() diff --git a/addons/escoria-core/_test/test_esc_compiler.tscn b/addons/escoria-core/_test/test_esc_compiler.tscn deleted file mode 100644 index 3022be8a..00000000 --- a/addons/escoria-core/_test/test_esc_compiler.tscn +++ /dev/null @@ -1,58 +0,0 @@ -[gd_scene load_steps=2 format=2] - -[ext_resource path="res://addons/escoria-core/_test/test_esc_compiler.gd" type="Script" id=1] - -[node name="Testsuite" type="Control"] -anchor_right = 1.0 -anchor_bottom = 1.0 -script = ExtResource( 1 ) -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="VBoxContainer" type="VBoxContainer" parent="."] -anchor_right = 1.0 -anchor_bottom = 1.0 -margin_right = 1.0 -margin_bottom = 1.0 -size_flags_horizontal = 3 -size_flags_vertical = 3 -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer"] -margin_right = 1281.0 -margin_bottom = 172.0 - -[node name="BasicFunctionality" type="CheckButton" parent="VBoxContainer/VBoxContainer"] -margin_right = 1281.0 -margin_bottom = 40.0 -text = "Basic Functionality" -align = 1 - -[node name="Conditions" type="CheckButton" parent="VBoxContainer/VBoxContainer"] -margin_top = 44.0 -margin_right = 1281.0 -margin_bottom = 84.0 -text = "Check conditions" -align = 1 - -[node name="EventFlags" type="CheckButton" parent="VBoxContainer/VBoxContainer"] -margin_top = 88.0 -margin_right = 1281.0 -margin_bottom = 128.0 -text = "Check event flags" -align = 1 - -[node name="Dialog" type="CheckButton" parent="VBoxContainer/VBoxContainer"] -margin_top = 132.0 -margin_right = 1281.0 -margin_bottom = 172.0 -text = "Check dialogs" -align = 1 - -[connection signal="pressed" from="VBoxContainer/VBoxContainer/BasicFunctionality" to="." method="_on_BasicFunctionality_pressed"] -[connection signal="pressed" from="VBoxContainer/VBoxContainer/Conditions" to="." method="_on_Conditions_pressed"] -[connection signal="pressed" from="VBoxContainer/VBoxContainer/EventFlags" to="." method="_on_EventFlags_pressed"] -[connection signal="pressed" from="VBoxContainer/VBoxContainer/Dialog" to="." method="_on_Dialog_pressed"] diff --git a/addons/escoria-core/_test/test_migrations.gd b/addons/escoria-core/_test/test_migrations.gd deleted file mode 100644 index 19ecb45d..00000000 --- a/addons/escoria-core/_test/test_migrations.gd +++ /dev/null @@ -1,20 +0,0 @@ -extends Control - - - -func _on_CheckESCMigrationManager_pressed() -> bool: - var savegame: ESCSaveGame = ESCSaveGame.new() - - savegame.globals["test"] = "testa" - - var migration_manager: ESCMigrationManager = ESCMigrationManager.new() - savegame = migration_manager.migrate( - savegame, - "1.0.0", - "2.0.0", - "res://addons/escoria-core/_test/testversions" - ) - - assert(savegame.globals["test"] == "testc") - - return true diff --git a/addons/escoria-core/_test/test_migrations.tscn b/addons/escoria-core/_test/test_migrations.tscn deleted file mode 100644 index bd8eadcf..00000000 --- a/addons/escoria-core/_test/test_migrations.tscn +++ /dev/null @@ -1,25 +0,0 @@ -[gd_scene load_steps=2 format=2] - -[ext_resource path="res://addons/escoria-core/_test/test_migrations.gd" type="Script" id=1] - -[node name="Control" type="Control"] -anchor_right = 1.0 -anchor_bottom = 1.0 -script = ExtResource( 1 ) -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="VBoxContainer" type="VBoxContainer" parent="."] -anchor_right = 1.0 -anchor_bottom = 1.0 -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="CheckESCMigrationManager" type="CheckButton" parent="VBoxContainer"] -margin_right = 1280.0 -margin_bottom = 40.0 -text = "Check ESCMigrationManager" - -[connection signal="pressed" from="VBoxContainer/CheckESCMigrationManager" to="." method="_on_CheckESCMigrationManager_pressed"] diff --git a/addons/escoria-core/_test/testversions/1.0.1.gd b/addons/escoria-core/_test/testversions/1.0.1.gd deleted file mode 100644 index a1cf8b8c..00000000 --- a/addons/escoria-core/_test/testversions/1.0.1.gd +++ /dev/null @@ -1,5 +0,0 @@ -extends ESCMigration - -func migrate(): - self._savegame.globals["test"] = "testb" - diff --git a/addons/escoria-core/_test/testversions/1.1.0.gd b/addons/escoria-core/_test/testversions/1.1.0.gd deleted file mode 100644 index 78404903..00000000 --- a/addons/escoria-core/_test/testversions/1.1.0.gd +++ /dev/null @@ -1,5 +0,0 @@ -extends ESCMigration - -func migrate(): - self._savegame.globals["test"] = "testc" - diff --git a/addons/escoria-core/default_bus_layout.tres b/addons/escoria-core/default_bus_layout.tres deleted file mode 100644 index 196e4fec..00000000 --- a/addons/escoria-core/default_bus_layout.tres +++ /dev/null @@ -1,21 +0,0 @@ -[gd_resource type="AudioBusLayout" format=2] - -[resource] -bus/1/name = "SFX" -bus/1/solo = false -bus/1/mute = false -bus/1/bypass_fx = false -bus/1/volume_db = 0.0 -bus/1/send = "Master" -bus/2/name = "Music" -bus/2/solo = false -bus/2/mute = false -bus/2/bypass_fx = false -bus/2/volume_db = 0.0 -bus/2/send = "Master" -bus/3/name = "Speech" -bus/3/solo = false -bus/3/mute = false -bus/3/bypass_fx = false -bus/3/volume_db = 0.0 -bus/3/send = "Master" diff --git a/addons/escoria-core/design/esc_background.svg b/addons/escoria-core/design/esc_background.svg deleted file mode 100644 index 01762fa6..00000000 --- a/addons/escoria-core/design/esc_background.svg +++ /dev/null @@ -1,17 +0,0 @@ - - - esc_background - - - - - - - - - - - - - - \ No newline at end of file diff --git a/addons/escoria-core/design/esc_exit.svg b/addons/escoria-core/design/esc_exit.svg deleted file mode 100644 index 5b1fcf14..00000000 --- a/addons/escoria-core/design/esc_exit.svg +++ /dev/null @@ -1,24 +0,0 @@ - - - esc_exit - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/addons/escoria-core/design/esc_item.svg b/addons/escoria-core/design/esc_item.svg deleted file mode 100644 index 86e28f06..00000000 --- a/addons/escoria-core/design/esc_item.svg +++ /dev/null @@ -1,14 +0,0 @@ - - - esc_item - - - - - - - - - - - \ No newline at end of file diff --git a/addons/escoria-core/design/esc_location.svg b/addons/escoria-core/design/esc_location.svg deleted file mode 100644 index 56d3c5bb..00000000 --- a/addons/escoria-core/design/esc_location.svg +++ /dev/null @@ -1,15 +0,0 @@ - - - esc_location - - - - - - - - - - - - \ No newline at end of file diff --git a/addons/escoria-core/design/esc_player.svg b/addons/escoria-core/design/esc_player.svg deleted file mode 100644 index 9a58d5ea..00000000 --- a/addons/escoria-core/design/esc_player.svg +++ /dev/null @@ -1,14 +0,0 @@ - - - esc_player - - - - - - - - - - - \ No newline at end of file diff --git a/addons/escoria-core/design/esc_room.svg b/addons/escoria-core/design/esc_room.svg deleted file mode 100644 index 917cbb6f..00000000 --- a/addons/escoria-core/design/esc_room.svg +++ /dev/null @@ -1,18 +0,0 @@ - - - esc_room - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/addons/escoria-core/design/esc_terrain.svg b/addons/escoria-core/design/esc_terrain.svg deleted file mode 100644 index 51be6a06..00000000 --- a/addons/escoria-core/design/esc_terrain.svg +++ /dev/null @@ -1,14 +0,0 @@ - - - esc_terrain - - - - - - - - - - - \ No newline at end of file diff --git a/addons/escoria-core/design/escoria-logo-small.png b/addons/escoria-core/design/escoria-logo-small.png deleted file mode 100644 index 50b62486..00000000 Binary files a/addons/escoria-core/design/escoria-logo-small.png and /dev/null differ diff --git a/addons/escoria-core/design/escoria-logo.png b/addons/escoria-core/design/escoria-logo.png deleted file mode 100644 index 2a5a52d3..00000000 Binary files a/addons/escoria-core/design/escoria-logo.png and /dev/null differ diff --git a/addons/escoria-core/design/escoria-logo.svg b/addons/escoria-core/design/escoria-logo.svg deleted file mode 100644 index 115d9abd..00000000 --- a/addons/escoria-core/design/escoria-logo.svg +++ /dev/null @@ -1,594 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - image/svg+xml - - - - - - - - - - ESC - RIA - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/addons/escoria-core/design/icons.sketch b/addons/escoria-core/design/icons.sketch deleted file mode 100644 index 348e920a..00000000 Binary files a/addons/escoria-core/design/icons.sketch and /dev/null differ diff --git a/addons/escoria-core/game/assets/images/no_image.png b/addons/escoria-core/game/assets/images/no_image.png deleted file mode 100644 index 7c06dbb1..00000000 Binary files a/addons/escoria-core/game/assets/images/no_image.png and /dev/null differ diff --git a/addons/escoria-core/game/assets/images/no_image.png.import b/addons/escoria-core/game/assets/images/no_image.png.import deleted file mode 100644 index d59713d9..00000000 --- a/addons/escoria-core/game/assets/images/no_image.png.import +++ /dev/null @@ -1,34 +0,0 @@ -[remap] - -importer="texture" -type="StreamTexture" -path="res://.import/no_image.png-7e4632ad2d21010b279ddaa4725bacb7.stex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://addons/escoria-core/game/assets/images/no_image.png" -dest_files=[ "res://.import/no_image.png-7e4632ad2d21010b279ddaa4725bacb7.stex" ] - -[params] - -compress/mode=0 -compress/lossy_quality=0.7 -compress/hdr_mode=0 -compress/bptc_ldr=0 -compress/normal_map=0 -flags/repeat=0 -flags/filter=false -flags/mipmaps=false -flags/anisotropic=false -flags/srgb=2 -process/fix_alpha_border=true -process/premult_alpha=false -process/HDR_as_SRGB=false -process/invert_color=false -stream=false -size_limit=0 -detect_3d=true -svg/scale=1.0 diff --git a/addons/escoria-core/game/assets/images/no_image.xcf b/addons/escoria-core/game/assets/images/no_image.xcf deleted file mode 100644 index 2a7ef082..00000000 Binary files a/addons/escoria-core/game/assets/images/no_image.xcf and /dev/null differ diff --git a/addons/escoria-core/game/assets/images/white.png b/addons/escoria-core/game/assets/images/white.png deleted file mode 100644 index 573faa33..00000000 Binary files a/addons/escoria-core/game/assets/images/white.png and /dev/null differ diff --git a/addons/escoria-core/game/core-scripts/behaviors/esc_movable.gd b/addons/escoria-core/game/core-scripts/behaviors/esc_movable.gd deleted file mode 100644 index a2367f83..00000000 --- a/addons/escoria-core/game/core-scripts/behaviors/esc_movable.gd +++ /dev/null @@ -1,517 +0,0 @@ -# Node that performs the moving (walk, teleport, terrain scaling...) actions on -# its parent node. -extends Node -class_name ESCMovable - - -# Tasks carried out by this walkable node -# NONE - The node is inactive -# WALK - The node walks the parent somewhere -# SLIDE - The node slides the parent somewhere -enum MovableTask { - NONE, - WALK, - SLIDE -} - - -# Character path through the scene as calculated by the Pathfinder -var walk_path: Array = [] - -# Current active walk path entry -var path_ofs: int - -# The destination where the character should be moving to -var walk_destination: Vector2 - -# The walk context currently carried out by this movable node -var walk_context: ESCWalkContext = null - -# Whether the character was moved at all -var moved: bool - -# Player Direction used to reflect the movement to the new position -var last_dir: int - -# The last scaling applied to the parent -var last_scale: Vector2 - -# Whether the current direction animation is flipped -var is_mirrored: bool - - -var _orig_speed: float = 0.0 - - -# Shortcut variable that references the node's parent -onready var parent = get_parent() - - -# Currenly running task -onready var task = MovableTask.NONE - - -# Add the signal "arrived" to the parent node, which is emitted when -# the destination position was reached -func _ready() -> void: - if not parent.has_user_signal("arrived"): - parent.add_user_signal("arrived") - - -# Main processing loop -# -# #### Parameters -# -# - delta: Time that has passed since the last call to this function -func _process(delta: float) -> void: - if Engine.is_editor_hint(): - return - - if task == MovableTask.WALK or task == MovableTask.SLIDE: - var old_pos = parent.get_position() - var new_pos = _calculate_movement(delta) - if new_pos == null: - return - - if task == MovableTask.WALK: - # Get the angle of the object to face the position to reach. - var angle: float = (old_pos.angle_to_point(new_pos)) - _perform_walk_orientation(angle) - - update_terrain() - else: - moved = false - set_process(false) - - -# Calculates the next position of the object. -# -# #### Parameters -# -# - delta: the time elapsed from last frame -# -# *Returns* -# The new Vector2 position of the object, or null if stop walking. -func _calculate_movement(delta: float): - # Initialize the current pos and previous pos variables - var pos: Vector2 = parent.get_position() - var old_pos: Vector2 = pos - - # Get next waypoint from the walkpath array. - var next: Vector2 - if walk_path.size() > 1: - next = walk_path[path_ofs + 1] - else: - next = walk_path[path_ofs] - - # Movement speed calculation - var movement_speed: float = parent.speed * delta * pow(last_scale.x, 2) * \ - parent.terrain.player_speed_multiplier - if walk_context.fast: - movement_speed *= parent.terrain.player_doubleclick_speed_multiplier - - # Calculate the direction vector from current position and next waypoint - var dir: Vector2 = (next - pos).normalized() - - # If we're close to the next waypoint (ie. distance < necessary movement - # speed to get to this waypoint, we consider the waypoint reached - # and pass to the next one. - # Else, calculate the new position. - var new_pos: Vector2 - if pos.distance_to(next) < movement_speed: - new_pos = next - path_ofs += 1 - else: - new_pos = pos + dir * movement_speed * parent.v_speed_damp - - # If current waypoint id is >= the number of waypoints, were're at the - # end of the walk: stop walking. - if path_ofs >= walk_path.size() - 1: - walk_stop(walk_destination) - return - - # Update current position variable - pos = new_pos - parent.set_position(pos) - return pos - -# Calculates the orientation of the object while walking, to play the right -# animation according to this orientation. -# -# #### Parameters -# -# - angle: the angle X axis and object's facing direction. -func _perform_walk_orientation(angle: float): - last_dir = _get_dir_deg(ESCUtils.get_deg_from_rad(angle), - parent.animations) - - var animation_player: ESCAnimationPlayer = \ - parent.get_animation_player() - - var current_animation = animation_player.get_animation() - - var animation_to_play = \ - parent.animations.directions[last_dir].animation - if current_animation != animation_to_play and \ - animation_player.has_animation(animation_to_play): - animation_player.play(animation_to_play) - elif current_animation != animation_to_play and \ - not animation_player.has_animation(animation_to_play): - current_animation = animation_to_play - escoria.logger.warn( - self, - "Character %s has no animation %s\nBypassing the missing animation and movement command." - % [parent.global_id, animation_to_play] - ) - - is_mirrored = parent.animations.directions[last_dir].mirrored - - -# Teleports this item to the target position. -# -# #### Parameters -# -# - target: Position2d or ESCItem to teleport to -func teleport(target: Node) -> void: - if target.has_method("get_interact_position"): - parent.global_position = target.get_interact_position() - escoria.logger.info( - self, - "Object %s is teleported to position %s." - % [target.name, parent.global_position] - ) - elif "position" in target: - escoria.logger.info( - self, - "Object %s teleported to position %s." - % [parent.global_id, str(target.global_position)] - ) - parent.global_position = target.global_position - else: - escoria.logger.error( - self, - "Target %s could not be teleported. Please configure the interact position parameter or create a child ESCLocation node." % target - ) - - -# Teleports this item to the target position. -# -# #### Parameters -# -# - target: Vector2 target position to teleport to -func teleport_to(target: Vector2) -> void: - escoria.logger.info( - self, - "Object %s teleported to position %s." - % [parent.global_id, str(target)] - ) - parent.global_position = target - - -# Walk to a given position -# -# #### Parameters -# -# - pos: Position to walk to -# - p_walk_context: Walk context to use -func walk_to(pos: Vector2, p_walk_context: ESCWalkContext = null) -> void: - if not parent.terrain: - walk_stop(parent.get_position()) - return - - if task == MovableTask.WALK: - if walk_context.target_object == p_walk_context.target_object \ - or walk_context.target_position \ - == p_walk_context.target_position: - walk_context.fast = p_walk_context.fast - - walk_context = p_walk_context - - if task == MovableTask.NONE: - task = MovableTask.WALK - - walk_path = parent.terrain.get_simple_path(parent.get_position(), pos, true) - - if walk_path.size() == 0: - task = MovableTask.NONE - walk_stop(parent.get_position()) - set_process(false) - return - moved = true - walk_destination = walk_path[walk_path.size()-1] - path_ofs = 0 - task = MovableTask.WALK - set_process(true) - - -# We have finished walking. Set the idle pose and complete -# -# #### Parameters -# -# - pos: Final target position -func walk_stop(pos: Vector2) -> void: - parent.global_position = pos -# parent.interact_status = parent.INTERACT_STATES.INTERACT_NONE - walk_path = [] - - if _orig_speed > 0: - parent.speed = _orig_speed - _orig_speed = 0.0 - - task = MovableTask.NONE - moved = false - set_process(false) - - # If we're heading to an object and reached its interaction position, - # orient towards the defined interaction direction set on the object - # (if any), can be ESCItem or ESCLocation - if walk_context.target_object and \ - walk_context.target_object.node.player_orients_on_arrival: - var orientation = walk_context.target_object.node.interaction_direction - last_dir = orientation - parent.get_animation_player().play( - parent.animations.idles[orientation].animation - ) - is_mirrored = parent.animations.idles[orientation].mirrored - else: - parent.get_animation_player().play( - parent.animations.idles[last_dir].animation - ) - is_mirrored = parent.animations.idles[last_dir].mirrored - - update_terrain() - - if walk_context.target_object: - escoria.logger.debug( - self, - "%s arrived at %s." % [ - parent.global_id, - walk_context.target_object.global_id - ] - ) - else: - escoria.logger.debug( - self, - "%s arrived at %s." % [ - parent.global_id, - walk_context.target_position - ] - ) - parent.emit_signal("arrived", walk_context) - - -# Update the sprite scale and lighting -# -# #### Parameters -# -# - on_event_finished_name: Used if this function is called from an ESC event -func update_terrain(on_event_finished_name = null) -> void: - if !parent.terrain or parent.terrain == null \ - or !is_instance_valid(parent.terrain): - return - if on_event_finished_name != null \ - and on_event_finished_name != ESCEventManager.EVENT_SETUP: - return - if parent.get("is_exit"): - return - if parent.get("dont_apply_terrain_scaling"): - return - if not parent.is_inside_tree(): - return - - var pos = parent.global_position - if pos.y <= VisualServer.CANVAS_ITEM_Z_MAX: - parent.z_index = pos.y - else: - parent.z_index = VisualServer.CANVAS_ITEM_Z_MAX - - var factor = parent.terrain.get_terrain(pos) - var scal = parent.terrain.get_scale_range(factor) - if scal != parent.get_scale(): - last_scale = scal - parent.scale = last_scale - - var color = parent.terrain.get_light(pos) - parent.modulate = color - - var sprite: Node = parent.get_sprite() - - # Do not flip the entire character, because that would conflict - # with shadows that expect to be siblings of $texture - # - # - Current sprite scale is >0, meaning it's currently heading to right - # - but calculated is_mirrored is <0, meaning it's going to head to left - # Or, on the contrary: - # - current sprite scale is <0, meaning it's currently heading to left - # - but calculated is_mirrored is >0, meaning it's going to head to right - # We're operating a 180° turn (from right to left, or from left to right) - # So we just inverse the sprite scale. - if is_mirrored and sprite.scale.x > 0 \ - or not is_mirrored and sprite.scale.x < 0: - sprite.scale.x *= -1 - parent.collision.scale.x *= -1 - - -# Get the player direction index based on degrees -# -# #### Parameters -# -# - deg: Degrees -# - animations: Player animations script -func _get_dir_deg(deg: int, animations: ESCAnimationResource) -> int: - # We turn the angle by -90° because angle_to_point gives the angle - # against X axis, not Y - deg = wrapi(deg - 90, 0, 360) - var dir = -1 - var i = 0 - - for direction_angle in animations.dir_angles: - if _is_angle_in_interval(deg, direction_angle): - dir = i - break - else: - i += 1 - continue - - # It's an error to have the animations misconfigured - if dir == -1: - escoria.logger.error( - self, - "No animation has been configured for angle %s." % str(deg) - ) - - return dir - - -# Returns true if given angle is inside the interval given by a starting_angle -# and the size. -# -# #### Parameters -# -# - angle: Angle to test -# - direction_angle: ESCDirectionAngle resource, containing the starting angle, -# and the size of interval -# eg: angle_start=90, angle_size=40 corresponds to angle between 90° and 130° -func _is_angle_in_interval( - angle: float, - direction_angle: ESCDirectionAngle -) -> bool: - var start_angle = direction_angle.angle_start - var end_angle = direction_angle.angle_start + direction_angle.angle_size - - if end_angle > 360 and angle < start_angle: - angle += 360 - - return (start_angle <= angle and angle <= end_angle) - - -# Sets character's angle and plays according animation. -# -# #### Parameters -# -# - deg int angle to set the character -# - wait float Wait this amount of seconds until continuing with turning around -func set_angle(deg: int, wait: float = 0.0) -> void: - if deg < 0 or deg > 360: - escoria.logger.error( - self, - "Invalid degree to turn to : %s. Valid angles are between 0 and 360." % str(deg) - ) - moved = true - - var current_dir = last_dir - var target_dir = _get_dir_deg(deg, parent.animations) - - var way_to_turn = get_shortest_way_to_dir(current_dir, target_dir) - - var dir = current_dir - while dir != target_dir: - dir += way_to_turn - if dir >= parent.animations.dir_angles.size(): - dir = 0 - if dir < 0: - dir = parent.animations.dir_angles.size() - 1 - - parent.get_animation_player().play( - parent.animations.idles[dir].animation - ) - if wait > 0.0: - yield(get_tree().create_timer(wait), "timeout") - is_mirrored = parent.animations.idles[dir].mirrored - - last_dir = _get_dir_deg(deg, parent.animations) - - # The character may have a state animation from before, which would be - # resumed, so we immediately force the correct idle animation - if parent.get_animation_player().get_animation() != \ - parent.animations.idles[last_dir].animation: - parent.get_animation_player().play( - parent.animations.idles[last_dir].animation - ) - update_terrain() - - -# Turns the character to face another item or character. -# -# #### Parameters -# -# - item_id id of the object to face. -# - float Wait this amount of seconds until continuing with turning around -func turn_to(item: Node, wait: float = 0.0) -> void: - set_angle( - wrapi( - rad2deg(parent.get_position().angle_to_point(item.get_position())), - 0, - 360 - ), - wait - ) - - -# Returns the angle that corresponds to the current direction of the object. -func _get_angle() -> int: - return parent.animations.dir_angles[last_dir].angle_start - - -# Return the shortest way to turn from a direction to another. Returned way is -# either: -# -1 (shortest way is to turn anti-clockwise) -# 0 (already at the right direction) -# 1 (clockwise). -# -# ####Parameters -# - current_dir: integer corresponding to the starting direction as defined in -# the attached ESCAnimationResource.directions. -# - target_dir: integer corresponding to the target direction as defined in -# the attached ESCAnimationResource.directions. -# -# *Returns* -# Integer: -1 (anti-clockwise), 1 (clockwise) or 0 (no movement needed). -func get_shortest_way_to_dir(current_dir: int, target_dir: int) -> int: - if current_dir < 0 or current_dir > parent.animations.dir_angles.size() - 1: - escoria.logger.error( - self, - "Invalid direction (current_dir) %s" % str(current_dir) - ) - - if target_dir < 0 or target_dir > parent.animations.dir_angles.size() - 1: - escoria.logger.error( - self, - "Invalid direction (target_dir) %s " % str(target_dir) - ) - - if current_dir == target_dir: - return 0 - - var internal = false - if max(current_dir, target_dir) - min(current_dir, target_dir) \ - < parent.animations.dir_angles.size() / 2: - internal = true - else: - internal = false - - if internal and current_dir < target_dir or \ - (not internal and current_dir > target_dir): - return 1 - else: - return -1 diff --git a/addons/escoria-core/game/core-scripts/esc/commands/accept_input.gd b/addons/escoria-core/game/core-scripts/esc/commands/accept_input.gd deleted file mode 100644 index 9a1e6c65..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/accept_input.gd +++ /dev/null @@ -1,74 +0,0 @@ -# `accept_input [type]` -# -# Sets how much input the game is to accept. This allows for cut scenes -# in which dialogue can be skipped (if [type] is set to SKIP), and ones where -# it can't (if [type] is set to NONE). -# -# **Parameters** -# -# - *type*: Type of inputs to accept (ALL) -# `ALL`: Accept all types of user input -# `SKIP`: Accept skipping dialogues but nothing else -# `NONE`: Deny all inputs (including opening menus) -# -# **Warning**: `SKIP` and `NONE` also disable autosaves. -# -# **Warning**: The type of user input accepted will persist even after the -# current event has ended. Remember to reset the input type at the end of -# cut-scenes! -# -# @ESC -extends ESCBaseCommand -class_name AcceptInputCommand - - -# The list of supported input types -const SUPPORTED_INPUT_TYPES = ["ALL", "NONE", "SKIP"] - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 1, - [TYPE_STRING], - ["ALL"] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not arguments[0] in SUPPORTED_INPUT_TYPES: - escoria.logger.error( - self, - "[%s]: invalid parameter. %s is not a valid parameter value." + - "Should be one of %s" - % [ - get_command_name(), - arguments[0], - str(SUPPORTED_INPUT_TYPES) - ] - ) - return false - return true - - -# Run the command -func run(command_params: Array) -> int: - var mode = escoria.inputs_manager.INPUT_ALL - match command_params[0]: - "NONE": - mode = escoria.inputs_manager.INPUT_NONE - "SKIP": - mode = escoria.inputs_manager.INPUT_SKIP - - escoria.inputs_manager.input_mode = mode - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/anim.gd b/addons/escoria-core/game/core-scripts/esc/commands/anim.gd deleted file mode 100644 index 3525c547..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/anim.gd +++ /dev/null @@ -1,61 +0,0 @@ -# `anim object name [reverse]` -# -# Executes the animation specified in "name" on "object" without blocking. -# The next command in the event will be executed immediately after the -# animation is started. -# -# **Parameters** -# -# * *object*: Global ID of the object with the animation -# * *name*: Name of the animation to play -# * *reverse*: Plays the animation in reverse when true -# -# @ESC -extends ESCBaseCommand -class_name AnimCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [TYPE_STRING, TYPE_STRING, TYPE_BOOL], - [null, null, false] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[0]): - escoria.logger.error( - self, - "[%s]: invalid object. Object with global id %s not found." - % [get_command_name(), arguments[0]] - ) - return false - return true - - -# Run the command -func run(command_params: Array) -> int: - var obj = escoria.object_manager.get_object(command_params[0]) - var anim_id = command_params[1] - var reverse = command_params[2] - var animator: ESCAnimationPlayer = \ - (obj.node as ESCItem).get_animation_player() - if reverse: - animator.play_backwards(anim_id) - else: - animator.play(anim_id) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - escoria.logger.debug( - self, - "[%s] interrupt() function not implemented." % get_command_name() - ) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/anim_block.gd b/addons/escoria-core/game/core-scripts/esc/commands/anim_block.gd deleted file mode 100644 index a96a5cb7..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/anim_block.gd +++ /dev/null @@ -1,67 +0,0 @@ -# `anim_block object name [reverse]` -# -# Executes the animation specified in "name" on "object" while blocking other -# events from starting. -# The next command in the event will be executed when the animation is -# finished playing. -# -# **Parameters** -# -# * *object*: Global ID of the object with the animation -# * *name*: Name of the animation to play -# * *reverse*: Plays the animation in reverse when true -# -# @ESC -extends ESCBaseCommand -class_name AnimBlockCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [TYPE_STRING, TYPE_STRING, TYPE_BOOL], - [null, null, false] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[0]): - escoria.logger.error( - self, - "[%s]: Object with global id %s not found." - % [get_command_name(), arguments[0]] - ) - return false - return true - - -# Run the command -func run(command_params: Array) -> int: - var obj = escoria.object_manager.get_object(command_params[0]) - var anim_id = command_params[1] - var reverse = command_params[2] - var animator: ESCAnimationPlayer = \ - (obj.node as ESCItem).get_animation_player() - if reverse: - animator.play_backwards(anim_id) - else: - animator.play(anim_id) - if animator.get_length(anim_id) < 1.0: - return ESCExecution.RC_OK - var animation_finished = yield(animator, "animation_finished") - while animation_finished != anim_id: - animation_finished = yield(animator, "animation_finished") - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - escoria.logger.debug( - self, - "[%s] interrupt() function not implemented." % get_command_name() - ) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/block_say.gd b/addons/escoria-core/game/core-scripts/esc/commands/block_say.gd deleted file mode 100644 index 990c8f8e..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/block_say.gd +++ /dev/null @@ -1,62 +0,0 @@ -# `block_say` -# -# `say` commands called subsequent to using the `block_say` command will reuse the -# dialog box type of the previous `say` command if both dialog box types between the two `say` -# commands match. -# -# Different dialog box types can be used across multiple `say` commands, with the latest one -# used being preserved for reuse by the next `say` command should the dialog box type specified by -# both `say` commands match. -# -# This reuse will continue until a call to `end_block_say` is made. -# -# Using `block_say` more than once prior to calling `end_block_say` is idempotent and has the -# following behaviour: -# -# - If no `say` command has yet been encountered since the first use of `block_say`, -# the result of using this command will be as described above. -# - If a `say` command has been encountered since the previous use of `block_say`, -# the dialog box used with that `say` command will continue to be reused for subsequent -# `say` commands should the dialog box type requested match. Note that the dialog box used with -# the next `say` command may be different than the one currently being reused. -# -# Example: -# `block say` -# `say player "Picture's looking good."` -# `say player "And so am I."` -# `end_block_say` -# -# This example will reuse the same dialog box type since they are the same between both `say` calls. -# -# @ESC -extends ESCBaseCommand -class_name BlockSayCommand - - -# Constructor -func _init() -> void: - pass - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new(0) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - return true - - -# Run the command -func run(command_params: Array) -> int: - escoria.dialog_player.enable_preserve_dialog_box() - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - escoria.logger.debug( - self, - "[%s] interrupt() function not implemented." % get_command_name() - ) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/camera_push.gd b/addons/escoria-core/game/core-scripts/esc/commands/camera_push.gd deleted file mode 100644 index 700f1662..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/camera_push.gd +++ /dev/null @@ -1,112 +0,0 @@ -# `camera_push target [time] [type]` -# -# Pushes (moves) the camera so it points at a specific `target`. If the camera -# was following a target (like the player) previously, it will no longer follow -# this target. -# -# Make sure the target is reachable if camera limits have been configured. -# -# **Parameters** -# -# - *target*: Global ID of the `ESCItem` to push the camera to. `ESCItem`s have -# a "camera_node" property that can be set to point to a node (usually an -# `ESCLocation` node). If the "camera_node" property is empty, `camera_push` -# will point the camera at the `ESCItem`s location. If however, the `ESCItem` -# has its "camera_node" property set, the command will instead point the -# camera at the node referenced by the `ESCItem`s "camera_node" property. -# - *time*: Number of seconds the transition should take (default: `1`) -# - *type*: Transition type to use (default: `QUAD`) -# -# Supported transitions include the names of the values used -# in the "TransitionType" enum of the "Tween" type (without the "TRANS_" prefix): -# -# See https://docs.godotengine.org/en/stable/classes/class_tween.html?highlight=tween#enumerations -# -# For more details see: https://docs.escoria-framework.org/camera -# -# @ESC -extends ESCCameraBaseCommand -class_name CameraPushCommand - -# The list of supported transitions as per the link mentioned above -const SUPPORTED_TRANSITIONS = ["LINEAR","SINE","QUINT","QUART","QUAD" ,"EXPO","ELASTIC","CUBIC", - "CIRC","BOUNCE","BACK"] - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 1, - [TYPE_STRING, [TYPE_REAL, TYPE_INT], TYPE_STRING], - [null, 1, "QUAD"] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[0]): - escoria.logger.error( - self, - "[%s]: invalid object. Object global id %s not found." - % [get_command_name(), arguments[0]] - ) - return false - - var target_pos = _get_target_pos(arguments[0]) - var camera: ESCCamera = escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera - - if not camera.check_point_is_inside_viewport_limits(target_pos): - generate_viewport_warning(target_pos, camera) - return false - - if not arguments[2] in SUPPORTED_TRANSITIONS: - escoria.logger.error( - self, - ( - "[{command_name}]: invalid transition type. Transition type {t_type} " + - "is not one of the accepted types : {allowed_types}" - ).format( - { - "command_name":get_command_name(), - "t_type":arguments[2], - "allowed_types":SUPPORTED_TRANSITIONS - } - ) - ) - return false - - return true - - -# Run the command -func run(command_params: Array) -> int: - (escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera)\ - .push( - escoria.object_manager.get_object(command_params[0]).node, - command_params[1], - ClassDB.class_get_integer_constant("Tween", "TRANS_%s" % command_params[2]) - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - escoria.logger.debug( - self, - "[%s] interrupt() function not implemented." % get_command_name() - ) - - -# Gets the appropriate target position from the `ESCItem`, as used by the camera. -# -# #### Parameters -# -# - target_global_id: The `global_id` of the `ESCItem` to check. -# -# **Returns** the item's position based on its camera node. -func _get_target_pos(target_global_id: String) -> Vector2: - var target = escoria.object_manager.get_object(target_global_id).node as ESCItem - return target.get_camera_node().global_position diff --git a/addons/escoria-core/game/core-scripts/esc/commands/camera_push_block.gd b/addons/escoria-core/game/core-scripts/esc/commands/camera_push_block.gd deleted file mode 100644 index 61c213c7..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/camera_push_block.gd +++ /dev/null @@ -1,127 +0,0 @@ -# `camera_push_block target [time] [type]` -# -# Pushes (moves) the camera so it points at a specific `target`. If the camera -# was following a target (like the player) previously, it will no longer follow -# this target. Blocks until the command completes. -# -# Make sure the target is reachable if camera limits have been configured. -# -# **Parameters** -# -# - *target*: Global ID of the `ESCItem` to push the camera to. `ESCItem`s have -# a "camera_node" property that can be set to point to a node (usually an -# `ESCLocation` node). If the "camera_node" property is empty, `camera_push_block` -# will point the camera at the `ESCItem`s location. If however, the `ESCItem` -# has its "camera_node" property set, the command will instead point the -# camera at the node referenced by the `ESCItem`s "camera_node" property. -# - *time*: Number of seconds the transition should take (default: `1`) -# - *type*: Transition type to use (default: `QUAD`) -# -# Supported transitions include the names of the values used -# in the "TransitionType" enum of the "Tween" type (without the "TRANS_" prefix). -# -# See https://docs.godotengine.org/en/stable/classes/class_tween.html?highlight=tween#enumerations -# -# For more details see: https://docs.escoria-framework.org/camera -# -# @ESC -extends ESCCameraBaseCommand -class_name CameraPushBlockCommand - - -# The list of supported transitions as per the link mentioned above -const SUPPORTED_TRANSITIONS = ["LINEAR","SINE","QUINT","QUART","QUAD" ,"EXPO","ELASTIC","CUBIC", - "CIRC","BOUNCE","BACK"] - - -# Tween for blocking -var _camera_tween: Tween - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 1, - [TYPE_STRING, [TYPE_REAL, TYPE_INT], TYPE_STRING], - [null, 1, "QUAD"] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[0]): - escoria.logger.error( - self, - "[%s]: invalid object. Object global id %s not found." - % [get_command_name(), arguments[0]] - ) - return false - - var target_pos = _get_target_pos(arguments[0]) - var camera: ESCCamera = escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera - - if not camera.check_point_is_inside_viewport_limits(target_pos): - generate_viewport_warning(target_pos, camera) - return false - - if not arguments[2] in SUPPORTED_TRANSITIONS: - escoria.logger.error( - self, - ( - "[{command_name}]: invalid transition type. Transition type {t_type} " + - "is not one of the accepted types : {allowed_types}" - ).format( - { - "command_name":get_command_name(), - "t_type":arguments[2], - "allowed_types":SUPPORTED_TRANSITIONS - } - ) - ) - return false - - _camera_tween = camera.get_tween() - - return true - - -# Run the command -func run(command_params: Array) -> int: - (escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera)\ - .push( - escoria.object_manager.get_object(command_params[0]).node, - command_params[1], - ClassDB.class_get_integer_constant("Tween", "TRANS_%s" % command_params[2]) - ) - - if command_params[1] > 0.0: - yield(_camera_tween, "tween_completed") - escoria.logger.debug( - self, - "camera_push_block tween complete." - ) - - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - escoria.logger.debug( - self, - "[%s] interrupt() function not implemented." % get_command_name() - ) - - -# Gets the appropriate target position from the `ESCItem`, as used by the camera. -# -# #### Parameters -# -# - target_global_id: The `global_id` of the `ESCItem` to check. -# -# **Returns** the ESCitem's position based on its camera node. -func _get_target_pos(target_global_id: String) -> Vector2: - var target = escoria.object_manager.get_object(target_global_id).node as ESCItem - return target.get_camera_node().global_position diff --git a/addons/escoria-core/game/core-scripts/esc/commands/camera_set_limits.gd b/addons/escoria-core/game/core-scripts/esc/commands/camera_set_limits.gd deleted file mode 100644 index 3a08797e..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/camera_set_limits.gd +++ /dev/null @@ -1,64 +0,0 @@ -# `camera_set_limits camlimits_id` -# -# Limits the current camera's movement to a limit defined in the `ESCRoom`'s -# definition. A limit is defined as an upper-left (x, y) coordinate, a width -# and a height that the camera must stay within. Multiple limits can be -# defined for a room, allowing for new areas to be seen once they have -# been 'unlocked'. -# -# **Parameters** -# -# - *camlimits_id*: Index of the camera limit defined in the `camera limits` -# list of the current `ESCRoom` -# -# For more details see: https://docs.escoria-framework.org/camera -# -# @ESC -extends ESCCameraBaseCommand -class_name CameraSetLimitsCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 1, - [TYPE_INT], - [null] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if escoria.main.current_scene.camera_limits.size() < arguments[0]: - escoria.logger.error( - self, - "[%s]: invalid limits id. Camera limit id (%d) is larger than the number of limits defined in this scene (%d)." - % [ - get_command_name(), - arguments[0], - escoria.main.current_scene.camera_limits.size() - ] - ) - return false - - return true - - -# Run the command -func run(command_params: Array) -> int: - var camera: ESCCamera = escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera - camera.clamp_to_viewport_limits() - escoria.main.set_camera_limits(command_params[0]) - - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - escoria.logger.debug( - self, - "[%s] interrupt() function not implemented." % get_command_name() - ) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/camera_set_pos.gd b/addons/escoria-core/game/core-scripts/esc/commands/camera_set_pos.gd deleted file mode 100644 index 70d4cd12..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/camera_set_pos.gd +++ /dev/null @@ -1,57 +0,0 @@ -# `camera_set_pos time x y` -# -# Moves the camera to the given absolute position over a time period. -# -# **Parameters** -# -# - *time*: Number of seconds the transition should take -# - *x*: Target X coordinate -# - "y*: Target Y coordinate -# -# For more details see: https://docs.escoria-framework.org/camera -# -# @ESC -extends ESCCameraBaseCommand -class_name CameraSetPosCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 3, - [[TYPE_REAL, TYPE_INT], TYPE_INT, TYPE_INT], - [null, null, null] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - var new_pos: Vector2 = Vector2(arguments[1], arguments[2]) - var camera: ESCCamera = escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera - - if not camera.check_point_is_inside_viewport_limits(new_pos): - generate_viewport_warning(new_pos, camera) - return false - - return true - - -# Run the command -func run(command_params: Array) -> int: - (escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera)\ - .set_target( - Vector2(command_params[1], command_params[2]), - command_params[0] - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - escoria.logger.debug( - self, - "[%s] interrupt() function not implemented." % get_command_name() - ) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/camera_set_pos_block.gd b/addons/escoria-core/game/core-scripts/esc/commands/camera_set_pos_block.gd deleted file mode 100644 index 5978c189..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/camera_set_pos_block.gd +++ /dev/null @@ -1,73 +0,0 @@ -# `camera_set_pos_block time x y` -# -# Moves the camera to the given absolute position over a time period. Blocks -# until the command completes. -# -# Make sure the coordinates are reachable if camera limits have been configured. -# -# **Parameters** -# -# - *time*: Number of seconds the transition should take -# - *x*: Target X coordinate -# - "y*: Target Y coordinate -# -# For more details see: https://docs.escoria-framework.org/camera -# -# @ESC -extends ESCCameraBaseCommand -class_name CameraSetPosBlockCommand - - -# Tween for blocking -var _camera_tween: Tween - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 3, - [[TYPE_REAL, TYPE_INT], TYPE_INT, TYPE_INT], - [null, null, null] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - var new_pos: Vector2 = Vector2(arguments[1], arguments[2]) - var camera: ESCCamera = escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera - - if not camera.check_point_is_inside_viewport_limits(new_pos): - generate_viewport_warning(new_pos, camera) - return false - - _camera_tween = camera.get_tween() - - return true - - -# Run the command -func run(command_params: Array) -> int: - (escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera)\ - .set_target( - Vector2(command_params[1], command_params[2]), - command_params[0] - ) - - if command_params[0] > 0.0: - yield(_camera_tween, "tween_completed") - escoria.logger.debug( - self, - "camera_set_pos_block tween complete." - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - escoria.logger.debug( - self, - "[%s] interrupt() function not implemented." % get_command_name() - ) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/camera_set_target.gd b/addons/escoria-core/game/core-scripts/esc/commands/camera_set_target.gd deleted file mode 100644 index a4ba45b3..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/camera_set_target.gd +++ /dev/null @@ -1,60 +0,0 @@ -# `camera_set_target time object` -# -# Configures the camera to follow the specified target `object` as it moves -# around the current room. The transition to focus on the `object` will happen -# over a time period. -# -# **Parameters** -# -# - *time*: Number of seconds the transition should take to move the camera -# to follow `object` -# - *object*: Global ID of the target object -# -# For more details see: https://docs.escoria-framework.org/camera -# -# @ESC -extends ESCCameraBaseCommand -class_name CameraSetTargetCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [[TYPE_REAL, TYPE_INT], TYPE_STRING], - [null, null] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[1]): - escoria.logger.error( - self, - "[%s]: Invalid object: Object with global id %s not found." - % [get_command_name(), arguments[1]] - ) - return false - - return true - - -# Run the command -func run(command_params: Array) -> int: - (escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera)\ - .set_target( - escoria.object_manager.get_object(command_params[1]).node, - command_params[0] - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - escoria.logger.debug( - self, - "[%s] interrupt() function not implemented." % get_command_name() - ) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/camera_set_target_block.gd b/addons/escoria-core/game/core-scripts/esc/commands/camera_set_target_block.gd deleted file mode 100644 index abcb9266..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/camera_set_target_block.gd +++ /dev/null @@ -1,77 +0,0 @@ -# `camera_set_target_block time object` -# -# Configures the camera to follow the specified target `object` (ESCItem) as it moves -# around the current room. The transition to focus on the `object` will happen -# over a time period. Blocks until the command completes. -# -# The camera will move as close as it can if camera limits have been configured -# and the `object` is at coordinates that are not reachable. -# -# **Parameters** -# -# - *time*: Number of seconds the transition should take to move the camera -# to follow `object` -# - *object*: Global ID of the target object -# -# For more details see: https://docs.escoria-framework.org/camera -# -# @ESC -extends ESCCameraBaseCommand -class_name CameraSetTargetBlockCommand - - -# Tween for blocking -var _camera_tween: Tween - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [[TYPE_REAL, TYPE_INT], TYPE_STRING], - [null, null] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[1]): - escoria.logger.error( - self, - "[%s]: Invalid object: Object with global id %s not found." - % [get_command_name(), arguments[1]] - ) - return false - - var camera: ESCCamera = escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera - _camera_tween = camera.get_tween() - - return true - - -# Run the command -func run(command_params: Array) -> int: - (escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera)\ - .set_target( - escoria.object_manager.get_object(command_params[1]).node, - command_params[0] - ) - - if command_params[0] > 0.0: - yield(_camera_tween, "tween_completed") - escoria.logger.debug( - self, - "camera_set_target_block tween complete." - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - escoria.logger.debug( - self, - "[%s] interrupt() function not implemented." % get_command_name() - ) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/camera_set_zoom.gd b/addons/escoria-core/game/core-scripts/esc/commands/camera_set_zoom.gd deleted file mode 100644 index d0827042..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/camera_set_zoom.gd +++ /dev/null @@ -1,46 +0,0 @@ -# `camera_set_zoom magnitude [time]` -# -# Zooms the camera in/out to the desired `magnitude`. Values larger than '1' zoom -# the camera out while smaller values zoom in. These values are relative to the -# default zoom value of '1', not the current value. As such, while using a value -# of '0.5' would double the size of the graphics, running the same command again -# would result in no change. The zoom will happen over the given time period. -# -# **Parameters** -# -# - *magnitude*: Magnitude of zoom -# - *time*: Number of seconds the transition should take, with a value of `0` -# meaning the zoom should happen instantly (default: `0`) -# -# For more details see: https://docs.escoria-framework.org/camera -# -# @ESC -extends ESCCameraBaseCommand -class_name CameraSetZoomCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 1, - [[TYPE_REAL, TYPE_INT], [TYPE_REAL, TYPE_INT]], - [null, 0.0] - ) - - -# Run the command -func run(command_params: Array) -> int: - (escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera)\ - .set_camera_zoom( - command_params[0], - command_params[1] - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - escoria.logger.debug( - self, - "[%s] interrupt() function not implemented." % get_command_name() - ) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/camera_set_zoom_block.gd b/addons/escoria-core/game/core-scripts/esc/commands/camera_set_zoom_block.gd deleted file mode 100644 index dfce5491..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/camera_set_zoom_block.gd +++ /dev/null @@ -1,73 +0,0 @@ -# `camera_set_zoom_block magnitude [time]` -# -# Zooms the camera in/out to the desired `magnitude`. Values larger than '1' zoom -# the camera out while smaller values zoom in. These values are relative to the -# default zoom value of '1', not the current value. As such, while using a value -# of '0.5' would double the size of the graphics, running the same command again -# would result in no change. The zoom will happen over the given time period. -# Blocks until the command completes. -# -# Zoom operations might not be as smooth as desired if the requested zoom -# level results in an edge of the camera meeting any defined camera limits. -# -# **Parameters** -# -# - *magnitude*: Magnitude of zoom -# - *time*: Number of seconds the transition should take, with a value of `0` -# meaning the zoom should happen instantly (default: `0`) -# -# For more details see: https://docs.escoria-framework.org/camera -# -# @ESC -extends ESCCameraBaseCommand -class_name CameraSetZoomBlockCommand - - -var _camera_tween: Tween - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 1, - [[TYPE_REAL, TYPE_INT], [TYPE_REAL, TYPE_INT]], - [null, 0.0] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - var camera: ESCCamera = escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera - _camera_tween = camera.get_tween() - - return true - - -# Run the command -func run(command_params: Array) -> int: - var camera: ESCCamera = escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera - - camera\ - .set_camera_zoom( - command_params[0], - command_params[1] - ) - - if command_params[1] > 0.0: - yield(_camera_tween, "tween_completed") - escoria.logger.debug( - self, - "camera_set_zoom_block tween complete." - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - escoria.logger.debug( - self, - "[%s] interrupt() function not implemented." % get_command_name() - ) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/camera_set_zoom_height.gd b/addons/escoria-core/game/core-scripts/esc/commands/camera_set_zoom_height.gd deleted file mode 100644 index 1e3de82e..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/camera_set_zoom_height.gd +++ /dev/null @@ -1,58 +0,0 @@ -# `camera_set_zoom_height pixels [time]` -# -# Zooms the camera in/out so it occupies the given height in pixels. -# -# **Parameters** -# -# - *pixels*: Target height in pixels -# - *time*: Number of seconds the transition should take, with a value of `0` -# meaning the zoom should happen instantly (default: `0`) -# -# For more details see: https://docs.escoria-framework.org/camera -# -# @ESC -extends ESCBaseCommand -class_name CameraSetZoomHeightCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 1, - [TYPE_INT, [TYPE_INT, TYPE_REAL]], - [null, 0.0] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if arguments[0] < 0: - escoria.logger.error( - self, - "[%s]: invalid height. Can't zoom to a negative height (%d)." - % [get_command_name(), arguments[0]] - ) - return false - - return true - - -# Run the command -func run(command_params: Array) -> int: - (escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera)\ - .set_camera_zoom( - command_params[0] / escoria.game_size.y, - command_params[1] - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - escoria.logger.debug( - self, - "[%s] interrupt() function not implemented." % get_command_name() - ) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/camera_set_zoom_height_block.gd b/addons/escoria-core/game/core-scripts/esc/commands/camera_set_zoom_height_block.gd deleted file mode 100644 index a573f732..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/camera_set_zoom_height_block.gd +++ /dev/null @@ -1,73 +0,0 @@ -# `camera_set_zoom_height_block pixels [time]` -# -# Zooms the camera in/out so it occupies the given height in pixels. -# Blocks until the command completes. -# -# **Parameters** -# -# - *pixels*: Target height in pixels (integer values only) -# - *time*: Number of seconds the transition should take, with a value of `0` -# meaning the zoom should happen instantly (default: `0`) -# -# For more details see: https://docs.escoria-framework.org/camera -# -# @ESC -extends ESCBaseCommand -class_name CameraSetZoomHeightBlockCommand - - -# Tween for blocking -var _camera_tween: Tween - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 1, - [TYPE_INT, [TYPE_INT, TYPE_REAL]], - [null, 0.0] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if arguments[0] <= 0: - escoria.logger.error( - self, - "[%s]: invalid height. Can't zoom to a negative height (%d)." - % [get_command_name(), arguments[0]] - ) - return false - - var camera: ESCCamera = escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera - _camera_tween = camera.get_tween() - - return true - - -# Run the command -func run(command_params: Array) -> int: - (escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera)\ - .set_camera_zoom( - command_params[0] / escoria.game_size.y, - command_params[1] - ) - - if command_params[1] > 0.0: - yield(_camera_tween, "tween_completed") - escoria.logger.debug( - self, - "camera_set_zoom_height_block tween complete." - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - escoria.logger.debug( - self, - "[%s] interrupt() function not implemented." % get_command_name() - ) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/camera_shift.gd b/addons/escoria-core/game/core-scripts/esc/commands/camera_shift.gd deleted file mode 100644 index f92fa09a..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/camera_shift.gd +++ /dev/null @@ -1,94 +0,0 @@ -# `camera_shift x y [time] [type]` -# -# Shifts the camera by the given horizontal and vertical amounts relative to the -# current location. -# -# **Parameters** -# -# - *x*: Shift by x pixels along the x-axis -# - *y*: Shift by y pixels along the y-axis -# - *time*: Number of seconds the transition should take, with a value of `0` -# meaning the zoom should happen instantly (default: `1`) -# - *type*: Transition type to use (default: `QUAD`) -# -# Supported transitions include the names of the values used -# in the "TransitionType" enum of the "Tween" type (without the "TRANS_" prefix): -# -# https://docs.godotengine.org/en/stable/classes/class_tween.html?highlight=tween#enumerations -# -# For more details see: https://docs.escoria-framework.org/camera -# -# @ESC -extends ESCCameraBaseCommand -class_name CameraShiftCommand - -# The list of supported transitions as per the link mentioned above -const SUPPORTED_TRANSITIONS = ["LINEAR","SINE","QUINT","QUART","QUAD" ,"EXPO","ELASTIC","CUBIC", - "CIRC","BOUNCE","BACK"] - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [ - [TYPE_INT, TYPE_REAL], - [TYPE_INT, TYPE_REAL], - [TYPE_INT, TYPE_REAL], - TYPE_STRING - ], - [null, null, 1, "QUAD"] - ) - - -# Run the command -func run(command_params: Array) -> int: - (escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera)\ - .shift( - Vector2( - command_params[0], - command_params[1] - ), - command_params[2], - ClassDB.class_get_integer_constant("Tween", "TRANS_%s" % command_params[3]) - ) - return ESCExecution.RC_OK - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not arguments[3] in SUPPORTED_TRANSITIONS: - escoria.logger.error( - self, - ( - "[{command_name}]: invalid transition type" + - "Transition type {t_type} is not one of the accepted types : {allowed_types}" - ).format( - { - "command_name": get_command_name(), - "t_type":arguments[3], - "allowed_types":SUPPORTED_TRANSITIONS - } - ) - ) - return false - - var camera: ESCCamera = escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera - var shift_by: Vector2 = Vector2(arguments[0], arguments[1]) - var new_pos: Vector2 = Vector2(camera.position.x + shift_by.x, camera.position.y + shift_by.y) - - if not camera.check_point_is_inside_viewport_limits(new_pos): - generate_viewport_warning(new_pos, camera) - return false - - return true - - -# Function called when the command is interrupted. -func interrupt(): - escoria.logger.debug( - self, - "[%s] interrupt() function not implemented." % get_command_name() - ) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/camera_shift_block.gd b/addons/escoria-core/game/core-scripts/esc/commands/camera_shift_block.gd deleted file mode 100644 index af62cfa4..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/camera_shift_block.gd +++ /dev/null @@ -1,112 +0,0 @@ -# `camera_shift_block x y [time] [type]` -# -# Shifts the camera by the given horizontal and vertical amounts relative to the -# current location. Blocks until the command completes. -# -# Make sure the destination coordinates are reachable if -# camera limits have been configured. -# -# **Parameters** -# -# - *x*: Shift by x pixels along the x-axis -# - *y*: Shift by y pixels along the y-axis -# - *time*: Number of seconds the transition should take, with a value of `0` -# meaning the zoom should happen instantly (default: `1`) -# - *type*: Transition type to use (default: `QUAD`) -# -# Supported transitions include the names of the values used -# in the "TransitionType" enum of the "Tween" type (without the "TRANS_" prefix). -# -# See https://docs.godotengine.org/en/stable/classes/class_tween.html?highlight=tween#enumerations -# -# For more details see: https://docs.escoria-framework.org/camera -# -# @ESC -extends ESCCameraBaseCommand -class_name CameraShiftBlockCommand - - -# The list of supported transitions as per the link mentioned above -const SUPPORTED_TRANSITIONS = ["LINEAR","SINE","QUINT","QUART","QUAD" ,"EXPO","ELASTIC","CUBIC", - "CIRC","BOUNCE","BACK"] - - -# Tween for blocking -var _camera_tween: Tween - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [ - [TYPE_INT, TYPE_REAL], - [TYPE_INT, TYPE_REAL], - [TYPE_INT, TYPE_REAL], - TYPE_STRING - ], - [null, null, 1, "QUAD"] - ) - - -# Run the command -func run(command_params: Array) -> int: - (escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera)\ - .shift( - Vector2( - command_params[0], - command_params[1] - ), - command_params[2], - ClassDB.class_get_integer_constant("Tween", "TRANS_%s" % command_params[3]) - ) - - if command_params[2] > 0.0: - yield(_camera_tween, "tween_completed") - escoria.logger.debug( - self, - "camera_shift_block tween complete." - ) - return ESCExecution.RC_OK - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not arguments[3] in SUPPORTED_TRANSITIONS: - escoria.logger.error( - self, - ( - "[{command_name}]: invalid transition type" + - "Transition type {t_type} is not one of the accepted types : {allowed_types}" - ).format( - { - "command_name": get_command_name(), - "t_type":arguments[3], - "allowed_types":SUPPORTED_TRANSITIONS - } - ) - ) - return false - - var camera: ESCCamera = escoria.object_manager.get_object(escoria.object_manager.CAMERA).node as ESCCamera - var shift_by: Vector2 = Vector2(arguments[0], arguments[1]) - var new_pos: Vector2 = Vector2(camera.position.x + shift_by.x, camera.position.y + shift_by.y) - - if not camera.check_point_is_inside_viewport_limits(new_pos): - generate_viewport_warning(new_pos, camera) - return false - - _camera_tween = camera.get_tween() - - return true - - -# Function called when the command is interrupted. -func interrupt(): - escoria.logger.debug( - self, - "[%s] interrupt() function not implemented." % get_command_name() - ) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/change_scene.gd b/addons/escoria-core/game/core-scripts/esc/commands/change_scene.gd deleted file mode 100644 index 76487e3d..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/change_scene.gd +++ /dev/null @@ -1,80 +0,0 @@ -# `change_scene path [enable_automatic_transition] [run_events]` -# -# Switches the game from the current scene to another scene. Use this to move -# the player to a new room when they walk through an unlocked door, for -# example. -# -# **Parameters** -# -# - *path*: Path of the new scene -# - *enable_automatic_transition*: Automatically transition to the new scene -# (default: `true`) -# - *run_events*: Run the standard ESC events of the new scene (default: `true`) -# -# @ESC -extends ESCBaseCommand -class_name ChangeSceneCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 1, - [TYPE_STRING, TYPE_BOOL, TYPE_BOOL], - [null, true, true] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array) -> bool: - if not .validate(arguments): - return false - - if not ResourceLoader.exists(arguments[0]): - escoria.logger.error( - self, - "[%s]: Invalid scene. Scene %s was not found." - % [get_command_name(), arguments[0]] - ) - return false - if not ResourceLoader.exists( - ESCProjectSettingsManager.get_setting(ESCProjectSettingsManager.GAME_SCENE) - ): - escoria.logger.error( - self, - "[%s]: Game scene not found. The path set in 'ui/game_scene' was not found: %s." - % [ - get_command_name(), - ESCProjectSettingsManager.get_setting( - ESCProjectSettingsManager.GAME_SCENE - ) - ] - ) - return false - - return true - - -# Run the command -func run(command_params: Array) -> int: - escoria.logger.info( - self, - "[%s] Changing scene to %s (enable_automatic_transition = %s)." - % [ - get_command_name(), - command_params[0], # scene file - command_params[1] # enable_automatic_transition - ] - ) - - escoria.room_manager.change_scene(command_params[0], command_params[1]) - - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - escoria.logger.debug( - self, - "[%s] interrupt() function not implemented." % get_command_name() - ) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/custom.gd b/addons/escoria-core/game/core-scripts/esc/commands/custom.gd deleted file mode 100644 index 849f24ab..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/custom.gd +++ /dev/null @@ -1,100 +0,0 @@ -# `custom object node func_name [params...]` -# -# -# Executes the specified Godot function. This function must be in a script -# attached to a child node of a registered `ESCItem`. -# -# **Parameters** -# -# - *object*: Global ID of the target `ESCItem` -# - *node*: Name of the child node of the target `ESCItem` -# - *func_name*: Name of the function to be called -# - params: Any arguments to be passed to the function (array and object parameters are not supported). -# Multiple parameters can be passed by simply passing them in as additional arguments separated by -# spaces, e.g. `custom the_object the_node the_function arg1 arg2 arg3` -# -# @ESC -extends ESCBaseCommand -class_name CustomCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 3, - [TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_ARRAY], - [null, null, null, []], - [true], - true - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[0]): - escoria.logger.error( - self, - "[%s]: invalid object. Object with global id %s not found." - % [get_command_name(), arguments[0]] - ) - return false - elif not escoria.object_manager.get_object(arguments[0]).node.has_node( - arguments[1] - ): - escoria.logger.error( - self, - "[%s]: invalid node. Object with global id %s has no child node called %s." - % [ - get_command_name(), - arguments[0], - arguments[1], - ] - ) - return false - elif not escoria.object_manager.get_object(arguments[0]).node\ - .get_node( - arguments[1] - )\ - .has_method( - arguments[2] - ): - escoria.logger.error( - self, - "[%s]: invalid function. Object with global id %s and node %s has no function called %s." - % [ - get_command_name(), - arguments[0], - arguments[1], - arguments[2], - ] - ) - return false - return true - - -# Run the command -func run(command_params: Array) -> int: - var object = escoria.object_manager.get_object( - command_params[0] - ) - # Global variables can be substituted into the command arguments by wrapping the global - # name in braces. - for loop in command_params[3].size(): - command_params[3][loop] = escoria.globals_manager.replace_globals(command_params[3][loop]) - - object.node.get_node(command_params[1]).call( - command_params[2], - command_params[3] - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - escoria.logger.debug( - self, - "[%s] interrupt() function not implemented." % get_command_name() - ) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/dec_global.gd b/addons/escoria-core/game/core-scripts/esc/commands/dec_global.gd deleted file mode 100644 index 98c095a5..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/dec_global.gd +++ /dev/null @@ -1,52 +0,0 @@ -# `dec_global name value` -# -# Subtract the given value from the specified global. -# -# **Parameters** -# -# - *name*: Name of the global to be changed -# - *value*: Value to be subtracted (default: 1) -# -# @ESC -extends ESCBaseCommand -class_name DecGlobalCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 1, - [TYPE_STRING, TYPE_INT], - [null, 1] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.globals_manager.get_global(arguments[0]) is int: - escoria.logger.error( - self, - "[%s]: invalid global. Global %s isn't an integer value." - % [get_command_name(), arguments[0]] - ) - return false - return true - - -# Run the command -func run(command_params: Array) -> int: - escoria.globals_manager.set_global( - command_params[0], - escoria.globals_manager.get_global(command_params[0]) - \ - command_params[1] - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/enable_terrain.gd b/addons/escoria-core/game/core-scripts/esc/commands/enable_terrain.gd deleted file mode 100644 index 63228710..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/enable_terrain.gd +++ /dev/null @@ -1,50 +0,0 @@ -# `enable_terrain node_name` -# -# Enables the `ESCTerrain`'s `NavigationPolygonInstance` specified by the given -# node name. It will also disable the previously-activated -# `NavigationPolygonInstance`. -# Use this to change where the player can walk, allowing them to walk into the -# next room once a door has been opened, for example. -# -# **Parameters** -# -# - *node_name*: Name of the `NavigationPolygonInstance` node to activate -# -# @ESC -extends ESCBaseCommand -class_name EnableTerrainCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 1, - [TYPE_STRING], - [null] - ) - - -# Run the command -func run(command_params: Array) -> int: - var name: String = command_params[0] - if escoria.room_terrain.has_node(name): - var new_active_navigation_instance = \ - escoria.room_terrain.get_node(name) - escoria.room_terrain.current_active_navigation_instance.enabled = false - escoria.room_terrain.current_active_navigation_instance = \ - new_active_navigation_instance - escoria.room_terrain.current_active_navigation_instance.enabled = true - return ESCExecution.RC_OK - else: - escoria.logger.error( - self, - "[%s]: Can not find terrain node. Terrain node %s could not be found." - % [get_command_name(), name] - ) - return ESCExecution.RC_ERROR - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/end_block_say.gd b/addons/escoria-core/game/core-scripts/esc/commands/end_block_say.gd deleted file mode 100644 index 4ef23e53..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/end_block_say.gd +++ /dev/null @@ -1,47 +0,0 @@ -# `end_block_say` -# -# `say` commands used subsequent to using the `end_block_say` command will no longer -# reuse the dialog box type used by the previous `say` command(s) encountered. -# -# Using `end_block_say` more than once is safe and idempotent. -# -# Example: -# `block say` -# `say player "Picture's looking good."` -# `say player "And so am I."` -# `end_block_say` -# -# This example will reuse the same dialog box type since they are the same between both `say` calls. -# -# @ESC -extends ESCBaseCommand -class_name EndBlockSayCommand - - -# Constructor -func _init() -> void: - pass - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new(0) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - return true - - -# Run the command -func run(command_params: Array) -> int: - escoria.dialog_player.disable_preserve_dialog_box() - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - escoria.logger.debug( - self, - "[%s] interrupt() function not implemented." % get_command_name() - ) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/hide_menu.gd b/addons/escoria-core/game/core-scripts/esc/commands/hide_menu.gd deleted file mode 100644 index bf58b789..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/hide_menu.gd +++ /dev/null @@ -1,76 +0,0 @@ -# `hide_menu menu_type` -# -# Hides either the main menu or the pause menu. Transitions from the menu using -# the default transition type (set in the Escoria project settings). -# -# **Parameters** -# -# - *menu_type*: Which menu to hide. Can be either `main` or `pause` (default: `main`) -# -# @ESC -extends ESCBaseCommand -class_name HideMenuCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 0, - [TYPE_STRING], - ["main"] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not arguments[0] in ["main", "pause"]: - escoria.logger.error( - self, - "[%s]: menu %s is invalid." % [get_command_name(), arguments[0]] - ) - return false - return true - - -# Run the command -func run(command_params: Array) -> int: - var transition_id: int - - # Transition out from menu - transition_id = escoria.main.scene_transition.transition( - "", - ESCTransitionPlayer.TRANSITION_MODE.OUT - ) - - if transition_id != ESCTransitionPlayer.TRANSITION_ID_INSTANT: - while yield( - escoria.main.scene_transition, - "transition_done" - ) != transition_id: - pass - - if command_params[0] == "main": - escoria.game_scene.hide_main_menu() - elif command_params[0] == "pause": - escoria.game_scene.unpause_game() - - if escoria.main.current_scene != null: - transition_id = escoria.main.scene_transition.transition() - - if transition_id != ESCTransitionPlayer.TRANSITION_ID_INSTANT: - while yield( - escoria.main.scene_transition, - "transition_done" - ) != transition_id: - pass - - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/inc_global.gd b/addons/escoria-core/game/core-scripts/esc/commands/inc_global.gd deleted file mode 100644 index 1c161aa8..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/inc_global.gd +++ /dev/null @@ -1,59 +0,0 @@ -# `inc_global name value` -# -# Adds the given value to the specified global. -# -# **Parameters** -# -# - *name*: Name of the global to be changed -# - *value*: Value to be added (default: 1) -# -# @ESC -extends ESCBaseCommand -class_name IncGlobalCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 1, - [TYPE_STRING, TYPE_INT], - [null, 1] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.globals_manager.has(arguments[0]): - escoria.logger.error( - self, - "[%s]: invalid global. Global %s does not exist." - % [get_command_name(), arguments[0]] - ) - return false - if not escoria.globals_manager.get_global(arguments[0]) is int: - escoria.logger.error( - self, - "[%s]: invalid global. Global %s isn't an integer value." - % [get_command_name(), arguments[0]] - ) - return false - return true - - -# Run the command -func run(command_params: Array) -> int: - escoria.globals_manager.set_global( - command_params[0], - escoria.globals_manager.get_global(command_params[0]) +\ - command_params[1] - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/inventory_add.gd b/addons/escoria-core/game/core-scripts/esc/commands/inventory_add.gd deleted file mode 100644 index 6d274e53..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/inventory_add.gd +++ /dev/null @@ -1,54 +0,0 @@ -# `inventory_add item` -# -# Adds an item to the inventory. If the player is picking up an object, you may -# want to use this command in conjunction with the `set_active` command so that -# the object 'disappears' from the scene as it's added to the inventory. -# -# **Parameters** -# -# - *item*: Global ID of the `ESCItem` to add to the inventory -# -# @ESC -extends ESCBaseCommand -class_name InventoryAddCommand - - -const ILLEGAL_STRINGS = ["/"] - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 1, - [TYPE_STRING], - [null] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - for s in ILLEGAL_STRINGS: - if s in arguments[0]: - escoria.logger.error( - self, - "[%s]: invalid item name. Item name %s cannot contain the string '%s'." - % [get_command_name(), arguments[0], s] - ) - return false - - return true - - -# Run the command -func run(command_params: Array) -> int: - escoria.inventory_manager.add_item(command_params[0]) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/inventory_remove.gd b/addons/escoria-core/game/core-scripts/esc/commands/inventory_remove.gd deleted file mode 100644 index 55f04771..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/inventory_remove.gd +++ /dev/null @@ -1,54 +0,0 @@ -# `inventory_remove item` -# -# Removes an item from the inventory. You may wish to use this command in -# conjuction with the `set_active` command to show an item in the scene, -# simulating placing the item somewhere, for example. -# -# **Parameters** -# -# - *item*: Global ID of the `ESCItem` to remove from the inventory -# -# @ESC -extends ESCBaseCommand -class_name InventoryRemoveCommand - - -const ILLEGAL_STRINGS = ["/"] - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 1, - [TYPE_STRING], - [null] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - for s in ILLEGAL_STRINGS: - if s in arguments[0]: - escoria.logger.error( - self, - "[%s]: invalid item name. Item name %s cannot contain the string '%s'." - % [get_command_name(), arguments[0], s] - ) - return false - - return true - - -# Run the command -func run(command_params: Array) -> int: - escoria.inventory_manager.remove_item(command_params[0]) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/play_snd.gd b/addons/escoria-core/game/core-scripts/esc/commands/play_snd.gd deleted file mode 100644 index dad8290f..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/play_snd.gd +++ /dev/null @@ -1,58 +0,0 @@ -# `play_snd file [player]` -# -# Plays the specified sound without blocking the currently running event. -# -# **Parameters** -# -# - *file*: Sound file to play -# - *player*: Sound player to use. Can either be `_sound`, which is used to play non- -# looping sound effects; `_music`, which plays looping music; or `_speech`, which -# plays non-looping voice files (default: `_sound`) -# -# @ESC -extends ESCBaseCommand -class_name PlaySndCommand - - -# The specified sound player -var _snd_player: String - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 1, - [TYPE_STRING, TYPE_STRING], - [null, "_sound"] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[1]): - escoria.logger.error( - self, - "[%s]: invalid sound player. Sound player %s not registered." - % [get_command_name(), arguments[1]] - ) - return false - if not ResourceLoader.exists(arguments[0]): - escoria.logger.error( - self, - "[%s]: invalid parameter. File %s not found." - % [get_command_name(), arguments[0]] - ) - return false - _snd_player = arguments[1] - return true - - -# Run the command -func run(command_params: Array) -> int: - escoria.object_manager.get_object(command_params[1]).node.set_state( - command_params[0] - ) - return ESCExecution.RC_OK diff --git a/addons/escoria-core/game/core-scripts/esc/commands/print.gd b/addons/escoria-core/game/core-scripts/esc/commands/print.gd deleted file mode 100644 index 3c14a03a..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/print.gd +++ /dev/null @@ -1,34 +0,0 @@ -# `print string` -# -# Prints a message to the Godot debug window. -# Use this for debugging game state. -# -# **Parameters** -# -# - *string*: The string to log -# -# @ESC -extends ESCBaseCommand -class_name PrintCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 1, - [TYPE_STRING], - [""] - ) - - -# Run the command -func run(command_params: Array) -> int: - # Replace the names of any globals in "{ }" with their value - print(escoria.globals_manager.replace_globals(command_params[0])) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/queue_event.gd b/addons/escoria-core/game/core-scripts/esc/commands/queue_event.gd deleted file mode 100644 index 96822f7a..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/queue_event.gd +++ /dev/null @@ -1,89 +0,0 @@ -# `queue_event object event [channel] [block]` -# -# Queue an event to run. -# -# If you queue multiple events on a channel and none of them are blocking -# events, all events will effectively run at the same time. As the events are -# placed on the channel's queue, if one event contains a blocking command, the -# next event on that channel's queue won't be processed until the blocking -# command finishes. -# -# **Parameters** -# -# - object: Object that holds the ESC script with the event -# - event: Name of the event to queue -# - channel: Channel to run the event on (default: `_front`). Using a -# previously unused channel name will create a new channel. -# - block: Whether to wait for the queue to finish. This is only possible, if -# the queued event is not to be run on the same event as this command -# (default: `false`) -# -# @ESC -extends ESCBaseCommand -class_name QueueEventCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [TYPE_STRING, TYPE_STRING, TYPE_STRING, TYPE_BOOL], - [null, null, "_front", false] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[0]): - escoria.logger.error( - self, - "Object with global id %s not found." % arguments[0] - ) - return false - var node = escoria.object_manager.get_object( - arguments[0] - ).node - if not "esc_script" in node or node.esc_script == "": - escoria.logger.error( - self, - "Object with global id %s has no ESC script." % arguments[0] - ) - return false - var esc_script = escoria.esc_compiler.load_esc_file(node.esc_script) - if not arguments[1] in esc_script.events: - escoria.logger.error( - self, - "Event with name %s not found." % arguments[1] - ) - return false - if arguments[3] and not escoria.event_manager.is_channel_free(arguments[2]): - escoria.logger.error( - self, - "The queue %s doesn't accept a new event." % arguments[2] - ) - return false - return true - - -# Run the command -func run(arguments: Array) -> int: - var node = escoria.object_manager.get_object( - arguments[0] - ).node - var esc_script = escoria.esc_compiler.load_esc_file(node.esc_script) - - return escoria.event_manager.queue_event_from_esc( - esc_script, - arguments[1], # event name - arguments[2], # channel name - arguments[3] # whether to block - ) - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/queue_resource.gd b/addons/escoria-core/game/core-scripts/esc/commands/queue_resource.gd deleted file mode 100644 index faf37474..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/queue_resource.gd +++ /dev/null @@ -1,52 +0,0 @@ -# `queue_resource path [front_of_queue]` -# -# Queues the loading of the given resource into the resource cache. -# -# **Parameters** -# -# - *path*: Path of the resource to cache -# - *front_of_queue*: Whether to put the resource at the front of the -# queue in order to load it as soon as possible (default: `false`) -# -# @ESC -extends ESCBaseCommand -class_name QueueResourceCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 1, - [], - [null, false] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array) -> bool: - if not .validate(arguments): - return false - - if not ResourceLoader.exists(arguments[0]): - escoria.logger.error( - self, - "[%s]: Invalid resource. Resource %s was not found." - % [get_command_name(), arguments[0]] - ) - return false - return true - - -# Run the command -func run(command_params: Array) -> int: - escoria.resource_cache.queue_resource( - command_params[0], - command_params[1] - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/rand_global.gd b/addons/escoria-core/game/core-scripts/esc/commands/rand_global.gd deleted file mode 100644 index c7bcc240..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/rand_global.gd +++ /dev/null @@ -1,40 +0,0 @@ -# `rand_global name max_value` -# -# Sets the given global to a random integer between 0 and `max_value` -# (inclusive). e.g. Setting `max_value` to 2 could result in '0', '1' or '2' -# being returned. -# -# **Parameters** -# -# - *name*: Name of the global to set -# - *max_value*: Maximum possible integer value (inclusive) (default: 1) -# -# @ESC -extends ESCBaseCommand -class_name RandGlobalCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 1, - [TYPE_STRING, TYPE_INT], - [null, 1] - ) - - -# Run the command -func run(command_params: Array) -> int: - randomize() - var rnd = randi() % (command_params[1] + 1) - escoria.globals_manager.set_global( - command_params[0], - rnd - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/repeat.gd b/addons/escoria-core/game/core-scripts/esc/commands/repeat.gd deleted file mode 100644 index f07eee33..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/repeat.gd +++ /dev/null @@ -1,29 +0,0 @@ -# `repeat` -# -# Makes the current script loop back to the start. Currently the only way to -# exit the loop is via the `stop` command which will stop the script -# completely. -# -# @ESC -extends ESCBaseCommand -class_name RepeatCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 0, - [], - [] - ) - - -# Run the command -func run(command_params: Array) -> int: - return ESCExecution.RC_CANCEL - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/say.gd b/addons/escoria-core/game/core-scripts/esc/commands/say.gd deleted file mode 100644 index 958dc27d..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/say.gd +++ /dev/null @@ -1,130 +0,0 @@ -# `say player text [type]` -# -# Displays the specified string as dialog spoken by the player. This command -# blocks further event execution until the dialog has finished being 'said' -# (either as displayed text or as audible speech from a file). -# -# Global variables can be substituted into the text by wrapping the global -# name in braces. -# e.g. say player "I have {coin_count} coins remaining". -# -# **Parameters** -# -# - *player*: Global ID of the `ESCPlayer` or `ESCItem` object that is active. -# You can specify `current_player` in order to refer to the currently active -# player, e.g. in cases where multiple players are playable such as in games -# like Maniac Mansion or Day of the Tentacle. -# - *text*: Text to display. -# - *type*: Dialog type to use. One of `floating` or `avatar`. -# (default: the value set in the setting "Escoria/UI/Default Dialog Type") -# -# The text supports translation keys by prepending the key followed by -# a colon (`:`) to the text. -# For more details see: https://docs.escoria-framework.org/en/devel/getting_started/dialogs.html#translations -# -# Playing an audio file while the text is being -# displayed is also supported by this mechanism. -# For more details see: https://docs.escoria-framework.org/en/devel/getting_started/dialogs.html#recorded_speech -# -# Example: `say player ROOM1_PICTURE:"Picture's looking good."` -# -# @ESC -extends ESCBaseCommand -class_name SayCommand - - -const CURRENT_PLAYER_KEYWORD = "CURRENT_PLAYER" - - -var globals_regex : RegEx # Regex to match global variables in strings - - -# Constructor -func _init() -> void: - globals_regex = RegEx.new() - # Use look-ahead/behind to capture the term (i.e. global) in braces - globals_regex.compile("(?<=\\{)(.*)(?=\\})") - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [TYPE_STRING, TYPE_STRING, TYPE_STRING], - [ - null, - null, - "" - ], - [ - true, - false, - true - ] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if arguments[0].to_upper() != CURRENT_PLAYER_KEYWORD \ - and not escoria.object_manager.has(arguments[0]): - escoria.logger.error( - self, - "[%s]: Invalid object: Object with global id %s not found." - % [get_command_name(), arguments[0]] - ) - return false - - return true - - -# Run the command -func run(command_params: Array) -> int: - var dict: Dictionary - - escoria.current_state = escoria.GAME_STATE.DIALOG - - if !escoria.dialog_player: - escoria.logger.error( - self, - "[%s]: No dialog player was registered and the say command was encountered." - % get_command_name() - ) - escoria.current_state = escoria.GAME_STATE.DEFAULT - return ESCExecution.RC_ERROR - - if not escoria.main.current_scene.player: - escoria.logger.warn( - self, - "[%s]: No player item in the current scene was registered and the say command was encountered." - % get_command_name() - ) - escoria.current_state = escoria.GAME_STATE.DEFAULT - return ESCExecution.RC_CANCEL - - # Replace the names of any globals in "{ }" with their value - command_params[1] = escoria.globals_manager.replace_globals(command_params[1]) - - var speaking_character_global_id = escoria.main.current_scene.player.global_id \ - if command_params[0].to_upper() == CURRENT_PLAYER_KEYWORD \ - else command_params[0] - - escoria.dialog_player.say( - speaking_character_global_id, - command_params[2], - command_params[1] - ) - yield(escoria.dialog_player, "say_finished") - escoria.current_state = escoria.GAME_STATE.DEFAULT - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - escoria.logger.debug( - self, - "[%s] interrupt() function not implemented." % get_command_name() - ) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/sched_event.gd b/addons/escoria-core/game/core-scripts/esc/commands/sched_event.gd deleted file mode 100644 index 2424b590..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/sched_event.gd +++ /dev/null @@ -1,69 +0,0 @@ -# `sched_event time object event` -# -# Schedules an event to run at a later time. -# -# If another event is already running when the scheduled -# event is supposed to start, execution of the scheduled event -# begins when the already-running event ends. -# -# **Parameters** -# -# - *time*: Time in seconds until the scheduled event starts -# - *object*: Global ID of the ESCItem that holds the ESC script -# - *event*: Name of the event to schedule -# -# @ESC -extends ESCBaseCommand -class_name SchedEventCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 3, - [TYPE_INT, TYPE_STRING, TYPE_STRING], - [null, null, null] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[1]): - escoria.logger.error( - self, - "[%s]: invalid object. Object with global id %s not found." - % [get_command_name(), arguments[1]] - ) - return false - elif not escoria.object_manager.get_object(arguments[1]).events\ - .has(arguments[2]): - escoria.logger.error( - self, - "[%s]: invalid object event. Object with global id %s has no event %s." - % [ - get_command_name(), - arguments[1], - arguments[2], - ] - ) - return false - return true - - -# Run the command -func run(command_params: Array) -> int: - escoria.event_manager.schedule_event( - escoria.object_manager.get_object(command_params[1])\ - .events[command_params[2]], - command_params[0] - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/set_active.gd b/addons/escoria-core/game/core-scripts/esc/commands/set_active.gd deleted file mode 100644 index fce251e0..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/set_active.gd +++ /dev/null @@ -1,50 +0,0 @@ -# `set_active object active` -# -# Changes the "active" state of the object. -# Inactive objects are invisible in the room. -# -# **Parameters** -# -# - *object* Global ID of the object -# - *active* Whether `object` should be active. `active` can be `true` or `false`. -# -# @ESC -extends ESCBaseCommand -class_name SetActiveCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [TYPE_STRING, TYPE_BOOL], - [null, null] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[0]): - escoria.logger.error( - self, - "[%s]: invalid object. Object with global id %s not found." - % [get_command_name(), arguments[0]] - ) - return false - return true - - -# Run the command -func run(command_params: Array) -> int: - escoria.object_manager.get_object(command_params[0]).active = \ - command_params[1] - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/set_active_if_exists.gd b/addons/escoria-core/game/core-scripts/esc/commands/set_active_if_exists.gd deleted file mode 100644 index dbf2149c..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/set_active_if_exists.gd +++ /dev/null @@ -1,41 +0,0 @@ -# `set_active_if_exists object active` -# -# *** FOR INTERNAL USE ONLY *** -# -# Changes the "active" state of the object in the current room if it currently -# exists in the object manager. If it doesn't, then, unlike set_active, we don't -# fail and we just carry on. -# -# Inactive objects are invisible in the room. -# -# **Parameters** -# -# - *object* Global ID of the object -# - *active* Whether `object` should be active. `active` can be `true` or `false`. -# -# @ESC -extends ESCBaseCommand -class_name SetActiveIfExistsCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [TYPE_STRING, TYPE_BOOL], - [null, null] - ) - - -# Run the command -func run(command_params: Array) -> int: - if escoria.object_manager.has(command_params[0]): - escoria.object_manager.get_object(command_params[0]).active = \ - command_params[1] - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/set_angle.gd b/addons/escoria-core/game/core-scripts/esc/commands/set_angle.gd deleted file mode 100644 index a7759fbe..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/set_angle.gd +++ /dev/null @@ -1,79 +0,0 @@ -# `set_angle object target_degrees [wait]` -# -# Turns a movable `ESCItem` or `ESCPlayer` to face a given target direction. -# -# Angles 0 and 360 are the same and correspond to UP/NORTH, -# 90 is RIGHT/EAST, 180 is DOWN/SOUTH, 270 is LEFT/WEST etc. -# The rotation direction will be determined by the shortest path - e.g. -# rotating from facing up (0 degrees) to left (270) will be a 90 degree turn -# anti-clockwise rather than a 270 degree clockwise turn. -# -# The final animation used is determined by the directions which have -# been configured for the object. If the item has a direction configured which -# has been drawn to show it facing to the right, and this direction has been -# defined to cover the angle from 45 to 135 degrees, setting the target angle -# to 120 degrees will result in the right-facing animation being used. -# -# The number of intermediate animations shown while turning the -# item will depend on the directions specified in the item's definition. A 16 -# direction character will turn through 8 different directions to turn 180 -# degrees, a 4 direction character only 2. The wait time will determine how -# long the idle animation for each direction is played before using the next -# direction's animation. As such, if wait was set to 1 second, a 16 direction -# character would take 8 seconds to turn 180 degrees, a 4 direction character -# would take 2 seconds. -# -# **Parameters** -# -# - *object*: Global ID of the object to turn -# - *target_degrees*: Number of degrees by which `object` is to be turned -# - *wait*: Number of seconds to wait for while playing each animation occurring -# between the current angle of `object` and the target angle. A value of -# `0` will complete the turn immediately (default: `0`) -# -# @ESC -extends ESCBaseCommand -class_name SetAngleCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [TYPE_STRING, [TYPE_REAL, TYPE_INT], [TYPE_REAL, TYPE_INT]], - [null, null, 0.0] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[0]): - escoria.logger.error( - self, - "[%s]: invalid object. Object with global id %s not found." - % [get_command_name(), arguments[0]] - ) - return false - return true - - -# Run the command -func run(command_params: Array) -> int: - # HACK Countering the fact that angle_to_point() function gives - # angle against X axis not Y, we need to check direction using (angle-90°). - # Since the ESC command already gives the right angle, we add 90. - escoria.object_manager.get_object(command_params[0]).node\ - .set_angle( - wrapi(int(command_params[1]) + 90, 0, 360), - command_params[2] - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/set_animations.gd b/addons/escoria-core/game/core-scripts/esc/commands/set_animations.gd deleted file mode 100644 index 627008bf..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/set_animations.gd +++ /dev/null @@ -1,77 +0,0 @@ -# `set_animations object animations` -# -# Sets the animation resource for the given `ESCPlayer` or movable `ESCItem`. -# -# **Parameters** -# -# - *object*: Global ID of the object whose animation resource is to be updated -# - *animations*: The path of the animation resource to use -# -# @ESC -extends ESCBaseCommand -class_name SetAnimationsCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [TYPE_STRING, TYPE_STRING], - [null, null] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[0]): - escoria.logger.error( - self, - "[%s]: invalid object. Object with global id %s not found." - % [get_command_name(), arguments[0]] - ) - return false - if not ResourceLoader.exists(arguments[1]): - escoria.logger.error( - self, - "[%s]: invalid animation resource. The animation resource %s was not found." - % [get_command_name(), arguments[1]] - ) - return false - - (escoria.object_manager.get_object(arguments[0]).node as ESCPlayer).validate_animations(load(arguments[1])) - - return true - - -# Run the command -func run(command_params: Array) -> int: - (escoria.object_manager.get_object(command_params[0]).node as ESCPlayer)\ - .animations = load(command_params[1]) - if not escoria.globals_manager.has( - escoria.room_manager.GLOBAL_ANIMATION_RESOURCES - ): - escoria.globals_manager.set_global( - escoria.room_manager.GLOBAL_ANIMATION_RESOURCES, - {}, - true - ) - var animations = escoria.globals_manager.get_global( - escoria.room_manager.GLOBAL_ANIMATION_RESOURCES - ) - animations[command_params[0]] = command_params[1] - escoria.globals_manager.set_global( - escoria.room_manager.GLOBAL_ANIMATION_RESOURCES, - animations, - true - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass - diff --git a/addons/escoria-core/game/core-scripts/esc/commands/set_global.gd b/addons/escoria-core/game/core-scripts/esc/commands/set_global.gd deleted file mode 100644 index 88328b5f..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/set_global.gd +++ /dev/null @@ -1,61 +0,0 @@ -# `set_global name value [force=false]` -# -# Changes the value of a global. -# -# **Parameters** -# -# - *name*: Name of the global -# - *value*: Value to set the global to (can be of type string, boolean, integer -# or float) -# - *force*: if false, setting a global whose name is reserved will -# trigger an error. Defaults to false. Reserved globals are: ESC_LAST_SCENE, -# FORCE_LAST_SCENE_NULL, ANIMATION_RESOURCES, ESC_CURRENT_SCENE -# -# @ESC -extends ESCBaseCommand -class_name SetGlobalCommand - - -const ILLEGAL_STRINGS = ["/"] - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [TYPE_STRING, [TYPE_INT, TYPE_BOOL, TYPE_STRING], TYPE_BOOL], - [null, null, false] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - for s in ILLEGAL_STRINGS: - if s in arguments[0]: - escoria.logger.error( - self, - "[%s]: invalid global variable. Global variable %s cannot contain the string '%s'." - % [get_command_name(), arguments[0], s] - ) - return false - - return true - - -# Run the command -func run(command_params: Array) -> int: - escoria.globals_manager.set_global( - command_params[0], - command_params[1], - command_params[2] - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/set_globals.gd b/addons/escoria-core/game/core-scripts/esc/commands/set_globals.gd deleted file mode 100644 index a4b91166..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/set_globals.gd +++ /dev/null @@ -1,38 +0,0 @@ -# `set_globals pattern value` -# -# Changes the value of multiple globals using a wildcard pattern, where `*` -# matches zero or more arbitrary characters and `?` matches any single -# character except a period ("."). -# -# **Parameters** -# -# - *pattern*: Pattern to use to match the names of the globals to change -# - *value*: Value to set (can be of type string, boolean, integer or float) -# -# @ESC -extends ESCBaseCommand -class_name SetGlobalsCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [TYPE_STRING, [TYPE_BOOL, TYPE_STRING, TYPE_INT]], - [null, null] - ) - - -# Run the command -func run(command_params: Array) -> int: - escoria.globals_manager.set_global_wildcard( - command_params[0], - command_params[1] - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/set_gui_visible.gd b/addons/escoria-core/game/core-scripts/esc/commands/set_gui_visible.gd deleted file mode 100644 index dcc1e696..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/set_gui_visible.gd +++ /dev/null @@ -1,35 +0,0 @@ -# `set_gui_visible visible` -# -# Show or hide the GUI. -# -# **Parameters** -# -# - *visible*: Whether the GUI should be visible (`true` or `false`) -# -# @ESC -extends ESCBaseCommand -class_name SetGuiVisibleCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 1, - [TYPE_BOOL], - [null] - ) - - -# Run the command -func run(command_params: Array) -> int: - if command_params[0]: - escoria.main.current_scene.game.show_ui() - else: - escoria.main.current_scene.game.hide_ui() - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/set_interactive.gd b/addons/escoria-core/game/core-scripts/esc/commands/set_interactive.gd deleted file mode 100644 index af8f4f3e..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/set_interactive.gd +++ /dev/null @@ -1,49 +0,0 @@ -# `set_interactive object interactive` -# -# Sets whether an object is interactive. -# -# **Parameters** -# -# - *object*: Global ID of the object to change -# - *interactive*: Whether the object should be interactive -# -# @ESC -extends ESCBaseCommand -class_name SetInteractiveCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [TYPE_STRING, TYPE_BOOL], - [null, null] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[0]): - escoria.logger.error( - self, - "[%s]: invalid object. Object with global id %s not found." - % [get_command_name(), arguments[0]] - ) - return false - return true - - -# Run the command -func run(command_params: Array) -> int: - escoria.object_manager.get_object(command_params[0]).interactive = \ - command_params[1] - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/set_speed.gd b/addons/escoria-core/game/core-scripts/esc/commands/set_speed.gd deleted file mode 100644 index 6c1698e5..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/set_speed.gd +++ /dev/null @@ -1,47 +0,0 @@ -# `set_speed object speed` -# -# Sets the speed of a `ESCPlayer` or movable `ESCItem`. -# -# **Parameters** -# -# - *object*: Global ID of the `ESCPlayer` or movable `ESCItem` -# - *speed*: Speed value for `object` in pixels per second. -# -# @ESC -extends ESCBaseCommand -class_name SetSpeedCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [TYPE_STRING, TYPE_INT], - [null, null] - ) - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[0]): - escoria.logger.error( - self, - "[%s]: invalid object. Object with global id %s not found." - % [get_command_name(), arguments[0]] - ) - return false - return true - -# Run the command -func run(command_params: Array) -> int: - (escoria.object_manager.get_object(command_params[0]).node as ESCItem).\ - set_speed(command_params[1]) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/set_state.gd b/addons/escoria-core/game/core-scripts/esc/commands/set_state.gd deleted file mode 100644 index 9de99887..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/set_state.gd +++ /dev/null @@ -1,62 +0,0 @@ -# `set_state object state [immediate]` -# -# Changes the state of `object` to the one specified. -# This command is primarily used to play animations. -# -# If the specified object's associated animation player has an animation -# with the same name, that animation is also played. -# -# When the "state" of the object is set - for example, a door may be set -# to a "closed" state - this plays the matching "close" animation if one exists -# (to show the door closing in the game). When you re-enter the room (via a -# different entry), or restore a saved game, the state of the door object -# will be restored - showing the door as a closed door. -# -# **Parameters** -# -# - *object*: Global ID of the object whose state is to be changed -# - *immediate*: If an animation for the state exists, specifies -# whether it is to skip to the last frame. Can be `true` or `false`. -# -# @ESC -extends ESCBaseCommand -class_name SetStateCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [TYPE_STRING, TYPE_STRING, TYPE_BOOL], - [null, null, false] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[0]): - escoria.logger.error( - self, - "[%s]: invalid object. Object %s not found." - % [get_command_name(), arguments[0]] - ) - return false - return true - - -# Run the command -func run(command_params: Array) -> int: - (escoria.object_manager.get_object(command_params[0]) as ESCObject).set_state( - command_params[1], - command_params[2] - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/show_menu.gd b/addons/escoria-core/game/core-scripts/esc/commands/show_menu.gd deleted file mode 100644 index c8dd5dd7..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/show_menu.gd +++ /dev/null @@ -1,77 +0,0 @@ -# `show_menu menu_type` -# -# Shows either the main menu or the pause menu. Transitions to the menu using -# the default transition type (set in the Escoria project settings). -# -# **Parameters** -# -# - *menu_type*: Which menu to show. Can be either `main` or `pause` (default: `main`) -# -# @ESC -extends ESCBaseCommand -class_name ShowMenuCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 0, - [TYPE_STRING], - ["main"] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not arguments[0] in ["main", "pause"]: - escoria.logger.error( - self, - "[%s]: menu %s is invalid." % [get_command_name(), arguments[0]] - ) - return false - return true - - -# Run the command -func run(command_params: Array) -> int: - if not escoria.game_scene.is_inside_tree(): - escoria.add_child(escoria.game_scene) - - # Transition out from current scene - var transition_id = escoria.main.scene_transition.transition( - "", - ESCTransitionPlayer.TRANSITION_MODE.OUT - ) - - if transition_id != ESCTransitionPlayer.TRANSITION_ID_INSTANT: - while yield( - escoria.main.scene_transition, - "transition_done" - ) != transition_id: - pass - - if command_params[0] == "main": - escoria.game_scene.show_main_menu() - elif command_params[0] == "pause": - escoria.game_scene.pause_game() - - # Transition in to menu - transition_id = escoria.main.scene_transition.transition() - - if transition_id != ESCTransitionPlayer.TRANSITION_ID_INSTANT: - while yield( - escoria.main.scene_transition, - "transition_done" - ) != transition_id: - pass - - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/slide.gd b/addons/escoria-core/game/core-scripts/esc/commands/slide.gd deleted file mode 100644 index 158d545a..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/slide.gd +++ /dev/null @@ -1,122 +0,0 @@ -# `slide object target [speed]` -# -# Moves `object` towards the position of `target`. This command is -# non-blocking. -# -# - *object*: Global ID of the object to move -# - *target*: Global ID of the target object -# - *speed*: The speed at which to slide in pixels per second (will default to -# the speed configured on the `object`) -# -# **Warning** This command does not respect the room's navigation polygons, so -# `object` can be moved even when outside walkable areas. -# -# @ESC -extends ESCBaseCommand -class_name SlideCommand - - -# A hash of tweens currently active for animated items -var _tweens: Dictionary - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [TYPE_STRING, TYPE_STRING, TYPE_INT], - [null, null, -1] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[0]): - escoria.logger.error( - self, - "[%s]: invalid first object. Object with global id %s not found." - % [get_command_name(), arguments[0]] - ) - return false - if not escoria.object_manager.has(arguments[1]): - escoria.logger.error( - self, - "[%s]: invalid second object. Object with global id %s not found." - % [get_command_name(), arguments[1]] - ) - return false - return true - - -# Slide the object by generating a tween -# -# #### Parameters -# -# - *source*: The item to slide -# - *destination*: The destination item to slide to -# - *speed*: The speed at which to slide in pixels per second (will default to -# the speed configured on the `object`) -# -# -# **Returns** The generated (and started) tween -func _slide_object( - source: ESCObject, - destination: ESCObject, - speed: int = -1 -) -> Tween: - if speed == -1: - speed = source.node.speed - - if _tweens.has(source.global_id): - var tween = (_tweens.get(source.global_id) as Tween) - tween.stop_all() - if (escoria.main as Node).has_node(tween.name): - (escoria.main as Node).remove_child(tween) - - var tween = Tween.new() - (escoria.main as Node).add_child(tween) - - tween.connect("tween_completed", self, "_on_tween_completed") - - var duration = source.node.position.distance_to( - destination.node.position - ) / speed - - tween.interpolate_property( - source.node, - "global_position", - source.node.global_position, - destination.node.global_position, - duration - ) - - tween.start() - - _tweens[source.global_id] = tween - - return tween - - - -# Run the command -func run(command_params: Array) -> int: - _slide_object( - escoria.object_manager.get_object(command_params[0]), - escoria.object_manager.get_object(command_params[1]), - command_params[2] - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - for tween in _tweens: - tween.stop_all() - - -func _on_tween_completed(tween: Tween, _key: NodePath): - if tween: - tween.queue_free() diff --git a/addons/escoria-core/game/core-scripts/esc/commands/slide_block.gd b/addons/escoria-core/game/core-scripts/esc/commands/slide_block.gd deleted file mode 100644 index c88b616f..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/slide_block.gd +++ /dev/null @@ -1,32 +0,0 @@ -# `slide_block object target [speed]` -# -# Moves `object` towards the position of `target`. This command is -# blocking. -# -# - *object*: Global ID of the object to move -# - *target*: Global ID of the target object -# - *speed*: The speed at which to slide in pixels per second (will default to -# the speed configured on the `object`) -# -# **Warning** This command does not respect the room's navigation polygons, so -# `object` can be moved even when outside walkable areas. -# -# @ESC -extends SlideCommand -class_name SlideBlockCommand - - -# Run the command -func run(command_params: Array) -> int: - var tween = _slide_object( - escoria.object_manager.get_object(command_params[0]), - escoria.object_manager.get_object(command_params[1]), - command_params[2] - ) - yield(tween, "tween_all_completed") - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - .interrupt() diff --git a/addons/escoria-core/game/core-scripts/esc/commands/spawn.gd b/addons/escoria-core/game/core-scripts/esc/commands/spawn.gd deleted file mode 100644 index f91c9b47..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/spawn.gd +++ /dev/null @@ -1,95 +0,0 @@ -# `spawn identifier path [is_active] [position_target]` -# -# Programmatically adds a new item to the scene. -# -# **Parameters** -# -# - *identifier*: Global ID to use for the new object -# - *path*: Path to the scene file of the object -# - *is_active*: Whether the new object should be set to active (default: `true`) -# - *position_target*: Global ID of another object that will be used to -# position the new object (when omitted, the new object's position is not specified) -# -# @ESC -extends ESCBaseCommand -class_name SpawnCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [TYPE_STRING, TYPE_STRING, TYPE_BOOL, TYPE_STRING], - [null, null, true, null] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if arguments[0].empty() \ - or arguments[0] in escoria.object_manager.RESERVED_OBJECTS: - escoria.logger.error( - self, - "[%s]: global_id (%s) is invalid. The global_id was either empty or is reserved." - % [get_command_name(), arguments[0]] - ) - return false - if not ResourceLoader.exists(arguments[1]): - escoria.logger.error( - self, - "[%s]: Invalid scene path: %s not found." - % [get_command_name(), arguments[1]] - ) - return false - if arguments[3] and not escoria.object_manager.has(arguments[3]): - escoria.logger.error( - self, - "[%s]: invalid object: Object with global id %s not found." - % [get_command_name(), arguments[3]] - ) - return false - return true - - -# Run the command -func run(command_params: Array) -> int: - var res_scene = escoria.resource_cache.get_resource(command_params[1]) - - # Load room scene - var scene = res_scene.instance() - if scene: - escoria.main.get_node("/root").add_child(scene) - if command_params[3]: - var obj = escoria.object_manager.get_object(command_params[3]) - scene.set_position(obj.get_global_position()) - escoria.inputs_manager.hotspot_focused = "" - - escoria.object_manager.register_object( - ESCObject.new( - command_params[0], - scene - ), - null, - true - ) - - escoria.object_manager.get_object(command_params[0]).active = \ - command_params[2] - - else: - escoria.logger.error( - self, - "[%s]: Invalid scene. Failed to load scene %s." - % [get_command_name(), command_params[1]] - ) - - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/stop.gd b/addons/escoria-core/game/core-scripts/esc/commands/stop.gd deleted file mode 100644 index 7b59f333..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/stop.gd +++ /dev/null @@ -1,29 +0,0 @@ -# `stop` -# -# Stops the current event's execution. Note that this will stop the current -# script entirely - if you're within a conditional block, the code after the -# conditional block will not be executed. -# -# @ESC -extends ESCBaseCommand -class_name StopCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 0, - [], - [] - ) - - -# Run the command -func run(command_params: Array) -> int: - return ESCExecution.RC_CANCEL - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/stop_snd.gd b/addons/escoria-core/game/core-scripts/esc/commands/stop_snd.gd deleted file mode 100644 index c9c9b12b..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/stop_snd.gd +++ /dev/null @@ -1,68 +0,0 @@ -# `stop_snd [audio_bus]` -# -# Stops the given audio bus's stream. -# -# By default there are 3 audio buses set up by Escoria : `_sound`, which is -# used to play non-looping sound effects; `_music`, which plays looping music; -# and `_speech`, which plays non-looping voice files (default: `_music`). -# -# Each simultaneous sound (e.g. multiple game sound effects) will require its -# own bus. To create additional buses, see the Godot sound documentation : -# [Audio buses](https://docs.godotengine.org/en/stable/tutorials/audio/audio_buses.html#doc-audio-buses) -# -# **Parameters** -# -# - *audio_bus*: Bus to stop ("_sound", "_music", "_speech", or a custom -# audio bus you have created.) -# -# @ESC -extends ESCBaseCommand -class_name StopSndCommand - - -# The specified sound player -var _snd_player: String - -# The previous sound state, saved for interrupting -var previous_snd_state: String - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 0, - [TYPE_STRING], - ["_music"] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[0]): - escoria.logger.error( - self, - "[%s]: invalid sound player. Sound player %s not registered." - % [get_command_name(), arguments[0]] - ) - return false - _snd_player = arguments[0] - return true - - -# Run the command -func run(command_params: Array) -> int: - previous_snd_state = escoria.object_manager.get_object(command_params[0]).node.state - escoria.object_manager.get_object(command_params[0]).node.set_state( - "off" - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - escoria.object_manager.get_object(_snd_player).node.set_state( - previous_snd_state - ) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/teleport.gd b/addons/escoria-core/game/core-scripts/esc/commands/teleport.gd deleted file mode 100644 index af276ea1..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/teleport.gd +++ /dev/null @@ -1,68 +0,0 @@ -# `teleport object target` -# -# Instantly moves an object to a new position. -# -# **Parameters** -# -# - *object*: Global ID of the object to move -# - *target*: Global ID of the object to use as the destination coordinates -# for `object` -# -# @ESC -extends ESCBaseCommand -class_name TeleportCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [TYPE_STRING, TYPE_STRING], - [null, null] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[0]): - escoria.logger.error( - self, - "[%s]: invalid first object. Object to teleport with global id %s not found." - % [get_command_name(), arguments[0]] - ) - return false - - if not (escoria.object_manager.get_object(arguments[0]).node as ESCItem): - escoria.logger.error( - self, - "[%s]: invalid first object. Object to teleport with global id %s must be of or derived from type ESCItem." - % [get_command_name(), arguments[0]] - ) - return false - - if not escoria.object_manager.has(arguments[1]): - escoria.logger.error( - self, - "[%s]: invalid second object. Destination location to teleport to with global id %s not found." - % [get_command_name(), arguments[1]] - ) - return false - return true - - -# Run the command -func run(command_params: Array) -> int: - (escoria.object_manager.get_object(command_params[0]).node as ESCItem) \ - .teleport( - escoria.object_manager.get_object(command_params[1]).node - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/teleport_pos.gd b/addons/escoria-core/game/core-scripts/esc/commands/teleport_pos.gd deleted file mode 100644 index e2a8bba5..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/teleport_pos.gd +++ /dev/null @@ -1,62 +0,0 @@ -# `teleport_pos object x y` -# -# Instantly moves an object to the specified (absolute) coordinates. -# -# **Parameters** -# -# - *object*: Global ID of the object to move -# - *x*: X-coordinate of destination position -# - *y*: Y-coordinate of destination position -# -# @ESC -extends ESCBaseCommand -class_name TeleportPosCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 3, - [TYPE_STRING, TYPE_INT, TYPE_INT], - [null, null, null] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[0]): - escoria.logger.error( - self, - "[%s]: invalid first object. Object to teleport with global id %s not found." - % [get_command_name(), arguments[0]] - ) - return false - - if not (escoria.object_manager.get_object(arguments[0]).node as ESCItem): - escoria.logger.error( - self, - "[%s]: invalid first object. Object to teleport with global id %s must be of or derived from type ESCItem." - % [get_command_name(), arguments[0]] - ) - return false - - return true - - -# Run the command -func run(command_params: Array) -> int: - (escoria.object_manager.get_object(command_params[0]).node as ESCItem) \ - .teleport_to( - Vector2(int(command_params[1]), int(command_params[2]) - ) - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/transition.gd b/addons/escoria-core/game/core-scripts/esc/commands/transition.gd deleted file mode 100644 index d67f2846..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/transition.gd +++ /dev/null @@ -1,90 +0,0 @@ -# `transition transition_name mode [delay]` -# -# Runs a transition effect - generally used when entering or leaving a room. -# Transitions are implemented as Godot shaders. Custom transitions can be made -# by creating a shader in the `game/scenes/transitions/shaders/` folder within -# the escoria-core plugin folder. -# -# **Parameters** -# -# - *transition_name*: Name of the transition shader from one of the transition -# directories -# - *mode*: Set to `in` to transition into or `out` to transition out of the room -# - *delay*: Delay in seconds before starting the transition (default: `1.0`) -# -# @ESC -extends ESCBaseCommand -class_name TransitionCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [TYPE_STRING, TYPE_STRING, TYPE_REAL], - [null, null, 1.0] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.main.scene_transition.has_transition(arguments[0]) \ - and not arguments[0].empty(): - escoria.logger.error( - self, - "[%s]: argument invalid. Transition with name '%s' doesn't exist." - % [get_command_name(), arguments[0]] - ) - return false - if not arguments[1] in ["in", "out"]: - escoria.logger.error( - self, - "[%s]: argument invalid" + - "Transition type 'in' or 'out' expected, but '%s' was provided." - % [get_command_name(), arguments[1]] - ) - return false - return true - - -# Run the command -func run(command_params: Array) -> int: - var transition_id = escoria.main.scene_transition.transition( - command_params[0], - ESCTransitionPlayer.TRANSITION_MODE.OUT if command_params[1] == "out" \ - else ESCTransitionPlayer.TRANSITION_MODE.IN, - command_params[2] - ) - - if transition_id == ESCTransitionPlayer.TRANSITION_ID_INSTANT: - escoria.logger.debug( - self, - "Performing instant transition." - ) - escoria.main.scene_transition.reset_shader_cutoff() - return ESCExecution.RC_OK - - escoria.logger.debug( - self, - "Starting transition #%s [%s, %s]." - % [transition_id, command_params[0], command_params[1]] - ) - while yield( - escoria.main.scene_transition, - "transition_done" - ) != transition_id: - pass - escoria.logger.debug( - self, - "Ending transition #%s [%s, %s]." - % [transition_id, command_params[0], command_params[1]]) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - # Do nothing - pass diff --git a/addons/escoria-core/game/core-scripts/esc/commands/turn_to.gd b/addons/escoria-core/game/core-scripts/esc/commands/turn_to.gd deleted file mode 100644 index 4fe4c120..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/turn_to.gd +++ /dev/null @@ -1,79 +0,0 @@ -# `turn_to object object_to_face [wait]` -# -# Turns `object` to face another object. -# -# Unlike movement commands, `turn_to` will not automatically reference an -# `ESCLocation` that is a child of an `ESCItem.` -# To turn towards an `ESCLocation` that is a child of an `ESCItem`, give the -# `ESCLocation` a `Global ID` and use this value as the `object_to_face` -# parameter. -# -# While turning, the number of directions the item faces will depend on -# the number of `directions` defined for the object. A 16 direction character -# for example will display 8 directions of animation while turning to face an -# object that is 180 degrees away, a 4 direction character would only face 2 -# directions to make the same turn. As the idle animation will be played for -# `wait` seconds for each direction the object faces, a 16 direction character -# would take 8 seconds to rotate 180 degrees with a 1 second `wait` time, -# whereas a 4 direction character would only take 2 seconds to make the same -# rotation. -# -# **Parameters** -# -# - *object*: Global ID of the object to be turned -# - *object_to_face*: Global ID of the object to turn towards -# - *wait*: Length of time to wait in seconds for each intermediate angle. -# If set to 0, the turnaround is immediate (default: `0`) -# -# @ESC -extends ESCBaseCommand -class_name TurnToCommand - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [TYPE_STRING, TYPE_STRING, TYPE_REAL], - [null, null, 0.0] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[0]): - escoria.logger.error( - self, - "[%s]: Cannot turn \"%s\". Object not found." - % [get_command_name(), arguments[0]] - ) - return false - if not escoria.object_manager.has(arguments[1]): - escoria.logger.error( - self, - "[%s]: Cannot turn \"%s\" towards \"%s\". \"%s\" was not found." - % [get_command_name(), arguments[0], arguments[1] , arguments[1]] - ) - return false - return true - - -# Run the command -func run(command_params: Array) -> int: - (escoria.object_manager.get_object(command_params[0]).node as ESCItem)\ - .turn_to( - escoria.object_manager.get_object(command_params[1]).node, - command_params[2] - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - escoria.logger.debug( - self, - "[%s] interrupt() function not implemented." % get_command_name() - ) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/wait.gd b/addons/escoria-core/game/core-scripts/esc/commands/wait.gd deleted file mode 100644 index d408e6c3..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/wait.gd +++ /dev/null @@ -1,58 +0,0 @@ -# `wait seconds` -# -# Blocks execution of the current event. -# -# **Parameters** -# -# - *seconds*: Number of seconds to block -# -# @ESC -extends ESCBaseCommand -class_name WaitCommand - -# Timer to wait for -var timer: Timer - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 1, - [[TYPE_INT, TYPE_REAL]], - [null] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - # We can't wait for 0 or fewer seconds, now, can we? - if arguments[0] <= 0.0: - escoria.logger.error( - self, - "[%s]: argument invalid. %s is an invalid amount of time to wait (must be positive)." - % [get_command_name(), arguments[0]] - ) - return false - - return true - -# Run the command -func run(command_params: Array) -> int: - timer = Timer.new() - timer.wait_time = float(command_params[0]) - escoria.add_child(timer) - timer.start() - yield(timer, "timeout") - escoria.remove_child(timer) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - if timer == null: - return - - timer.emit_signal("timeout") diff --git a/addons/escoria-core/game/core-scripts/esc/commands/walk.gd b/addons/escoria-core/game/core-scripts/esc/commands/walk.gd deleted file mode 100644 index a5debcda..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/walk.gd +++ /dev/null @@ -1,77 +0,0 @@ -# `walk object target [walk_fast]` -# -# Moves the specified `ESCPlayer` or movable `ESCItem` to the `target` -# ESCItem's location while playing `object`'s walking animation. This command -# is non-blocking. -# This command will use the normal walk speed by default. -# If the `target` ESCItem has a child ESCLocation node, the walk destination -# will be the position of the ESCLocation. -# -# **Parameters** -# -# - *object*: Global ID of the object to move -# - *target*: Global ID of the target object -# - *walk_fast*: Whether to walk fast (`true`) or normal speed (`false`) -# (default: false) -# -# @ESC -extends ESCBaseCommand -class_name WalkCommand - - -# Walking object -var walking_object_node: ESCItem - -# Target object -var target_object_node: ESCObject - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [TYPE_STRING, TYPE_STRING, TYPE_BOOL], - [null, null, false] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[0]): - escoria.logger.error( - self, - "[%s]: invalid first object. The object with global id %s to make walk was not found." - % [get_command_name(), arguments[0]] - ) - return false - if not escoria.object_manager.has(arguments[1]): - escoria.logger.error( - self, - "[%s]: invalid second object. The object to walk to with global id %s was not found." - % [get_command_name(), arguments[1]] - ) - return false - - walking_object_node = (escoria.object_manager.get_object( - arguments[0]).node as ESCItem - ) - target_object_node = escoria.object_manager.get_object(arguments[1]) - return true - - -# Run the command -func run(command_params: Array) -> int: - escoria.action_manager.do( - escoria.action_manager.ACTION.BACKGROUND_CLICK, - command_params - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - if walking_object_node != null: - walking_object_node.stop_walking_now() diff --git a/addons/escoria-core/game/core-scripts/esc/commands/walk_block.gd b/addons/escoria-core/game/core-scripts/esc/commands/walk_block.gd deleted file mode 100644 index d3179478..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/walk_block.gd +++ /dev/null @@ -1,79 +0,0 @@ -# `walk_block object target [walk_fast]` -# -# Moves the specified `ESCPlayer` or movable `ESCItem` to the `target` -# ESCItem's location while playing `object`'s walking animation. This command -# is blocking. -# This command will use the normal walk speed by default. -# If the `target` ESCItem has a child ESCLocation node, the walk destination -# will be the position of the ESCLocation. -# -# **Parameters** -# -# - *object*: Global ID of the object to move -# - *target*: Global ID of the target object -# - *walk_fast*: Whether to walk fast (`true`) or normal speed (`false`). -# (default: false) -# -# @ESC -extends ESCBaseCommand -class_name WalkBlockCommand - - -# Walking object -var walking_object_node: ESCItem - -# Target object -var target_object_node: ESCObject - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 2, - [TYPE_STRING, TYPE_STRING, TYPE_BOOL], - [null, null, false] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[0]): - escoria.logger.error( - self, - "[%s]: invalid first object. The object to make walk with global id %s was not found." - % [get_command_name(), arguments[0]] - ) - return false - if not escoria.object_manager.has(arguments[1]): - escoria.logger.error( - self, - "[%s]: invalid second object. The object to walk to with global id %s was not found." - % [get_command_name(), arguments[1]] - ) - return false - - walking_object_node = (escoria.object_manager.get_object( - arguments[0]).node as ESCItem - ) - target_object_node = escoria.object_manager.get_object(arguments[1]) - return true - - -# Run the command -func run(command_params: Array) -> int: - escoria.action_manager.do( - escoria.action_manager.ACTION.BACKGROUND_CLICK, - command_params - ) - yield(walking_object_node, "arrived") - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - if walking_object_node != null and is_instance_valid(walking_object_node) \ - and not walking_object_node is ESCPlayer: - walking_object_node.stop_walking_now() diff --git a/addons/escoria-core/game/core-scripts/esc/commands/walk_to_pos.gd b/addons/escoria-core/game/core-scripts/esc/commands/walk_to_pos.gd deleted file mode 100644 index d24faccd..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/walk_to_pos.gd +++ /dev/null @@ -1,65 +0,0 @@ -# `walk_to_pos object x y [walk_fast]` -# -# Moves the specified `ESCPlayer` or movable `ESCItem` to the absolute -# coordinates provided while playing the `object`'s walking animation. -# This command is non-blocking. -# This command will use the normal walk speed by default. -# -# **Parameters** -# -# - *object*: Global ID of the object to move -# - *x*: X-coordinate of target position -# - *y*: Y-coordinate of target position -# - *walk_fast*: Whether to walk fast (`true`) or normal speed (`false`). -# (default: false) -# -# @ESC -extends ESCBaseCommand -class_name WalkToPosCommand - - -# Walking object -var walking_object_node: ESCItem - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 3, - [TYPE_STRING, TYPE_INT, TYPE_INT, TYPE_BOOL], - [null, null, null, false] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[0]): - escoria.logger.error( - self, - "[%s]: invalid first object. The object to make walk with global id %s was not found." - % [get_command_name(), arguments[0]] - ) - return false - - walking_object_node = (escoria.object_manager.get_object( - arguments[0]).node as ESCItem - ) - return true - - -# Run the command -func run(command_params: Array) -> int: - escoria.action_manager.do(escoria.action_manager.ACTION.BACKGROUND_CLICK, [ - command_params[0], - Vector2(command_params[1], command_params[2]), command_params[3] - ]) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - if walking_object_node != null and not walking_object_node is ESCPlayer: - walking_object_node.stop_walking_now() diff --git a/addons/escoria-core/game/core-scripts/esc/commands/walk_to_pos_block.gd b/addons/escoria-core/game/core-scripts/esc/commands/walk_to_pos_block.gd deleted file mode 100644 index 4776cd29..00000000 --- a/addons/escoria-core/game/core-scripts/esc/commands/walk_to_pos_block.gd +++ /dev/null @@ -1,69 +0,0 @@ -# `walk_to_pos_block object x y [walk_fast]` -# -# Moves the specified `ESCPlayer` or movable `ESCItem` to the absolute -# coordinates provided while playing the `object`'s walking animation. -# This command is blocking. -# This command will use the normal walk speed by default. -# -# **Parameters** -# -# - *object*: Global ID of the object to move -# - *x*: X-coordinate of target position -# - *y*: Y-coordinate of target position -# - *walk_fast*: Whether to walk fast (`true`) or normal speed (`false`). -# (default: false) -# -# @ESC -extends ESCBaseCommand -class_name WalkToPosBlockCommand - - -# Walking object -var walking_object_node: ESCItem - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - return ESCCommandArgumentDescriptor.new( - 3, - [TYPE_STRING, TYPE_INT, TYPE_INT, TYPE_BOOL], - [null, null, null, false] - ) - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array): - if not .validate(arguments): - return false - - if not escoria.object_manager.has(arguments[0]): - escoria.logger.error( - self, - "[%s]: invalid first object. The object to make walk with global id %s was not found." - % [get_command_name(), arguments[0]] - ) - return false - - walking_object_node = (escoria.object_manager.get_object( - arguments[0]).node as ESCItem - ) - return true - - -# Run the command -func run(command_params: Array) -> int: - escoria.action_manager.do(escoria.action_manager.ACTION.BACKGROUND_CLICK, [ - command_params[0], - Vector2(command_params[1], command_params[2]), command_params[3] - ]) - yield( - (escoria.object_manager.get_object(command_params[0]).node as ESCItem), - "arrived" - ) - return ESCExecution.RC_OK - - -# Function called when the command is interrupted. -func interrupt(): - if walking_object_node != null and not walking_object_node is ESCPlayer: - walking_object_node.stop_walking_now() diff --git a/addons/escoria-core/game/core-scripts/esc/esc_action_manager.gd b/addons/escoria-core/game/core-scripts/esc/esc_action_manager.gd deleted file mode 100644 index 877f341c..00000000 --- a/addons/escoria-core/game/core-scripts/esc/esc_action_manager.gd +++ /dev/null @@ -1,769 +0,0 @@ -# Manages currently carried out actions -extends Resource -class_name ESCActionManager - - -# The current action verb was changed -signal action_changed - -# Emitted, when an action has been completed -signal action_finished - -# Emitted when the action input state has changed -signal action_input_state_changed - - -# States of the action input (verb, item, target) -# (I) -> AWAITING_VERB_OR_ITEM -> AWAITING_ITEM -> COMPLETED -> (E) -# or -# (I) -> AWAITING_VERB_OR_ITEM -> AWAITING_ITEM -> AWAITING_TARGET_ITEM -> COMPLETED -> (E) -# or -# (I) -> AWAITING_VERB_OR_ITEM -> AWAITING_VERB -> AWAITING_VERB_CONFIRMATION -> COMPLETED -> (E) -enum ACTION_INPUT_STATE { - # Initial state - AWAITING_VERB_OR_ITEM, - # After initial state, verb is defined - AWAITING_ITEM, - # Item defined requires combine, waiting for  target - AWAITING_TARGET_ITEM - # After initial state, item is defined - AWAITING_VERB, - # Item was defined first, next verb, need verb confirmation - AWAITING_VERB_CONFIRMATION, - # Final state - COMPLETED -} - -# Actions understood by the do(...) method -# * BACKGROUND_CLICK: Object is to move from its current position -# * ITEM_LEFT_CLICK: Item has been clicked on with LMB. -# * ITEM_RIGHT_CLICK: Item has been clicked on with RMB. -# * TRIGGER_IN: Character has moved into a trigger area. -# * TRIGGER_OUT: Character has moved out of a trigger area. -enum ACTION { - BACKGROUND_CLICK, - ITEM_LEFT_CLICK, - ITEM_RIGHT_CLICK, - TRIGGER_IN, - TRIGGER_OUT -} - - -# Basic required internal actions -const ACTION_ARRIVED = "arrived" -const ACTION_EXIT_SCENE = "exit_scene" -const ACTION_WALK = "walk" - - -# Current verb used -var current_action: String = "" setget set_current_action - -# Current tool (ESCItem/ESCInventoryItem) used -var current_tool: ESCObject - -# Current target where the tool is being used on/with (if any) -var current_target: ESCObject - -# Current action input state -var action_state = ACTION_INPUT_STATE.AWAITING_VERB_OR_ITEM \ - setget set_action_input_state - - -# Run a generic action -# -# #### Parameters -# -# - action: type of the action to run -# - params: Parameters for the action -# - BACKGROUND_CLICK: [moving_obj, target, walk_fast] -# - ITEM_LEFT_CLICK: [item, input_event] -# - ITEM_RIGHT_CLICK: [item, input_event] -# - TRIGGER_IN: [trigger_id, object_id, trigger_in_verb] -# - TRIGGER_OUT: [trigger_id, object_id, trigger_out_verb] -# - can_interrupt: if true, this command will interrupt any ongoing event -# before it is finished -func do(action: int, params: Array = [], can_interrupt: bool = false) -> void: - if escoria.current_state == escoria.GAME_STATE.DEFAULT: - match action: - ACTION.BACKGROUND_CLICK: - if can_interrupt: - escoria.event_manager.interrupt() - - var walk_fast = false - if params.size() > 2: - walk_fast = true if params[2] else false - - # Check moving object. - if not escoria.object_manager.has(params[0]): - escoria.logger.error( - self, - "Walk action requested for nonexisting object: %s." - % params[0] - ) - return - - var moving_obj = escoria.object_manager.get_object(params[0]) - var target - - if params[1] is String: - if not escoria.object_manager.has(params[1]): - escoria.logger.error( - self, - "Walk action requested to nonexisting destination object: %s." - % params[1] - ) - return - - target = escoria.object_manager.get_object(params[1]) - elif params[1] is Vector2: - target = params[1] - - self.perform_walk(moving_obj, target, walk_fast) - - ACTION.ITEM_LEFT_CLICK: - if params[0] is String: - escoria.logger.info( - self, - "item_left_click on item %s." % params[0] - ) - - if can_interrupt: - escoria.event_manager.interrupt() - - var item = escoria.object_manager.get_object(params[0]) - - self.perform_inputevent_on_object(item, params[1]) - - ACTION.ITEM_RIGHT_CLICK: - if params[0] is String: - escoria.logger.info( - self, - "item_right_click on item %s." % params[0] - ) - - if can_interrupt: - escoria.event_manager.interrupt() - - var item = escoria.object_manager.get_object(params[0]) - - self.perform_inputevent_on_object(item, params[1], true) - - ACTION.TRIGGER_IN: - var trigger_id = params[0] - var object_id = params[1] - var trigger_in_verb = params[2] - escoria.logger.info( - self, - "trigger_in on trigger %s activated by %s." % [ - trigger_id, - object_id - ] - ) - escoria.event_manager.queue_event( - escoria.object_manager.get_object(trigger_id).events[ - trigger_in_verb - ] - ) - - ACTION.TRIGGER_OUT: - var trigger_id = params[0] - var object_id = params[1] - var trigger_out_verb = params[2] - escoria.logger.info( - self, - "trigger_out on trigger %s activated by %s." % [ - trigger_id, - object_id - ] - ) - escoria.event_manager.queue_event( - escoria.object_manager.get_object(trigger_id).events[ - trigger_out_verb - ] - ) - - _: - escoria.logger.warn( - self, - "Action received: %s with params %s.", [action, params] - ) - elif escoria.current_state == escoria.GAME_STATE.WAIT: - pass - - -# Sets the current state of action input. -# -# ## Parameters -# - p_state: the action input state to set -func set_action_input_state(p_state): - action_state = p_state - emit_signal("action_input_state_changed") - - -# Set the current action verb -# -# ## Parameters -# - action: The action verb to set -func set_current_action(action: String): - if action != current_action: - clear_current_tool() - - current_action = action - - if action_state == ACTION_INPUT_STATE.AWAITING_VERB_OR_ITEM: - set_action_input_state(ACTION_INPUT_STATE.AWAITING_ITEM) - elif action_state == ACTION_INPUT_STATE.AWAITING_VERB: - set_action_input_state(ACTION_INPUT_STATE.AWAITING_VERB_CONFIRM) - - emit_signal("action_changed") - - -# Clear the current action -func clear_current_action(): - set_current_action("") - set_action_input_state(ACTION_INPUT_STATE.AWAITING_VERB_OR_ITEM) - emit_signal("action_changed") - - -# Clear the current tool -func clear_current_tool(): - current_tool = null - current_target = null - if action_state == ACTION_INPUT_STATE.AWAITING_VERB: - set_action_input_state(ACTION_INPUT_STATE.AWAITING_VERB_OR_ITEM) - elif action_state == ACTION_INPUT_STATE.AWAITING_TARGET_ITEM: - set_action_input_state(ACTION_INPUT_STATE.AWAITING_ITEM) - - -# Checks if the specified action is valid and returns the associated event; -# otherwise, we see if there's a "fallback" event and use that if necessary and, -# if not, we return no event as there's nothing to do. -# -# #### Parameters -# -# - action: Action to execute (defined in attached ESC file and in -# action verbs UI) eg: arrived, use, look, pickup... -# - target: Target ESC object -# - combine_with: ESC object to combine with -# -# *Returns* the appropriate ESCEvent to queue/run, or null if none can be found -# or there's a reason not to run an event. -func _get_event_to_queue( - action: String, - target: ESCObject, - combine_with: ESCObject = null -) -> ESCEvent: - - escoria.logger.info( - self, - "Checking if action '%s' on '%s' is valid..." % [action, target] - ) - - var event_to_return: ESCEvent = null - - # If we're using an action which item requires to combine - if target.node is ESCItem \ - and action in target.node.combine_when_selected_action_is_in: - - # Check if object must be in inventory to be used - if target.node.use_from_inventory_only: - if escoria.inventory_manager.inventory_has(target.global_id): - # Player has item in inventory, we check the element to use on - if combine_with: - var do_combine = true - if combine_with.node is ESCItem \ - and combine_with.node.use_from_inventory_only\ - and not escoria.inventory_manager.inventory_has( - combine_with.global_id - ): - do_combine = false - - if do_combine: - var target_event = "%s %s" % [ - action, - combine_with.global_id - ] - var combine_with_event = "%s %s" % [ - action, - target.global_id - ] - - if target.events.has(target_event): - event_to_return = target.events[target_event] - elif combine_with.events.has(combine_with_event)\ - and not combine_with.node.combine_is_one_way: - - event_to_return = combine_with.events[combine_with_event] - else: - # Check to see if there isn't a "fallback" action to - # run before we declare this a failure. - if escoria.action_default_script \ - and escoria.action_default_script.events.has(action): - - event_to_return = escoria.action_default_script.events[action] - else: - var errors = [ - "Attempted to execute action %s between item %s and item %s" % [ - action, - target.global_id, - combine_with.global_id - ] - ] - - if combine_with.node.combine_is_one_way: - errors.append( - ("Reason: %s's item interaction " + \ - "is one-way.") % combine_with.global_id - ) - - escoria.logger.warn( - self, - "Invalid action: " + str(errors) - ) - else: - escoria.logger.warn( - self, - "Invalid action on item: " + - ( - "Trying to combine object %s with %s, "+ - "but %s is not in inventory." - ) % [ - target.global_id, - combine_with.global_id, - combine_with.global_id - ] - ) - else: - escoria.logger.warn( - self, - "Invalid action on item: " + - "Trying to run action %s on object %s, " % - [ - action, - target.node.global_id - ] - + "but item must be in inventory." - ) - else: - if target.events.has(action): - event_to_return = target.events[action] - elif escoria.action_default_script \ - and escoria.action_default_script.events.has(action): - - # If there's a "fallback" action to run, return it - event_to_return = escoria.action_default_script.events[action] - else: - escoria.logger.warn( - self, - "Invalid action: " + - "Event for action %s on object %s not found." % [ - action, - target.global_id - ] - ) - - return event_to_return - - -# Runs the specified event. -# -# #### Parameters -# -# - event: the event to be run -# -# *Returns* the return code of the event once executed -func _run_event(event: ESCEvent) -> int: - escoria.event_manager.queue_event(event) - - var event_returned = yield( - escoria.event_manager, - "event_finished" - ) - - while event_returned[1] != event.name: - event_returned = yield( - escoria.event_manager, - "event_finished" - ) - - clear_current_action() - emit_signal("action_finished") - - return event_returned[0] - - -# Makes an object walk to a destination. This can be either a 2D position or -# another object. -# -# #### Parameters -# -# - moving_obj_id: global id of the object that needs to move -# - destination: Position2D or ESCObject holding the moving object to head to -# - is_fast: if true, the walk is performed at fast speed (defined in the moving -# object. -func perform_walk( - moving_obj: ESCObject, - destination, - is_fast: bool = false -): - # Walk to Position2D. - if destination is Vector2: - var walk_context = ESCWalkContext.new( - null, - destination, - is_fast, - true - ) - moving_obj.node.walk_to(destination, walk_context) - - # Walk to object - elif destination is ESCObject: - if destination.node: - var target_position: Vector2 - if destination.node is ESCLocation: - target_position = destination.node.global_position - else: - target_position = destination.node.get_interact_position() - - var walk_context = ESCWalkContext.new( - destination, - target_position, - is_fast, - true - ) - - moving_obj.node.walk_to(target_position, walk_context) - - else: - escoria.logger.error( - self, - "Function expected either a Vector2 or ESCObject type " + \ - "for destination parameter. Destination provided was: %s." % destination - ) - return - - -# Event handler when an object/item was clicked -# -# #### Parameters -# -# - obj: Object that was left clicked -# - event: Input event that was received -# - default_action: if true, run the inventory default action -func perform_inputevent_on_object( - obj: ESCObject, - event: InputEvent, - default_action: bool = false -): - """ - This algorithm: - - validates the requested action - - grabs the corresponding event for the action, if available - - makes the player move to the clicked object location, if needed - (if it is located in the room for example) and wait for reaching. - - when reached, performs an action depending on current defined action - * no current action defined: do nothing else - * current action defined: - * item requires no combination: perform the current action - on the item - * item requires combination: check the status of the combination - A combination requires 3 elements to fulfill: - 1/ a verb action - 2/ a first "tool" (item to use) - 3/ a second "tool" (item to use ON) - Whatever the user inputs to fulfill the combination (this is - determined by gamedev in his game.gd script) - - combination not fulfilled: no not perform until fulfilled - - combination fulfilled: perform the combination. - * else do nothing, except if default_action is requested. - In this case, perform the default_action on the item. - """ - - escoria.logger.info( - self, - "%s to perform event %s." % [obj.global_id, event] - ) - - # Don't interact after player movement towards object - # (because object is inactive for example) - var dont_interact = false - - # We need to have the new action input state BEFORE initiating the player - # move so we determine now if the object clicked will require a combination - # depending on the used action verb. - var tool_just_set = _set_tool_and_action(obj, default_action) - var need_combine = _check_item_needs_combine() - - # If the current tool was not set, this is our first item, make it the tool - if not current_tool or (current_tool and not need_combine): - current_tool = obj - # Else, if we have a tool and combination required, this is our second item, - # make it the target. - elif need_combine and not tool_just_set: - current_target = obj - - # Update the action input state - if action_state == ACTION_INPUT_STATE.AWAITING_TARGET_ITEM and current_target: - set_action_input_state(ACTION_INPUT_STATE.COMPLETED) - elif action_state == ACTION_INPUT_STATE.AWAITING_ITEM and \ - not need_combine: - set_action_input_state(ACTION_INPUT_STATE.COMPLETED) - elif action_state == ACTION_INPUT_STATE.AWAITING_ITEM and need_combine and not tool_just_set: - set_action_input_state(ACTION_INPUT_STATE.AWAITING_TARGET_ITEM) - - var event_to_queue: ESCEvent = null - - # Manage exits - if obj.node.is_exit and current_action in ["", ACTION_WALK]: - event_to_queue = _get_event_to_queue(ACTION_EXIT_SCENE, obj) - else: - # Manage movements towards object before activating it - if current_action in ["", ACTION_WALK] and \ - not escoria.inventory_manager.inventory_has(obj.global_id): - event_to_queue = _get_event_to_queue(ACTION_ARRIVED, obj) - # Manage action on object - elif not current_action in ["", ACTION_WALK]: - if need_combine and current_target: - event_to_queue = _get_event_to_queue( - current_action, - current_tool, - current_target - ) - else: - # Check if object must be in inventory to be used and update - # action state if necessary - if obj.node.use_from_inventory_only and \ - escoria.inventory_manager.inventory_has(obj.global_id) and \ - need_combine: - - # We're missing a target here for our tool to be used on - current_tool = obj - set_action_input_state( - ACTION_INPUT_STATE.AWAITING_TARGET_ITEM - ) - - # We need to wait for that target - return - else: - event_to_queue = _get_event_to_queue( - current_action, - obj - ) - - # Get out of here if there's a specified action but an event couldn't be found. - # Note that `event_to_queue` may still be null, but we do need to start the - # player walking towards the destination. - if current_action and not event_to_queue: - clear_current_action() - emit_signal("action_finished") - return - - var event_flags = event_to_queue.flags if event_to_queue else 0 - - if escoria.main.current_scene.player: - var destination_position: Vector2 = escoria.main.current_scene.player \ - .global_position - - # If clicked object not in inventory, player walks towards it - if not obj.node is ESCPlayer and \ - not escoria.inventory_manager.inventory_has(obj.global_id) and \ - not event_flags & ESCEvent.FLAG_TK: - var context = _walk_towards_object( - obj, - event.position, - event.doubleclick - ) - - if context is GDScriptFunctionState: - context = yield(context, "completed") - - # In case of an interrupted walk, we don't want to proceed. - if context == null: - return - - destination_position = context.target_position - dont_interact = context.dont_interact_on_arrival - - var player_global_pos = escoria.main.current_scene.player.global_position - var clicked_position = event.position - - # Using this instead of is_equal_approx due to - # https://github.com/godotengine/godot/issues/65257 - if (player_global_pos - destination_position).length() > 1: - dont_interact = true - escoria.logger.info( - self, - "Player could not reach destination coordinates %s. " % str(destination_position) \ - + "Any requested action for %s will not fire." % obj.global_id - ) - if escoria.event_manager.EVENT_CANT_REACH in obj.events: - escoria.event_manager.queue_event(obj.events[escoria.event_manager.EVENT_CANT_REACH]) - else: - escoria.logger.info( - self, - "%s event not found for object %s so nothing to do." % \ - [escoria.event_manager.EVENT_CANT_REACH, obj.global_id] - ) - - # If no interaction should happen after player has arrived, leave - # immediately. - if not dont_interact and event_to_queue: - _run_event(event_to_queue) - - -# Determines whether the object in question can be acted upon. -# -# #### Parameters -# -# - global_id: the global ID of the item to examine -# -# *Returns* True iff the item represented by global_id can be acted upon. -func is_object_actionable(global_id: String) -> bool: - var obj: ESCObject = escoria.object_manager.get_object(global_id) as ESCObject - - return _is_object_actionable(obj) - - -# Prepare the "obj" object for current_action: if required, set the object as -# current tool. -# -# #### Parameters -# -# - obj: the ESCObject to prepare -# - default_action: if true, the default action set on the item is used -# -# *Returns* True if the tool was set in this function -func _set_tool_and_action(obj: ESCObject, default_action: bool): - var tool_just_set: bool = false - # Check if current_action and current_tool are already set - if current_action and current_tool: - if not current_action in escoria.action_manager\ - .current_tool.node.combine_when_selected_action_is_in: - current_tool = obj - tool_just_set = true - elif default_action: - if escoria.inventory_manager.inventory_has(obj.global_id): - current_action = obj.node.default_action_inventory - else: - current_action = obj.node.default_action - elif current_action in obj.node.combine_when_selected_action_is_in: - current_tool = obj - tool_just_set = true - return tool_just_set - - -# Checks if object requires a combination with another, according to -# currently selected action verb (or check with default action of the item). -# -# *Returns* True if current action on "obj" requires a combination -func _check_item_needs_combine() -> bool: - return current_action \ - and current_tool \ - and current_action in current_tool.node.combine_when_selected_action_is_in - - -# Makes the player character walk towards the clicked item. -# Returns the resulting walk context. -# -# #### Parameters -# -# - obj: the object that was clicked -# - clicked_position: the Position2D of the input click -# - walk_fast: if true, the player will walk fast to the object -func _walk_towards_object( - obj: ESCObject, - clicked_position: Vector2, - walk_fast: bool -) -> ESCWalkContext: - var destination_position: Vector2 - var dont_interact: bool = false - - if obj == null || obj.node == null: - escoria.logger.error( - self, - "walk_towards_object error. obj or obj.node not populated." - ) - var interact_position = obj.node.get_interact_position() - # If clicked object is interactive, get destination position from it. - if escoria.object_manager.get_object(obj.global_id).interactive: - if interact_position != null: - destination_position = interact_position - else: - destination_position = obj.node.position - else: - destination_position = clicked_position - dont_interact = true - - # Create walk context - var walk_context = ESCWalkContext.new( - obj, - destination_position, - walk_fast, - dont_interact - ) - - # Walk towards the clicked object - escoria.main.current_scene.player.walk_to(destination_position, - walk_context) - - escoria.logger.debug( - self, - "Player walking to destination. Yielding." -) - - # Wait for the player to arrive before continuing with action. - var context: ESCWalkContext = yield( - escoria.main.current_scene.player, - "arrived" - ) - - if context.target_object != obj: - escoria.logger.debug( - self, - "Original walk context target does not match " \ - + "yielded walk context. Likely interrutped walk.") - return - - escoria.logger.info( - self, - "Context arrived: %s." % context - ) - - # Confirm that reached item was the one user clicked in the first place. - # Don't interact if that is not the case. - if (context.target_object and context.target_object.\ - global_id != walk_context.\ - target_object.global_id) or \ - (context.target_position != walk_context.target_position): - walk_context.dont_interact_on_arrival = true - - return context - - -# Determines whether the object in question can be acted upon. -# -# #### Parameters -# -# - obj: the ESCObject to examine -# -# *Returns* True iff 'obj' can be acted upon. -func _is_object_actionable(obj: ESCObject) -> bool: - var object_is_actionable: bool = true - - if not obj: - return false - - if not obj.active: - escoria.logger.trace( - self, - "Item %s is not active." % obj.global_id - ) - object_is_actionable = false - elif not obj.interactive: - escoria.logger.trace( - self, - "Item %s is not interactive." % obj.global_id - ) - object_is_actionable = false - - return object_is_actionable diff --git a/addons/escoria-core/game/core-scripts/esc/esc_command_registry.gd b/addons/escoria-core/game/core-scripts/esc/esc_command_registry.gd deleted file mode 100644 index 6b5aabf1..00000000 --- a/addons/escoria-core/game/core-scripts/esc/esc_command_registry.gd +++ /dev/null @@ -1,48 +0,0 @@ -# A registry of ESC command objects -extends Reference -class_name ESCCommandRegistry - - -# The registry of registered commands -var registry: Dictionary = {} - - -# Load a command by its name -# -# #### Parameters -# -# - command_name: Name of command to load -# **Returns** The command object -func load_command(command_name: String) -> ESCBaseCommand: - for command_directory in ESCProjectSettingsManager.get_setting( - ESCProjectSettingsManager.COMMAND_DIRECTORIES - ): - if ResourceLoader.exists("%s/%s.gd" % [command_directory, command_name]): - registry[command_name] = load( - "%s/%s.gd" % [ - command_directory.trim_suffix("/"), - command_name - ] - ).new() - return registry[command_name] - - escoria.logger.error( - self, - "No command class could be found for command %s." - % command_name - ) - - return null - - -# Retrieve a command from the command registry -# -# #### Parameters -# -# - command_name: The name of the command -# **Returns** The command object -func get_command(command_name: String) -> ESCBaseCommand: - if self.registry.has(command_name): - return self.registry[command_name] - else: - return self.load_command(command_name) diff --git a/addons/escoria-core/game/core-scripts/esc/esc_compiler.gd b/addons/escoria-core/game/core-scripts/esc/esc_compiler.gd deleted file mode 100644 index 189d3c68..00000000 --- a/addons/escoria-core/game/core-scripts/esc/esc_compiler.gd +++ /dev/null @@ -1,291 +0,0 @@ -# Compiler of the ESC language -extends Resource -class_name ESCCompiler - - -# A RegEx for comment lines -const COMMENT_REGEX = '^\\s*#.*$' - -# A RegEx for empty lines -const EMPTY_REGEX = '^\\s*$' - -# A RegEx for finding out the indent of a line -const INDENT_REGEX_GROUP = "indent" -const INDENT_REGEX = '^(?<%s>\\s*)' % INDENT_REGEX_GROUP - -# This must match ESCProjectSettingsManager.COMMAND_DIRECTORIES. -# We do not reference it directly to avoid circular dependencies. -const COMMAND_DIRECTORIES = "escoria/main/command_directories" - -# RegEx objects for use by the ESC compiler -var _comment_regex -var _empty_regex -var _indent_regex -var _event_regex -var _command_regex -var _dialog_regex -var _dialog_end_regex -var _dialog_option_regex -var _group_regex -# Regex to match globals in debug strings -var _globals_regex: RegEx - -# The currently compiled event -var _current_event = null - -# A stack of groups currently compiling -var _groups_stack = [] - -# A stack of dialogs currently compiling -var _dialogs_stack = [] - -# A stack of dialog options currently compiling -var _dialogs_option_stack = [] - -# A pointer to the current container (group, dialog option) -# that should get the current command -var _command_container = [] - -# The currently identified indent -var _current_indent = 0 - - -func _init(): - # Assure command list preference - # (we use ProjectSettings instead of ESCProjectSettingsManager - # here because this is called from escoria._init()) - if not ProjectSettings.has_setting(COMMAND_DIRECTORIES): - ProjectSettings.set_setting(COMMAND_DIRECTORIES, [ - "res://addons/escoria-core/game/core-scripts/esc/commands" - ]) - var property_info = { - "name": COMMAND_DIRECTORIES, - "type": TYPE_STRING_ARRAY - } - ProjectSettings.add_property_info(property_info) - - # Compile all regex objects just once - _comment_regex = RegEx.new() - _comment_regex.compile(COMMENT_REGEX) - _empty_regex = RegEx.new() - _empty_regex.compile(EMPTY_REGEX) - _indent_regex = RegEx.new() - _indent_regex.compile(INDENT_REGEX) - - _event_regex = RegEx.new() - _event_regex.compile(ESCEvent.REGEX) - _command_regex = RegEx.new() - _command_regex.compile(ESCCommand.REGEX) - _dialog_regex = RegEx.new() - _dialog_regex.compile(ESCDialog.REGEX) - _dialog_end_regex = RegEx.new() - _dialog_end_regex.compile(ESCDialog.END_REGEX) - _dialog_option_regex = RegEx.new() - _dialog_option_regex.compile(ESCDialogOption.REGEX) - _group_regex = RegEx.new() - _group_regex.compile(ESCGroup.REGEX) - # Use look-ahead/behind to capture the term in braces - _globals_regex = RegEx.new() - _globals_regex.compile("(?<=\\{)(.*)(?=\\})") - -# Load an ESC file from a file resource -func load_esc_file(path: String) -> ESCScript: - escoria.logger.debug(self, "Parsing file %s." % path) - if File.new().file_exists(path): - var file = File.new() - file.open(path, File.READ) - var lines = [] - while not file.eof_reached(): - lines.append(file.get_line()) - return self.compile(lines, path) - else: - escoria.logger.error( - self, - "Can not find ESC file: file %s could not be found." % path - ) - return null - - -# Compiles an array of ESC script strings to an ESCScript -func compile(lines: Array, path: String = "") -> ESCScript: - var script = ESCScript.new() - - if lines.size() > 0: - var events = self._compile(lines, path) - for event in events: - event.source = path - script.events[event.name] = event - - return script - - -# Compile an array of ESC script lines into an array of ESC objects -func _compile(lines: Array, path: String = "") -> Array: - var returned = [] - - while lines.size() > 0: - var line = lines.pop_front().strip_edges(false, true) - escoria.logger.trace( - self, - "Parsing line %s." % line - ) - if _comment_regex.search(line) or _empty_regex.search(line): - # Ignore comments and empty lines - escoria.logger.trace( - self, - "Line is empty or a comment. Skipping." - ) - continue - var indent = \ - ESCUtils.get_re_group( - _indent_regex.search(line), - INDENT_REGEX_GROUP - ).length() - - if _event_regex.search(line): - var event = ESCEvent.new(line) - escoria.logger.trace( - self, - "Line is the event %s." % event.name - ) - var event_lines = [] - while lines.size() > 0: - var next_line = lines.pop_front() - if not _event_regex.search(next_line): - event_lines.append(next_line) - else: - lines.push_front(next_line) - break - if event_lines.size() > 0: - escoria.logger.trace( - self, - "Compiling the next %d lines into the event." % \ - event_lines.size() - ) - event.statements = self._compile(event_lines, path) - returned.append(event) - elif _group_regex.search(line): - var group = ESCGroup.new(line) - escoria.logger.trace( - self, - "Line is a group." - ) - var group_lines = [] - while lines.size() > 0: - var next_line = lines.pop_front() - if _comment_regex.search(next_line) or \ - _empty_regex.search(next_line): - continue - var next_line_indent = \ - ESCUtils.get_re_group( - _indent_regex.search(next_line), - INDENT_REGEX_GROUP - ).length() - if next_line_indent > indent: - group_lines.append(next_line) - else: - lines.push_front(next_line) - break - if group_lines.size() > 0: - escoria.logger.trace( - self, - "Compiling the next %d lines into the group." % \ - group_lines.size() - ) - group.statements = self._compile(group_lines, path) - returned.append(group) - elif _dialog_regex.search(line): - var dialog = ESCDialog.new() - dialog.load_string(line) - escoria.logger.trace( - self, - "Line is a dialog." - ) - var dialog_lines = [] - while lines.size() > 0: - var next_line = lines.pop_front() - if _comment_regex.search(next_line) or \ - _empty_regex.search(next_line): - continue - var end_line = _dialog_end_regex.search(next_line) - if end_line and \ - ESCUtils.get_re_group( - end_line, - INDENT_REGEX_GROUP - ).length() == indent: - break - else: - dialog_lines.append(next_line) - if dialog_lines.size() > 0: - escoria.logger.trace( - self, - "Compiling the next %d lines into the dialog." % \ - dialog_lines.size() - ) - dialog.options = self._compile(dialog_lines, path) - # Remove the end line from the stack - lines.pop_front() - returned.append(dialog) - elif _dialog_option_regex.search(line): - var dialog_option = ESCDialogOption.new() - dialog_option.load_string(line) - escoria.logger.trace( - self, - "Line is the dialog option %s." % \ - dialog_option.option - ) - var dialog_option_lines = [] - while lines.size() > 0: - var next_line = lines.pop_front() - if _comment_regex.search(next_line) or \ - _empty_regex.search(next_line): - continue - var next_line_indent = \ - ESCUtils.get_re_group( - _indent_regex.search(next_line), - INDENT_REGEX_GROUP - ).length() - if next_line_indent > indent: - dialog_option_lines.append(next_line) - else: - if _dialog_end_regex.search(next_line) or \ - _dialog_option_regex.search(next_line): - lines.push_front(next_line) - break - - # There MUST be AT LEAST ONE statement/line for a dialog - # option's block that's properly indented - escoria.logger.error( - self, - "Dialog option '%s' has at least one line in its block that is not indented sufficiently." \ - % line - ) - if dialog_option_lines.size() > 0: - escoria.logger.trace( - self, - "Compiling the next %d lines into the event." - % dialog_option_lines.size() - ) - dialog_option.statements = self._compile(dialog_option_lines, path) - returned.append(dialog_option) - elif _command_regex.search(line): - var command = ESCCommand.new(line) - if command.command_exists(): - returned.append(command) - else: - escoria.logger.error( - self, - "Command \"%s\" cannot be found under folder %s.\nPlease confirm setting \"%s\" is set to the folder where ESC commands are stored." - % [ - command.name, - ProjectSettings.get_setting(COMMAND_DIRECTORIES), - ESCProjectSettingsManager.COMMAND_DIRECTORIES - ] - ) - else: - escoria.logger.error( - self, - "Invalid ESC line detected.\nLine couldn't be compiled: %s." - % line - ) - return returned diff --git a/addons/escoria-core/game/core-scripts/esc/esc_event_manager.gd b/addons/escoria-core/game/core-scripts/esc/esc_event_manager.gd deleted file mode 100644 index 926419d3..00000000 --- a/addons/escoria-core/game/core-scripts/esc/esc_event_manager.gd +++ /dev/null @@ -1,478 +0,0 @@ -# A manager for running events -# There are different "channels" an event can run on. -# The usual events happen in the foreground channel _front, but -# additional event queues can be added as required. -# Additionally, events can be scheduled to be queued in the future -extends Node -class_name ESCEventManager - - -# Emitted when the event started execution -signal event_started(event_name) - -# Emitted when an event is started in a channel of the background queue -signal background_event_started(channel_name, event_name) - -# Emitted when the event did finish running -signal event_finished(return_code, event_name) - -# Emitted when a background event was finished -signal background_event_finished(return_code, event_name, channel_name) - - -# Pre-defined ESC events -const EVENT_PRINT = "print" -const EVENT_EXIT_SCENE = "exit_scene" -const EVENT_INIT = "init" -const EVENT_LOAD = "load" -const EVENT_NEW_GAME = "newgame" -const EVENT_READY = "ready" -const EVENT_ROOM_SELECTOR = "room_selector" -const EVENT_SETUP = "setup" -const EVENT_TRANSITION_IN = "transition_in" -const EVENT_TRANSITION_OUT = "transition_out" -const EVENT_CANT_REACH = "cant_reach" - - -# Event channel names -const CHANNEL_FRONT = "_front" - - -# A list of currently scheduled events -var scheduled_events: Array = [] - -# A list of constantly running events in multiple background channels -var events_queue: Dictionary = { - CHANNEL_FRONT: [] -} - -# Currently running event in background channels -var _running_events: Dictionary = {} - -# Whether an event can be played on a specific channel -var _channels_state: Dictionary = {} - -# Whether we're currently waiting for an async event to complete, per channel -var _yielding: Dictionary = {} - -# Whether we're currently changing the scene. -var _changing_scene: bool = false setget set_changing_scene - -# ESC "change_scene" command. -var _change_scene: ChangeSceneCommand - - -# Constructor -func _init(): - _change_scene = ChangeSceneCommand.new() - - -# Make sure to stop when pausing the game -func _ready(): - self.pause_mode = Node.PAUSE_MODE_STOP - - -# Handle the events queue and scheduled events -# -# #### Parameters -# - delta: Time passed since the last process call -func _process(delta: float) -> void: - var channel_yielding: bool - - for channel_name in events_queue.keys(): - channel_yielding = _yielding.get(channel_name, false) - - if events_queue[channel_name].size() == 0 or channel_yielding: - continue - if is_channel_free(channel_name): - _channels_state[channel_name] = false - _running_events[channel_name] = \ - events_queue[channel_name].pop_front() - escoria.logger.debug( - self, - "Popping event '%s' from background queue %s " % [ - _running_events[channel_name].name, - channel_name, - ] + - "to source %s." % _running_events[channel_name].source \ - if not _running_events[channel_name].source.empty() - else "(unknown)" - ) - if not _running_events[channel_name].is_connected( - "finished", self, "_on_event_finished" - ): - _running_events[channel_name].connect( - "finished", - self, - "_on_event_finished", - [channel_name], - CONNECT_ONESHOT - ) - if not _running_events[channel_name].is_connected( - "interrupted", self, "_on_event_finished" - ): - _running_events[channel_name].connect( - "interrupted", - self, - "_on_event_finished", - [channel_name], - CONNECT_ONESHOT - ) - - if channel_name == CHANNEL_FRONT: - emit_signal( - "event_started", - _running_events[channel_name].name - ) - else: - emit_signal( - "background_event_started", - channel_name, - _running_events[channel_name].name - ) - - var event_flags = _running_events[channel_name].flags - if event_flags & ESCEvent.FLAG_NO_TT: - escoria.main.current_scene.game.tooltip_node.hide() - - if event_flags & ESCEvent.FLAG_NO_UI: - escoria.main.current_scene.game.hide_ui() - - if event_flags & ESCEvent.FLAG_NO_SAVE: - escoria.save_manager.save_enabled = false - - var rc = _running_events[channel_name].run() - - if rc is GDScriptFunctionState: - _yielding[channel_name] = true - rc = yield(rc, "completed") - _yielding[channel_name] = false - - for event in self.scheduled_events: - (event as ESCScheduledEvent).timeout -= delta - if (event as ESCScheduledEvent).timeout <= 0: - self.scheduled_events.erase(event) - self.events_queue[CHANNEL_FRONT].append(event.event) - - -# Queue a new event based on input from an ESC command, most likely "queue_event" -# -# #### Parameters -# - script_object: Compiled script object, i.e. the one with the event to queue -# - event: Name of the event to queue -# - channel: Channel to run the event on (default: `_front`) -# - block: Whether to wait for the queue to finish. This is only possible, if -# the queued event is not to be run on the same event as this command -# (default: `false`) -# -# **Returns** indicator of success/status -func queue_event_from_esc(script_object: ESCScript, event: String, - channel: String, block: bool) -> int: - - if _changing_scene: - return ESCExecution.RC_WONT_QUEUE - - if channel == CHANNEL_FRONT: - queue_event(script_object.events[event]) - else: - queue_background_event( - channel, - script_object.events[event] - ) - if block: - if channel == CHANNEL_FRONT: - var rc = yield(self, "event_finished") - while rc[1] != event: - rc = yield(self, "event_finished") - return rc[0] - else: - var rc = yield(self, "background_event_finished") - while rc[1] != event and rc[2] != channel: - rc = yield(self, "background_event_finished") - return rc[0] - - return ESCExecution.RC_OK - - -# Queue a new event to run in the foreground -# -# #### Parameters -# - event: Event to run -func queue_event(event: ESCEvent, force: bool = false) -> void: - if _changing_scene and not force: - escoria.logger.info( - self, - "Changing scenes. Won't queue event '%s'." % event.name - ) - return - - # Don't queue the same event more than once in a row. - var last_event = _get_last_event_queued(CHANNEL_FRONT) - - # Check the queue first to see if appending the event will result in - # consecutive occurrences of the event. If not, be sure to check if the same - # event is currently running. - if last_event != null and last_event.name == event.name: - var message = "Event '%s' is already the most-recently queued event in channel '%s'." + \ - " Won't be queued again." - - escoria.logger.debug(self, message % [event.name, CHANNEL_FRONT]) - return - elif _is_event_running(event, CHANNEL_FRONT): - # Don't queue the same event if it's already running. - escoria.logger.debug( - self, - "Event %s already running in channel '%s'. Won't be queued." - % [event.name, CHANNEL_FRONT] - ) - - return - - escoria.logger.debug( - self, - "Queueing event %s in channel %s." % [event.name, CHANNEL_FRONT] - ) - self.events_queue[CHANNEL_FRONT].append(event) - - -# Schedule an event to run after a timeout -# -# #### Parameters -# - event: Event to run -# - timeout: Number of seconds to wait before adding the event to the -# front queue -func schedule_event(event: ESCEvent, timeout: float) -> void: - scheduled_events.append(ESCScheduledEvent.new(event, timeout)) - - -# Queue the run of an event in a background channel -# -# #### Parameters -# - channel_name: Name of the channel to use -# - event: Event to run -func queue_background_event(channel_name: String, event: ESCEvent) -> void: - if not channel_name in events_queue: - events_queue[channel_name] = [] - - # Don't queue the same event more than once in a row. - var last_event = _get_last_event_queued(channel_name) - - # Check the queue first to see if appending the event will result in - # consecutive occurrences of the event. If not, be sure to check if the same - # event is currently running. - if last_event != null and last_event.name == event.name: - var message = "Event '%s' is already the most-recently queued event in channel '%s'." + \ - " Won't be queued again." - - escoria.logger.debug(self, message % [event.name, channel_name]) - return - elif _is_event_running(event, CHANNEL_FRONT): - # Don't queue the same event if it's already running. - escoria.logger.debug( - self, - "Event %s already running in channel '%s'. Won't be queued." - % [event.name, channel_name] - ) - - return - - events_queue[channel_name].append(event) - - -# Interrupt the events currently running and any that are pending. -# -# #### Parameters -# - exceptions: an optional list of events which should be left running or queued -func interrupt(exceptions: PoolStringArray = []) -> void: - if escoria.main.current_scene != null \ - and escoria.main.current_scene.player != null \ - and escoria.main.current_scene.player.is_moving(): - escoria.main.current_scene.player.stop_walking_now() - - for channel_name in _running_events.keys(): - if _running_events[channel_name] != null and not _running_events[channel_name].name in exceptions: - escoria.logger.debug( - self, - "Interrupting running event %s in channel %s..." - % [_running_events[channel_name].name, channel_name]) - _running_events[channel_name].interrupt() - _channels_state[channel_name] = true - - var events_to_clear: Array = [] - - for channel_name in events_queue.keys(): - if events_queue[channel_name] != null: - var found_exception: bool = false - - for event in events_queue[channel_name]: - if event.name in exceptions: - found_exception = true - continue - - escoria.logger.debug( - self, - "Interrupting queued event %s in channel %s..." - % [event.name, channel_name]) - event.interrupt() - events_to_clear.append(event) - - # If we found an exception, we can't just clear out the entire - # channel's queue and so we remove everything but the exceptions in - # the channel. Otherwise, we're safe to just clear it out. - if found_exception: - for event in events_to_clear: - if events_queue[channel_name].has(event): - events_queue[channel_name].erase(event) - else: - events_queue[channel_name].clear() - - -# Clears the event queues. -func clear_event_queue(): - for channel_name in events_queue.keys(): - events_queue[channel_name].clear() - - -# Check whether a channel is free to run more events -# -# #### Parameters -# - name: Name of the channel to test -# **Returns** Whether the channel can currently accept a new event -func is_channel_free(name: String) -> bool: - return _channels_state[name] if name in _channels_state else true - - -# Get the currently running event in a channel -# -# #### Parameters -# - name: Name of the channel -# **Returns** The currently running event or null -func get_running_event(name: String) -> ESCEvent: - return _running_events[name] if name in _running_events else null - - -# Setter for _changing_scene. -# -# #### Parameterse -# - value: boolean value to set _changing_scene to -func set_changing_scene(p_is_changing_scene: bool) -> void: - escoria.logger.trace( - self, - "Setting _changing_scene to %s." % p_is_changing_scene - ) - - _changing_scene = p_is_changing_scene - - # If we're changing scenes, interrupt any (other) running events and purge - # all event queues. - if _changing_scene: - interrupt([EVENT_INIT, EVENT_EXIT_SCENE, _change_scene.get_command_name()]) - - -# The event finished running -# -# #### Parameters -# - finished_event: statement object representing the event that finished -# - finished_statement: statement object representing the "deepest" statement (most likely a command) -# that just completed; this is useful for interrupted or failed statements especially -# - return_code: Return code of the finished event -# - channel_name: Name of the channel that the event came from -func _on_event_finished(finished_event: ESCStatement, finished_statement: ESCStatement, return_code: int, channel_name: String) -> void: - var event = _running_events[channel_name] - if not event: - escoria.logger.warn( - self, - "Event '%s' finished without being in _running_events[%s]." - % [finished_event.name, channel_name] - ) - return - - escoria.logger.debug( - self, - "Event '%s' ended with return code %d." % [event.name, return_code] - ) - - var event_flags = event.flags - if event_flags & ESCEvent.FLAG_NO_TT: - escoria.main.current_scene.game.tooltip_node.show() - - if event_flags & ESCEvent.FLAG_NO_UI: - escoria.main.current_scene.game.show_ui() - - if event_flags & ESCEvent.FLAG_NO_SAVE: - escoria.save_manager.save_enabled = true - - # If the return code was RC_CANCEL due to an event finishing with "stop" command for example - # we convert it to RC_OK so that other processed waiting for RC_OK can carry on. - # - # We also make sure that a failed command/event doesn't leave the game in a state where it - # isn't accepting inputs, e.g. if a previous command in the event was `accept_input NONE`. - if return_code == ESCExecution.RC_CANCEL: - return_code = ESCExecution.RC_OK - elif return_code == ESCExecution.RC_ERROR: - _generate_statement_error_warning(finished_statement, event.name) - - escoria.inputs_manager.input_mode = escoria.inputs_manager.INPUT_ALL - - _running_events[channel_name] = null - _channels_state[channel_name] = true - - if channel_name == CHANNEL_FRONT: - emit_signal( - "event_finished", - return_code, - event.name - ) - else: - emit_signal( - "background_event_finished", - return_code, - event.name, - channel_name - ) - - -# Gets the event at the tail of the specified channel's event queue, if one -# exists. -# -# #### Parameters -# - channel_name: The name of the channel to check. -# -# *Returns* the last ESCEvent queued for the given channel, or null if the -# channel's queue is empty. -func _get_last_event_queued(channel_name: String) -> ESCEvent: - if self.events_queue[channel_name].size() > 0: - return self.events_queue[channel_name].back() - - return null - - -# Checks to see if the specified event is already running in the given channel. -# -# #### Parameters -# - event: The event to check to see if it's already running. -# - channel_name: The name of the channel to check. -# -# *Returns* true iff event is currently running in the specified channel. -func _is_event_running(event: ESCEvent, channel_name: String) -> bool: - var running_event: ESCEvent = get_running_event(channel_name) - - return running_event != null and running_event.name == event.name - - -# Generates a logger warning concerning an errored-out statement. -func _generate_statement_error_warning(statement: ESCStatement, event_name: String) -> void: - var warning_string: String = "Statement '%s' returned an error in event '%s'" \ - % [statement.name, event_name] - - if statement is ESCCommand and statement.parameters.size() > 0: - var statement_params: String = "[" + PoolStringArray(statement.parameters).join(", ") + "]" - - warning_string += " with parameters: %s" % statement_params - - warning_string += ". Resetting input mode to 'ALL'." - - escoria.logger.warn( - self, - warning_string - ) diff --git a/addons/escoria-core/game/core-scripts/esc/esc_globals_manager.gd b/addons/escoria-core/game/core-scripts/esc/esc_globals_manager.gd deleted file mode 100644 index 4458a2c1..00000000 --- a/addons/escoria-core/game/core-scripts/esc/esc_globals_manager.gd +++ /dev/null @@ -1,149 +0,0 @@ -# A resource that manages the ESC global states -# The ESC global state is basically simply a dictionary of keys with -# values. Values can be bool, integer or strings -extends Resource -class_name ESCGlobalsManager - - -# Emitted when a global is changed -signal global_changed(global, old_value, new_value) - - -# The globals registry -export(Dictionary) var _globals = {} - - -# Registry of globals that are to be reserved for internal use only. -var _reserved_globals: Dictionary = {} - -# Use look-ahead/behind to capture the term in braces -var globals_regex: RegEx = RegEx.new() - -# Constructor -func _init(): - globals_regex.compile("(?<=\\{)(.*)(?=\\})") - - -# Check if a global was registered -# -# #### Parameters -# -# - key: The global key to check -# **Returns** Whether the global was registered -func has(key: String) -> bool: - return _globals.has(key) - - -# Registers a global as being reserved and initializes it. -# -# #### Parameters -# -# - key: The key of the global to register -# - value: The initial value (optional) -func register_reserved_global(key: String, value = null) -> void: - if key in _reserved_globals: - escoria.logger.error( - self, - "Can not override reserved global: Global key %s is already " + - "registered as reserved." - % key - ) - var old_value = _globals[key] if _globals.has(key) else "" - _reserved_globals[key] = value - _globals[key] = value - - if value != null: - emit_signal("global_changed", key, old_value, _globals[key]) - - -# Get the current value of a global -# -# #### Parameters -# -# - key: The key of the global to return the value -# **Returns** The value of the global -func get_global(key: String): - if _globals.has(key): - return _globals[key] - return null - - -# Filter the globals and return all matching keys and their values as -# a dictionary -# Check out [the Godot docs](https://docs.godotengine.org/en/stable/classes/class_string.html#class-string-method-match) -# for the pattern format -# -# #### Parameters -# -# - pattern: The pattern that the keys have to match -# **Returns** A dictionary of matching keys and their values -func filter(pattern: String) -> Dictionary: - var ret = {} - for global_key in _globals.keys(): - if global_key.match(pattern): - ret[global_key] = _globals[global_key] - return ret - - -# Set the value of a global -# -# #### Parameters -# -# - key: The key of the global to modify -# - value: The new value -func set_global(key: String, value, ignore_reserved: bool = false) -> void: - if key in _reserved_globals and not ignore_reserved: - escoria.logger.error( - self, - "Global key %s is reserved and can not be overridden." % key - ) - - emit_signal( - "global_changed", - key, - _globals[key] if _globals.has(key) else null, - value - ) - _globals[key] = value - - -# Set all globals that match the pattern to the value -# Check out [the Godot docs](https://docs.godotengine.org/en/stable/classes/class_string.html#class-string-method-match) -# for the pattern format -# -# #### Parameters -# -# - pattern: The wildcard pattern to match -# - value: The new value -func set_global_wildcard(pattern: String, value) -> void: - for global_key in _globals.keys: - if global_key.match(pattern): - self.set_global(global_key, value) - - -# Look to see if any globals (names in braces) should be interpreted -# -# #### Parameters -# -# * string: Text in which to replace globals -# -# *Returns* the provided string with globals variables replaced with their values -func replace_globals(string: String) -> String: - for result in globals_regex.search_all(string): - var globresult = escoria.globals_manager.get_global( - str(result.get_string()) - ) - string = string.replace( - "{" + result.get_string() + "}", str(globresult) - ) - return string - - -# Save the state of globals in the savegame. -# -# #### Parameters -# - p_savegame: ESCSaveGame resource that holds all data of the save -func save_game(p_savegame: ESCSaveGame) -> void: - p_savegame.globals = {} - for g in _globals: - p_savegame.globals[g] = _globals[g] diff --git a/addons/escoria-core/game/core-scripts/esc/esc_inventory_manager.gd b/addons/escoria-core/game/core-scripts/esc/esc_inventory_manager.gd deleted file mode 100644 index 28958518..00000000 --- a/addons/escoria-core/game/core-scripts/esc/esc_inventory_manager.gd +++ /dev/null @@ -1,49 +0,0 @@ -# A manager for inventory objects -extends Resource -class_name ESCInventoryManager - - -# Check if the player has an inventory item -# -# #### Parameters -# -# - item: Inventory item id -# **Returns** Whether the player has the inventory -func inventory_has(item: String) -> bool: - return escoria.globals_manager.has("i/%s" % item) - - -# Get all inventory items -# **Returns** The items in the inventory -func items_in_inventory() -> Array: - var items = [] - var filtered = escoria.globals_manager.filter("i/*") - for glob in filtered.keys(): - if filtered[glob]: - items.append(glob.rsplit("i/", false)[0]) - return items - - -# Remove an item from the inventory -# -# #### Parameters -# -# - item: Inventory item id -func remove_item(item: String): - if not inventory_has(item): - escoria.logger.error( - self, - "Error removing inventory item: " + - "Trying to remove non-existent item %s." % item - ) - else: - escoria.globals_manager.set_global("i/%s" % item, false) - - -# Add an item to the inventory -# -# #### Parameters -# -# - item: Inventory item id -func add_item(item: String): - escoria.globals_manager.set_global("i/%s" % item, true) diff --git a/addons/escoria-core/game/core-scripts/esc/esc_object_manager.gd b/addons/escoria-core/game/core-scripts/esc/esc_object_manager.gd deleted file mode 100644 index 1ff09932..00000000 --- a/addons/escoria-core/game/core-scripts/esc/esc_object_manager.gd +++ /dev/null @@ -1,533 +0,0 @@ -# A manager for ESC objects -extends Resource -class_name ESCObjectManager - - -const CAMERA = "_camera" -const MUSIC = "_music" -const SOUND = "_sound" -const SPEECH = "_speech" - -const RESERVED_OBJECTS = [ - MUSIC, - SOUND, - SPEECH, -] - - -# The array of registered objects (organized by room, so each entry is a structure -# representing a room and its registered objects). This also includes one -# "room" for reserved objects; that is, we use one entry of the array to -# hold all reserved objects. This entry can be identified by the "is_reserved" -# property being set to true. -# -# "Reserved objects" are those which are named in the RESERVED_OBJECTS const -# array and include objects that are used internally by Escoria in every room, -# e.g. a music player, a sound player, a speech player, the main camera. -# -# In almost all cases, the reserved objects' entry doesn't need updating once -# created. -# -# Example structure: -# -# [ -# { -# is_reserved: true, # Indicates this is the "reserved objects" entry -# room: "", -# room_instance_id: "", -# objects: -# { -# "_camera": camera -# }, -# }, -# { -# is_reserved: false, # Indicates this an entry for a room's objectss -# room_global_id: "", -# room_instance_id: "", -# objects: -# { -# "obj1": val1, -# "obj2": val2 -# } -# } -# ] -var room_objects: Array = [] - -# We also store the current room's ids for retrieving the right objects. -var current_room_key: ESCRoomObjectsKey - -# To avoid having to look this up all the time, we hold a reference. -var reserved_objects_container: ESCRoomObjects - - -func _init() -> void: - reserved_objects_container = ESCRoomObjects.new() - reserved_objects_container.is_reserved = true - reserved_objects_container.objects = {} - room_objects.push_back(reserved_objects_container) - - current_room_key = ESCRoomObjectsKey.new() - - -# Updates which object manager room is to be treated as the currently active one. -# -# #### Parameters -# -# - room: Room to register the object with in the object manager -func set_current_room(room: ESCRoom) -> void: - if room == null: - escoria.logger.error( - self, - "Unable to set current room: No room was specified.\n" + - "Please pass in a valid ESCRoom as an argument to the method." - ) - - current_room_key.room_global_id = room.global_id - current_room_key.room_instance_id = room.get_instance_id() - - -# Register the object in the manager -# -# #### Parameters -# -# - object: Object to register -# - room: Room to register the object with in the object manager -# - force: Register the object, even if it has already been registered -# - auto_unregister: Automatically unregister object on tree_exited -func register_object(object: ESCObject, room: ESCRoom = null, force: bool = false, \ - auto_unregister: bool = true) -> void: - - if object.global_id.empty(): - object.global_id = str(object.node.get_path()).split("/root/", false)[0] - object.node.global_id = object.global_id - escoria.logger.warn( - self, - "Registering ESCObject %s with empty global_id." % object.node.name + - "Using node's full path as global_id: %s" - % object.node.global_id - ) - - # If this is a reserved object, let's make sure it's in the right place. - # Note that we also don't allow it to auto unregister and, as such, we need - # to make sure we clean these up when the application exits. - if object.global_id in RESERVED_OBJECTS: - reserved_objects_container.objects[object.global_id] = object - return - - var room_key: ESCRoomObjectsKey = ESCRoomObjectsKey.new() - - # If a room was passed in, then we're going to register the object with it; - # otherwise, we register the object with the "current room". - if room == null or room.global_id.empty(): - # We duplicate the key so as to not hold a reference when current_room_key - # changes. - if current_room_key.room_global_id.empty(): - escoria.logger.error( - self, - "The current room has no Global ID.\n" + - "Please set the ESCRoom's Global ID property." - ) - room_key.room_global_id = current_room_key.room_global_id - room_key.room_instance_id = current_room_key.room_instance_id - - if not room_key.is_valid(): - # This condition should very likely never happen. - escoria.logger.error( - self, - "No room was specified to register object with, and no current room is properly set.\n" + - "Please either pass in a valid ESCRoom to this method, or " + \ - "call set_current_room() with a valid ESCRoom first." - ) - else: - room_key.room_global_id = room.global_id - room_key.room_instance_id = room.get_instance_id() - - if not force and _object_exists_in_room(object, room_key) \ - and _object_state_in_room_is_default(object, room_key): - escoria.logger.warn( - self, - "Object with global id '%s' in room %s already registered from node path %s." - % [ - object.global_id, - room_key.room_global_id, - get_object(object.global_id, room).node.get_path() - ] - ) - return - # Object exists in room, set it to is last state (if different from - # "default") - elif _object_exists_in_room(object, room_key): - # Object is already known, set its state to last known state - object.set_state(get_object(object.global_id).state) - - # If the object is already connected, disconnect it for the case of - # forcing the registration, since we don't know if this object will be - # overwritten ("forced") in the future and, if it is, if it's set to - # auto-unregister or not. In most cases, objects are set to auto unregister. - if object.node.is_connected( - "tree_exited", - self, - "unregister_object" - ): - object.node.disconnect( - "tree_exited", - self, - "unregister_object" - ) - - if force: - # If this ID already exists and we're about to overwrite it, do the - # safe thing and unregister the old object first - unregister_object_by_global_id(object.global_id, room_key) - - if auto_unregister: - object.node.connect( - "tree_exited", - self, - "unregister_object", - [object, room_key] - ) - - if "is_interactive" in object.node and object.node.is_interactive: - object.interactive = true - - if "esc_script" in object.node and not object.node.esc_script.empty(): - var script = escoria.esc_compiler.load_esc_file( - object.node.esc_script - ) - object.events = script.events - - var objects: Dictionary = _get_room_objects_objects(room_key) - objects[object.global_id] = object - - # If object state is not STATE_DEFAULT, save it in manager's object states - if object.state != ESCObject.STATE_DEFAULT: - if get_object(object.global_id) == null: - escoria.logger.error( - self, - "Object with global id %s in room (%s, %s) not found in Object Manager." - % [ - object.global_id, - room_key.room_global_id, - room_key.room_instance_id - ] - ) - else: - get_object(object.global_id).state = object.state - - # If this is the first object for the room, that means we have a brand new - # room and it needs to be setup and tracked. - if objects.size() == 1: - var room_container: ESCRoomObjects = ESCRoomObjects.new() - room_container.room_global_id = room_key.room_global_id - room_container.room_instance_id = room_key.room_instance_id - room_container.is_reserved = false - room_container.objects = objects - room_objects.push_back(room_container) - - -# Check whether an object was registered -# -# #### Parameters -# -# - global_id: Global ID of object -# - room: ESCRoom instance the object is registered with. -# ***Returns*** Whether the object exists in the object registry -func has(global_id: String, room: ESCRoom = null) -> bool: - if global_id in RESERVED_OBJECTS: - if reserved_objects_container == null: - return false - - return reserved_objects_container.objects.has(global_id) - - var room_key: ESCRoomObjectsKey - - if room == null: - room_key = current_room_key - else: - room_key = ESCRoomObjectsKey.new() - room_key.room_global_id = room.global_id - room_key.room_instance_id = room.get_instance_id() - - if not _room_exists(room_key): - return false - - return _object_exists_in_room(ESCObject.new(global_id, null), room_key) - - -# Get the object from the object registry -# -# #### Parameters -# -# - global_id: The global id of the object to retrieve -# - room: ESCRoom instance the object is registered with. -# ***Returns*** The retrieved object, or null if not found -func get_object(global_id: String, room: ESCRoom = null) -> ESCObject: - if global_id in RESERVED_OBJECTS: - if reserved_objects_container.objects.has(global_id): - return reserved_objects_container.objects[global_id] - else: - escoria.logger.warn( - self, - "Reserved object with global id %s not found in object manager!" - % global_id - ) - return null - - var room_key: ESCRoomObjectsKey - - if room == null: - room_key = current_room_key - else: - room_key = ESCRoomObjectsKey.new() - room_key.room_global_id = room.global_id - room_key.room_instance_id = room.get_instance_id() - - if not _room_exists(room_key): - escoria.logger.warn( - self, - "Specified room is empty/not found.\n" + - "Object with global id %s in room instance (%s, %s) not found." - % [global_id, room_key.room_global_id, room_key.room_instance_id] - ) - return null - - var objects: Dictionary = _get_room_objects_objects(room_key) - - if objects.has(global_id): - return objects[global_id] - else: - escoria.logger.warn( - self, - "Object with global id %s in room instance (%s, %s) not found." - % [global_id, room_key.room_global_id, room_key.room_instance_id] - ) - if escoria.inventory_manager.inventory_has(global_id): - # item is in the inventory and may be registered to a different room - for single_room in room_objects: - # these are arrays of the objects still registered for each room - if single_room.objects.has(global_id): - escoria.logger.info( - self, - "Object with global id %s found in room instance (%s, %s) through the inventory." - % [global_id, room_key.room_global_id, room_key.room_instance_id] - ) - return single_room.objects[global_id] - return null - - -# Remove an object from the registry -# -# #### Parameters -# -# - object: The object to unregister -# - room_key: The room under which the object should be unregistered. -func unregister_object(object: ESCObject, room_key: ESCRoomObjectsKey) -> void: - if not _object_exists_in_room(object, room_key): - # Report this as a warning and not an error since this method may be - # called as part of an objectd's forced registration and the object not - # yet being managed. - escoria.logger.debug( - self, - "Unable to unregister object.\n" + - "Object with global ID %s room (%s, %s) not found. If this was " - % [ - "?" if object == null else object.global_id, - room_key.room_global_id, - room_key.room_instance_id - ] + - "part of a 'forced' registration, ignore this warning." - ) - - return - - var room_objects = _get_room_objects_objects(room_key) - - if not escoria.is_quitting and escoria.inventory_manager.inventory_has(object.global_id): - # Re-instance the node if it is an item present in inventory; that is, - # re-register it with the new current room. - if object.node != null: - object.node = object.node.duplicate() - register_object(object, null, true) - - if object.state == ESCObject.STATE_DEFAULT: - room_objects.erase(object.global_id) - - # If this room is truly empty, it's time to do away with it. - if room_objects.size() == 0: - _erase_room(room_key) - - -# Remove an object from the registry by global_id -# -# #### Parameters -# -# - global_id: The global_id of the object to unregister -# - room_key: The room under which the object should be unregistered. -func unregister_object_by_global_id(global_id: String, room_key: ESCRoomObjectsKey) -> void: - unregister_object(ESCObject.new(global_id, null), room_key) - - -# Insert data to save into savegame. For now, we only save the current room's -# objects. -# -# #### Parameters -# -# - p_savegame: The savegame resource -func save_game(p_savegame: ESCSaveGame) -> void: - if not current_room_key.is_valid() or not _room_exists(current_room_key): - escoria.logger.error( - self, - "No current room specified or found." - ) - - var objects: Dictionary = _get_room_objects_objects(current_room_key) - - p_savegame.objects = {} - - for obj_global_id in objects: - if not objects[obj_global_id] is ESCObject: - continue - p_savegame.objects[obj_global_id] = \ - objects[obj_global_id].get_save_data() - - # Add in reserved objects, too. - objects = reserved_objects_container.objects - - for obj_global_id in objects: - if not objects[obj_global_id] is ESCObject: - continue - p_savegame.objects[obj_global_id] = \ - objects[obj_global_id].get_save_data() - - -# Returns the current room's starting location. If more than one exists, the -# first one encountered is returned. -func get_start_location() -> ESCLocation: - if _room_exists(current_room_key): - for object in _get_room_objects_objects(current_room_key).values(): - if is_instance_valid(object.node) \ - and object.node is ESCLocation \ - and object.node.is_start_location: - return object - - escoria.logger.warn( - self, - "Room has no ESCLocation node with 'is_start_location' enabled. " + - "Player will be set at position (0,0)." - ) - return null - - -# Determines whether 'container' represents the current room the player is in. -# -# #### Parameters -# -# - container: The entry in the object manager array being checked. -# **Returns** True iff container represents the the current room the player is in. -func _is_current_room(container: ESCRoomObjects) -> bool: - return _compare_container_to_key(container, current_room_key) - - -# Determines whether 'container' represents the room specified. -# -# #### Parameters -# -# - container: The entry in the object manager array being checked. -# - room_key: The key representing the desired room in the object manager array. -# **Returns** True iff container represents the the object manager entry specified -# by room_key. -func _compare_container_to_key(container: ESCRoomObjects, room_key: ESCRoomObjectsKey) -> bool: - return container.room_global_id == room_key.room_global_id - - -# Checks whether an entry in the object manager array corresponds to the passed in -# room key. -# -# #### Parameters -# -# - room_key: The key representing the desired room in the object manager array. -# **Returns** True iff an entry in the object manager array corresponds to room_key. -func _room_exists(room_key: ESCRoomObjectsKey) -> bool: - for room_container in room_objects: - if _compare_container_to_key(room_container, room_key): - return true - - return false - - -# Checks whether the specified object exists in the specified object manager entry. -# -# #### Parameters -# -# - object: The object to check for existence. -# - room_key: The key representing the desired room in the object manager array. -# **Returns** True iff object exists in the object manager entry specified by room_key. -func _object_exists_in_room(object: ESCObject, room_key: ESCRoomObjectsKey) -> bool: - if object == null: - escoria.logger.warn( - self, - "Cannot check room for \"null\" objects." - ) - - return false - - for room_container in room_objects: - if _compare_container_to_key(room_container, room_key) \ - and room_container.objects.has(object.global_id): - return true - - return false - - -# Checks whether the specified object's state is "default" in the specified object manager entry. -# -# #### Parameters -# -# - object: The object to check for existence. -# - room_key: The key representing the desired room in the object manager array. -# **Returns** True if object's state is "default" in the object manager entry specified by room_key. -func _object_state_in_room_is_default(object: ESCObject, room_key: ESCRoomObjectsKey) -> bool: - if object == null: - escoria.logger.warn( - self, - "Cannot check room for \"null\" objects." - ) - - return false - - for room_container in room_objects: - if _compare_container_to_key(room_container, room_key) \ - and room_container.objects.get(object.global_id).state == ESCObject.STATE_DEFAULT: - return true - - return false - - -# Returns the objects currently being managed in the object manager entry specified -# by the specified room key. -# -# #### Parameters -# -# - room_key: The key representing the desired room in the object manager array. -# **Returns** A reference to the dictionary of the entry's objects, or an empty -# dictionary otherwise. -func _get_room_objects_objects(room_key: ESCRoomObjectsKey) -> Dictionary: - for room_container in room_objects: - if _compare_container_to_key(room_container, room_key): - return room_container.objects - - return {} - - -# Completely removes the entry in the object manager array specified by the room -# key. -# -# #### Parameters -# -# - room_key: The key representing the desired room in the object manager array. -func _erase_room(room_key: ESCRoomObjectsKey) -> void: - for room_container in room_objects: - if _compare_container_to_key(room_container, room_key): - room_objects.erase(room_container) - return diff --git a/addons/escoria-core/game/core-scripts/esc/esc_room_manager.gd b/addons/escoria-core/game/core-scripts/esc/esc_room_manager.gd deleted file mode 100644 index df75e5a1..00000000 --- a/addons/escoria-core/game/core-scripts/esc/esc_room_manager.gd +++ /dev/null @@ -1,448 +0,0 @@ -extends Resource -class_name ESCRoomManager - - -# Reserved globals which can not be overridden; prefixed with "GLOBAL_" -# -# Contains the global_id of previous room -const GLOBAL_LAST_SCENE = "ESC_LAST_SCENE" - -# If true, ESC_LAST_SCENE is not considered for automatic transitions -const GLOBAL_FORCE_LAST_SCENE_NULL = "FORCE_LAST_SCENE_NULL" - -const GLOBAL_ANIMATION_RESOURCES = "ANIMATION_RESOURCES" - -# Contains the global_id of the current room -const GLOBAL_CURRENT_SCENE = "ESC_CURRENT_SCENE" - -# Dict of the reserved globals to register and their initial values. -const RESERVED_GLOBALS = { - GLOBAL_LAST_SCENE: "", - GLOBAL_FORCE_LAST_SCENE_NULL: false, - GLOBAL_ANIMATION_RESOURCES: {}, - GLOBAL_CURRENT_SCENE: "" -} - - -# ESC commands kept around for references to their command names. -var _transition: TransitionCommand -var _wait: WaitCommand -var _accept_input: AcceptInputCommand - - -func _init() -> void: - _transition = TransitionCommand.new() - _wait = WaitCommand.new() - _accept_input = AcceptInputCommand.new() - - -# Registers all reserved global flags for use. -func register_reserved_globals() -> void: - for key in RESERVED_GLOBALS: - escoria.globals_manager.register_reserved_global( \ - key, - RESERVED_GLOBALS[key]) - - -# Performs the actions needed in order to change the current scene to the one -# specified by room_path. -# -# #### Parameters -# -# - room_path: Node path to the room that is to become the new current room. -# - enable_automatic_transitions: Whether to play the transition between rooms -# automatically or to leave the responsibility to the developer. -func change_scene(room_path: String, enable_automatic_transitions: bool) -> void: - if escoria.main and escoria.main.current_scene and escoria.main.current_scene.filename == room_path: - escoria.logger.info( - self, - "Attempting to change scene to same scene as the current scene. Aborting." - ) - return - - # We're changing scenes, so users shouldn't be able to do stuff during. - escoria.inputs_manager.input_mode = escoria.inputs_manager.INPUT_NONE - - # Clear the event queue to remove other events (there could be duplicate - # events in there so we avoid running these multiple times). Also sets a - # flag indicating a changing scene and interrupts any other currently-running - # events. - escoria.event_manager.set_changing_scene(true) - - # If FORCE_LAST_SCENE_NULL is true, force ESC_LAST_SCENE to empty - if escoria.globals_manager.get_global( \ - GLOBAL_FORCE_LAST_SCENE_NULL): - - escoria.globals_manager.set_global( - GLOBAL_LAST_SCENE, - null, - true - ) - elif escoria.main.current_scene: - # If FORCE_LAST_SCENE_NULL is false, set ESC_LAST_SCENE = current roomid - escoria.globals_manager.set_global( - GLOBAL_LAST_SCENE, - escoria.main.current_scene.global_id, - true - ) - - if escoria.dialog_player: - escoria.dialog_player.interrupt() - - escoria.inputs_manager.hover_stack.clear() - - # Check if game scene was loaded - if not escoria.game_scene: - escoria.logger.error( - self, - "Failed loading game scene %s." % \ - ESCProjectSettingsManager.get_setting( - ESCProjectSettingsManager.GAME_SCENE - ) - ) - - if escoria.main.current_scene \ - and escoria.game_scene.get_parent() == escoria.main.current_scene: - escoria.main.current_scene.remove_child(escoria.game_scene) - - # Load room scene - var res_room = escoria.resource_cache.get_resource(room_path) - - var room_scene = res_room.instance() - if room_scene: - if enable_automatic_transitions \ - and escoria.event_manager.get_running_event( - escoria.event_manager.CHANNEL_FRONT - ) != null \ - and escoria.event_manager.get_running_event( - escoria.event_manager.CHANNEL_FRONT - ).name == escoria.event_manager.EVENT_ROOM_SELECTOR: - room_scene.enabled_automatic_transitions = true - else: - room_scene.enabled_automatic_transitions = enable_automatic_transitions - - # If the game scene is already in the tree but not a child of the room - # we remove it - if escoria.game_scene.is_inside_tree() \ - and escoria.game_scene.get_parent() != room_scene: - var game_parent = escoria.game_scene.get_parent() - game_parent.remove_child(escoria.game_scene) - - room_scene.add_child(escoria.game_scene) - room_scene.move_child(escoria.game_scene, 0) - room_scene.game = escoria.game_scene - escoria.main.set_scene(room_scene) - - # We know the scene has been loaded. Make its global ID available for - # use by ESC script. - escoria.globals_manager.set_global( - escoria.room_manager.GLOBAL_CURRENT_SCENE, - room_scene.global_id, - true - ) - - # Clear queued resources - escoria.resource_cache.clear() - - escoria.inputs_manager.hotspot_focused = "" - else: - escoria.logger.error( - self, - "Failed loading room scene %s." % room_path - ) - - -# Sanitize camera limits, add player node and set the global id to the -# name of this node if it's not set manually -# -# #### Parameters -# -# - room: The ESCRoom to be initialized for use. -func init_room(room: ESCRoom) -> void: - if not is_instance_valid(room) || room == null: - escoria.logger.error( - self, - "No valid room was specified for initialization." - ) - - if room.camera_limits.empty(): - room.camera_limits.push_back(Rect2()) - - if room.camera_limits.size() == 1 and room.camera_limits[0].has_no_area(): - for child in room.get_children(): - if child is ESCBackground: - room.camera_limits[0] = \ - Rect2(0, 0, child.rect_size.x, child.rect_size.y) - - if Engine.is_editor_hint(): - return - - if room.has_node("game"): - room.game = room.get_node("game") - - if room.game == null: - room.game = escoria.game_scene - room.add_child(room.game) - room.move_child(room.game, 0) - - if room.is_run_directly: - if escoria.main.current_scene == null: - escoria.main.set_scene(room) - - # If the room node isn't at (0,0), the walk_stop function will offset the - # player by the same number of pixels when they're at the terrain edge and - # move them when it shouldn't. - if room.position != Vector2(0,0): - escoria.logger.error( - self, - "The room node's coordinates must be (0,0) instead of %s." - % room.position - ) - - _perform_script_events(room) - - -# Performs the ESC script events "setup" and "ready", in this order, if they are -# present. Also manages automatic transitions. -# -# #### Parameters -# -# - room: The ESCRoom to be initialized for use. -func _perform_script_events(room: ESCRoom) -> void: - # Used to track whether any yields have been executed before the call to - # set_scene_finish. - var yielded: bool = false - - if room.enabled_automatic_transitions \ - and not room.is_run_directly: - var script_transition_out = escoria.esc_compiler.compile([ - "%s%s" % [ESCEvent.PREFIX, escoria.event_manager.EVENT_TRANSITION_OUT], - "%s %s out" % - [ - _transition.get_command_name(), - ESCProjectSettingsManager.get_setting( - ESCProjectSettingsManager.DEFAULT_TRANSITION - ) - ], - "%s 0.1" % _wait.get_command_name() - ], - get_class() - ) - escoria.event_manager.queue_event( - script_transition_out.events[escoria.event_manager.EVENT_TRANSITION_OUT], - true - ) - - # Unpause the game if it was - escoria.set_game_paused(false) - - # Wait for transition_out event to be done - var rc = yield(escoria.event_manager, "event_finished") - while rc[1] != escoria.event_manager.EVENT_TRANSITION_OUT: - rc = yield(escoria.event_manager, "event_finished") - if rc[0] != ESCExecution.RC_OK: - return rc[0] - - yielded = true - - # With the room transitioned out, finish any room prep and run :setup if - # it exists. - if room.player_scene: - room.player = room.player_scene.instance() - room.add_child(room.player) - escoria.object_manager.register_object( - ESCObject.new( - room.player.global_id, - room.player - ), - room, - true - ) - - if escoria.globals_manager.has( - escoria.room_manager.GLOBAL_ANIMATION_RESOURCES - ): - var animations = escoria.globals_manager.get_global( - escoria.room_manager.GLOBAL_ANIMATION_RESOURCES - ) - - if room.player.global_id in animations and \ - ResourceLoader.exists(animations[room.player.global_id]): - room.player.animations = ResourceLoader.load( - animations[room.player.global_id] - ) - room.player.update_idle() - - #escoria.object_manager.get_object(escoria.object_manager.CAMERA).node.set_target(room.player) - - if room.global_id.empty(): - room.global_id = room.name - - # Manage player location at room start - if room.player != null \ - and escoria.object_manager.get_start_location() != null: - room.player.teleport(escoria.object_manager.get_start_location().node) - - # We make sure 'room' is set as the new current_scene, but without making - # it visible/the current scene tree. - if not yielded: - escoria.main.finish_current_scene_init(room) - - # Add new camera to scene being prepared. - var new_player_camera: ESCCamera = escoria.resource_cache.get_resource( - escoria.CAMERA_SCENE_PATH - ).instance() - new_player_camera.register() - room.player_camera = new_player_camera - - # We must first set the camera limits, and then worry about subsequent - # player setup since it relies on this. - escoria.main.set_camera_limits(0, room) - - # Add the camera in to the scene tree but don't make it active just yet. - new_player_camera.current = false - room.add_child(new_player_camera) - room.move_child(new_player_camera, 0) - - var setup_event_added: bool = false - - # Run the setup event, if there is one. - setup_event_added = _run_script_event(escoria.event_manager.EVENT_SETUP, room) - - if setup_event_added: - # Wait for setup event to be done - var rc = yield(escoria.event_manager, "event_finished") - while rc[1] != escoria.event_manager.EVENT_SETUP: - rc = yield(escoria.event_manager, "event_finished") - if rc[0] != ESCExecution.RC_OK: - return rc[0] - - yielded = true - - # As far as the event manager is concerned, we're done changing scenes and - # so should resume allowing events to be queued and processed. - escoria.event_manager.set_changing_scene(false) - - if room.player: - escoria.object_manager.get_object(escoria.object_manager.CAMERA).node.set_target(room.player) - - # Conclude the call to set_scene (thankyouverymuch, coroutines), including - # making the new room visible. - escoria.main.set_scene_finish() - - # Hide main and pause menus - escoria.game_scene.hide_main_menu() - escoria.game_scene.unpause_game() - - # Maybe this is ok to put in set_scene_finish() above? But it might be a bit - # confusing to not see the matching camera.current updates. - new_player_camera.make_current() - - # We know the scene has been loaded. Make its global ID available for - # use by ESC script. - escoria.globals_manager.set_global( - escoria.room_manager.GLOBAL_CURRENT_SCENE, - room.global_id, - true - ) - - # Clear queued resources - escoria.resource_cache.clear() - - escoria.inputs_manager.hotspot_focused = "" - - var command_strings: PoolStringArray = [] - - command_strings.append("%s%s" % [ESCEvent.PREFIX, escoria.event_manager.EVENT_TRANSITION_IN]) - - if room.enabled_automatic_transitions \ - or ( - not room.enabled_automatic_transitions \ - and escoria.globals_manager.get_global( \ - escoria.room_manager.GLOBAL_FORCE_LAST_SCENE_NULL) - ): - - command_strings.append("%s %s in" % - [ - _transition.get_command_name(), - ESCProjectSettingsManager.get_setting( - ESCProjectSettingsManager.DEFAULT_TRANSITION - ) - ] - ) - - command_strings.append("%s 0.1" % _wait.get_command_name()) - - command_strings.append("%s ALL" % _accept_input.get_command_name()) - - var script_transition_in = escoria.esc_compiler.compile(command_strings, get_class()) - - escoria.event_manager.queue_event( - script_transition_in.events[escoria.event_manager.EVENT_TRANSITION_IN] - ) - - var ready_event_added: bool = false - # Run the ready event, if there is one. - ready_event_added = _run_script_event(escoria.event_manager.EVENT_READY, room) - - if ready_event_added: - # Wait for ready event to be done - var rc = yield(escoria.event_manager, "event_finished") - while rc[1] != escoria.event_manager.EVENT_READY: - rc = yield(escoria.event_manager, "event_finished") - if rc[0] != ESCExecution.RC_OK: - return rc[0] - - # Now that :ready is finished, if FORCE_LAST_SCENE_NULL was true, reset it - # to false - if escoria.globals_manager.get_global( \ - escoria.room_manager.GLOBAL_FORCE_LAST_SCENE_NULL): - - escoria.globals_manager.set_global( - escoria.room_manager.GLOBAL_FORCE_LAST_SCENE_NULL, - false, - true - ) - escoria.globals_manager.set_global( - escoria.room_manager.GLOBAL_LAST_SCENE, - escoria.main.current_scene.global_id \ - if escoria.main.current_scene != null else "", - true - ) - - # Make the room's global ID available for use in ESC script. - escoria.globals_manager.set_global( - escoria.room_manager.GLOBAL_CURRENT_SCENE, - escoria.main.current_scene.global_id \ - if escoria.main.current_scene != null else "", - true - ) - - -# Runs the script event from the script attached, if any. -# -# #### Parameters -# -# - event_name: the name of the event to run -# - room: The ESCRoom to be initialized for use. -# -# *Returns* true if the event was correctly added. Will be false if the event -# does not exist in the script. -func _run_script_event(event_name: String, room: ESCRoom): - if not room.esc_script: - return false - if room.compiled_script == null: - room.compiled_script = \ - escoria.esc_compiler.load_esc_file(room.esc_script) - - if room.compiled_script.events.has(event_name): - escoria.logger.debug( - self, - "Queuing room script event %s " % event_name + - "composed of %s statements." - % room.compiled_script.events[event_name].statements.size() - ) - escoria.event_manager.queue_event(room.compiled_script.events[event_name], true) - return true - else: - return false diff --git a/addons/escoria-core/game/core-scripts/esc/types/esc_base_command.gd b/addons/escoria-core/game/core-scripts/esc/types/esc_base_command.gd deleted file mode 100644 index b750afa7..00000000 --- a/addons/escoria-core/game/core-scripts/esc/types/esc_base_command.gd +++ /dev/null @@ -1,56 +0,0 @@ -# A base class for every ESC command. -# Extending classes have to override the configure and run function -extends Resource -class_name ESCBaseCommand - - -# Regex for creating command name based on the script's filename, including -# named groups -const PATH_REGEX_GROUP = "path" -const FILE_REGEX_GROUP = "file" -const EXTENSION_REGEX_GROUP = "extension" -const COMMAND_NAME_REGEX = "(?<%s>.+)\/(?<%s>[^.]+)(?<%s>\\.[^.]*$|$)" % \ - [PATH_REGEX_GROUP, FILE_REGEX_GROUP, EXTENSION_REGEX_GROUP] - -# Regex matcher for command names -var command_name_regex: RegEx = RegEx.new() - - -func _init() -> void: - command_name_regex.compile(COMMAND_NAME_REGEX) - - -# Return the descriptor of the arguments of this command -func configure() -> ESCCommandArgumentDescriptor: - escoria.logger.error( - self, - "Command %s did not override configure. Please implement a configure() function." % get_command_name() - ) - return ESCCommandArgumentDescriptor.new() - - -# Validate whether the given arguments match the command descriptor -func validate(arguments: Array) -> bool: - return self.configure().validate(get_command_name(), arguments) - - -# Run the command -func run(command_params: Array) -> int: - escoria.logger.error( - self, - "Command %s did not override run. Please implement a run() function." % get_command_name() - ) - return 0 - - -# Return the name of the command based on the script's filename -func get_command_name() -> String: - return command_name_regex.search(get_script().get_path()).get_string(FILE_REGEX_GROUP) - - -# Function called when the command is interrupted. -func interrupt(): - escoria.logger.debug( - self, - "Command %s did not override interrupt. Please implement an interrupt() function." % get_command_name() - ) diff --git a/addons/escoria-core/game/core-scripts/esc/types/esc_camera_base_command.gd b/addons/escoria-core/game/core-scripts/esc/types/esc_camera_base_command.gd deleted file mode 100644 index a5869f57..00000000 --- a/addons/escoria-core/game/core-scripts/esc/types/esc_camera_base_command.gd +++ /dev/null @@ -1,29 +0,0 @@ -extends ESCBaseCommand -class_name ESCCameraBaseCommand - - -# Generaters a log entry when attempting to move the camera to an invalid position. -# -# #### Parameters -# -# - pos: The offending position. -# - camera: The camera object that `pos` was checked against. -func generate_viewport_warning(pos: Vector2, camera: ESCCamera) -> void: - var camera_limit: Rect2 = camera.get_camera_limit_rect() - var message: String = \ - """ - [%s]: Invalid camera position. Camera cannot be moved to %s as this is outside the viewport with current camera limit %s. - Current valid ranges for positions are: x = %s inclusive; y = %s inclusive. - """ - - escoria.logger.warn( - self, - message - % [ - get_command_name(), - pos.floor(), - camera_limit, - camera.get_current_valid_viewport_values_x(), - camera.get_current_valid_viewport_values_y() - ] - ) diff --git a/addons/escoria-core/game/core-scripts/esc/types/esc_command.gd b/addons/escoria-core/game/core-scripts/esc/types/esc_command.gd deleted file mode 100644 index 9311fc98..00000000 --- a/addons/escoria-core/game/core-scripts/esc/types/esc_command.gd +++ /dev/null @@ -1,159 +0,0 @@ -# An ESC command -extends ESCStatement -class_name ESCCommand - - -# Regex matching command lines -const REGEX = \ - '^(\\s*)(?[^\\s]+)(\\s(?([^\\[]|$)+))?' +\ - '(\\[(?[^\\]]+)\\])?' - - -# The name of this command -var name: String - -# Parameters of this command -var parameters: Array = [] - -# A list of ESCConditions to run this command. -# Conditions are combined using logical AND -var conditions: Array = [] - - -# Create a command from a command string -func _init(command_string): - var command_regex = RegEx.new() - command_regex.compile(REGEX) - - if command_regex.search(command_string): - for result in command_regex.search_all(command_string): - if "name" in result.names: - self.name = ESCUtils.get_re_group(result, "name") - if "parameters" in result.names: - # Split parameters by whitespace but allow quoted - # parameters - var quote_open = false - var parameter_values = PoolStringArray([]) - var parsed_parameters = \ - ESCUtils.sanitize_whitespace( - ESCUtils.get_re_group( - result, - "parameters" - ).strip_edges() - ) - for parameter in parsed_parameters.split(" "): - if len(parameter) > 1 and parameter.begins_with('"') and parameter.ends_with('"'): - parameters.append( - parameter - ) - elif not quote_open \ - and parameter.count(":") == 1 \ - and ':"' in parameter \ - and (parameter.ends_with(':"') or not parameter.ends_with('"')): - # The second clause in this helps to handle dialogue that starts with a space - # and also allowing single-word dialogue to be handled in a separate elif. - quote_open = true - parameter_values.append(parameter) - elif not quote_open and parameter.begins_with('"'): - quote_open = true - parameter_values.append(parameter) - elif parameter.ends_with('"'): - quote_open = false - parameter_values.append( - parameter.substr(0, len(parameter)) - ) - parameters.append(parameter_values.join(" ")) - parameter_values.resize(0) - elif quote_open: - parameter_values.append(parameter) - else: - parameters.append(parameter) - if "conditions" in result.names: - for condition in ESCUtils.get_re_group( - result, - "conditions" - ).split(","): - self.conditions.append( - ESCCondition.new(condition.strip_edges()) - ) - else: - escoria.logger.error( - self, - "Invalid command detected: %s\nCommand regexp didn't match." - % command_string - ) - - -# Check, if conditions match -func is_valid() -> bool: - if not command_exists(): - escoria.logger.error( - self, - "Invalid command detected: %s" % self.name + - "Command implementation not found in any command directory." - ) - return false - - return .is_valid() - - -# Checks that the command exists -# -# *Returns* True if the command exists, else false. -func command_exists() -> bool: - for base_path in ESCProjectSettingsManager.get_setting( - ESCProjectSettingsManager.COMMAND_DIRECTORIES - ): - var command_path = "%s/%s.gd" % [ - base_path.trim_suffix("/"), - self.name - ] - if ResourceLoader.exists(command_path): - return true - return false - - -# Run this command -func run() -> int: - var command_object = escoria.command_registry.get_command(self.name) - if command_object == null: - return ESCExecution.RC_ERROR - else: - var argument_descriptor = command_object.configure() - var prepared_arguments = argument_descriptor.prepare_arguments( - self.parameters - ) - - if command_object.validate(prepared_arguments): - escoria.logger.debug( - self, - "Running command %s with parameters %s." - % [self.name, prepared_arguments] - ) - var rc = command_object.run(prepared_arguments) - if rc is GDScriptFunctionState: - rc = yield(rc, "completed") - - escoria.logger.debug( - self, - "[%s] Return code: %d." % [self.name, rc] - ) - return rc - else: - return ESCExecution.RC_ERROR - - -# This function interrupts the command. If it was not started, it will not run. -# If it had already started, the execution will be considered as finished -# immediately and finish. If it was already finished, nothing will happen. -func interrupt(): - _is_interrupted = true - var command = escoria.command_registry.get_command(self.name) - if command.has_method("interrupt"): - command.interrupt() - - -# Override of built-in _to_string function to display the statement. -func _to_string() -> String: - return "Command %s with parameters: %s" % [name, str(parameters)] - diff --git a/addons/escoria-core/game/core-scripts/esc/types/esc_command_argument_descriptor.gd b/addons/escoria-core/game/core-scripts/esc/types/esc_command_argument_descriptor.gd deleted file mode 100644 index c25c5016..00000000 --- a/addons/escoria-core/game/core-scripts/esc/types/esc_command_argument_descriptor.gd +++ /dev/null @@ -1,187 +0,0 @@ -# The descriptor of the arguments of an ESC command -extends Reference -class_name ESCCommandArgumentDescriptor - -# As the get_type command was deprecated with Godot 2.x w we need a way to determine -# variable types. Ideally these wouldn't be hardcoded but there's no GDScript 3.x command to -# turn a type back to its name. -const GODOT_TYPE_LIST = ["nil", "bool", "int", "real", "string", \ - "vector2", "rect2", "vector3", "matrix32", "plane", "quat", \ - "aabb", "matrix3", "transform", "color", "image", "node_path", \ - "rid", "object", "input_event", "dictionary", "array", \ - "raw_array", "int_array", "real_array", "string_array", \ - "vector2_array", "vector3_array", "color_array", "max"] - - -# Maximum number of total arugments the command can handle -var max_args: int = 0 - -# Number of required arguments the command expects -var min_args: int = 0 - -# The types the arguments as TYPE_ constants. If the command is called with -# more arguments than there are entries in the types array, the additional -# arguments will be checked against the last entry of the types array. -var types: Array = [] - -# The default values for the arguments -var defaults: Array = [] - -# Whether to strip quotes on specific arguments -var strip_quotes: Array = [] - -# Whether the final argument is a series of varargs -var has_varargs: bool = false - - -# Initialize the descriptor -func _init( - p_min_args: int = 0, - p_types: Array = [], - p_defaults: Array = [], - p_strip_quotes: Array = [true], - p_has_varargs: bool = false -): - max_args = p_types.size() - min_args = p_min_args - types = p_types - defaults = p_defaults - strip_quotes = p_strip_quotes - has_varargs = p_has_varargs - - -# Combine the default argument values with the given arguments -func prepare_arguments(arguments: Array) -> Array: - var complete_arguments = defaults - var varargs = [] - - for index in range(arguments.size()): - # If we have too many arguments passed in, complete_arguments won't - # be able to match 1:1. This condition will be validated later but so - # to avoid duplicating validation code, just grow complete_arguments - # since the arguments won't be used anyway. - if index >= complete_arguments.size(): - if has_varargs: - varargs.append(arguments[index]) - else: - complete_arguments.append(arguments[index]) - elif index == complete_arguments.size() - 1 and has_varargs: - # Varargs are a special case and need to be gathered and added at - # the end as an array, untyped and unchecked. They should also only - # appear at the very end of a command's argument list. - varargs.append(arguments[index]) - else: - complete_arguments[index] = ESCUtils.get_typed_value( - arguments[index], - types[index] - ) - var strip = strip_quotes[0] - if strip_quotes.size() == complete_arguments.size(): - strip = strip_quotes[index] - - if strip and typeof(complete_arguments[index]) == TYPE_STRING: - complete_arguments[index] = complete_arguments[index].replace( - '"', - '' - ) - - if has_varargs: - complete_arguments[complete_arguments.size() - 1] = varargs - - return complete_arguments - - -# Validate whether the given arguments match the command descriptor -func validate(command: String, arguments: Array) -> bool: - var required_args_count: int = _count_leading_non_null_values(arguments, min_args) - - if required_args_count < min_args: - var verb = "was" if required_args_count == 1 else "were" - - escoria.logger.error( - self, - "Invalid arguments for command %s. " % command + - "Arguments didn't match minimum size {num}: Only {args} {verb} found." \ - .format({"num":self.min_args,"args":required_args_count,"verb":verb}) - ) - - if arguments.size() > self.max_args and not has_varargs: - escoria.logger.error( - self, - "Invalid arguments for command %s" % command + - "Maximum number of arguments ({num}) exceeded: {args}.".format( - {"num":self.max_args,"args":arguments} - ) - ) - - for index in range(arguments.size()): - if arguments[index] == null: - # No type checking for null values - continue - - if has_varargs and index == arguments.size() - 1: - # If we have varargs at the end, do not validate them. - continue - - var correct = false - var types_index = index - if types_index > types.size(): - types_index = types.size() - 1 - if not self.types[types_index] is Array: - self.types[types_index] = [self.types[index]] - for type in self.types[types_index]: - if not correct: - correct = self._is_type(arguments[index], type) - - if not correct: - var allowed_types = "[ " - for type in self.types[types_index]: - allowed_types += GODOT_TYPE_LIST[type] + " or " - allowed_types = allowed_types.substr(0, allowed_types.length() - 3) + "]" - escoria.logger.error( - self, - "Argument type did not match descriptor for command \"%s\"\n" - % command + - "Argument %d (\"%s\") is of type %s. Expected %s." - % [ - index, - arguments[index], - GODOT_TYPE_LIST[typeof(arguments[index])], - allowed_types - ] - ) - return true - - -# Check whether the given argument is of the given type -# -# #### Parameters -# -# - argument: Argument to test -# - type: Type to check -# *Returns* Whether the argument is of the given type -func _is_type(argument, type: int) -> bool: - return typeof(argument) == type - - -# Counts the number of non-null values that exist at the beginning of the array up -# to a specified index. -# -# #### Parameters -# -# - array_to_check: Array to check for leading non-null values -# - max_index: Maximum (inclusive) index to check in array_to_check -# -# *Returns* the total number of entries at the start of -# array_to_check that are not null -func _count_leading_non_null_values(array_to_check: Array, max_index: int) -> int: - if array_to_check == null or max_index < 0: - return 0 - - var leading_non_nulls_count: int = 0 - - for i in range(max_index): - if array_to_check[i] != null: - leading_non_nulls_count += 1 - - return leading_non_nulls_count diff --git a/addons/escoria-core/game/core-scripts/esc/types/esc_condition.gd b/addons/escoria-core/game/core-scripts/esc/types/esc_condition.gd deleted file mode 100644 index 8662f305..00000000 --- a/addons/escoria-core/game/core-scripts/esc/types/esc_condition.gd +++ /dev/null @@ -1,145 +0,0 @@ -# A condition to run a command -extends Reference -class_name ESCCondition - - -# Valid comparison types -enum { - COMPARISON_NONE, - COMPARISON_EQ, - COMPARISON_GT, - COMPARISON_LT, - COMPARISON_ACTIVITY -} - - -# Regex that matches condition lines -const REGEX = \ - '^(?!)?(?eq|gt|lt)? ?(?i\/)?' + \ - '(?a\/)?(?[^ ]+)( (?.+))?$' - - -const COMPARISON_DESCRIPTION = [ - "Checking if %s %s %s true%s", - "Checking if %s %s %s equals %s", - "Checking if %s %s %s greater than %s", - "Checking if %s %s %s less than %s", - "Checking if %s %s %s active%s" -] - - -# Name of the flag compared -var flag: String - -# Whether this condition is negated -var negated: bool = false - -# Whether this condition is regarding an inventory item ("i/...") -var inventory: bool = false - -# An optional comparison type. Use the COMPARISON-Enum -var comparison: int = COMPARISON_NONE - -# The value used together with the comparison type -var comparison_value - - -# Create a new condition from an ESC condition string -func _init(comparison_string: String): - var comparison_regex = RegEx.new() - comparison_regex.compile( - REGEX - ) - - if comparison_regex.search(comparison_string): - for result in comparison_regex.search_all(comparison_string): - if "is_negated" in result.names: - self.negated = true - if "comparison" in result.names: - match ESCUtils.get_re_group(result, "comparison"): - "eq": self.comparison = COMPARISON_EQ - "gt": self.comparison = COMPARISON_GT - "lt": self.comparison = COMPARISON_LT - _: - escoria.logger.error( - self, - "Invalid comparison type detected: %s" % - comparison_string + - "Comparison type %s unknown" % - ESCUtils.get_re_group( - result, - "comparison" - ) - ) - if "comparison_value" in result.names: - self.comparison_value = ESCUtils.get_typed_value( - ESCUtils.get_re_group( - result, - "comparison_value" - ) - ) - if "is_inventory" in result.names: - self.inventory = true - if "is_activity" in result.names: - self.comparison = COMPARISON_ACTIVITY - if "flag" in result.names: - self.flag = ESCUtils.get_re_group(result, "flag") - else: - escoria.logger.error( - self, - "Invalid comparison detected: %s\nComparison regexp didn't match." - % comparison_string - ) - - -# Run this comparison against the globals -func run() -> bool: - var global_name = self.flag - - escoria.logger.debug( - self, - COMPARISON_DESCRIPTION[self.comparison] % [ - "inventory item" if self.inventory else "global value", - self.flag, - "is not" if self.negated else "is", - "" if self.comparison in [COMPARISON_NONE, COMPARISON_ACTIVITY] \ - else self.comparison_value - ] - ) - - if self.inventory: - global_name = "i/%s" % flag - - var return_value = false - - if self.comparison == COMPARISON_NONE and \ - escoria.globals_manager.has(global_name) and \ - escoria.globals_manager.get_global(global_name) is bool and \ - escoria.globals_manager.get_global(global_name): - return_value = true - elif self.comparison == COMPARISON_EQ and \ - escoria.globals_manager.get_global(global_name) == \ - self.comparison_value: - return_value = true - elif self.comparison == COMPARISON_GT and \ - escoria.globals_manager.get_global(global_name) > \ - self.comparison_value: - return_value = true - elif self.comparison == COMPARISON_LT and \ - escoria.globals_manager.get_global(global_name) < \ - self.comparison_value: - return_value = true - elif self.comparison == COMPARISON_ACTIVITY and \ - escoria.object_manager.has(global_name) and \ - escoria.object_manager.get_object(global_name).active: - return_value = true - - if self.negated: - return_value = not return_value - - escoria.logger.debug( - self, - "It is" if return_value else "It isn't" - ) - - return return_value diff --git a/addons/escoria-core/game/core-scripts/esc/types/esc_dialog.gd b/addons/escoria-core/game/core-scripts/esc/types/esc_dialog.gd deleted file mode 100644 index 8e874c9b..00000000 --- a/addons/escoria-core/game/core-scripts/esc/types/esc_dialog.gd +++ /dev/null @@ -1,116 +0,0 @@ -# An ESC dialog -extends ESCStatement -class_name ESCDialog - - -# Regex that matches dialog lines -const REGEX = \ - '^(\\s*)\\?( (?[^ ]+))?' +\ - '( (?[^ ]+))?( (?.+))?$' - - -# A Regex that matches the end of a dialog -const END_REGEX = \ - '^(?\\s*)!.*$' - - -# Avatar used in the dialog -var avatar: String = "-" - -# Timeout until the timeout_option option is selected. Use 0 for no timeout -var timeout: int = 0 - -# The dialog option to select when timeout is reached -var timeout_option: int = 0 - -# A list of ESCDialogOptions -var options: Array - - -# Construct a dialog from an ESC dialog string -# -# #### Parameters -# - dialog_string: ESC dialog string -func load_string(dialog_string: String): - var dialog_regex = RegEx.new() - dialog_regex.compile(REGEX) - - if dialog_regex.search(dialog_string): - for result in dialog_regex.search_all(dialog_string): - if "avatar" in result.names: - self.avatar = ESCUtils.get_re_group(result, "avatar") - if "timeout" in result.names: - self.timeout = int( - ESCUtils.get_re_group(result, "timeout") - ) - if "timeout_option" in result.names: - self.timeout_option = int( - ESCUtils.get_re_group(result, "timeout_option") - ) - else: - escoria.logger.error( - self, - "Invalid dialog detected: %s\nDialog regexp didn't match." - % dialog_string - ) - - -# Check if dialog is valid -func is_valid() -> bool: - if self.avatar != "-" and not ResourceLoader.exists(self.avatar): - escoria.logger.error( - self, - "Avatar scene not found: %s." % self.avatar - ) - return false - if self.timeout_option > self.options.size() \ - or self.timeout_option < 0: - escoria.logger.error( - self, - "Invalid timeout_option parameter given: %d." % self.timeout_option - ) - return false - - return true - - -# Run this dialog -func run(): - escoria.logger.debug( - self, - "Starting dialog." - ) - - escoria.current_state = escoria.GAME_STATE.DIALOG - - if !escoria.dialog_player: - escoria.dialog_player = escoria.main.current_scene.get_node( - "game/ui/dialog_layer/dialog_player" - ) - - escoria.dialog_player.start_dialog_choices(self) - - var option = yield( - escoria.dialog_player, - "option_chosen" - ) as ESCDialogOption - - var rc = ESCExecution.RC_OK - - # If no valid option was returned, it means this level of dialog is done. - # If this is the case and the current level of dialog has a parent, it means - # it is still yielding and so will be shown again. - if option: - rc = option.run() - if rc is GDScriptFunctionState: - rc = yield(rc, "completed") - if rc != ESCExecution.RC_CANCEL: - # We also set this here in case a chosen option doesn't yield, since this block - # will return normally and not allow the current_state reset at the bottom of this - # method to run. - escoria.current_state = escoria.GAME_STATE.DEFAULT - return self.run() - - escoria.current_state = escoria.GAME_STATE.DEFAULT - - return rc diff --git a/addons/escoria-core/game/core-scripts/esc/types/esc_dialog_option.gd b/addons/escoria-core/game/core-scripts/esc/types/esc_dialog_option.gd deleted file mode 100644 index 7dd85294..00000000 --- a/addons/escoria-core/game/core-scripts/esc/types/esc_dialog_option.gd +++ /dev/null @@ -1,75 +0,0 @@ -# An option of an ESC dialog -extends ESCStatement -class_name ESCDialogOption - - -# Regex that matches dialog option lines -const REGEX = \ - '^[^-]*- (?[^:]+)?:?"' +\ - '(?