You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.5 KiB
34 lines
1.5 KiB
/**
|
|
* 战斗表现时钟(独立于 SkillPresentationEnv,避免 Skill ↔ Env ↔ TextGrid 循环引用)。
|
|
*
|
|
* **纪律:** 须与战斗倍速 / Spine 时间轴对齐的延迟(出手、命中、段数间隔等)
|
|
* 一律走 `schedulePresentation`(BattleClock 逻辑秒),禁止 Skill.scheduleOnce 墙钟。
|
|
* 仅下一帧 defer、纯 UI 引导等特殊情况可用 Cocos scheduleOnce。
|
|
*
|
|
* BattleRuntime.tick 传入 session 的 dt 已含 TimeScale;BattleClock.advance 不再二次乘倍速。
|
|
*/
|
|
export function getBattleTimeScale(): number {
|
|
const battle = gg.game?.CurentBattle as { TimeScale?: number } | undefined;
|
|
return Math.max(0, battle?.TimeScale ?? 1);
|
|
}
|
|
|
|
/**
|
|
* 战斗逻辑时钟调度(与 Spine playSkillSpine 的 battle 倍速一致)。
|
|
* @param delayLogicalSec Spine 时间轴秒数或逻辑秒(勿再除以 TimeScale)
|
|
*/
|
|
export function schedulePresentation(delayLogicalSec: number, fn: () => void): void {
|
|
scheduleBattleClock(delayLogicalSec, fn);
|
|
}
|
|
|
|
/** @deprecated 请用 schedulePresentation */
|
|
export function scheduleBattleClock(delaySec: number, fn: () => void): void {
|
|
const battle = gg.game?.CurentBattle as { session?: { clock: { schedule: (d: number, f: () => void) => void } } } | undefined;
|
|
const session = battle?.session;
|
|
const delay = Math.max(0, delaySec);
|
|
if (session?.clock) {
|
|
session.clock.schedule(delay, fn);
|
|
return;
|
|
}
|
|
// 非战斗(首页等):无 session 时走墙钟,禁止立即执行导致时序错乱
|
|
setTimeout(fn, delay * 1000);
|
|
}
|
|
|