From c9a6f802c7a7a1f009bd90731fba31e3cfa09938 Mon Sep 17 00:00:00 2001 From: Dennis Ploeger Date: Thu, 18 Nov 2021 20:01:03 +0100 Subject: [PATCH] feat: Optimizes animation commands (#446) Co-authored-by: Dennis Ploeger --- .../game/core-scripts/esc/commands/anim.gd | 2 +- .../esc/commands/{cut_scene.gd => anim_block.gd} | 8 ++++---- .../game/core-scripts/esc/commands/set_state.gd | 12 +++++++++--- .../game/core-scripts/esc_animation_player.gd | 6 ++++++ project.godot | 12 ++++++------ 5 files changed, 26 insertions(+), 14 deletions(-) rename addons/escoria-core/game/core-scripts/esc/commands/{cut_scene.gd => anim_block.gd} (89%) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/anim.gd b/addons/escoria-core/game/core-scripts/esc/commands/anim.gd index 97a38e433..1f755f11f 100644 --- a/addons/escoria-core/game/core-scripts/esc/commands/anim.gd +++ b/addons/escoria-core/game/core-scripts/esc/commands/anim.gd @@ -4,7 +4,7 @@ # without blocking. The next command in the event will be executed immediately # after. Optional parameters: # -# * reverse: plays the animation in reverse when true +# * `reverse`: plays the animation in reverse when true # # @ESC extends ESCBaseCommand diff --git a/addons/escoria-core/game/core-scripts/esc/commands/cut_scene.gd b/addons/escoria-core/game/core-scripts/esc/commands/anim_block.gd similarity index 89% rename from addons/escoria-core/game/core-scripts/esc/commands/cut_scene.gd rename to addons/escoria-core/game/core-scripts/esc/commands/anim_block.gd index faa2845d7..7f923e195 100644 --- a/addons/escoria-core/game/core-scripts/esc/commands/cut_scene.gd +++ b/addons/escoria-core/game/core-scripts/esc/commands/anim_block.gd @@ -1,14 +1,14 @@ -# `cut_scene object name [reverse]` +# `anim_block object name [reverse]` # # Executes the animation specificed with the "name" parameter on the object, # blocking. The next command in the event will be executed when the animation # is finished playing. Optional parameters: # -# * reverse plays the animation in reverse when true +# * `reverse`: plays the animation in reverse when true # # @ESC extends ESCBaseCommand -class_name CutSceneCommand +class_name AnimBlockCommand # Return the descriptor of the arguments of this command @@ -24,7 +24,7 @@ func configure() -> ESCCommandArgumentDescriptor: func validate(arguments: Array): if not escoria.object_manager.objects.has(arguments[0]): escoria.logger.report_errors( - "anim: invalid object", + "anim_block.gd:validate", [ "Object with global id %s not found." % arguments[0] ] 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 index a2bf8bd5f..a5a11f355 100644 --- a/addons/escoria-core/game/core-scripts/esc/commands/set_state.gd +++ b/addons/escoria-core/game/core-scripts/esc/commands/set_state.gd @@ -1,9 +1,15 @@ # `set_state object state [immediate]` # -# Changes the state of an object, and executes the state animation if present. +# Changes the state of an object to the given state. +# +# If the associated animation player has an animation with the same name, +# it also plays that animation. +# # The command can be used to change the appearance of an item or a player -# character. -# If `immediate` is set to true, the animation is run directly +# character. See https://docs.escoria-framework.org/states for details. +# +# If `immediate` is set to true, the animation is directly skipped to the last +# frame # # @ESC extends ESCBaseCommand diff --git a/addons/escoria-core/game/core-scripts/esc_animation_player.gd b/addons/escoria-core/game/core-scripts/esc_animation_player.gd index ed45e97f6..3c6120754 100644 --- a/addons/escoria-core/game/core-scripts/esc_animation_player.gd +++ b/addons/escoria-core/game/core-scripts/esc_animation_player.gd @@ -136,6 +136,12 @@ func seek_end(name: String): # # - name: Name of the animation played func _on_animation_finished(name: String): + if _is_animation_player: + _animation_player.stop() + _animation_player.seek(0) + else: + _animated_sprite.stop() + _animated_sprite.frame = 0 emit_signal("animation_finished", name) diff --git a/project.godot b/project.godot index c90948523..019282a2f 100644 --- a/project.godot +++ b/project.godot @@ -15,6 +15,11 @@ _global_script_classes=[ { "path": "res://addons/escoria-core/game/core-scripts/esc/commands/accept_input.gd" }, { "base": "ESCBaseCommand", +"class": "AnimBlockCommand", +"language": "GDScript", +"path": "res://addons/escoria-core/game/core-scripts/esc/commands/anim_block.gd" +}, { +"base": "ESCBaseCommand", "class": "AnimCommand", "language": "GDScript", "path": "res://addons/escoria-core/game/core-scripts/esc/commands/anim.gd" @@ -65,11 +70,6 @@ _global_script_classes=[ { "path": "res://addons/escoria-core/game/core-scripts/esc/commands/custom.gd" }, { "base": "ESCBaseCommand", -"class": "CutSceneCommand", -"language": "GDScript", -"path": "res://addons/escoria-core/game/core-scripts/esc/commands/cut_scene.gd" -}, { -"base": "ESCBaseCommand", "class": "DebugCommand", "language": "GDScript", "path": "res://addons/escoria-core/game/core-scripts/esc/commands/debug.gd" @@ -536,6 +536,7 @@ _global_script_classes=[ { } ] _global_script_class_icons={ "AcceptInputCommand": "", +"AnimBlockCommand": "", "AnimCommand": "", "CameraPushCommand": "", "CameraSetLimitsCommand": "", @@ -546,7 +547,6 @@ _global_script_class_icons={ "CameraShiftCommand": "", "ChangeSceneCommand": "", "CustomCommand": "", -"CutSceneCommand": "", "DebugCommand": "", "DecGlobalCommand": "", "ESCActionManager": "",