Skip to content

Commit e2edadb

Browse files
committed
fix: improve audio volume handling and resource manager mechanism and size limit
1 parent 0cf9d37 commit e2edadb

3 files changed

Lines changed: 16 additions & 12 deletions

File tree

src/composables/useScriptPlayer.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export function useScriptPlayer() {
8181
}
8282

8383
const ratio = elapsed / duration
84-
audio.volume = startVolume + (targetVolume - startVolume) * ratio
84+
const newVolume = startVolume + (targetVolume - startVolume) * ratio
85+
audio.volume = Math.max(0, Math.min(1, newVolume))
8586
requestAnimationFrame(fade)
8687
}
8788

@@ -92,7 +93,7 @@ export function useScriptPlayer() {
9293
const rawUrl = getBgmUrl(id, currentRegion.value)
9394
const url = resourceManager.getResolvedUrl(rawUrl)
9495
// Boost volume because script values (e.g. 0.1) are often too quiet for web playback
95-
const adjustedVolume = Math.min(volume * 5.0, 1.0)
96+
const adjustedVolume = Math.max(0, Math.min(volume * 5.0, 1.0))
9697

9798
if (bgmAudio && !bgmAudio.paused && (bgmAudio.src === url || bgmAudio.src === rawUrl)) {
9899
// Same BGM, just update volume
@@ -338,7 +339,7 @@ export function useScriptPlayer() {
338339
let blocksFound = 0
339340
let index = startIndex
340341
let isPreloading = true
341-
let hasEncounteredChoice = false
342+
let inChoiceBlock = false
342343

343344
while (index < scriptLines.value.length) {
344345
const line = scriptLines.value[index]
@@ -349,13 +350,12 @@ export function useScriptPlayer() {
349350
const cmd = parseLine(line)
350351

351352
if (cmd.type === 'choice') {
352-
hasEncounteredChoice = true
353+
inChoiceBlock = true
353354
// Reset for new branch so we scan into it
354355
blocksFound = 0
355356
isPreloading = true
356357
} else if (cmd.type === 'choiceEnd') {
357-
// End of choice block, stop scanning
358-
break
358+
inChoiceBlock = false
359359
}
360360

361361
if (isPreloading) {
@@ -403,14 +403,14 @@ export function useScriptPlayer() {
403403

404404
if (blocksFound >= limitBlocks) {
405405
isPreloading = false
406-
// If we haven't seen a choice, we can stop now.
407-
// Because we are just in linear text and reached the limit.
408-
if (!hasEncounteredChoice) {
409-
break
410-
}
411406
}
412407
}
413408

409+
// If we are not preloading and not inside a choice block (waiting for other options), we can stop.
410+
if (!isPreloading && !inChoiceBlock) {
411+
break
412+
}
413+
414414
index++
415415
}
416416
}

src/utils/resourceManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ResourceManager {
1414

1515
private currentSize: number = 0
1616
// Limit to 50MB (approx)
17-
private readonly MAX_SIZE: number = 50 * 1024 * 1024
17+
private readonly MAX_SIZE: number = 100 * 1024 * 1024
1818

1919
async preload(url: string): Promise<void> {
2020
if (this.cache.has(url)) {

src/views/PlayerView.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,4 +412,8 @@ button:hover {
412412
:deep(ruby) {
413413
ruby-position: over;
414414
}
415+
416+
:deep(rt) {
417+
font-size: 0.7em;
418+
}
415419
</style>

0 commit comments

Comments
 (0)