Skip to content

Commit

Permalink
fixing code
Browse files Browse the repository at this point in the history
  • Loading branch information
moxie-coder committed Jan 12, 2025
1 parent 5c61fb3 commit 15aeab9
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 215 deletions.
4 changes: 2 additions & 2 deletions Project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@
<haxelib name="linc_luajit" if="LUA_ALLOWED"/>
<!--<haxelib name="hxCodec" if="VIDEOS_ALLOWED"/>-->

<section if="cpp">
<haxelib name="hxvlc" if="VIDEOS_ALLOWED" /> <!--Welcome home, hxvlc!-->
</section>

<haxelib name="hxdiscord_rpc" if="DISCORD_ALLOWED" />
<haxelib name="flxanimate"/>

<!-- Enables a terminal log prompt on debug builds -->
<haxelib name="hxcpp-debug-server" if="debug"/>
<haxedef name="HXC_LIBVLC_LOGGING" if="VIDEOS_ALLOWED debug" />
<haxedef name="HXVLC_NO_SHARE_DIRECTORY" if="VIDEOS_ALLOWED" />

<!--Disable the Flixel core focus lost screen-->
<haxedef name="FLX_NO_FOCUS_LOST_SCREEN" />
Expand Down
79 changes: 12 additions & 67 deletions source/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1928,12 +1928,12 @@ class PlayState extends MusicBeatState
/* VIDEO */
/***************/
var videoCutscene:FlxVideoSprite = null;
public function startVideo(name:String, ?callback:Void->Void = null)
public function startVideo(name:String, ?library:String = null, ?callback:Void->Void = null)
{
#if VIDEOS_ALLOWED
inCutscene = true;

var filepath:String = Paths.video(name);
var filepath:String = Paths.video(name, library);
#if sys
if(!FileSystem.exists(filepath))
#else
Expand All @@ -1947,19 +1947,18 @@ class PlayState extends MusicBeatState
videoCutscene = new FlxVideoSprite(0, 0);
videoCutscene.active = false;
videoCutscene.antialiasing = true;
videoCutscene.bitmap.onFormatSetup.add(function():Void
videoCutscene.bitmap.onFormatSetup.add(function()
{
if (video.bitmap != null && video.bitmap.bitmapData != null)
if (videoCutscene.bitmap != null && videoCutscene.bitmap.bitmapData != null)
{
final scale:Float = Math.min(FlxG.width / video.bitmap.bitmapData.width, FlxG.height / video.bitmap.bitmapData.height);
final scale:Float = Math.min(FlxG.width / videoCutscene.bitmap.bitmapData.width, FlxG.height / videoCutscene.bitmap.bitmapData.height);

videoCutscene.setGraphicSize(video.bitmap.bitmapData.width * scale, video.bitmap.bitmapData.height * scale);
videoCutscene.setGraphicSize(videoCutscene.bitmap.bitmapData.width * scale, videoCutscene.bitmap.bitmapData.height * scale);
videoCutscene.updateHitbox();
videoCutscene.screenCenter();
}
});
videoCutscene.bitmap.onEndReached.add(videoCutscene.destroy);
//#if (hxCodec < "3.0.0")
videoCutscene.load(filepath);

function startAndEnd()
Expand All @@ -1970,49 +1969,16 @@ class PlayState extends MusicBeatState
startCountdown();
}

// Lily, if you're reading this, copy this to the mobile branch, thanks! - SyncGit12
/*#if mobile
final file:String = FileSystem.readDirectory('./')[0];
#else
final file:String = haxe.io.Path.join(['Paths.video', FileSystem.readDirectory('Paths.video')[0]]);
#end*/

trace('This might not work! YAY :DDDDD');

if (file != null && file.length > 0)
video.load(file);
else
{
return;
}

/*
if (callback != null)
videoCutscene.finishCallback = callback;
else{
videoCutscene.finishCallback = function()
{
startAndEnd();
if (heyStopTrying) openfl.system.System.exit(0);
return;
}
}
*/

add(videoCutscene);

#else
videoCutscene.play(filepath);
videoCutscene.play();
if (callback != null)
return; // Might crash the game btw
else{
return; // Might crash the game btw
}
//#end // No...
callback();
else
startAndEnd();
#else
FlxG.log.warn('Platform not supported!');
if (callback != null)
return;
callback();
else
startAndEnd();
return;
Expand Down Expand Up @@ -3605,28 +3571,7 @@ class PlayState extends MusicBeatState
new FlxTimer().start(10, function(tmr:FlxTimer)
{
#if VIDEOS_ALLOWED
var vidSpr:FlxSprite;
var videoDone:Bool = true;
var video:MP4Handler = new MP4Handler(); // it plays but it doesn't show???
vidSpr = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, FlxColor.WHITE);
add(vidSpr);
#if (hxCodec < "3.0.0")
video.playVideo(Paths.video('scary'), false, false);
video.finishCallback = function()
{
videoDone = true;
vidSpr.visible = false;
Sys.exit(0);
};
#else
video.play(Paths.video('scary'));
video.onEndReached.add(function(){
video.dispose();
videoDone = true;
vidSpr.visible = false;
Sys.exit(0);
});
#end
startVideo('scary', function() Sys.exit(0));
#else
throw 'You should RUN, any minute now.'; // thought this'd be cooler
// Sys.exit(0);
Expand Down
201 changes: 55 additions & 146 deletions source/StartupState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -19,103 +19,54 @@ class StartupState extends MusicBeatState

var canChristmas = false;

public function startVideo(name:String, ?callback:Void->Void = null)
var vidSprite:FlxVideoSprite = null;

public function startVideo(name:String, ?library:String = null, ?callback:Void->Void = null)
{
#if VIDEOS_ALLOWED
var filepath:String = Paths.video(name, library);
#if sys
if(!FileSystem.exists(filepath))
#else
if(!OpenFlAssets.exists(filepath))
#end
{
FlxG.log.warn('Couldnt find video file: ' + name);
return;
}

vidSprite = new FlxVideoSprite(0, 0);
vidSprite.active = false;
vidSprite.antialiasing = true;
vidSprite.bitmap.onFormatSetup.add(function()
{
#if VIDEOS_ALLOWED
inCutscene = true;

var filepath:String = Paths.video(name);
#if sys
if(!FileSystem.exists(filepath))
#else
if(!OpenFlAssets.exists(filepath))
#end
if (vidSprite.bitmap != null && vidSprite.bitmap.bitmapData != null)
{
FlxG.log.warn('Couldnt find video file: ' + name);
return;
final scale:Float = Math.min(FlxG.width / vidSprite.bitmap.bitmapData.width, FlxG.height / vidSprite.bitmap.bitmapData.height);

vidSprite.setGraphicSize(vidSprite.bitmap.bitmapData.width * scale, vidSprite.bitmap.bitmapData.height * scale);
vidSprite.updateHitbox();
vidSprite.screenCenter();
}

vidSprite = new FlxVideoSprite(0, 0);
vidSprite.active = false;
vidSprite.antialiasing = true;
vidSprite.bitmap.onFormatSetup.add(function():Void
{
if (video.bitmap != null && video.bitmap.bitmapData != null)
{
final scale:Float = Math.min(FlxG.width / video.bitmap.bitmapData.width, FlxG.height / video.bitmap.bitmapData.height);

vidSprite.setGraphicSize(video.bitmap.bitmapData.width * scale, video.bitmap.bitmapData.height * scale);
vidSprite.updateHitbox();
vidSprite.screenCenter();
}
});
vidSprite.bitmap.onEndReached.add(vidSprite.destroy);
//#if (hxCodec < "3.0.0")
vidSprite.load(filepath);

/*public function startAndEnd()
{
if(endingSong)
endSong();
else
startCountdown();
}*/

/*public function goToTitle()
{
FlxG.switchState(TitleState.new);
super.update(elapsed);
}*/
});
vidSprite.bitmap.onEndReached.add(vidSprite.destroy);
vidSprite.load(filepath);

trace('This might not work! YAY :DDDDD');

// Lily, if you're reading this, copy this to the mobile branch, thanks! - SyncGit12
/*#if mobile
final file:String = FileSystem.readDirectory('./')[0];
#else
final file:String = haxe.io.Path.join(['Paths.video', FileSystem.readDirectory('Paths.video')[0]]);
#end*/

trace('This might not work! YAY :DDDDD');

if (file != null && file.length > 0)
video.load(file);
else
{
return;
}

/*
if (callback != null)
vidSprite.finishCallback = callback;
else{
vidSprite.finishCallback = function()
{
startAndEnd();
if (heyStopTrying) openfl.system.System.exit(0);
return;
}
}
*/

add(vidSprite);

#else
vidSprite.load(filepath);
if (callback != null)
return; // Might crash the game btw
else{
return; // Might crash the game btw
}
//#end // No...
#else
FlxG.log.warn('Platform not supported!');
if (callback != null)
return; // Might crash the game btw
else
return; // Might crash the game btw
return;
#end
}
insert(0, vidSprite);
vidSprite.play();

if (callback != null)
callback();
#else
FlxG.log.warn('Platform not supported!');
if (callback != null)
callback();

return;
#end
}

override public function create():Void
{
Expand All @@ -142,7 +93,10 @@ class StartupState extends MusicBeatState
skipTxt.scrollFactor.set();
skipTxt.alpha = 0;
skipTxt.y -= skipTxt.textField.textHeight;
add(skipTxt);
if (vidSprite != null)
insert(1, skipTxt);
else
add(skipTxt);

FlxTween.tween(skipTxt, {alpha: 1}, 1);

Expand All @@ -164,26 +118,9 @@ class StartupState extends MusicBeatState
}

function doIntro() {
/*
#if debug // for testing purposes
final vidSprite = new MP4Handler(); // it plays but it doesn't show???
#if (hxCodec < "3.0.0")
vidSprite.playVideo(Paths.video('broCopiedDenpa', 'splash'), false, false);
vidSprite.finishCallback = function()
{
try { vidSprite.dispose(); }
catch (e) {}
FlxG.switchState(TitleState.new);
};
#else
vidSprite.play(Paths.video('broCopiedDenpa', 'splash'));
vidSprite.onEndReached.add(function(){
vidSprite.dispose();
FlxG.switchState(TitleState.new);
});
#end
startVideo('broCopiedDenpa', 'splash');
#else
*/
final theIntro:Int = FlxG.random.int(0, maxIntros);
switch (theIntro) {
case 0:
Expand Down Expand Up @@ -217,41 +154,11 @@ class StartupState extends MusicBeatState
FlxTween.tween(logo, {alpha: 1, "scale.x": 1, "scale.y": 1}, 1.35, {ease: FlxEase.expoOut, onComplete: _ -> onIntroDone(0.6)});
case 4:
#if VIDEOS_ALLOWED
var vidSprite = new FlxVideoSprite(); // it plays but it doesn't show??
vidSprite.load(Paths.video('bambiStartup', 'splash'));
vidSprite.finishCallback = function()
{
try { vidSprite.dispose(); }
catch (e) {}
FlxG.switchState(TitleState.new);
};
#else
vidSprite.load(Paths.video('bambiStartup', 'splash'));
vidSprite.onEndReached.add(function(){
vidSprite.dispose();
FlxG.switchState(TitleState.new);
});
#end
//#end // No...
startVideo('bambiStartup', 'splash');
#end
case 5:
#if VIDEOS_ALLOWED
var vidSprite = new MP4Handler(); // it plays but it doesn't show???
//#if (hxCodec < "3.0.0")
var vidSprite = new FlxVideoSprite(); // it plays but it doesn't show??
vidSprite.load(Paths.video('broCopiedDenpa', 'splash'));
vidSprite.finishCallback = function()
{
try { vidSprite.dispose(); }
catch (e) {}
FlxG.switchState(TitleState.new);
};
#else
vidSprite.load(Paths.video('broCopiedDenpa', 'splash'));
vidSprite.onEndReached.add(function(){
vidSprite.dispose();
FlxG.switchState(TitleState.new);
});
#end
startVideo('broCopiedDenpa', 'splash');
#end
case 6:
if (canChristmas)
Expand All @@ -262,9 +169,11 @@ class StartupState extends MusicBeatState
logo.updateHitbox();
logo.screenCenter();
FlxTween.tween(logo, {alpha: 1, "scale.x": 1, "scale.y": 1}, 2, {ease: FlxEase.expoOut, onComplete: _ -> onIntroDone(1.5)});
} else doIntro();
}
else
doIntro();
}
// #end
#end
}

override function update(elapsed:Float)
Expand Down

3 comments on commit 15aeab9

@SyncGit12
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!, im glad to help here

@moxie-coder
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!, im glad to help here

it’s not perfect since I’m still having issues with hxvlc, and also it’s still site buggy due to the latter

@SyncGit12
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah just made a issue about it lol

Please sign in to comment.