From 32aaf98fa673dbec4ebf4bbd52e0edcc838e3a56 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Tue, 23 Apr 2024 22:31:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=95=BF=E5=BA=A6=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/game/enemy/damage.ts | 4 ++++ src/plugin/utils.ts | 16 ++++++++++++++++ src/ui/danmakuEditor.vue | 7 ++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/game/enemy/damage.ts b/src/game/enemy/damage.ts index 50a1c42..ca51114 100644 --- a/src/game/enemy/damage.ts +++ b/src/game/enemy/damage.ts @@ -938,6 +938,10 @@ export function calDamageWith( damage -= hpmax * turn; if (flags.hard === 1) damage *= 0.9; + if (flags.chapter > 1 && damage < 0) { + damage *= 0.25; + } + return damage; } diff --git a/src/plugin/utils.ts b/src/plugin/utils.ts index 11e1305..fb93cff 100644 --- a/src/plugin/utils.ts +++ b/src/plugin/utils.ts @@ -511,3 +511,19 @@ export function getIconHeight(icon: AllIds | 'hero') { } return core.getBlockInfo(icon)?.height ?? 32; } + +const ascii = 16 ** 2; +const other = 16 ** 4; +const emoji = 16 ** 5; +export function calStringSize(str: string) { + let size = 0; + + for (const char of str) { + const num = char.charCodeAt(0); + if (num < ascii) size += 1; + else if (num < other) size += 2; + else if (num < emoji) size += 2.5; + } + + return size; +} diff --git a/src/ui/danmakuEditor.vue b/src/ui/danmakuEditor.vue index aad0de5..5c97ca6 100644 --- a/src/ui/danmakuEditor.vue +++ b/src/ui/danmakuEditor.vue @@ -154,7 +154,7 @@ import { Danmaku } from '@/core/main/custom/danmaku'; import { GameUi } from '@/core/main/custom/ui'; import { sleep } from 'mutate-animate'; import { fixedUi } from '@/core/main/init/ui'; -import { tip } from '@/plugin/utils'; +import { calStringSize, tip } from '@/plugin/utils'; import { gameKey } from '@/core/main/init/hotkey'; import { isNil } from 'lodash-es'; import { stringifyCSS, parseCss, getIconHeight } from '@/plugin/utils'; @@ -294,6 +294,11 @@ function close() { } function input(value: string) { + const size = calStringSize(value); + if (size > 200) { + tip('warning', '弹幕长度超限!'); + return; + } danmaku.text = value; }