From bbe310bc77279b10ac41c10b44f4698db8bd3d51 Mon Sep 17 00:00:00 2001 From: Litrix Date: Tue, 25 Mar 2025 13:05:54 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=88=20perf:=202048=E8=AE=A1=E5=88=86?= =?UTF-8?q?=E6=9D=BF=E6=95=B0=E5=AD=97=E6=98=BE=E7=A4=BA=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 2 +- src/components/game2048/Game2048.vue | 4 +- src/components/game2048/Game2048Score.vue | 10 +- .../game2048/Game2048ScoreDigit.vue | 72 ++++++++++ src/components/game2048/Game2048ScoreV2.vue | 135 ++++++++++++++++++ src/components/game2048/Game2048V2.vue | 62 ++++---- src/env.ts | 2 +- src/utils/async-queue.ts | 16 ++- src/utils/double-queue.ts | 48 ++++--- src/utils/future.ts | 23 +-- src/utils/types.ts | 3 + src/views/Game2048PageV2.vue | 11 +- 12 files changed, 314 insertions(+), 74 deletions(-) create mode 100644 src/components/game2048/Game2048ScoreDigit.vue create mode 100644 src/components/game2048/Game2048ScoreV2.vue diff --git a/.env b/.env index 3e950b1..fcab86e 100644 --- a/.env +++ b/.env @@ -2,4 +2,4 @@ VITE_REQUEST_BASE_URL=https://wzpmc.cn:18080 # VITE_REQUEST_BASE_URL=http://172.16.114.84:58082 VITE_WEBSOCKET_BASE_URL=wss://wzpmc.cn:18080 # VITE_WEBSOCKET_BASE_URL=ws://172.16.114.84:58082 -VITE_GAME_2048_DEBUG=true +VITE_GAME_2048_DEBUG=false diff --git a/src/components/game2048/Game2048.vue b/src/components/game2048/Game2048.vue index 37bab42..b7f39c5 100644 --- a/src/components/game2048/Game2048.vue +++ b/src/components/game2048/Game2048.vue @@ -295,8 +295,8 @@ let enteredBackgroundTileCount = 0; */ let maxId = 0; const tileGrid = reactive([]); -const tileAddFutureMap = new FutureMap(); -const tileTransitionFutureMap = new FutureMap(); +const tileAddFutureMap = new FutureMap(); +const tileTransitionFutureMap = new FutureMap(); const tileBackgroundColorMapping: Record = { 2: 'rgb(238, 228, 218)', 4: 'rgb(237, 224, 200)', diff --git a/src/components/game2048/Game2048Score.vue b/src/components/game2048/Game2048Score.vue index 068375a..bc4f695 100644 --- a/src/components/game2048/Game2048Score.vue +++ b/src/components/game2048/Game2048Score.vue @@ -4,7 +4,7 @@ 最高数字
-
{{ displayedScore }}
+
{{ score }}
@@ -43,13 +43,15 @@ import { nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'; const props = defineProps<{ score: number; }>(); -const displayedScore = ref(props.score); +const score = ref(props.score); const scoreDiv = ref(); const scoreQueue = new AsyncQueue(); let isUnmounted = false; watch( () => props.score, (score) => { + console.log(score); + scoreQueue.push(score); }, ); @@ -57,13 +59,13 @@ onMounted(async () => { let continuouslyRolling = false; while (!isUnmounted) { try { - const score = await scoreQueue.shift(); + const s = await scoreQueue.shift(); await scoreDiv.value?.animate([{ transform: 'none' }, { transform: 'translateY(-100%)' }], { easing: continuouslyRolling ? 'linear' : 'ease-in', fill: 'forwards', duration: 100 / (scoreQueue.size + 1 + Number(continuouslyRolling)), }).finished; - displayedScore.value = score; + score.value = s; await nextTick(); continuouslyRolling = scoreQueue.size > 0; await scoreDiv.value?.animate([{ transform: 'translateY(100%)' }, { transform: 'none' }], { diff --git a/src/components/game2048/Game2048ScoreDigit.vue b/src/components/game2048/Game2048ScoreDigit.vue new file mode 100644 index 0000000..4bac8bc --- /dev/null +++ b/src/components/game2048/Game2048ScoreDigit.vue @@ -0,0 +1,72 @@ + + + + diff --git a/src/components/game2048/Game2048ScoreV2.vue b/src/components/game2048/Game2048ScoreV2.vue new file mode 100644 index 0000000..902b3d8 --- /dev/null +++ b/src/components/game2048/Game2048ScoreV2.vue @@ -0,0 +1,135 @@ + + + + + diff --git a/src/components/game2048/Game2048V2.vue b/src/components/game2048/Game2048V2.vue index d6baec1..305a74f 100644 --- a/src/components/game2048/Game2048V2.vue +++ b/src/components/game2048/Game2048V2.vue @@ -57,6 +57,25 @@ line-height: 1; } +