@@ -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 }
0 commit comments