Skip to content

Commit

Permalink
Cutscene System V3
Browse files Browse the repository at this point in the history
  • Loading branch information
poec987 committed Sep 14, 2024
1 parent 5c504e3 commit 4a1c517
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 5 deletions.
Binary file added assets/preload/videos/scopophobia-end.mp4
Binary file not shown.
File renamed without changes.
4 changes: 2 additions & 2 deletions source/FreeplayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class FreeplayState extends MusicBeatState

PlayState.lastFPpage = page;
PlayState.lastFPselect = curSelected;
LoadingState.loadAndSwitchState(new PlayState());
PlayState.checkForCutscene(song, new PlayState());
}

public function refreshSongList(skipDestroy:Bool=false) {
Expand Down Expand Up @@ -303,7 +303,7 @@ class FreeplayState extends MusicBeatState
PlayState.isStoryMode = false;

PlayState.storyWeek = PlayState.stageDictionary[PlayState.SONG.stage];
LoadingState.loadAndSwitchState(new PlayState());
PlayState.checkForCutscene(poop, new PlayState());
}
catch(e) {
trace(e);
Expand Down
18 changes: 15 additions & 3 deletions source/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2324,7 +2324,7 @@ class PlayState extends MusicBeatState
transIn = FlxTransitionableState.defaultTransIn;
transOut = FlxTransitionableState.defaultTransOut;

FlxG.switchState(new StoryMenuState());
checkForCutscene(PlayState.curSong.toLowerCase()+"-end", new StoryMenuState());

// if ()
StoryMenuState.weekUnlocked[Std.int(Math.min(storyWeek + 1, StoryMenuState.weekUnlocked.length - 1))] = true;
Expand Down Expand Up @@ -2352,7 +2352,7 @@ class PlayState extends MusicBeatState
PlayState.SONG = Song.loadFromJson(PlayState.storyPlaylist[0].toLowerCase(), PlayState.storyPlaylist[0]);
FlxG.sound.music.stop();

LoadingState.loadAndSwitchState(new PlayState());
checkForCutscene(PlayState.storyPlaylist[0].toLowerCase(), new PlayState());
}
}
else
Expand All @@ -2361,11 +2361,23 @@ class PlayState extends MusicBeatState
}
}

public static function checkForCutscene(vidName:String, nextState:flixel.FlxState) {
var files:Array<String> = sys.FileSystem.readDirectory('assets/data/'+SONG.song.toLowerCase().trim());

if (FileSystem.exists(Paths.video(vidName))) {
VideoCutsceneState.videoFile = vidName.trim();
VideoCutsceneState.targetState = nextState;
LoadingState.loadAndSwitchState(new VideoCutsceneState());
} else {
LoadingState.loadAndSwitchState(nextState);
}
}

function returnToFreeplay() {
trace('WENT BACK TO FREEPLAY??');
FreeplayState.lastPage = lastFPpage;
FreeplayState.lastSelected = lastFPselect;
FlxG.switchState(new FreeplayState());
checkForCutscene(PlayState.curSong.toLowerCase()+"-end", new FreeplayState());
}

public function startVideo(name:String)
Expand Down
61 changes: 61 additions & 0 deletions source/VideoCutsceneState.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package;

import flixel.FlxG;
import flixel.FlxState;

#if (hxCodec >= "3.0.0") import hxcodec.flixel.FlxVideo as VideoHandler;
#elseif (hxCodec >= "2.6.1") import hxcodec.VideoHandler as VideoHandler;
#elseif (hxCodec == "2.6.0") import VideoHandler;
#else import vlc.MP4Handler as VideoHandler; #end

#if desktop
import sys.FileSystem;
#end

class VideoCutsceneState extends MusicBeatState {

public static var videoFile:String;
public static var targetState:flixel.FlxState;

public override function create() {
super.create();

FlxG.sound.music.stop();

startVideo(videoFile);
}

public function startVideo(name:String)
{
var filepath:String = Paths.video(name);
#if sys
if(!FileSystem.exists(filepath))
#else
if(!OpenFlAssets.exists(filepath))
#end
{
FlxG.log.warn('Couldnt find video file: ' + name);
return;
}

var video:VideoHandler = new VideoHandler();
#if (hxCodec >= "3.0.0")
// Recent versions
video.play(filepath);
video.onEndReached.add(function()
{
video.dispose();
FlxG.switchState(targetState);
return;
}, true);
#else
// Older versions
video.playVideo(filepath);
video.finishCallback = function()
{
FlxG.switchState(targetState);
return;
}
#end
}
}

0 comments on commit 4a1c517

Please sign in to comment.