* System interface method that CinematicParser calls with * each shot. * @param {Shot} shot * @returns {AbstractCommand[]}
(shot)
| 53 | * @returns {AbstractCommand[]} |
| 54 | */ |
| 55 | parseSetupShot (shot) { |
| 56 | const commands = [] |
| 57 | const music = getSetupMusic(shot) |
| 58 | if (music) { |
| 59 | const lastBackgroundMusic = this.undoSystemState.lastBackgroundMusic |
| 60 | this.undoSystemState.lastBackgroundMusic = _.cloneDeep(music) |
| 61 | const musicCommand = new SyncFunction(async () => { |
| 62 | await store.dispatch('audio/stopTrack', 'background') |
| 63 | |
| 64 | const srcFiles = [] |
| 65 | if (music.files.mp3) { |
| 66 | srcFiles.push(music.files.mp3) |
| 67 | } |
| 68 | if (music.files.ogg) { |
| 69 | srcFiles.push(music.files.ogg) |
| 70 | if (!music.files.mp3) { |
| 71 | // We usually have an .mp3 with the same filename, but in many cinematics we didn't specify it. |
| 72 | // Safari cannot play .ogg, so we need to specify the .mp3 file. |
| 73 | srcFiles.push(music.files.ogg.replace(/\.ogg$/, '.mp3')) |
| 74 | } |
| 75 | } |
| 76 | await store.dispatch('audio/playSound', { |
| 77 | track: 'background', |
| 78 | volume: BACKGROUND_VOLUME, |
| 79 | src: srcFiles.map(f => `/file/${f}`), |
| 80 | loop: music.loop |
| 81 | }) |
| 82 | }) |
| 83 | musicCommand.undoCommandFactory = () => { |
| 84 | if (lastBackgroundMusic) { |
| 85 | return new SyncFunction(async () => { |
| 86 | await store.dispatch('audio/stopTrack', 'background') |
| 87 | await store.dispatch('audio/playSound', { |
| 88 | track: 'background', |
| 89 | src: Object.values(lastBackgroundMusic.files).map(f => `/file/${f}`), |
| 90 | loop: lastBackgroundMusic.loop |
| 91 | }) |
| 92 | }) |
| 93 | } else { |
| 94 | return new SyncFunction(() => store.dispatch('audio/stopTrack', 'background')) |
| 95 | } |
| 96 | } |
| 97 | commands.push(musicCommand) |
| 98 | } |
| 99 | return commands |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * System interface method that CinematicParser calls on each dialogNode |