video fix for zips
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -721,7 +721,7 @@ class PlayState extends MusicBeatState
|
||||
var videoCutsceneAlt = Paths.file('songs/${PlayState.SONG.meta.name.toLowerCase()}/${prefix}cutscene.mp4');
|
||||
var dialogue = Paths.file('songs/${PlayState.SONG.meta.name.toLowerCase()}/${prefix}dialogue.xml');
|
||||
persistentUpdate = true;
|
||||
if (cutsceneScriptPath != null) {
|
||||
if (cutsceneScriptPath != null && Assets.exists(cutsceneScriptPath)) {
|
||||
openSubState(new ScriptedCutscene(cutsceneScriptPath, function() {
|
||||
callback();
|
||||
}));
|
||||
|
||||
@@ -65,6 +65,11 @@ class ZipFolderLibrary extends AssetLibrary implements ModsAssetLibrary {
|
||||
return Image.fromBytes(unzip(assets[_parsedAsset]));
|
||||
}
|
||||
|
||||
public override function getPath(id:String):String {
|
||||
if (!__parseAsset(id)) return null;
|
||||
return getAssetPath();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public inline function unzip(f:SysZipEntry)
|
||||
@@ -88,7 +93,8 @@ class ZipFolderLibrary extends AssetLibrary implements ModsAssetLibrary {
|
||||
}
|
||||
|
||||
private function getAssetPath() {
|
||||
return _parsedAsset;
|
||||
trace('[ZIP]$zipPath/$_parsedAsset');
|
||||
return '[ZIP]$zipPath/$_parsedAsset';
|
||||
}
|
||||
|
||||
public function getFiles(folder:String):Array<String> {
|
||||
|
||||
@@ -18,6 +18,9 @@ class MainState extends FlxState {
|
||||
Main.loadGameSettings();
|
||||
initiated = true;
|
||||
|
||||
#if sys
|
||||
CoolUtil.deleteFolder('./.temp/'); // delete temp folder
|
||||
#end
|
||||
Options.save();
|
||||
|
||||
FlxG.bitmap.reset();
|
||||
@@ -46,5 +49,9 @@ class MainState extends FlxState {
|
||||
FlxG.switchState(new BetaWarningState());
|
||||
betaWarningShown = true;
|
||||
}
|
||||
|
||||
#if sys
|
||||
sys.FileSystem.createDirectory('./.temp/');
|
||||
#end
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,29 @@ class CoolUtil
|
||||
return Json.parse(Assets.getText(assetPath));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a folder recursively
|
||||
* @param delete Path to the folder.
|
||||
*/
|
||||
public static function deleteFolder(delete:String) {
|
||||
#if sys
|
||||
if (!sys.FileSystem.exists(delete)) return;
|
||||
var files:Array<String> = sys.FileSystem.readDirectory(delete);
|
||||
for(file in files) {
|
||||
if (sys.FileSystem.isDirectory(delete + "/" + file)) {
|
||||
deleteFolder(delete + "/" + file);
|
||||
sys.FileSystem.deleteDirectory(delete + "/" + file);
|
||||
} else {
|
||||
try {
|
||||
sys.FileSystem.deleteFile(delete + "/" + file);
|
||||
} catch(e) {
|
||||
Logs.trace("Could not delete " + delete + "/" + file, WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut to parse a JSON string
|
||||
* @param str Path to the JSON string
|
||||
|
||||
Reference in New Issue
Block a user