From ba896508cc9f47316ead50c116d6b60c9c8abfac Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Thu, 31 Aug 2023 01:56:35 -0400 Subject: [PATCH] cartoons and stuff --- assets | 2 +- source/funkin/audio/FlxStreamSound.hx | 49 ++++++++++++++++++++++ source/funkin/freeplayStuff/DJBoyfriend.hx | 31 +++++++++++--- 3 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 source/funkin/audio/FlxStreamSound.hx diff --git a/assets b/assets index 096b42fb7..386dcac52 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 096b42fb7d263752cd39ab76ef0cc1bcb391ea51 +Subproject commit 386dcac52e7b8ddc8cc4ad3864bd8d51f01564d1 diff --git a/source/funkin/audio/FlxStreamSound.hx b/source/funkin/audio/FlxStreamSound.hx new file mode 100644 index 000000000..a572ad436 --- /dev/null +++ b/source/funkin/audio/FlxStreamSound.hx @@ -0,0 +1,49 @@ +package funkin.audio; + +import flash.media.Sound; +#if flash11 +import flash.utils.ByteArray; +#end +import flixel.sound.FlxSound; +import flixel.system.FlxAssets.FlxSoundAsset; +import openfl.Assets; +#if (openfl >= "8.0.0") +import openfl.utils.AssetType; +#end + +/** + * a FlxSound that just overrides loadEmbedded to allow for "streamed" sounds to load with better performance! + */ +class FlxStreamSound extends FlxSound +{ + public function new() + { + super(); + } + + override public function loadEmbedded(EmbeddedSound:FlxSoundAsset, Looped:Bool = false, AutoDestroy:Bool = false, ?OnComplete:Void->Void):FlxSound + { + if (EmbeddedSound == null) return this; + + cleanup(true); + + if ((EmbeddedSound is Sound)) + { + _sound = EmbeddedSound; + } + else if ((EmbeddedSound is Class)) + { + _sound = Type.createInstance(EmbeddedSound, []); + } + else if ((EmbeddedSound is String)) + { + if (Assets.exists(EmbeddedSound, AssetType.SOUND) + || Assets.exists(EmbeddedSound, AssetType.MUSIC)) _sound = Assets.getMusic(EmbeddedSound); + else + FlxG.log.error('Could not find a Sound asset with an ID of \'$EmbeddedSound\'.'); + } + + // NOTE: can't pull ID3 info from embedded sound currently + return init(Looped, AutoDestroy, OnComplete); + } +} diff --git a/source/funkin/freeplayStuff/DJBoyfriend.hx b/source/funkin/freeplayStuff/DJBoyfriend.hx index 3fa1d206e..58318df15 100644 --- a/source/funkin/freeplayStuff/DJBoyfriend.hx +++ b/source/funkin/freeplayStuff/DJBoyfriend.hx @@ -5,6 +5,8 @@ import flixel.util.FlxSignal; import funkin.util.assets.FlxAnimationUtil; import funkin.graphics.adobeanimate.FlxAtlasSprite; import flixel.system.FlxSound; +import flixel.util.FlxTimer; +import funkin.audio.FlxStreamSound; class DJBoyfriend extends FlxAtlasSprite { @@ -169,7 +171,7 @@ class DJBoyfriend extends FlxAtlasSprite addOffset('bf dj afk', 0, 0); } - var cartoonSnd:FlxSound; + var cartoonSnd:FlxStreamSound; public var playingCartoon:Bool = false; @@ -180,21 +182,40 @@ class DJBoyfriend extends FlxAtlasSprite // tv is OFF, but getting turned on FlxG.sound.play(Paths.sound('tv_on')); - cartoonSnd = new FlxSound(); + cartoonSnd = new FlxStreamSound(); FlxG.sound.defaultSoundGroup.add(cartoonSnd); } else { // plays it smidge after the click - new FlxTimer().start(0.5, 1, function(_) { + new FlxTimer().start(0.1, function(_) { FlxG.sound.play(Paths.sound('channel_switch')); }); } // cartoonSnd.loadEmbedded(Paths.sound("cartoons/peck")); // cartoonSnd.play(); - // play sound of random flash toon - // if tv is already playing, play a new one + loadCartoon(); + } + + function loadCartoon() + { + cartoonSnd.loadEmbedded(Paths.sound(getRandomFlashToon()), false, false, function() { + anim.play("Boyfriend DJ watchin tv OG", true, false, 60); + }); + cartoonSnd.play(true, FlxG.random.float(0, cartoonSnd.length)); + } + + var cartoonList:Array = Assets.list().filter(function(path) return path.startsWith("assets/sounds/cartoons/")); + + function getRandomFlashToon():String + { + var randomFile = FlxG.random.getObject(cartoonList); + + randomFile = randomFile.replace("assets/sounds/", ""); + randomFile = randomFile.substring(0, randomFile.length - 4); + + return randomFile; } public function confirm():Void