From f399ed369c069d43983d7ffb47702c2f381cd697 Mon Sep 17 00:00:00 2001 From: Haoyu Xu Date: Sun, 5 Oct 2025 20:51:07 +0800 Subject: [PATCH] feat: handle single animation case hypergryph why --- apps/showcase/src/components/player.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/apps/showcase/src/components/player.js b/apps/showcase/src/components/player.js index d12868c..767aedd 100644 --- a/apps/showcase/src/components/player.js +++ b/apps/showcase/src/components/player.js @@ -45,6 +45,8 @@ export default class Player { async init() { const _this = this + const hasOtherAnimation = + this.#animationList.filter((item) => item === 'Idle').length > 0 const playerConfig = { atlasUrl: `${import.meta.env.BASE_URL}${buildConfig.default_assets_dir}${buildConfig.filename}.atlas`, premultipliedAlpha: true, @@ -87,6 +89,7 @@ export default class Player { } }, complete: () => { + if (!hasOtherAnimation) return if ( performance.now() - _this.#resetTime >= 8 * 1000 && Math.random() < 0.3 @@ -108,6 +111,13 @@ export default class Player { }, }) widget.canvas.onclick = function () { + if (!hasOtherAnimation) return + if ( + _this.#animationList.filter((item) => item === 'Idle') + .length === 0 + ) { + return + } if (_this.#isPlayingInteract) { return } @@ -191,7 +201,11 @@ export default class Player { const animationList = this.#animationList.filter((animation) => animation.startsWith(name) ) - return animationList[Math.floor(Math.random() * animationList.length)] + if (animationList.length > 0) + return animationList[ + Math.floor(Math.random() * animationList.length) + ] + else return 'Idle' } get usePadding() {