fix: polish bark battle creation flow
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user