From bb8b0b59b19dcfaeba535be7f3ab738898170bfb Mon Sep 17 00:00:00 2001 From: EliteMasterEric Date: Sun, 2 Jul 2023 16:46:40 -0400 Subject: [PATCH] Video cutscenes in Week 7 no longer broken --- source/funkin/Paths.hx | 8 +++++++- source/funkin/play/PlayState.hx | 18 ++++++++++++++++++ source/funkin/play/cutscene/VideoCutscene.hx | 3 ++- source/funkin/play/song/SongData.hx | 5 +++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/source/funkin/Paths.hx b/source/funkin/Paths.hx index 3943d84ee..ee2dfe5fd 100644 --- a/source/funkin/Paths.hx +++ b/source/funkin/Paths.hx @@ -6,7 +6,8 @@ import openfl.utils.Assets as OpenFlAssets; class Paths { - inline public static var SOUND_EXT = #if web "mp3" #else "ogg" #end; + public static var SOUND_EXT = #if web "mp3" #else "ogg" #end; + public static var VIDEO_EXT = "mp4"; static var currentLevel:String; @@ -96,6 +97,11 @@ class Paths return getPath('music/$key.$SOUND_EXT', MUSIC, library); } + inline static public function videos(key:String, ?library:String) + { + return getPath('videos/$key.$VIDEO_EXT', BINARY, library); + } + inline static public function voices(song:String, ?suffix:String = '') { if (suffix == null) suffix = ""; // no suffix, for a sorta backwards compatibility with older-ish voice files diff --git a/source/funkin/play/PlayState.hx b/source/funkin/play/PlayState.hx index 92356db09..2506c2433 100644 --- a/source/funkin/play/PlayState.hx +++ b/source/funkin/play/PlayState.hx @@ -1422,6 +1422,7 @@ class PlayState extends MusicBeatState // Handle keybinds. if (!isInCutscene && !disableKeys) keyShit(true); if (!isInCutscene && !disableKeys) debugKeyShit(); + if (isInCutscene && !disableKeys) handleCutsceneKeys(elapsed); // Dispatch the onUpdate event to scripted elements. dispatchEvent(new UpdateScriptEvent(elapsed)); @@ -1429,6 +1430,23 @@ class PlayState extends MusicBeatState static final CUTSCENE_KEYS:Array = [SPACE, ESCAPE, ENTER]; + function handleCutsceneKeys(elapsed:Float):Void + { + if (VideoCutscene.isPlaying()) + { + // This is a video cutscene. + + if (controls.CUTSCENE_SKIP) + { + trySkipVideoCutscene(elapsed); + } + else + { + trySkipVideoCutscene(-1); + } + } + } + public function trySkipVideoCutscene(elapsed:Float):Void { if (skipTimer == null || skipTimer.animation == null) return; diff --git a/source/funkin/play/cutscene/VideoCutscene.hx b/source/funkin/play/cutscene/VideoCutscene.hx index 652ca0287..24cf78c2a 100644 --- a/source/funkin/play/cutscene/VideoCutscene.hx +++ b/source/funkin/play/cutscene/VideoCutscene.hx @@ -30,7 +30,8 @@ class VideoCutscene if (!openfl.Assets.exists(filePath)) { - trace('ERROR: Video file does not exist: ${filePath}'); + // Display a popup. + lime.app.Application.current.window.alert('Video file does not exist: ${filePath}', 'Error playing video'); return; } diff --git a/source/funkin/play/song/SongData.hx b/source/funkin/play/song/SongData.hx index 9e3d56b77..41fc4515e 100644 --- a/source/funkin/play/song/SongData.hx +++ b/source/funkin/play/song/SongData.hx @@ -1,6 +1,8 @@ package funkin.play.song; import flixel.util.typeLimit.OneOfTwo; +import funkin.modding.events.ScriptEvent; +import funkin.modding.events.ScriptEventDispatcher; import funkin.play.song.ScriptedSong; import funkin.util.assets.DataAssets; import haxe.DynamicAccess; @@ -96,6 +98,9 @@ class SongDataParser { var song:Song = songCache.get(songId); trace('Successfully fetch song: ${songId}'); + + var event:ScriptEvent = new ScriptEvent(ScriptEvent.CREATE, false); + ScriptEventDispatcher.callEvent(song, event); return song; } else