video fix for zips

This commit is contained in:
Yoshman29
2023-04-02 19:39:50 +02:00
parent 7b9c984cf9
commit d9ca22bbda
5 changed files with 84 additions and 5 deletions
+46 -3
View File
@@ -1,10 +1,17 @@
package funkin.cutscenes;
import flixel.addons.display.FlxBackdrop;
#if sys
import sys.io.File;
#end
import funkin.ui.FunkinText;
/**
* Substate made for video cutscenes. To use it in a scripted cutscene, call `startVideo`.
*/
class VideoCutscene extends Cutscene {
public static var curVideo:Int = 0;
var path:String;
var localPath:String;
@@ -13,6 +20,10 @@ class VideoCutscene extends Cutscene {
var videoSprite:FlxSprite;
#end
var cutsceneCamera:FlxCamera;
var text:FunkinText;
var loadingBackdrop:FlxBackdrop;
var videoReady:Bool = false;
public function new(path:String, callback:Void->Void) {
super(callback);
@@ -35,9 +46,31 @@ class VideoCutscene extends Cutscene {
videoSprite = new FlxSprite();
videoSprite.cameras = [cutsceneCamera];
videoSprite.antialiasing = true;
add(videoSprite);
video.playMP4(localPath, false, videoSprite);
if (localPath.startsWith("[ZIP]")) {
text = new FunkinText(10, 10, Std.int(FlxG.width / 2), "Loading video...");
text.cameras = [cutsceneCamera];
text.visible = false;
@:privateAccess
text.regenGraphic();
add(text);
loadingBackdrop = new FlxBackdrop(text.graphic, X);
loadingBackdrop.y = FlxG.height - 20 - loadingBackdrop.height;
loadingBackdrop.cameras = [cutsceneCamera];
add(loadingBackdrop);
// ZIP PATH: EXPORT
// TODO: this but better and more ram friendly
localPath = './.temp/video-${curVideo++}.mp4';
Main.execAsync(function() {
File.saveBytes(localPath, Assets.getBytes(path));
videoReady = true;
});
} else {
video.playMP4(localPath, false, videoSprite);
}
add(videoSprite);
#end
cameras = [cutsceneCamera];
@@ -45,7 +78,17 @@ class VideoCutscene extends Cutscene {
public override function update(elapsed:Float) {
super.update(elapsed);
#if !VIDEO_CUTSCENES
#if VIDEO_CUTSCENES
if (videoReady) {
videoReady = false;
video.playMP4(localPath, false, videoSprite);
if (loadingBackdrop != null)
loadingBackdrop.visible = false;
}
if (loadingBackdrop != null) {
loadingBackdrop.x -= elapsed * FlxG.width * 0.5;
}
#else
close();
#end
}