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; 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`. * Substate made for video cutscenes. To use it in a scripted cutscene, call `startVideo`.
*/ */
class VideoCutscene extends Cutscene { class VideoCutscene extends Cutscene {
public static var curVideo:Int = 0;
var path:String; var path:String;
var localPath:String; var localPath:String;
@@ -14,6 +21,10 @@ class VideoCutscene extends Cutscene {
#end #end
var cutsceneCamera:FlxCamera; var cutsceneCamera:FlxCamera;
var text:FunkinText;
var loadingBackdrop:FlxBackdrop;
var videoReady:Bool = false;
public function new(path:String, callback:Void->Void) { public function new(path:String, callback:Void->Void) {
super(callback); super(callback);
localPath = Assets.getPath(this.path = path); localPath = Assets.getPath(this.path = path);
@@ -35,9 +46,31 @@ class VideoCutscene extends Cutscene {
videoSprite = new FlxSprite(); videoSprite = new FlxSprite();
videoSprite.cameras = [cutsceneCamera]; videoSprite.cameras = [cutsceneCamera];
videoSprite.antialiasing = true; 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 #end
cameras = [cutsceneCamera]; cameras = [cutsceneCamera];
@@ -45,7 +78,17 @@ class VideoCutscene extends Cutscene {
public override function update(elapsed:Float) { public override function update(elapsed:Float) {
super.update(elapsed); 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(); close();
#end #end
} }
+1 -1
View File
@@ -721,7 +721,7 @@ class PlayState extends MusicBeatState
var videoCutsceneAlt = Paths.file('songs/${PlayState.SONG.meta.name.toLowerCase()}/${prefix}cutscene.mp4'); 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'); var dialogue = Paths.file('songs/${PlayState.SONG.meta.name.toLowerCase()}/${prefix}dialogue.xml');
persistentUpdate = true; persistentUpdate = true;
if (cutsceneScriptPath != null) { if (cutsceneScriptPath != null && Assets.exists(cutsceneScriptPath)) {
openSubState(new ScriptedCutscene(cutsceneScriptPath, function() { openSubState(new ScriptedCutscene(cutsceneScriptPath, function() {
callback(); callback();
})); }));
+7 -1
View File
@@ -65,6 +65,11 @@ class ZipFolderLibrary extends AssetLibrary implements ModsAssetLibrary {
return Image.fromBytes(unzip(assets[_parsedAsset])); 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) public inline function unzip(f:SysZipEntry)
@@ -88,7 +93,8 @@ class ZipFolderLibrary extends AssetLibrary implements ModsAssetLibrary {
} }
private function getAssetPath() { private function getAssetPath() {
return _parsedAsset; trace('[ZIP]$zipPath/$_parsedAsset');
return '[ZIP]$zipPath/$_parsedAsset';
} }
public function getFiles(folder:String):Array<String> { public function getFiles(folder:String):Array<String> {
+7
View File
@@ -18,6 +18,9 @@ class MainState extends FlxState {
Main.loadGameSettings(); Main.loadGameSettings();
initiated = true; initiated = true;
#if sys
CoolUtil.deleteFolder('./.temp/'); // delete temp folder
#end
Options.save(); Options.save();
FlxG.bitmap.reset(); FlxG.bitmap.reset();
@@ -46,5 +49,9 @@ class MainState extends FlxState {
FlxG.switchState(new BetaWarningState()); FlxG.switchState(new BetaWarningState());
betaWarningShown = true; betaWarningShown = true;
} }
#if sys
sys.FileSystem.createDirectory('./.temp/');
#end
} }
} }
+23
View File
@@ -50,6 +50,29 @@ class CoolUtil
return Json.parse(Assets.getText(assetPath)); 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 * Shortcut to parse a JSON string
* @param str Path to the JSON string * @param str Path to the JSON string