feat: accessibility settings, subtitle/QTE improvements, docs update
This commit is contained in:
@@ -4,14 +4,13 @@ type QTEUpdateCallback = (remaining: number, total: number) => void
|
||||
type QTEResultCallback = (success: boolean) => void
|
||||
|
||||
export class QTESystem {
|
||||
// QTE (Quick Time Event / 快速反应事件):
|
||||
// 视频播放到特定时间点时弹出按键提示,玩家在倒计时内按下指定按键,
|
||||
// 成功/失败/超时分别导向不同剧情分支,并应用对应的 effects 效果。
|
||||
private timerId: ReturnType<typeof setInterval> | null = null
|
||||
private timeoutId: ReturnType<typeof setTimeout> | null = null
|
||||
private keyHandler: ((e: KeyboardEvent) => void) | null = null
|
||||
private tickMs = 50
|
||||
private active = false
|
||||
timeLimitMultiplier = 1
|
||||
singleKeyMode = false
|
||||
|
||||
trigger(
|
||||
qte: QTEDefinition,
|
||||
@@ -22,11 +21,13 @@ export class QTESystem {
|
||||
this.active = true
|
||||
|
||||
const startTime = Date.now()
|
||||
const total = qte.timeLimit * 1000
|
||||
const adjustedLimit = qte.timeLimit * this.timeLimitMultiplier
|
||||
const total = adjustedLimit * 1000
|
||||
|
||||
this.keyHandler = (e: KeyboardEvent) => {
|
||||
if (!this.active) return
|
||||
const matched = qte.keys.some(
|
||||
const targetKeys = this.singleKeyMode ? [' '] : qte.keys
|
||||
const matched = targetKeys.some(
|
||||
(k) => k.toLowerCase() === e.key.toLowerCase()
|
||||
)
|
||||
if (matched) {
|
||||
@@ -40,7 +41,7 @@ export class QTESystem {
|
||||
if (!this.active) return
|
||||
const elapsed = Date.now() - startTime
|
||||
const remaining = Math.max(0, total - elapsed)
|
||||
onUpdate(remaining / 1000, qte.timeLimit)
|
||||
onUpdate(remaining / 1000, adjustedLimit)
|
||||
if (remaining <= 0) {
|
||||
this.clear()
|
||||
onResult(false)
|
||||
|
||||
Reference in New Issue
Block a user