Skip to content

Commit

Permalink
fix: sound effect on sub-scenes
Browse files Browse the repository at this point in the history
This commit fixes an issue that would cause the sound effect to not stop when it's started in a sub-scene parent.

closes #22
  • Loading branch information
ThePedroo committed Oct 11, 2023
1 parent 4a38972 commit cebae49
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
20 changes: 20 additions & 0 deletions android/app/src/main/java/com/perforvnm/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,16 @@ class MainActivity : Activity() {
buttonSubScenes.layoutParams = layoutParamsSubScenes

buttonSubScenes.setOnClickListener {
if (mediaPlayer != null) {
mediaPlayer!!.stop()
mediaPlayer!!.release()
mediaPlayer = null
}

handler.removeCallbacksAndMessages(null)

findViewById<FrameLayout>(android.R.id.content).setOnClickListener(null)

scene2(true)
}

Expand All @@ -1756,6 +1766,16 @@ class MainActivity : Activity() {
buttonSubScenes2.layoutParams = layoutParamsSubScenes2

buttonSubScenes2.setOnClickListener {
if (mediaPlayer != null) {
mediaPlayer!!.stop()
mediaPlayer!!.release()
mediaPlayer = null
}

handler.removeCallbacksAndMessages(null)

findViewById<FrameLayout>(android.R.id.content).setOnClickListener(null)

scene3(true)
}

Expand Down
2 changes: 1 addition & 1 deletion src/coder.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ ${finishScene.join('\n')}\n\n`, 6, 0)

helper.replace('__PERFORVNM_HEADER__', addHeaders ? '\n' + addHeaders : '')

const startMusicCode = helper.codePrepare(`
const startMusicCode = helper.codePrepare(`\n
mediaPlayer = MediaPlayer.create(this, R.raw.${visualNovel.menu?.background.music})
if (mediaPlayer != null) {
Expand Down
23 changes: 10 additions & 13 deletions src/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -1209,14 +1209,10 @@ function finalize(scene) {
buttonMenu.layoutParams = layoutParamsMenu\n\n`
)

if (finishScene.length != 0) {
sceneCode += helper.codePrepare(`
sceneCode += helper.codePrepare(`
buttonMenu.setOnClickListener {
${finishScene.join('\n\n')}
__PERFORVNM_START_MUSIC__\n\n`, 2, 0)
} else {
sceneCode += helper.codePrepare('buttonMenu.setOnClickListener {__PERFORVNM_START_MUSIC__' + '\n\n', 0, 4, false)
}
${finishScene.join('\n\n')}__PERFORVNM_START_MUSIC__\n\n`, 2
)

sceneCode += helper.codePrepare(`
${(visualNovel.menu ? 'menu()' : '__PERFORVNM_MENU__')}
Expand Down Expand Up @@ -1247,13 +1243,10 @@ ${finishScene.join('\n\n')}
buttonBack.layoutParams = layoutParamsBack\n\n`, 2
)

if (finishScene.length != 0) {
sceneCode += helper.codePrepare(`
sceneCode += helper.codePrepare(`
buttonBack.setOnClickListener {
${finishScene.join('\n\n')}\n\n`, 2, 0)
} else {
sceneCode += helper.codePrepare('buttonBack.setOnClickListener {\n', 0, 2, false)
}
${finishScene.join('\n\n')}\n\n`, 2
)

const oldScene = visualNovel.subScenes.find((subScene) => subScene.next == scene.name) || visualNovel.scenes[visualNovel.scenes.length - 1]

Expand Down Expand Up @@ -1320,6 +1313,8 @@ ${finishScene.join('\n\n')}\n\n`, 2, 0)

sceneCode += helper.codePrepare(`
buttonSubScenes.setOnClickListener {
${finishScene.join('\n\n')}
__PERFORVNM_SUBSCENE_1__
}
Expand All @@ -1342,6 +1337,8 @@ ${finishScene.join('\n\n')}\n\n`, 2, 0)
buttonSubScenes2.layoutParams = layoutParamsSubScenes2
buttonSubScenes2.setOnClickListener {
${finishScene.join('\n\n')}
__PERFORVNM_SUBSCENE_2__
}
Expand Down

0 comments on commit cebae49

Please sign in to comment.