From 17e282a835232f9d2732716c04efcd9953836bf9 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Tue, 21 Feb 2023 23:27:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BC=80=E5=A7=8B=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugin/utils.ts | 13 ++++++++++-- src/ui/start.vue | 50 +++++++++++++++++++++------------------------ 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/plugin/utils.ts b/src/plugin/utils.ts index 6083d79..ea5d7fe 100644 --- a/src/plugin/utils.ts +++ b/src/plugin/utils.ts @@ -197,9 +197,18 @@ export function download(content: string, name: string) { * @param funcs 函数列表 * @param interval 调用间隔 */ -export async function doByInterval(funcs: (() => void)[], interval: number) { +export async function doByInterval( + funcs: (() => void)[], + interval: number, + awaitFirst: boolean = false +) { for await (const fn of funcs) { - await sleep(interval); + if (awaitFirst) { + await sleep(interval); + } fn(); + if (!awaitFirst) { + await sleep(interval); + } } } diff --git a/src/ui/start.vue b/src/ui/start.vue index ed4a11a..f46fbe3 100644 --- a/src/ui/start.vue +++ b/src/ui/start.vue @@ -50,7 +50,7 @@ import { nextTick, onMounted, onUnmounted, reactive, ref } from 'vue'; import { RightOutlined, SoundOutlined } from '@ant-design/icons-vue'; import { sleep } from 'mutate-animate'; import { Matrix4 } from '../plugin/webgl/matrix'; -import { keycode } from '../plugin/utils'; +import { doByInterval, keycode } from '../plugin/utils'; import { KeyCode } from '../plugin/keyCodes'; let startdiv: HTMLDivElement; @@ -184,20 +184,18 @@ async function showHard() { 'left 0.4s ease-out, top 0.4s ease-out, opacity 0.4s linear'; cursor.style.opacity = '0'; buttons.forEach(v => (v.style.transition = '')); - ids.unshift(toshow.pop()!); - await sleep(150); - ids.unshift(toshow.pop()!); - await sleep(150); - ids.unshift(toshow.pop()!); - await sleep(150); - ids.unshift(toshow.pop()!); - await sleep(400); + + await doByInterval( + Array(4).fill(() => ids.unshift(toshow.pop()!)), + 150 + ); + await sleep(250); text.value = hard; - toshow.push(hardIds.shift()!); - await sleep(150); - toshow.push(hardIds.shift()!); - await sleep(150); - toshow.push(hardIds.shift()!); + + await doByInterval( + Array(3).fill(() => toshow.push(hardIds.shift()!)), + 150 + ); selected.value = 'easy'; nextTick(() => { buttons = toshow @@ -219,24 +217,22 @@ async function setButtonAnimate() { 'left 0.4s ease-out, top 0.4s ease-out, opacity 0.4s linear'; cursor.style.opacity = '0'; buttons.forEach(v => (v.style.transition = '')); - hardIds.unshift(toshow.pop()!); - await sleep(150); - hardIds.unshift(toshow.pop()!); - await sleep(150); - hardIds.unshift(toshow.pop()!); + await doByInterval( + Array(3).fill(() => hardIds.unshift(toshow.pop()!)), + 150 + ); } text.value = text1; if (played) { text.value = text2; } - await sleep(400); - toshow.push(ids.shift()!); - await sleep(150); - toshow.push(ids.shift()!); - await sleep(150); - toshow.push(ids.shift()!); - await sleep(150); - toshow.push(ids.shift()!); + await sleep(250); + + await doByInterval( + Array(4).fill(() => toshow.push(ids.shift()!)), + 150 + ); + selected.value = 'start-game'; nextTick(() => { buttons = toshow