[Refactor] Added playTween utility function (#6545)

* Added `playTween` utility function

Co-authored-by: innerthunder <168692175+innerthunder@users.noreply.github.com>

* Update comment wording for benjie

---------

Co-authored-by: innerthunder <168692175+innerthunder@users.noreply.github.com>
This commit is contained in:
Bertie690 2025-09-13 14:36:38 -04:00 committed by GitHub
parent 465f0c2ced
commit c217f47942
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

26
src/utils/anim-utils.ts Normal file
View File

@ -0,0 +1,26 @@
import { globalScene } from "#app/global-scene";
import type { SceneBase } from "#app/scene-base";
/**
* Plays a Tween animation, resolving once the animation completes.
* @param config - The config for a single Tween
* @param scene - The {@linkcode SceneBase} on which the Tween plays; default {@linkcode globalScene}
* @returns A Promise that resolves once the Tween has been played.
*
* @privateRemarks
* The `config` input should not include an `onComplete` field as that callback is
* used to resolve the Promise containing the Tween animation.
* However, `config`'s type cannot be changed to something like `Omit<TweenBuilderConfig, "onComplete">`
* due to how the type for `TweenBuilderConfig` is defined.
*/
export async function playTween(
config: Phaser.Types.Tweens.TweenBuilderConfig,
scene: SceneBase = globalScene,
): Promise<void> {
await new Promise(resolve =>
scene.tweens.add({
...config,
onComplete: resolve,
}),
);
}