Skip to content

Commit

Permalink
ok but what if async
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealJake12 committed Jan 26, 2024
1 parent ca47b87 commit 77062a1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 58 deletions.
50 changes: 15 additions & 35 deletions source/CoolUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,23 @@ class CoolUtil
public static function precacheVideo(name:String):Void
{
#if VIDEOS
if (OpenFlAssets.exists(Paths.video(name)))
if (FileSystem.exists(Paths.video(name)))
{
if (!loadedVideos.contains(name))
Handle.initAsync([], function(success:Bool):Void
{
var cache:VideoHandler = new VideoHandler();
cache.mute = true;
cache.load(Paths.video(name));
loadedVideos.push(name);
FlxG.log.add('Video file has been cached: ' + name);
}
else
{
FlxG.log.add('Video file has already been cached: ' + name);
}
if (!loadedVideos.contains(name))
{
var cache:VideoHandler = new VideoHandler();
cache.mute = true;
cache.load(Paths.video(name));
loadedVideos.push(name);
FlxG.log.add('Video file has been cached: ' + name);
}
else
{
FlxG.log.add('Video file has already been cached: ' + name);
}
});
}
else
{
Expand All @@ -238,29 +241,6 @@ class CoolUtil
#end
}

#if FEATURE_FILESYSTEM
/*
* this function is not working. It was solely used for hscript shit. Don't need it anymore.
*/
public static function findFilesInPath(path:String, extns:Array<String>, ?filePath:Bool = false, ?deepSearch:Bool = true):Array<String>
{
var files:Array<String> = [];

if (LimeAssets.exists(path))
{
for (file in readAssetsDirectoryFromLibrary(path, 'TEXT'))
{
var path = haxe.io.Path.join([path, file]);
var pathsFiles:Array<String> = findFilesInPath(path, extns);

for (_ in pathsFiles)
files.push(_);
}
}
return files;
}
#end

public static inline function getFileStringFromPath(file:String):String
{
return Path.withoutDirectory(Path.withoutExtension(file));
Expand Down
57 changes: 34 additions & 23 deletions source/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import debug.ChartingState;
#if VIDEOS
import hxvlc.flixel.FlxVideo as VideoHandler;
import hxvlc.flixel.FlxVideoSprite as VideoSprite;
import hxvlc.libvlc.Handle;
#end
import stages.Stage;
import stages.TankmenBG;
Expand Down Expand Up @@ -6527,36 +6528,46 @@ class PlayState extends MusicBeatState
function playCutscene(name:String, ?atend:Bool)
{
#if VIDEOS
inCutscene = true;
inCinematic = true;
var diff:String = CoolUtil.getSuffixFromDiff(CoolUtil.difficultyArray[storyDifficulty]);
cutscene = new VideoHandler();
cutscene.load(Paths.video(name));
inst.stop();
cutscene.onEndReached.add(function()
Handle.initAsync([], function(success:Bool):Void
{
inCutscene = false;
if (atend == true)
if (!success)
return;

inCutscene = true;
inCinematic = true;
var diff:String = CoolUtil.getSuffixFromDiff(CoolUtil.difficultyArray[storyDifficulty]);
cutscene = new VideoHandler();
cutscene.load(Paths.video(name));
inst.stop();
cutscene.onEndReached.add(function()
{
if (storyPlaylist.length <= 0)
LoadingState.loadAndSwitchState(new StoryMenuState());
else
inCutscene = false;
if (atend == true)
{
SONG = Song.loadFromJson(storyPlaylist[0].toLowerCase(), diff);
LoadingState.loadAndSwitchState(new PlayState());
if (storyPlaylist.length <= 0)
LoadingState.loadAndSwitchState(new StoryMenuState());
else
{
SONG = Song.loadFromJson(storyPlaylist[0].toLowerCase(), diff);
LoadingState.loadAndSwitchState(new PlayState());
}
}
}
else
{
createTimer(0.5, function(timer)
else
{
startCountdown();
});
}
createTimer(0.5, function(timer)
{
startCountdown();
});
}

cutscene.dispose();
cutscene.dispose();
});

new FlxTimer().start(0.001, function(tmr:FlxTimer):Void
{
cutscene.play();
});
});
cutscene.play();
#else
FlxG.log.warn("Platform Not Supported.");
#end
Expand Down

0 comments on commit 77062a1

Please sign in to comment.