fix: polish bark battle creation flow

This commit is contained in:
kdletters
2026-05-22 05:00:07 +08:00
parent 01da85a577
commit bf82f04b64
73 changed files with 9362 additions and 2663 deletions

View File

@@ -15,11 +15,67 @@ export const DEFAULT_BARK_BATTLE_CONFIG: BarkBattleConfig = {
roundDurationMs: 30_000,
countdownMs: 3_000,
drawThreshold: 12,
barkThreshold: 0.5,
minBarkGapMs: 300,
barkThreshold: 0.35,
minBarkGapMs: 150,
minBarkDurationMs: 90,
maxBarkDurationMs: 900,
balanceFactor: 32,
calibrationMaxWaitMs: 4_000,
opponentBasePower: 0.22,
};
const BASE_ONOMATOPOEIA = [
'轰!',
'炸场!',
'冲啊!',
'破阵!',
'爆发!',
'燃起来!',
'顶上去!',
'压过去!',
'震翻全场!',
'声浪拉满!',
] as const;
const DOG_ONOMATOPOEIA = ['轰汪!', '汪爆!', '嗷呜!'] as const;
const TECH_ONOMATOPOEIA = ['能量爆裂!', '超频!', '电光轰鸣!'] as const;
const FANTASY_ONOMATOPOEIA = ['龙吼!', '雷鸣!', '战鼓!'] as const;
type BarkBattleOnomatopoeiaSeed = {
themeDescription?: string;
playerImageDescription?: string;
opponentImageDescription?: string;
};
function pushUnique(target: string[], words: readonly string[]) {
for (const word of words) {
if (!target.includes(word)) {
target.push(word);
}
}
}
export function buildBarkBattleDefaultOnomatopoeia(
seed: BarkBattleOnomatopoeiaSeed = {},
) {
const joined = [
seed.themeDescription,
seed.playerImageDescription,
seed.opponentImageDescription,
]
.join(' ')
.toLowerCase();
const words: string[] = [];
if (/||||||shiba|husky|corgi|dog/u.test(joined)) {
pushUnique(words, DOG_ONOMATOPOEIA);
}
if (/||||||||laser|robot|mecha|cyber/u.test(joined)) {
pushUnique(words, TECH_ONOMATOPOEIA);
}
if (/||||||dragon|knight|magic/u.test(joined)) {
pushUnique(words, FANTASY_ONOMATOPOEIA);
}
pushUnique(words, BASE_ONOMATOPOEIA);
return words.slice(0, 16);
}

View File

@@ -26,6 +26,11 @@ export class BarkBattleController {
this.restart();
}
updateConfigForActiveRound(config: BarkBattleConfig) {
this.config = config;
this.detector = this.createDetector();
}
finishNow() {
if (this.session.snapshot.phase !== 'playing') {
this.session = this.session.startMockRound();

View File

@@ -72,4 +72,22 @@ describe('BarkBattleController', () => {
expect(controller.getSnapshot().player.barkCount).toBe(2);
});
it('默认阈值和冷却降低后,真实输入能快速连续触发声浪', () => {
const controller = new BarkBattleController({
...DEFAULT_BARK_BATTLE_CONFIG,
countdownMs: 0,
});
controller.startWithMockInput();
controller.submitInputSample(0.36, 0);
controller.submitInputSample(0.38, 150);
controller.submitInputSample(0.1, 170);
controller.submitInputSample(0.39, 300);
controller.submitInputSample(0.1, 320);
expect(DEFAULT_BARK_BATTLE_CONFIG.barkThreshold).toBeLessThanOrEqual(0.35);
expect(DEFAULT_BARK_BATTLE_CONFIG.minBarkGapMs).toBeLessThanOrEqual(150);
expect(controller.getSnapshot().player.barkCount).toBe(3);
});
});