-
Notifications
You must be signed in to change notification settings - Fork 485
Make Eternal Loom animation dynamic based on threads collected by the player #2864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
844d4a5
implemented uisfx_player
Un-player0 79bf0dc
Moved sound files to first_party
Un-player0 dff43b4
created multiple players
Un-player0 9a21a52
updated code to fit new players
Un-player0 be91aec
Merge branch 'endlessm:main' into main
Un-player0 de4f0a4
random pitch for sliders and buttons
Un-player0 02097c9
Merge branch 'main' of https://github.com/Un-player0/threadbare-issue…
Un-player0 d4b1c33
audiostreams accessed by their unique names
Un-player0 a7ccf9f
Merge branch 'endlessm:main' into main
Un-player0 eb0371b
Merge branch 'endlessm:main' into main
Un-player0 3409e38
Eternal Loom new animation
Un-player0 6998727
small update
Un-player0 c6aa7e9
Merge branch 'endlessm:main' into main
Un-player0 d363067
formatting
Un-player0 507448b
formatting
Un-player0 e622078
small improvements
Un-player0 afc0e1b
small improvements
Un-player0 d961f24
randomness and curve length
Un-player0 b549616
new animation PathFollow2D
Un-player0 ab60cc7
small fix
Un-player0 fd9f674
Suggestions and small improvements
Un-player0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
scenes/game_elements/props/eternal_loom/components/loom_offering_animation.gd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| # SPDX-FileCopyrightText: The Threadbare Authors | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
| @tool | ||
| class_name LoomOfferingAnimation | ||
| extends Node2D | ||
|
|
||
| signal animation_finished | ||
|
|
||
| const WORLD_IMAGINATION = preload("uid://6bf8rum68wq3") | ||
| const WORLD_MEMORY = preload("uid://5wscjc8yqqts") | ||
| const WORLD_SPIRIT = preload("uid://cepg1o3ihp055") | ||
|
|
||
| ## The time in seconds it takes for the animation to finish, determines the speed of threads | ||
| @export var animation_time: float = 5.0 | ||
| ## Number of threads in the animation for the in-editor preview | ||
| @export var debug_thread_count: int = 6 | ||
|
|
||
| @export_tool_button("Play") var play_animation: Callable = play_loom_animation_debug | ||
|
|
||
| @onready var animation_path: Path2D = %AnimationPath | ||
| @onready var loom_offering_sound: AudioStreamPlayer2D = $LoomOfferingSound | ||
|
|
||
|
|
||
| func play_loom_animation() -> void: | ||
| _loom_animation_play(GameState.quest.inventory.items) | ||
|
|
||
|
|
||
| ## Only used for the in-editor preview | ||
| func play_loom_animation_debug() -> void: | ||
| var debug_items: Array[InventoryItem] | ||
| # TODO: InventoryItem needs a utility function to obtain all types except NONE. | ||
| var item_types := InventoryItem.COLORS_PER_TYPE.keys() | ||
| for i in range(debug_thread_count): | ||
| var item := InventoryItem.new() | ||
| item.type = item_types.pick_random() | ||
| debug_items.append(item) | ||
| _loom_animation_play(debug_items) | ||
|
|
||
|
|
||
| func _loom_animation_play(thread_list: Array[InventoryItem]) -> void: | ||
| if thread_list.is_empty(): | ||
| animation_finished.emit() | ||
| return | ||
|
|
||
| var separation := 1.0 / thread_list.size() | ||
|
|
||
| # Time it takes for all threads to loop | ||
| var loop_time := animation_time * 0.7 | ||
|
|
||
| loom_offering_sound.play() | ||
|
|
||
| var counter: int = 0 | ||
| for thread in thread_list: | ||
| var path_follow := PathFollow2D.new() | ||
| path_follow.rotates = false | ||
| var sprite := Sprite2D.new() | ||
|
|
||
| sprite.texture = thread.get_world_texture() | ||
| path_follow.add_child(sprite) | ||
|
|
||
| animation_path.add_child(path_follow) | ||
|
|
||
| # Starting point for each thread | ||
| path_follow.progress_ratio = counter * separation | ||
|
|
||
| # Time variation between threads | ||
| var time_variation := loop_time / (2.0 * thread_list.size()) | ||
|
|
||
| var tween := path_follow.create_tween() | ||
|
|
||
| # The first thread is the last to end | ||
| if counter == 0: | ||
| tween.finished.connect(_on_animation_finished) | ||
|
|
||
| # Animation Start | ||
| tween.tween_property(sprite, "scale", Vector2(0, 0), 0) | ||
|
|
||
| tween.tween_property(sprite, "scale", Vector2(1, 1), 0.5) | ||
| # Loop around | ||
| tween.parallel().tween_property( | ||
| path_follow, "progress_ratio", 2.0, loop_time - time_variation * counter | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, so when counter is zero this property is tweened by |
||
| ) | ||
|
|
||
| # Animation end | ||
| ( | ||
| tween | ||
| . tween_property(sprite, "global_position", animation_path.global_position, 0.25) | ||
| . set_ease(Tween.EASE_OUT) | ||
| ) | ||
| tween.parallel().tween_property(sprite, "modulate", Color(0, 0, 0, 0), 0.5) | ||
| tween.parallel().tween_property(sprite, "scale", Vector2(3, 3), 0.5) | ||
| tween.tween_callback(_thread_free.bind(sprite)) | ||
| counter += 1 | ||
|
|
||
|
|
||
| # Remove thread once animation finishes | ||
| func _thread_free(thread: Sprite2D) -> void: | ||
| thread.queue_free() | ||
|
|
||
|
|
||
| func _on_animation_finished() -> void: | ||
| animation_finished.emit() | ||
1 change: 1 addition & 0 deletions
1
scenes/game_elements/props/eternal_loom/components/loom_offering_animation.gd.uid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| uid://byu17bpk0v5n7 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent! Yes I see you need one PathFollow2D per thread.