mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-01-19 12:49:25 +08:00
fix: 长度计算
This commit is contained in:
parent
a735676535
commit
32aaf98fa6
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user