Replace calls to FlxG.sound.playMusic with ones that set the BPM.

This commit is contained in:
EliteMasterEric 2024-03-23 23:38:07 -04:00
parent ecea5e89e2
commit 24b03e4f6b
6 changed files with 51 additions and 27 deletions

2
assets

@ -1 +1 @@
Subproject commit 024ade791ffc39afcf8b075841b19ca0f67b00d5 Subproject commit 3e8bea70e7dcc76df67a0e87b85ef28ed5140371

View file

@ -290,10 +290,11 @@ class FunkinSound extends FlxSound implements ICloneable<FunkinSound>
* @param key The key of the music you want to play. Music should be at `music/<key>/<key>.ogg`. * @param key The key of the music you want to play. Music should be at `music/<key>/<key>.ogg`.
* @param params A set of additional optional parameters. * @param params A set of additional optional parameters.
* Data should be at `music/<key>/<key>-metadata.json`. * Data should be at `music/<key>/<key>-metadata.json`.
* @return Whether the music was started. `false` if music was already playing or could not be started
*/ */
public static function playMusic(key:String, params:FunkinSoundPlayMusicParams):Void public static function playMusic(key:String, params:FunkinSoundPlayMusicParams):Bool
{ {
if (!(params.overrideExisting ?? false) && (FlxG.sound.music?.exists ?? false) && FlxG.sound.music.playing) return; if (!(params.overrideExisting ?? false) && (FlxG.sound.music?.exists ?? false) && FlxG.sound.music.playing) return false;
if (!(params.restartTrack ?? false) && FlxG.sound.music?.playing) if (!(params.restartTrack ?? false) && FlxG.sound.music?.playing)
{ {
@ -303,7 +304,7 @@ class FunkinSound extends FlxSound implements ICloneable<FunkinSound>
// Stop here if we would play a matching music track. // Stop here if we would play a matching music track.
if (existingSound._label == Paths.music('$key/$key')) if (existingSound._label == Paths.music('$key/$key'))
{ {
return; return false;
} }
} }
} }
@ -328,11 +329,20 @@ class FunkinSound extends FlxSound implements ICloneable<FunkinSound>
FlxG.sound.music.kill(); FlxG.sound.music.kill();
} }
var music = FunkinSound.load(Paths.music('$key/$key'), params?.startingVolume ?? 1.0, true, false, true); var music = FunkinSound.load(Paths.music('$key/$key'), params?.startingVolume ?? 1.0, params.loop ?? true, false, true);
if (music != null) FlxG.sound.music = music; if (music != null)
{
FlxG.sound.music = music;
// Prevent repeat update() and onFocus() calls. // Prevent repeat update() and onFocus() calls.
FlxG.sound.list.remove(FlxG.sound.music); FlxG.sound.list.remove(FlxG.sound.music);
return true;
}
else
{
return false;
}
} }
/** /**
@ -451,6 +461,12 @@ typedef FunkinSoundPlayMusicParams =
*/ */
var ?restartTrack:Bool; var ?restartTrack:Bool;
/**
* Whether the music should loop or play once.
* @default `true`
*/
var ?loop:Bool;
/** /**
* Whether to check for `SongMusicData` to update the Conductor with. * Whether to check for `SongMusicData` to update the Conductor with.
* @default `true` * @default `true`

View file

@ -13,6 +13,7 @@ import flixel.text.FlxBitmapText;
import flixel.tweens.FlxEase; import flixel.tweens.FlxEase;
import funkin.ui.freeplay.FreeplayState; import funkin.ui.freeplay.FreeplayState;
import flixel.tweens.FlxTween; import flixel.tweens.FlxTween;
import funkin.audio.FunkinSound;
import flixel.util.FlxGradient; import flixel.util.FlxGradient;
import flixel.util.FlxTimer; import flixel.util.FlxTimer;
import funkin.graphics.shaders.LeftMaskShader; import funkin.graphics.shaders.LeftMaskShader;
@ -48,9 +49,13 @@ class ResultState extends MusicBeatSubState
else else
resultsVariation = NORMAL; resultsVariation = NORMAL;
var loops:Bool = resultsVariation != SHIT; FunkinSound.playMusic('results$resultsVariation',
{
FlxG.sound.playMusic(Paths.music("results" + resultsVariation), 1, loops); startingVolume: 1.0,
overrideExisting: true,
restartTrack: true,
loop: resultsVariation != SHIT
});
// TEMP-ish, just used to sorta "cache" the 3000x3000 image! // TEMP-ish, just used to sorta "cache" the 3000x3000 image!
var cacheBullShit:FlxSprite = new FlxSprite().loadGraphic(Paths.image("resultScreen/soundSystem")); var cacheBullShit:FlxSprite = new FlxSprite().loadGraphic(Paths.image("resultScreen/soundSystem"));
@ -348,9 +353,12 @@ class ResultState extends MusicBeatSubState
if (controls.PAUSE) if (controls.PAUSE)
{ {
FlxTween.tween(FlxG.sound.music, {volume: 0}, 0.8); FlxTween.tween(FlxG.sound.music, {volume: 0}, 0.8);
FlxTween.tween(FlxG.sound.music, {pitch: 3}, 0.1, {onComplete: _ -> { FlxTween.tween(FlxG.sound.music, {pitch: 3}, 0.1,
FlxTween.tween(FlxG.sound.music, {pitch: 0.5}, 0.4); {
}}); onComplete: _ -> {
FlxTween.tween(FlxG.sound.music, {pitch: 0.5}, 0.4);
}
});
if (params.storyMode) if (params.storyMode)
{ {
openSubState(new funkin.ui.transition.StickerSubState(null, (sticker) -> new StoryMenuState(sticker))); openSubState(new funkin.ui.transition.StickerSubState(null, (sticker) -> new StoryMenuState(sticker)));

View file

@ -71,8 +71,6 @@ class LatencyState extends MusicBeatSubState
// trace("EVENT LISTENER: " + key); // trace("EVENT LISTENER: " + key);
}); });
// FlxG.sound.playMusic(Paths.sound('soundTest'));
// funnyStatsGraph.hi // funnyStatsGraph.hi
Conductor.instance.forceBPM(60); Conductor.instance.forceBPM(60);

View file

@ -1131,7 +1131,6 @@ class FreeplayState extends MusicBeatSubState
function changeSelection(change:Int = 0):Void function changeSelection(change:Int = 0):Void
{ {
FunkinSound.playOnce(Paths.sound('scrollMenu'), 0.4); FunkinSound.playOnce(Paths.sound('scrollMenu'), 0.4);
// FlxG.sound.playMusic(Paths.inst(songs[curSelected].songName));
var prevSelected:Int = curSelected; var prevSelected:Int = curSelected;
@ -1174,20 +1173,25 @@ class FreeplayState extends MusicBeatSubState
{ {
if (curSelected == 0) if (curSelected == 0)
{ {
FlxG.sound.playMusic(Paths.music('freeplay/freeplayRandom'), 0); FunkinSound.playMusic('freeplayRandom',
{
startingVolume: 0.0,
overrideExisting: true,
restartTrack: true
});
FlxG.sound.music.fadeIn(2, 0, 0.8); FlxG.sound.music.fadeIn(2, 0, 0.8);
} }
else else
{ {
// TODO: Stream the instrumental of the selected song? // TODO: Stream the instrumental of the selected song?
if (prevSelected == 0) var didReplace:Bool = FunkinSound.playMusic('freakyMenu',
{
startingVolume: 0.0,
overrideExisting: true,
restartTrack: false
});
if (didReplace)
{ {
FunkinSound.playMusic('freakyMenu',
{
startingVolume: 0.0,
overrideExisting: true,
restartTrack: false
});
FlxG.sound.music.fadeIn(2, 0, 0.8); FlxG.sound.music.fadeIn(2, 0, 0.8);
} }
} }

View file

@ -389,8 +389,6 @@ class TitleState extends MusicBeatState
{ {
cheatActive = true; cheatActive = true;
FlxG.sound.playMusic(Paths.music('tutorialTitle'), 1);
var spec:SpectogramSprite = new SpectogramSprite(FlxG.sound.music); var spec:SpectogramSprite = new SpectogramSprite(FlxG.sound.music);
add(spec); add(spec);