1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-15 19:33:36 +00:00
Funkin/source/funkin/ui/freeplay/FreeplayState.hx

2222 lines
65 KiB
Haxe
Raw Normal View History

package funkin.ui.freeplay;
2021-04-08 00:19:49 +00:00
import flixel.addons.transition.FlxTransitionableState;
import flixel.addons.ui.FlxInputText;
2021-08-22 00:45:03 +00:00
import flixel.FlxCamera;
2020-10-21 18:05:27 +00:00
import flixel.FlxSprite;
2021-10-22 03:08:48 +00:00
import flixel.group.FlxGroup;
import flixel.group.FlxGroup.FlxTypedGroup;
2024-03-12 03:42:32 +00:00
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
2021-08-21 23:53:08 +00:00
import flixel.input.touch.FlxTouch;
2021-08-24 19:28:04 +00:00
import flixel.math.FlxAngle;
import flixel.math.FlxPoint;
import flixel.system.debug.watch.Tracker.TrackerProfile;
2020-10-21 18:05:27 +00:00
import flixel.text.FlxText;
2021-10-22 03:08:48 +00:00
import flixel.tweens.FlxEase;
2021-03-02 05:46:28 +00:00
import flixel.tweens.FlxTween;
2024-06-20 20:17:53 +00:00
import flixel.tweens.misc.ShakeTween;
2020-11-07 02:17:27 +00:00
import flixel.util.FlxColor;
2021-10-22 03:08:48 +00:00
import flixel.util.FlxSpriteUtil;
2021-10-21 21:40:53 +00:00
import flixel.util.FlxTimer;
2024-03-12 03:42:32 +00:00
import funkin.audio.FunkinSound;
import funkin.data.freeplay.player.PlayerRegistry;
import funkin.data.song.SongRegistry;
2024-06-20 20:17:53 +00:00
import funkin.data.story.level.LevelRegistry;
import funkin.effects.IntervalShake;
import funkin.graphics.adobeanimate.FlxAtlasSprite;
2024-03-12 03:42:32 +00:00
import funkin.graphics.FunkinCamera;
import funkin.graphics.FunkinSprite;
import funkin.graphics.shaders.AngleMask;
2024-06-20 20:17:53 +00:00
import funkin.graphics.shaders.GaussianBlurShader;
import funkin.graphics.shaders.HSVShader;
import funkin.graphics.shaders.PureColor;
import funkin.graphics.shaders.StrokeShader;
import funkin.input.Controls;
import funkin.play.PlayStatePlaylist;
2024-06-20 20:17:53 +00:00
import funkin.play.scoring.Scoring;
import funkin.play.scoring.Scoring.ScoringRank;
import funkin.play.song.Song;
import funkin.save.Save;
import funkin.save.Save.SaveScoreData;
import funkin.ui.AtlasText;
2024-06-20 20:17:53 +00:00
import funkin.ui.freeplay.charselect.PlayableCharacter;
import funkin.ui.freeplay.SongMenuItem.FreeplayRank;
import funkin.ui.mainmenu.MainMenuState;
import funkin.ui.MusicBeatSubState;
2024-06-20 20:17:53 +00:00
import funkin.ui.story.Level;
import funkin.ui.transition.LoadingState;
import funkin.ui.transition.StickerSubState;
import funkin.util.MathUtil;
2024-06-20 20:17:53 +00:00
import funkin.util.SortUtil;
import lime.utils.Assets;
2024-06-20 20:17:53 +00:00
import openfl.display.BlendMode;
2020-10-21 18:05:27 +00:00
2024-02-05 18:35:30 +00:00
/**
* Parameters used to initialize the FreeplayState.
*/
typedef FreeplayStateParams =
{
?character:String,
?fromResults:FromResultsParams,
};
/**
* A set of parameters for transitioning to the FreeplayState from the ResultsState.
*/
typedef FromResultsParams =
{
/**
* The previous rank the song hand, if any. Null if it had no score before.
*/
var ?oldRank:ScoringRank;
2024-06-01 23:25:52 +00:00
/**
* Whether or not to play the rank animation on returning to freeplay.
*/
var playRankAnim:Bool;
/**
* The new rank the song has.
*/
var newRank:ScoringRank;
/**
* The song ID to play the animation on.
*/
var songId:String;
/**
* The difficulty ID to play the animation on.
*/
var difficultyId:String;
2024-02-05 18:35:30 +00:00
};
/**
* The state for the freeplay menu, allowing the player to select any song to play.
*/
2024-06-20 20:17:53 +00:00
@:nullSafety
class FreeplayState extends MusicBeatSubState
2020-10-21 18:05:27 +00:00
{
//
// Params
//
/**
* The current character for this FreeplayState.
* You can't change this without transitioning to a new FreeplayState.
*/
final currentCharacterId:String;
final currentCharacter:PlayableCharacter;
2024-02-09 19:58:57 +00:00
/**
* For the audio preview, the duration of the fade-in effect.
*/
public static final FADE_IN_DURATION:Float = 0.5;
/**
* For the audio preview, the duration of the fade-out effect.
2024-05-31 21:16:26 +00:00
*
2024-02-09 19:58:57 +00:00
*/
public static final FADE_OUT_DURATION:Float = 0.25;
/**
* For the audio preview, the volume at which the fade-in starts.
*/
public static final FADE_IN_START_VOLUME:Float = 0.25;
/**
* For the audio preview, the volume at which the fade-in ends.
*/
public static final FADE_IN_END_VOLUME:Float = 1.0;
/**
* For the audio preview, the volume at which the fade-out starts.
*/
public static final FADE_OUT_END_VOLUME:Float = 0.0;
var songs:Array<Null<FreeplaySongData>> = [];
var diffIdsCurrent:Array<String> = [];
var diffIdsTotal:Array<String> = [];
2020-10-21 18:05:27 +00:00
2023-01-23 00:55:30 +00:00
var curSelected:Int = 0;
var currentDifficulty:String = Constants.DEFAULT_DIFFICULTY;
2020-11-07 02:17:27 +00:00
2023-01-23 00:55:30 +00:00
var fp:FreeplayScore;
var txtCompletion:AtlasText;
2023-01-23 00:55:30 +00:00
var lerpCompletion:Float = 0;
var intendedCompletion:Float = 0;
var lerpScore:Float = 0;
var intendedScore:Int = 0;
2020-10-21 18:05:27 +00:00
var grpDifficulties:FlxTypedSpriteGroup<DifficultySprite>;
2021-12-07 22:41:18 +00:00
2023-01-23 00:55:30 +00:00
var coolColors:Array<Int> = [
0xFF9271FD,
0xFF9271FD,
0xFF223344,
2023-01-23 00:55:30 +00:00
0xFF941653,
0xFFFC96D7,
0xFFA0D1FF,
0xFFFF78BF,
0xFFF6B604
2023-01-23 00:55:30 +00:00
];
2021-03-02 05:46:28 +00:00
var grpSongs:FlxTypedGroup<Alphabet>;
var grpCapsules:FlxTypedGroup<SongMenuItem>;
var curPlaying:Bool = false;
2020-11-01 19:16:22 +00:00
2024-06-20 20:17:53 +00:00
var dj:Null<FreeplayDJ> = null;
var ostName:FlxText;
var albumRoll:AlbumRoll;
var letterSort:LetterSort;
var exitMovers:ExitMoverData = new Map();
2022-09-26 22:22:45 +00:00
2024-06-20 20:17:53 +00:00
var stickerSubState:Null<StickerSubState> = null;
2023-04-06 05:39:27 +00:00
2024-04-02 01:59:53 +00:00
public static var rememberedDifficulty:Null<String> = Constants.DEFAULT_DIFFICULTY;
public static var rememberedSongId:Null<String> = 'tutorial';
var funnyCam:FunkinCamera;
var rankCamera:FunkinCamera;
var rankBg:FunkinSprite;
var rankVignette:FlxSprite;
var backingTextYeah:FlxAtlasSprite;
var orangeBackShit:FunkinSprite;
var alsoOrangeLOL:FunkinSprite;
var pinkBack:FunkinSprite;
var confirmGlow:FlxSprite;
var confirmGlow2:FlxSprite;
var confirmTextGlow:FlxSprite;
var moreWays:BGScrollingText;
var funnyScroll:BGScrollingText;
var txtNuts:BGScrollingText;
var funnyScroll2:BGScrollingText;
var moreWays2:BGScrollingText;
var funnyScroll3:BGScrollingText;
var bgDad:FlxSprite;
var cardGlow:FlxSprite;
var fromResultsParams:Null<FromResultsParams> = null;
var prepForNewRank:Bool = false;
public function new(?params:FreeplayStateParams, ?stickers:StickerSubState)
2023-04-06 05:39:27 +00:00
{
currentCharacterId = params?.character ?? Constants.DEFAULT_CHARACTER;
2024-06-20 20:17:53 +00:00
var fetchPlayableCharacter = function():PlayableCharacter {
var result = PlayerRegistry.instance.fetchEntry(params?.character ?? Constants.DEFAULT_CHARACTER);
if (result == null) throw 'No valid playable character with id ${params?.character}';
return result;
};
currentCharacter = fetchPlayableCharacter();
2024-02-05 18:35:30 +00:00
fromResultsParams = params?.fromResults;
2024-06-01 23:25:52 +00:00
if (fromResultsParams?.playRankAnim == true)
{
prepForNewRank = true;
}
2024-06-20 20:17:53 +00:00
super(FlxColor.TRANSPARENT);
if (stickers?.members != null)
2023-04-06 05:39:27 +00:00
{
stickerSubState = stickers;
}
2024-06-20 20:17:53 +00:00
// We build a bunch of sprites BEFORE create() so we can guarantee they aren't null later on.
albumRoll = new AlbumRoll();
fp = new FreeplayScore(460, 60, 7, 100);
cardGlow = new FlxSprite(-30, -30).loadGraphic(Paths.image('freeplay/cardGlow'));
confirmGlow = new FlxSprite(-30, 240).loadGraphic(Paths.image('freeplay/confirmGlow'));
confirmTextGlow = new FlxSprite(-8, 115).loadGraphic(Paths.image('freeplay/glowingText'));
rankCamera = new FunkinCamera('rankCamera', 0, 0, FlxG.width, FlxG.height);
funnyCam = new FunkinCamera('freeplayFunny', 0, 0, FlxG.width, FlxG.height);
funnyScroll = new BGScrollingText(0, 220, currentCharacter.getFreeplayDJText(1), FlxG.width / 2, false, 60);
funnyScroll2 = new BGScrollingText(0, 335, currentCharacter.getFreeplayDJText(1), FlxG.width / 2, false, 60);
grpCapsules = new FlxTypedGroup<SongMenuItem>();
grpDifficulties = new FlxTypedSpriteGroup<DifficultySprite>(-300, 80);
letterSort = new LetterSort(400, 75);
grpSongs = new FlxTypedGroup<Alphabet>();
moreWays = new BGScrollingText(0, 160, currentCharacter.getFreeplayDJText(2), FlxG.width, true, 43);
moreWays2 = new BGScrollingText(0, 397, currentCharacter.getFreeplayDJText(2), FlxG.width, true, 43);
pinkBack = FunkinSprite.create('freeplay/pinkBack');
rankBg = new FunkinSprite(0, 0);
rankVignette = new FlxSprite(0, 0).loadGraphic(Paths.image('freeplay/rankVignette'));
sparks = new FlxSprite(0, 0);
sparksADD = new FlxSprite(0, 0);
txtCompletion = new AtlasText(1185, 87, '69', AtlasFont.FREEPLAY_CLEAR);
txtNuts = new BGScrollingText(0, 285, currentCharacter.getFreeplayDJText(3), FlxG.width / 2, true, 43);
ostName = new FlxText(8, 8, FlxG.width - 8 - 8, 'OFFICIAL OST', 48);
orangeBackShit = new FunkinSprite(84, 440).makeSolidColor(Std.int(pinkBack.width), 75, 0xFFFEDA00);
bgDad = new FlxSprite(pinkBack.width * 0.74, 0).loadGraphic(Paths.image('freeplay/freeplayBGdad'));
alsoOrangeLOL = new FunkinSprite(0, orangeBackShit.y).makeSolidColor(100, Std.int(orangeBackShit.height), 0xFFFFD400);
confirmGlow2 = new FlxSprite(confirmGlow.x, confirmGlow.y).loadGraphic(Paths.image('freeplay/confirmGlow2'));
funnyScroll3 = new BGScrollingText(0, orangeBackShit.y + 10, currentCharacter.getFreeplayDJText(1), FlxG.width / 2, 60);
backingTextYeah = new FlxAtlasSprite(640, 370, Paths.animateAtlas("freeplay/backing-text-yeah"),
{
FrameRate: 24.0,
Reversed: false,
// ?OnComplete:Void -> Void,
ShowPivot: false,
Antialiasing: true,
ScrollFactor: new FlxPoint(1, 1),
});
2023-04-06 05:39:27 +00:00
}
override function create():Void
2023-01-23 00:55:30 +00:00
{
2023-04-06 05:39:27 +00:00
super.create();
2024-05-03 03:02:47 +00:00
FlxG.state.persistentUpdate = false;
2023-01-23 00:55:30 +00:00
FlxTransitionableState.skipNextTransIn = true;
2021-10-22 03:08:48 +00:00
2023-04-06 05:39:27 +00:00
if (stickerSubState != null)
{
this.persistentUpdate = true;
this.persistentDraw = true;
openSubState(stickerSubState);
stickerSubState.degenStickers();
}
2023-01-23 00:55:30 +00:00
#if discord_rpc
// Updating Discord Rich Presence
DiscordClient.changePresence('In the Menus', null);
2023-01-23 00:55:30 +00:00
#end
2021-05-06 10:54:57 +00:00
2023-01-23 00:55:30 +00:00
var isDebug:Bool = false;
2021-05-06 10:54:57 +00:00
2023-01-23 00:55:30 +00:00
#if debug
isDebug = true;
#end
2021-05-06 10:54:57 +00:00
if (prepForNewRank == false)
{
FunkinSound.playMusic('freakyMenu',
2024-06-01 23:25:52 +00:00
{
overrideExisting: true,
restartTrack: false
});
}
2020-11-01 19:16:22 +00:00
// Add a null entry that represents the RANDOM option
songs.push(null);
2021-03-01 23:59:51 +00:00
2023-09-29 00:29:19 +00:00
// programmatically adds the songs via LevelRegistry and SongRegistry
for (levelId in LevelRegistry.instance.listSortedLevelIds())
2023-09-29 00:29:19 +00:00
{
2024-06-20 20:17:53 +00:00
var level:Null<Level> = LevelRegistry.instance.fetchEntry(levelId);
if (level == null)
{
trace('[WARN] Could not find level with id (${levelId})');
continue;
}
for (songId in level.getSongs())
2023-09-29 00:29:19 +00:00
{
2024-06-20 20:17:53 +00:00
var song:Null<Song> = SongRegistry.instance.fetchEntry(songId);
if (song == null)
{
trace('[WARN] Could not find song with id (${songId})');
continue;
}
// Only display songs which actually have available difficulties for the current character.
var displayedVariations = song.getVariationsByCharacter(currentCharacter);
trace('Displayed Variations (${songId}): $displayedVariations');
var availableDifficultiesForSong:Array<String> = song.listDifficulties(displayedVariations, false);
trace('Available Difficulties: $availableDifficultiesForSong');
if (availableDifficultiesForSong.length == 0) continue;
songs.push(new FreeplaySongData(levelId, songId, song, displayedVariations));
for (difficulty in availableDifficultiesForSong)
{
diffIdsTotal.pushUnique(difficulty);
}
2023-09-29 00:29:19 +00:00
}
}
2021-09-06 18:50:04 +00:00
2023-01-23 00:55:30 +00:00
// LOAD MUSIC
2020-10-21 18:05:27 +00:00
2023-01-23 00:55:30 +00:00
// LOAD CHARACTERS
2020-10-21 18:05:27 +00:00
2023-01-23 00:55:30 +00:00
trace(FlxG.width);
trace(FlxG.camera.zoom);
trace(FlxG.camera.initialZoom);
trace(FlxCamera.defaultZoom);
2020-10-25 20:51:06 +00:00
pinkBack.color = 0xFFFFD4E9; // sets it to pink!
2023-01-23 00:55:30 +00:00
pinkBack.x -= pinkBack.width;
2021-10-22 03:08:48 +00:00
2023-01-23 00:55:30 +00:00
FlxTween.tween(pinkBack, {x: 0}, 0.6, {ease: FlxEase.quartOut});
add(pinkBack);
2021-10-22 03:08:48 +00:00
2023-01-23 00:55:30 +00:00
add(orangeBackShit);
2021-10-22 03:08:48 +00:00
2023-01-23 00:55:30 +00:00
add(alsoOrangeLOL);
2021-10-22 03:08:48 +00:00
2023-03-16 04:17:52 +00:00
exitMovers.set([pinkBack, orangeBackShit, alsoOrangeLOL],
{
x: -pinkBack.width,
y: pinkBack.y,
speed: 0.4,
wait: 0
});
2023-01-23 00:55:30 +00:00
FlxSpriteUtil.alphaMaskFlxSprite(orangeBackShit, pinkBack, orangeBackShit);
orangeBackShit.visible = false;
alsoOrangeLOL.visible = false;
2021-10-22 03:08:48 +00:00
confirmTextGlow.blend = BlendMode.ADD;
confirmTextGlow.visible = false;
confirmGlow.blend = BlendMode.ADD;
confirmGlow.visible = false;
confirmGlow2.visible = false;
add(confirmGlow2);
add(confirmGlow);
add(confirmTextGlow);
2023-01-23 00:55:30 +00:00
var grpTxtScrolls:FlxGroup = new FlxGroup();
add(grpTxtScrolls);
grpTxtScrolls.visible = false;
2021-10-22 03:08:48 +00:00
FlxG.debugger.addTrackerProfile(new TrackerProfile(BGScrollingText, ['x', 'y', 'speed', 'size']));
moreWays.funnyColor = 0xFFFFF383;
moreWays.speed = 6.8;
2023-01-23 00:55:30 +00:00
grpTxtScrolls.add(moreWays);
2021-10-22 03:08:48 +00:00
2023-03-16 04:17:52 +00:00
exitMovers.set([moreWays],
2023-03-16 01:05:15 +00:00
{
2023-03-16 05:03:45 +00:00
x: FlxG.width * 2,
speed: 0.4,
2023-03-16 01:05:15 +00:00
});
funnyScroll.funnyColor = 0xFFFF9963;
funnyScroll.speed = -3.8;
2023-01-23 00:55:30 +00:00
grpTxtScrolls.add(funnyScroll);
2021-10-22 03:08:48 +00:00
2023-03-16 04:17:52 +00:00
exitMovers.set([funnyScroll],
2023-03-16 01:05:15 +00:00
{
2023-03-16 05:03:45 +00:00
x: -funnyScroll.width * 2,
2023-03-16 01:05:15 +00:00
y: funnyScroll.y,
2023-03-16 05:03:45 +00:00
speed: 0.4,
2023-03-16 01:05:15 +00:00
wait: 0
});
txtNuts.speed = 3.5;
2023-01-23 00:55:30 +00:00
grpTxtScrolls.add(txtNuts);
2023-03-16 04:17:52 +00:00
exitMovers.set([txtNuts],
2023-03-16 01:05:15 +00:00
{
2023-03-16 05:03:45 +00:00
x: FlxG.width * 2,
speed: 0.4,
2023-03-16 01:05:15 +00:00
});
2021-10-22 03:08:48 +00:00
funnyScroll2.funnyColor = 0xFFFF9963;
funnyScroll2.speed = -3.8;
2023-01-23 00:55:30 +00:00
grpTxtScrolls.add(funnyScroll2);
2021-10-22 03:08:48 +00:00
2023-03-16 04:17:52 +00:00
exitMovers.set([funnyScroll2],
2023-03-16 01:05:15 +00:00
{
2023-03-16 05:03:45 +00:00
x: -funnyScroll2.width * 2,
speed: 0.5,
2023-03-16 01:05:15 +00:00
});
moreWays2.funnyColor = 0xFFFFF383;
moreWays2.speed = 6.8;
2023-01-23 00:55:30 +00:00
grpTxtScrolls.add(moreWays2);
2023-03-16 04:17:52 +00:00
exitMovers.set([moreWays2],
2023-03-16 01:05:15 +00:00
{
2023-03-16 05:03:45 +00:00
x: FlxG.width * 2,
speed: 0.4
2023-03-16 01:05:15 +00:00
});
funnyScroll3.funnyColor = 0xFFFEA400;
funnyScroll3.speed = -3.8;
2023-01-23 00:55:30 +00:00
grpTxtScrolls.add(funnyScroll3);
2023-03-16 04:17:52 +00:00
exitMovers.set([funnyScroll3],
2023-03-16 01:05:15 +00:00
{
2023-03-16 05:03:45 +00:00
x: -funnyScroll3.width * 2,
speed: 0.3
2023-03-16 01:05:15 +00:00
});
add(backingTextYeah);
cardGlow.blend = BlendMode.ADD;
cardGlow.visible = false;
add(cardGlow);
if (currentCharacter?.getFreeplayDJData() != null)
{
dj = new FreeplayDJ(640, 366, currentCharacterId);
exitMovers.set([dj],
{
x: -dj.width * 1.6,
speed: 0.5
});
add(dj);
}
2023-01-23 00:55:30 +00:00
bgDad.shader = new AngleMask();
bgDad.visible = false;
var blackOverlayBullshitLOLXD:FlxSprite = new FlxSprite(FlxG.width).makeGraphic(Std.int(bgDad.width), Std.int(bgDad.height), FlxColor.BLACK);
add(blackOverlayBullshitLOLXD); // used to mask the text lol!
2024-06-11 19:57:45 +00:00
// this makes the texture sizes consistent, for the angle shader
bgDad.setGraphicSize(0, FlxG.height);
blackOverlayBullshitLOLXD.setGraphicSize(0, FlxG.height);
bgDad.updateHitbox();
blackOverlayBullshitLOLXD.updateHitbox();
2023-03-16 04:17:52 +00:00
exitMovers.set([blackOverlayBullshitLOLXD, bgDad],
2023-03-16 01:05:15 +00:00
{
x: FlxG.width * 1.5,
2023-03-16 04:17:52 +00:00
speed: 0.4,
2023-03-16 01:05:15 +00:00
wait: 0
});
2023-01-23 00:55:30 +00:00
add(bgDad);
2024-06-11 19:57:45 +00:00
FlxTween.tween(blackOverlayBullshitLOLXD, {x: pinkBack.width * 0.74}, 0.7, {ease: FlxEase.quintOut});
2023-01-23 00:55:30 +00:00
blackOverlayBullshitLOLXD.shader = bgDad.shader;
rankBg.makeSolidColor(FlxG.width, FlxG.height, 0xD3000000);
add(rankBg);
2023-01-23 00:55:30 +00:00
add(grpSongs);
add(grpCapsules);
add(grpDifficulties);
2023-03-16 04:17:52 +00:00
exitMovers.set([grpDifficulties],
{
x: -300,
speed: 0.25,
wait: 0
});
for (diffId in diffIdsTotal)
{
var diffSprite:DifficultySprite = new DifficultySprite(diffId);
diffSprite.difficultyId = diffId;
grpDifficulties.add(diffSprite);
}
2023-01-23 00:55:30 +00:00
2023-03-16 01:05:15 +00:00
grpDifficulties.group.forEach(function(spr) {
2023-01-23 00:55:30 +00:00
spr.visible = false;
});
for (diffSprite in grpDifficulties.group.members)
{
if (diffSprite == null) continue;
if (diffSprite.difficultyId == currentDifficulty) diffSprite.visible = true;
}
2023-01-23 00:55:30 +00:00
albumRoll.albumId = null;
add(albumRoll);
2023-08-09 23:34:19 +00:00
albumRoll.applyExitMovers(exitMovers);
2023-08-09 23:34:19 +00:00
2023-01-23 00:55:30 +00:00
var overhangStuff:FlxSprite = new FlxSprite().makeGraphic(FlxG.width, 64, FlxColor.BLACK);
overhangStuff.y -= overhangStuff.height;
add(overhangStuff);
FlxTween.tween(overhangStuff, {y: 0}, 0.3, {ease: FlxEase.quartOut});
var fnfFreeplay:FlxText = new FlxText(8, 8, 0, 'FREEPLAY', 48);
fnfFreeplay.font = 'VCR OSD Mono';
2023-01-23 00:55:30 +00:00
fnfFreeplay.visible = false;
2023-03-16 01:05:15 +00:00
ostName.font = 'VCR OSD Mono';
ostName.alignment = RIGHT;
ostName.visible = false;
2024-01-11 05:52:42 +00:00
exitMovers.set([overhangStuff, fnfFreeplay, ostName],
2023-03-16 01:05:15 +00:00
{
2023-03-16 04:17:52 +00:00
y: -overhangStuff.height,
2023-03-16 01:05:15 +00:00
x: 0,
speed: 0.2,
wait: 0
});
var sillyStroke:StrokeShader = new StrokeShader(0xFFFFFFFF, 2, 2);
2023-01-23 00:55:30 +00:00
fnfFreeplay.shader = sillyStroke;
2024-04-30 07:22:30 +00:00
ostName.shader = sillyStroke;
2023-01-23 00:55:30 +00:00
add(fnfFreeplay);
2024-01-11 05:52:42 +00:00
add(ostName);
2023-01-23 00:55:30 +00:00
var fnfHighscoreSpr:FlxSprite = new FlxSprite(860, 70);
2023-01-23 00:55:30 +00:00
fnfHighscoreSpr.frames = Paths.getSparrowAtlas('freeplay/highscore');
fnfHighscoreSpr.animation.addByPrefix('highscore', 'highscore small instance 1', 24, false);
2023-01-23 00:55:30 +00:00
fnfHighscoreSpr.visible = false;
fnfHighscoreSpr.setGraphicSize(0, Std.int(fnfHighscoreSpr.height * 1));
fnfHighscoreSpr.updateHitbox();
add(fnfHighscoreSpr);
2023-03-16 01:05:15 +00:00
new FlxTimer().start(FlxG.random.float(12, 50), function(tmr) {
fnfHighscoreSpr.animation.play('highscore');
2023-01-23 00:55:30 +00:00
tmr.time = FlxG.random.float(20, 60);
}, 0);
fp.visible = false;
add(fp);
var clearBoxSprite:FlxSprite = new FlxSprite(1165, 65).loadGraphic(Paths.image('freeplay/clearBox'));
2024-04-30 05:33:29 +00:00
clearBoxSprite.visible = false;
add(clearBoxSprite);
2023-01-23 00:55:30 +00:00
txtCompletion.visible = false;
add(txtCompletion);
2023-08-09 20:15:34 +00:00
add(letterSort);
letterSort.visible = false;
exitMovers.set([letterSort],
{
y: -100,
speed: 0.3
});
letterSort.changeSelectionCallback = (str) -> {
switch (str)
{
case 'fav':
2023-08-09 20:15:34 +00:00
generateSongList({filterType: FAVORITE}, true);
case 'ALL':
2023-08-09 23:34:19 +00:00
generateSongList(null, true);
2024-06-07 17:04:45 +00:00
case '#':
generateSongList({filterType: REGEXP, filterData: '0-9'}, true);
2023-08-09 20:15:34 +00:00
default:
generateSongList({filterType: REGEXP, filterData: str}, true);
}
// We want to land on the first song of the group, rather than random song when changing letter sorts
// that is, only if there's more than one song in the group!
if (grpCapsules.members.length > 0)
{
2024-06-10 20:13:32 +00:00
FunkinSound.playOnce(Paths.sound('scrollMenu'), 0.4);
curSelected = 1;
changeSelection();
}
2023-08-09 20:15:34 +00:00
};
2024-04-30 05:33:29 +00:00
exitMovers.set([fp, txtCompletion, fnfHighscoreSpr, txtCompletion, clearBoxSprite],
2023-03-16 04:17:52 +00:00
{
x: FlxG.width,
speed: 0.3
});
var diffSelLeft:DifficultySelector = new DifficultySelector(20, grpDifficulties.y - 10, false, controls);
var diffSelRight:DifficultySelector = new DifficultySelector(325, grpDifficulties.y - 10, true, controls);
diffSelLeft.visible = false;
diffSelRight.visible = false;
add(diffSelLeft);
add(diffSelRight);
// be careful not to "add()" things in here unless it's to a group that's already added to the state
// otherwise it won't be properly attatched to funnyCamera (relavent code should be at the bottom of create())
2024-06-20 20:17:53 +00:00
var onDJIntroDone = function() {
2023-08-09 23:34:19 +00:00
// when boyfriend hits dat shiii
2023-09-20 03:27:07 +00:00
albumRoll.playIntro();
2023-08-09 23:34:19 +00:00
2023-01-23 00:55:30 +00:00
FlxTween.tween(grpDifficulties, {x: 90}, 0.6, {ease: FlxEase.quartOut});
diffSelLeft.visible = true;
diffSelRight.visible = true;
2023-08-09 20:15:34 +00:00
letterSort.visible = true;
2023-03-16 04:17:52 +00:00
exitMovers.set([diffSelLeft, diffSelRight],
{
x: -diffSelLeft.width * 2,
speed: 0.26
});
2023-01-23 00:55:30 +00:00
2023-03-16 01:05:15 +00:00
new FlxTimer().start(1 / 24, function(handShit) {
2023-01-23 00:55:30 +00:00
fnfHighscoreSpr.visible = true;
fnfFreeplay.visible = true;
2024-01-11 05:52:42 +00:00
ostName.visible = true;
2023-01-23 00:55:30 +00:00
fp.visible = true;
fp.updateScore(0);
2024-04-30 05:33:29 +00:00
clearBoxSprite.visible = true;
2023-01-23 00:55:30 +00:00
txtCompletion.visible = true;
intendedCompletion = 0;
2023-03-16 01:05:15 +00:00
new FlxTimer().start(1.5 / 24, function(bold) {
2023-01-23 00:55:30 +00:00
sillyStroke.width = 0;
sillyStroke.height = 0;
2023-09-20 03:27:07 +00:00
changeSelection();
2023-01-23 00:55:30 +00:00
});
});
pinkBack.color = 0xFFFFD863;
2023-01-23 00:55:30 +00:00
bgDad.visible = true;
orangeBackShit.visible = true;
alsoOrangeLOL.visible = true;
grpTxtScrolls.visible = true;
2024-05-14 00:20:23 +00:00
// render optimisation
2024-05-23 17:52:28 +00:00
if (_parentState != null) _parentState.persistentDraw = false;
cardGlow.visible = true;
FlxTween.tween(cardGlow, {alpha: 0, "scale.x": 1.2, "scale.y": 1.2}, 0.45, {ease: FlxEase.sineOut});
2024-06-20 20:17:53 +00:00
if (prepForNewRank && fromResultsParams != null)
{
rankAnimStart(fromResultsParams);
}
2024-06-20 20:17:53 +00:00
};
2024-07-04 18:48:24 +00:00
if (dj != null)
{
2024-06-20 20:17:53 +00:00
dj.onIntroDone.add(onDJIntroDone);
2024-07-04 18:48:24 +00:00
}
else
{
2024-06-20 20:17:53 +00:00
onDJIntroDone();
}
2023-01-23 00:55:30 +00:00
2023-08-09 06:47:22 +00:00
generateSongList(null, false);
2023-01-23 00:55:30 +00:00
// dedicated camera for the state so we don't need to fuk around with camera scrolls from the mainmenu / elsewhere
2023-01-23 00:55:30 +00:00
funnyCam.bgColor = FlxColor.TRANSPARENT;
FlxG.cameras.add(funnyCam, false);
2023-01-23 00:55:30 +00:00
rankVignette.scale.set(2, 2);
rankVignette.updateHitbox();
rankVignette.blend = BlendMode.ADD;
// rankVignette.cameras = [rankCamera];
add(rankVignette);
rankVignette.alpha = 0;
2023-03-16 01:05:15 +00:00
forEach(function(bs) {
2023-01-23 00:55:30 +00:00
bs.cameras = [funnyCam];
});
rankCamera.bgColor = FlxColor.TRANSPARENT;
FlxG.cameras.add(rankCamera, false);
rankBg.cameras = [rankCamera];
rankBg.alpha = 0;
2024-06-02 06:53:07 +00:00
if (prepForNewRank)
{
rankCamera.fade(0xFF000000, 0, false, null, true);
}
2023-01-23 00:55:30 +00:00
}
2024-06-20 20:17:53 +00:00
var currentFilter:Null<SongFilter> = null;
var currentFilteredSongs:Array<Null<FreeplaySongData>> = [];
/**
* Given the current filter, rebuild the current song list.
*
* @param filterStuff A filter to apply to the song list (regex, startswith, all, favorite)
2024-04-17 02:12:07 +00:00
* @param force Whether the capsules should "jump" back in or not using their animation
* @param onlyIfChanged Only apply the filter if the song list has changed
*/
public function generateSongList(filterStuff:Null<SongFilter>, force:Bool = false, onlyIfChanged:Bool = true):Void
2023-01-23 00:55:30 +00:00
{
2024-06-20 20:17:53 +00:00
var tempSongs:Array<Null<FreeplaySongData>> = songs;
2023-01-23 00:55:30 +00:00
// Remember just the difficulty because it's important for song sorting.
if (rememberedDifficulty != null)
{
currentDifficulty = rememberedDifficulty;
}
2024-04-17 02:12:07 +00:00
if (filterStuff != null) tempSongs = sortSongs(tempSongs, filterStuff);
2023-01-23 00:55:30 +00:00
// Filter further by current selected difficulty.
if (currentDifficulty != null)
{
tempSongs = tempSongs.filter(song -> {
if (song == null) return true; // Random
return song.songDifficulties.contains(currentDifficulty);
});
}
if (onlyIfChanged)
{
// == performs equality by reference
if (tempSongs.isEqualUnordered(currentFilteredSongs)) return;
}
// Only now do we know that the filter is actually changing.
// If curSelected is 0, the result will be null and fall back to the rememberedSongId.
rememberedSongId = grpCapsules.members[curSelected]?.songData?.songId ?? rememberedSongId;
for (cap in grpCapsules.members)
{
cap.songText.resetText();
cap.kill();
}
currentFilter = filterStuff;
currentFilteredSongs = tempSongs;
curSelected = 0;
var hsvShader:HSVShader = new HSVShader();
2023-08-09 06:47:22 +00:00
var randomCapsule:SongMenuItem = grpCapsules.recycle(SongMenuItem);
randomCapsule.init(FlxG.width, 0, null);
2023-08-06 20:24:34 +00:00
randomCapsule.onConfirm = function() {
capsuleOnConfirmRandom(randomCapsule);
2023-08-06 20:24:34 +00:00
};
randomCapsule.y = randomCapsule.intendedY(0) + 10;
randomCapsule.targetPos.x = randomCapsule.x;
randomCapsule.alpha = 0;
2023-08-06 20:24:34 +00:00
randomCapsule.songText.visible = false;
randomCapsule.favIcon.visible = false;
2024-06-05 03:36:32 +00:00
randomCapsule.favIconBlurred.visible = false;
randomCapsule.ranking.visible = false;
randomCapsule.blurredRanking.visible = false;
2023-08-06 20:24:34 +00:00
randomCapsule.initJumpIn(0, force);
randomCapsule.hsvShader = hsvShader;
2023-08-06 20:24:34 +00:00
grpCapsules.add(randomCapsule);
2023-01-23 00:55:30 +00:00
for (i in 0...tempSongs.length)
{
2024-06-20 20:17:53 +00:00
var tempSong = tempSongs[i];
if (tempSong == null) continue;
2023-08-09 06:47:22 +00:00
var funnyMenu:SongMenuItem = grpCapsules.recycle(SongMenuItem);
2024-06-20 20:17:53 +00:00
funnyMenu.init(FlxG.width, 0, tempSong);
2023-09-29 00:29:19 +00:00
funnyMenu.onConfirm = function() {
capsuleOnConfirmDefault(funnyMenu);
};
2023-08-04 21:10:27 +00:00
funnyMenu.y = funnyMenu.intendedY(i + 1) + 10;
2023-01-23 00:55:30 +00:00
funnyMenu.targetPos.x = funnyMenu.x;
funnyMenu.ID = i;
2023-09-19 23:10:30 +00:00
funnyMenu.capsule.alpha = 0.5;
2023-01-23 00:55:30 +00:00
funnyMenu.songText.visible = false;
2024-06-20 20:17:53 +00:00
funnyMenu.favIcon.visible = tempSong.isFav;
funnyMenu.favIconBlurred.visible = tempSong.isFav;
funnyMenu.hsvShader = hsvShader;
2023-01-23 00:55:30 +00:00
funnyMenu.newText.animation.curAnim.curFrame = 45 - ((i * 4) % 45);
funnyMenu.checkClip();
2024-06-02 06:53:07 +00:00
funnyMenu.forcePosition();
2023-01-23 00:55:30 +00:00
grpCapsules.add(funnyMenu);
}
FlxG.console.registerFunction('changeSelection', changeSelection);
2023-09-20 03:27:07 +00:00
rememberSelection();
2023-01-23 00:55:30 +00:00
changeSelection();
changeDiff(0, true);
2023-01-23 00:55:30 +00:00
}
2024-04-17 02:12:07 +00:00
/**
* Filters an array of songs based on a filter
* @param songsToFilter What data to use when filtering
* @param songFilter The filter to apply
* @return Array<FreeplaySongData>
*/
2024-06-20 20:17:53 +00:00
public function sortSongs(songsToFilter:Array<Null<FreeplaySongData>>, songFilter:SongFilter):Array<Null<FreeplaySongData>>
2024-04-17 02:12:07 +00:00
{
2024-06-20 20:17:53 +00:00
var filterAlphabetically = function(a:Null<FreeplaySongData>, b:Null<FreeplaySongData>):Int {
return SortUtil.alphabetically(a?.songName ?? '', b?.songName ?? '');
};
2024-04-17 02:12:07 +00:00
switch (songFilter.filterType)
{
case REGEXP:
// filterStuff.filterData has a string with the first letter of the sorting range, and the second one
// this creates a filter to return all the songs that start with a letter between those two
// if filterData looks like "A-C", the regex should look something like this: ^[A-C].*
// to get every song that starts between A and C
var filterRegexp:EReg = new EReg('^[' + songFilter.filterData + '].*', 'i');
songsToFilter = songsToFilter.filter(str -> {
if (str == null) return true; // Random
return filterRegexp.match(str.songName);
});
songsToFilter.sort(filterAlphabetically);
2024-04-17 02:12:07 +00:00
case STARTSWITH:
// extra note: this is essentially a "search"
songsToFilter = songsToFilter.filter(str -> {
if (str == null) return true; // Random
2024-06-20 20:17:53 +00:00
return str.songName.toLowerCase().startsWith(songFilter.filterData ?? '');
2024-04-17 02:12:07 +00:00
});
case ALL:
// no filter!
case FAVORITE:
songsToFilter = songsToFilter.filter(str -> {
if (str == null) return true; // Random
return str.isFav;
});
songsToFilter.sort(filterAlphabetically);
2024-04-17 02:12:07 +00:00
default:
// return all on default
}
2024-04-17 02:12:07 +00:00
return songsToFilter;
}
2024-06-01 23:25:52 +00:00
var sparks:FlxSprite;
var sparksADD:FlxSprite;
2024-06-20 20:17:53 +00:00
function rankAnimStart(fromResults:FromResultsParams):Void
{
busy = true;
2024-06-06 00:49:33 +00:00
grpCapsules.members[curSelected].sparkle.alpha = 0;
// grpCapsules.members[curSelected].forcePosition();
2024-06-20 20:17:53 +00:00
rememberedSongId = fromResults.songId;
rememberedDifficulty = fromResults.difficultyId;
changeSelection();
changeDiff();
2024-06-02 02:36:47 +00:00
2024-06-20 20:17:53 +00:00
if (dj != null) dj.fistPump();
// rankCamera.fade(FlxColor.BLACK, 0.5, true);
rankCamera.fade(0xFF000000, 0.5, true, null, true);
2024-05-31 06:30:42 +00:00
if (FlxG.sound.music != null) FlxG.sound.music.volume = 0;
rankBg.alpha = 1;
2024-06-20 20:17:53 +00:00
if (fromResults.oldRank != null)
2024-06-01 23:25:52 +00:00
{
grpCapsules.members[curSelected].fakeRanking.rank = fromResults.oldRank;
grpCapsules.members[curSelected].fakeBlurredRanking.rank = fromResults.oldRank;
sparks.frames = Paths.getSparrowAtlas('freeplay/sparks');
sparks.animation.addByPrefix('sparks', 'sparks', 24, false);
sparks.visible = false;
sparks.blend = BlendMode.ADD;
sparks.setPosition(517, 134);
sparks.scale.set(0.5, 0.5);
add(sparks);
sparks.cameras = [rankCamera];
sparksADD.visible = false;
sparksADD.frames = Paths.getSparrowAtlas('freeplay/sparksadd');
sparksADD.animation.addByPrefix('sparks add', 'sparks add', 24, false);
sparksADD.setPosition(498, 116);
sparksADD.blend = BlendMode.ADD;
sparksADD.scale.set(0.5, 0.5);
add(sparksADD);
sparksADD.cameras = [rankCamera];
switch (fromResults.oldRank)
{
case SHIT:
sparksADD.color = 0xFF6044FF;
case GOOD:
sparksADD.color = 0xFFEF8764;
case GREAT:
sparksADD.color = 0xFFEAF6FF;
case EXCELLENT:
sparksADD.color = 0xFFFDCB42;
case PERFECT:
sparksADD.color = 0xFFFF58B4;
case PERFECT_GOLD:
sparksADD.color = 0xFFFFB619;
}
// sparksADD.color = sparks.color;
}
grpCapsules.members[curSelected].doLerp = false;
// originalPos.x = grpCapsules.members[curSelected].x;
// originalPos.y = grpCapsules.members[curSelected].y;
originalPos.x = 320.488;
originalPos.y = 235.6;
trace(originalPos);
2024-06-01 23:25:52 +00:00
grpCapsules.members[curSelected].ranking.visible = false;
grpCapsules.members[curSelected].blurredRanking.visible = false;
rankCamera.zoom = 1.85;
FlxTween.tween(rankCamera, {"zoom": 1.8}, 0.6, {ease: FlxEase.sineIn});
funnyCam.zoom = 1.15;
FlxTween.tween(funnyCam, {"zoom": 1.1}, 0.6, {ease: FlxEase.sineIn});
grpCapsules.members[curSelected].cameras = [rankCamera];
// grpCapsules.members[curSelected].targetPos.set((FlxG.width / 2) - (grpCapsules.members[curSelected].width / 2),
// (FlxG.height / 2) - (grpCapsules.members[curSelected].height / 2));
grpCapsules.members[curSelected].setPosition((FlxG.width / 2) - (grpCapsules.members[curSelected].width / 2),
(FlxG.height / 2) - (grpCapsules.members[curSelected].height / 2));
new FlxTimer().start(0.5, _ -> {
rankDisplayNew(fromResults);
});
}
function rankDisplayNew(fromResults:Null<FromResultsParams>):Void
{
2024-06-01 23:25:52 +00:00
grpCapsules.members[curSelected].ranking.visible = true;
grpCapsules.members[curSelected].blurredRanking.visible = true;
grpCapsules.members[curSelected].ranking.scale.set(20, 20);
grpCapsules.members[curSelected].blurredRanking.scale.set(20, 20);
2024-06-20 20:17:53 +00:00
if (fromResults != null && fromResults.newRank != null)
2024-06-11 19:57:45 +00:00
{
grpCapsules.members[curSelected].ranking.animation.play(fromResults.newRank.getFreeplayRankIconAsset(), true);
}
FlxTween.tween(grpCapsules.members[curSelected].ranking, {"scale.x": 1, "scale.y": 1}, 0.1);
2024-06-20 20:17:53 +00:00
if (fromResults != null && fromResults.newRank != null)
2024-06-11 19:57:45 +00:00
{
grpCapsules.members[curSelected].blurredRanking.animation.play(fromResults.newRank.getFreeplayRankIconAsset(), true);
}
FlxTween.tween(grpCapsules.members[curSelected].blurredRanking, {"scale.x": 1, "scale.y": 1}, 0.1);
new FlxTimer().start(0.1, _ -> {
2024-06-01 23:25:52 +00:00
if (fromResults?.oldRank != null)
{
grpCapsules.members[curSelected].fakeRanking.visible = false;
grpCapsules.members[curSelected].fakeBlurredRanking.visible = false;
sparks.visible = true;
sparksADD.visible = true;
sparks.animation.play('sparks', true);
sparksADD.animation.play('sparks add', true);
sparks.animation.finishCallback = anim -> {
sparks.visible = false;
sparksADD.visible = false;
};
}
switch (fromResultsParams?.newRank)
{
case SHIT:
FunkinSound.playOnce(Paths.sound('ranks/rankinbad'));
case PERFECT:
FunkinSound.playOnce(Paths.sound('ranks/rankinperfect'));
case PERFECT_GOLD:
FunkinSound.playOnce(Paths.sound('ranks/rankinperfect'));
default:
FunkinSound.playOnce(Paths.sound('ranks/rankinnormal'));
}
rankCamera.zoom = 1.3;
FlxTween.tween(rankCamera, {"zoom": 1.5}, 0.3, {ease: FlxEase.backInOut});
grpCapsules.members[curSelected].x -= 10;
grpCapsules.members[curSelected].y -= 20;
FlxTween.tween(funnyCam, {"zoom": 1.05}, 0.3, {ease: FlxEase.elasticOut});
grpCapsules.members[curSelected].capsule.angle = -3;
FlxTween.tween(grpCapsules.members[curSelected].capsule, {angle: 0}, 0.5, {ease: FlxEase.backOut});
IntervalShake.shake(grpCapsules.members[curSelected].capsule, 0.3, 1 / 30, 0.1, 0, FlxEase.quadOut);
});
new FlxTimer().start(0.4, _ -> {
FlxTween.tween(funnyCam, {"zoom": 1}, 0.8, {ease: FlxEase.sineIn});
FlxTween.tween(rankCamera, {"zoom": 1.2}, 0.8, {ease: FlxEase.backIn});
FlxTween.tween(grpCapsules.members[curSelected], {x: originalPos.x - 7, y: originalPos.y - 80}, 0.8 + 0.5, {ease: FlxEase.quartIn});
});
new FlxTimer().start(0.6, _ -> {
rankAnimSlam(fromResults);
});
}
function rankAnimSlam(fromResultsParams:Null<FromResultsParams>)
{
// FlxTween.tween(rankCamera, {"zoom": 1.9}, 0.5, {ease: FlxEase.backOut});
FlxTween.tween(rankBg, {alpha: 0}, 0.5, {ease: FlxEase.expoIn});
// FlxTween.tween(grpCapsules.members[curSelected], {angle: 5}, 0.5, {ease: FlxEase.backIn});
switch (fromResultsParams?.newRank)
{
case SHIT:
FunkinSound.playOnce(Paths.sound('ranks/loss'));
case GOOD:
FunkinSound.playOnce(Paths.sound('ranks/good'));
case GREAT:
FunkinSound.playOnce(Paths.sound('ranks/great'));
case EXCELLENT:
FunkinSound.playOnce(Paths.sound('ranks/excellent'));
case PERFECT:
FunkinSound.playOnce(Paths.sound('ranks/perfect'));
case PERFECT_GOLD:
FunkinSound.playOnce(Paths.sound('ranks/perfect'));
default:
FunkinSound.playOnce(Paths.sound('ranks/loss'));
}
FlxTween.tween(grpCapsules.members[curSelected], {"targetPos.x": originalPos.x, "targetPos.y": originalPos.y}, 0.5, {ease: FlxEase.expoOut});
new FlxTimer().start(0.5, _ -> {
funnyCam.shake(0.0045, 0.35);
if (fromResultsParams?.newRank == SHIT)
{
2024-06-20 20:17:53 +00:00
if (dj != null) dj.pumpFistBad();
}
else
{
2024-06-20 20:17:53 +00:00
if (dj != null) dj.pumpFist();
}
rankCamera.zoom = 0.8;
funnyCam.zoom = 0.8;
FlxTween.tween(rankCamera, {"zoom": 1}, 1, {ease: FlxEase.elasticOut});
FlxTween.tween(funnyCam, {"zoom": 1}, 0.8, {ease: FlxEase.elasticOut});
for (index => capsule in grpCapsules.members)
{
var distFromSelected:Float = Math.abs(index - curSelected) - 1;
if (distFromSelected < 5)
{
if (index == curSelected)
{
FlxTween.cancelTweensOf(capsule);
// capsule.targetPos.x += 50;
capsule.fadeAnim();
rankVignette.color = capsule.getTrailColor();
rankVignette.alpha = 1;
FlxTween.tween(rankVignette, {alpha: 0}, 0.6, {ease: FlxEase.expoOut});
capsule.doLerp = false;
capsule.setPosition(originalPos.x, originalPos.y);
IntervalShake.shake(capsule, 0.6, 1 / 24, 0.12, 0, FlxEase.quadOut, function(_) {
capsule.doLerp = true;
capsule.cameras = [funnyCam];
// NOW we can interact with the menu
busy = false;
2024-06-06 00:49:33 +00:00
grpCapsules.members[curSelected].sparkle.alpha = 0.7;
playCurSongPreview(capsule);
}, null);
// FlxTween.tween(capsule, {"targetPos.x": capsule.targetPos.x - 50}, 0.6,
// {
// ease: FlxEase.backInOut,
// onComplete: function(_) {
// capsule.cameras = [funnyCam];
// }
// });
FlxTween.tween(capsule, {angle: 0}, 0.5, {ease: FlxEase.backOut});
}
if (index > curSelected)
{
// capsule.color = FlxColor.RED;
new FlxTimer().start(distFromSelected / 20, _ -> {
capsule.doLerp = false;
capsule.capsule.angle = FlxG.random.float(-10 + (distFromSelected * 2), 10 - (distFromSelected * 2));
FlxTween.tween(capsule.capsule, {angle: 0}, 0.5, {ease: FlxEase.backOut});
IntervalShake.shake(capsule, 0.6, 1 / 24, 0.12 / (distFromSelected + 1), 0, FlxEase.quadOut, function(_) {
capsule.doLerp = true;
});
});
}
if (index < curSelected)
{
// capsule.color = FlxColor.BLUE;
new FlxTimer().start(distFromSelected / 20, _ -> {
capsule.doLerp = false;
capsule.capsule.angle = FlxG.random.float(-10 + (distFromSelected * 2), 10 - (distFromSelected * 2));
FlxTween.tween(capsule.capsule, {angle: 0}, 0.5, {ease: FlxEase.backOut});
IntervalShake.shake(capsule, 0.6, 1 / 24, 0.12 / (distFromSelected + 1), 0, FlxEase.quadOut, function(_) {
capsule.doLerp = true;
});
});
}
}
index += 1;
}
});
new FlxTimer().start(2, _ -> {
// dj.fistPump();
prepForNewRank = false;
});
}
2023-01-23 00:55:30 +00:00
var touchY:Float = 0;
var touchX:Float = 0;
var dxTouch:Float = 0;
var dyTouch:Float = 0;
var velTouch:Float = 0;
var veloctiyLoopShit:Float = 0;
var touchTimer:Float = 0;
var initTouchPos:FlxPoint = new FlxPoint();
var spamTimer:Float = 0;
var spamming:Bool = false;
/**
* If true, disable interaction with the interface.
*/
var busy:Bool = false;
var originalPos:FlxPoint = new FlxPoint();
2024-03-12 03:42:32 +00:00
override function update(elapsed:Float):Void
2023-01-23 00:55:30 +00:00
{
super.update(elapsed);
#if debug
if (FlxG.keys.justPressed.T)
{
2024-06-20 20:17:53 +00:00
rankAnimStart(fromResultsParams ??
{
playRankAnim: true,
newRank: PERFECT_GOLD,
songId: "tutorial",
difficultyId: "hard"
});
}
if (FlxG.keys.justPressed.P)
{
FlxG.switchState(FreeplayState.build(
{
{
character: currentCharacterId == "pico" ? "bf" : "pico",
}
}));
}
2024-06-01 23:25:52 +00:00
// if (FlxG.keys.justPressed.H)
// {
// rankDisplayNew(fromResultsParams);
// }
// if (FlxG.keys.justPressed.G)
// {
// rankAnimSlam(fromResultsParams);
// }
#end
2024-07-08 20:40:10 +00:00
if (controls.FREEPLAY_CHAR_SELECT && !busy)
{
FlxG.switchState(new funkin.ui.charSelect.CharSelectSubState());
}
if (controls.FREEPLAY_FAVORITE && !busy)
2023-01-23 00:55:30 +00:00
{
var targetSong = grpCapsules.members[curSelected]?.songData;
if (targetSong != null)
2023-01-23 00:55:30 +00:00
{
var realShit:Int = curSelected;
var isFav = targetSong.toggleFavorite();
if (isFav)
{
grpCapsules.members[realShit].favIcon.visible = true;
2024-06-05 03:36:32 +00:00
grpCapsules.members[realShit].favIconBlurred.visible = true;
grpCapsules.members[realShit].favIcon.animation.play('fav');
2024-06-05 03:36:32 +00:00
grpCapsules.members[realShit].favIconBlurred.animation.play('fav');
FunkinSound.playOnce(Paths.sound('fav'), 1);
2024-06-02 06:53:07 +00:00
grpCapsules.members[realShit].checkClip();
grpCapsules.members[realShit].selected = grpCapsules.members[realShit].selected; // set selected again, so it can run it's getter function to initialize movement
busy = true;
grpCapsules.members[realShit].doLerp = false;
FlxTween.tween(grpCapsules.members[realShit], {y: grpCapsules.members[realShit].y - 5}, 0.1, {ease: FlxEase.expoOut});
FlxTween.tween(grpCapsules.members[realShit], {y: grpCapsules.members[realShit].y + 5}, 0.1,
{
ease: FlxEase.expoIn,
startDelay: 0.1,
onComplete: function(_) {
grpCapsules.members[realShit].doLerp = true;
busy = false;
}
});
}
else
{
grpCapsules.members[realShit].favIcon.animation.play('fav', true, true, 9);
2024-06-05 03:36:32 +00:00
grpCapsules.members[realShit].favIconBlurred.animation.play('fav', true, true, 9);
FunkinSound.playOnce(Paths.sound('unfav'), 1);
new FlxTimer().start(0.2, _ -> {
grpCapsules.members[realShit].favIcon.visible = false;
2024-06-05 03:36:32 +00:00
grpCapsules.members[realShit].favIconBlurred.visible = false;
2024-06-02 06:53:07 +00:00
grpCapsules.members[realShit].checkClip();
});
busy = true;
grpCapsules.members[realShit].doLerp = false;
FlxTween.tween(grpCapsules.members[realShit], {y: grpCapsules.members[realShit].y + 5}, 0.1, {ease: FlxEase.expoOut});
FlxTween.tween(grpCapsules.members[realShit], {y: grpCapsules.members[realShit].y - 5}, 0.1,
{
ease: FlxEase.expoIn,
startDelay: 0.1,
onComplete: function(_) {
grpCapsules.members[realShit].doLerp = true;
busy = false;
}
});
}
2023-01-23 00:55:30 +00:00
}
}
lerpScore = MathUtil.smoothLerp(lerpScore, intendedScore, elapsed, 0.5);
lerpCompletion = MathUtil.smoothLerp(lerpCompletion, intendedCompletion, elapsed, 0.5);
2023-01-23 00:55:30 +00:00
if (Math.isNaN(lerpScore))
{
lerpScore = intendedScore;
}
if (Math.isNaN(lerpCompletion))
{
lerpCompletion = intendedCompletion;
}
2023-01-23 00:55:30 +00:00
fp.updateScore(Std.int(lerpScore));
txtCompletion.text = '${Math.floor(lerpCompletion * 100)}';
// Right align the completion percentage
switch (txtCompletion.text.length)
{
case 3:
2024-04-30 05:33:29 +00:00
txtCompletion.offset.x = 10;
case 2:
2024-04-30 05:33:29 +00:00
txtCompletion.offset.x = 0;
case 1:
2024-04-30 05:33:29 +00:00
txtCompletion.offset.x = -24;
default:
2024-04-30 05:33:29 +00:00
txtCompletion.offset.x = 0;
}
2023-01-23 00:55:30 +00:00
handleInputs(elapsed);
}
function handleInputs(elapsed:Float):Void
{
if (busy) return;
2023-01-23 00:55:30 +00:00
var upP:Bool = controls.UI_UP_P;
var downP:Bool = controls.UI_DOWN_P;
var accepted:Bool = controls.ACCEPT;
2023-01-23 00:55:30 +00:00
if (FlxG.onMobile)
{
for (touch in FlxG.touches.list)
{
if (touch.justPressed)
{
initTouchPos.set(touch.screenX, touch.screenY);
}
if (touch.pressed)
{
var dx:Float = initTouchPos.x - touch.screenX;
var dy:Float = initTouchPos.y - touch.screenY;
2023-01-23 00:55:30 +00:00
var angle:Float = Math.atan2(dy, dx);
var length:Float = Math.sqrt(dx * dx + dy * dy);
2023-01-23 00:55:30 +00:00
FlxG.watch.addQuick('LENGTH', length);
FlxG.watch.addQuick('ANGLE', Math.round(FlxAngle.asDegrees(angle)));
2023-01-23 00:55:30 +00:00
}
}
if (FlxG.touches.getFirst() != null)
{
if (touchTimer >= 1.5) accepted = true;
2023-01-23 00:55:30 +00:00
touchTimer += elapsed;
var touch:FlxTouch = FlxG.touches.getFirst();
velTouch = Math.abs((touch.screenY - dyTouch)) / 50;
dyTouch = touch.screenY - touchY;
dxTouch = touch.screenX - touchX;
if (touch.justPressed)
{
touchY = touch.screenY;
dyTouch = 0;
velTouch = 0;
touchX = touch.screenX;
dxTouch = 0;
}
if (Math.abs(dxTouch) >= 100)
{
touchX = touch.screenX;
if (dxTouch != 0) dxTouch < 0 ? changeDiff(1) : changeDiff(-1);
2023-01-23 00:55:30 +00:00
}
if (Math.abs(dyTouch) >= 100)
{
touchY = touch.screenY;
if (dyTouch != 0) dyTouch < 0 ? changeSelection(1) : changeSelection(-1);
2023-01-23 00:55:30 +00:00
}
}
else
{
touchTimer = 0;
}
}
#if mobile
for (touch in FlxG.touches.list)
{
if (touch.justPressed)
{
// accepted = true;
}
}
#end
if ((controls.UI_UP || controls.UI_DOWN))
2023-01-23 00:55:30 +00:00
{
if (spamming)
{
if (spamTimer >= 0.07)
{
spamTimer = 0;
if (controls.UI_UP)
{
changeSelection(-1);
}
2023-01-23 00:55:30 +00:00
else
{
2023-01-23 00:55:30 +00:00
changeSelection(1);
}
2023-01-23 00:55:30 +00:00
}
}
else if (spamTimer >= 0.9)
{
spamming = true;
}
else if (spamTimer <= 0)
{
if (controls.UI_UP)
{
changeSelection(-1);
}
else
{
changeSelection(1);
}
}
spamTimer += elapsed;
2024-06-20 20:17:53 +00:00
if (dj != null) dj.resetAFKTimer();
2023-01-23 00:55:30 +00:00
}
else
{
spamming = false;
spamTimer = 0;
}
2024-05-12 00:21:59 +00:00
#if !html5
2023-01-23 00:55:30 +00:00
if (FlxG.mouse.wheel != 0)
{
2024-06-20 20:17:53 +00:00
if (dj != null) dj.resetAFKTimer();
2024-05-11 23:35:04 +00:00
changeSelection(-Math.round(FlxG.mouse.wheel));
2023-01-23 00:55:30 +00:00
}
2024-05-12 00:21:59 +00:00
#else
if (FlxG.mouse.wheel < 0)
{
2024-06-20 20:17:53 +00:00
if (dj != null) dj.resetAFKTimer();
2024-05-15 01:21:47 +00:00
changeSelection(-Math.round(FlxG.mouse.wheel / 8));
2023-01-23 00:55:30 +00:00
}
2024-05-12 00:21:59 +00:00
else if (FlxG.mouse.wheel > 0)
{
2024-06-20 20:17:53 +00:00
if (dj != null) dj.resetAFKTimer();
2024-05-12 00:21:59 +00:00
changeSelection(-Math.round(FlxG.mouse.wheel / 8));
}
#end
2023-01-23 00:55:30 +00:00
if (controls.UI_LEFT_P)
2023-01-23 00:55:30 +00:00
{
2024-06-20 20:17:53 +00:00
if (dj != null) dj.resetAFKTimer();
2023-01-23 00:55:30 +00:00
changeDiff(-1);
generateSongList(currentFilter, true);
2023-01-23 00:55:30 +00:00
}
if (controls.UI_RIGHT_P)
2023-01-23 00:55:30 +00:00
{
2024-06-20 20:17:53 +00:00
if (dj != null) dj.resetAFKTimer();
2023-01-23 00:55:30 +00:00
changeDiff(1);
generateSongList(currentFilter, true);
2023-01-23 00:55:30 +00:00
}
2024-05-03 01:23:55 +00:00
if (controls.BACK)
2023-01-23 00:55:30 +00:00
{
busy = true;
2023-03-17 02:02:56 +00:00
FlxTween.globalManager.clear();
FlxTimer.globalManager.clear();
2024-06-20 20:17:53 +00:00
if (dj != null) dj.onIntroDone.removeAll();
2023-03-17 02:02:56 +00:00
2024-03-23 21:50:48 +00:00
FunkinSound.playOnce(Paths.sound('cancelMenu'));
2023-01-23 00:55:30 +00:00
2023-03-16 01:05:15 +00:00
var longestTimer:Float = 0;
// FlxTween.color(bgDad, 0.33, 0xFFFFFFFF, 0xFF555555, {ease: FlxEase.quadOut});
FlxTween.color(pinkBack, 0.25, 0xFFFFD863, 0xFFFFD0D5, {ease: FlxEase.quadOut});
cardGlow.visible = true;
cardGlow.alpha = 1;
cardGlow.scale.set(1, 1);
FlxTween.tween(cardGlow, {alpha: 0, "scale.x": 1.2, "scale.y": 1.2}, 0.25, {ease: FlxEase.sineOut});
orangeBackShit.visible = false;
alsoOrangeLOL.visible = false;
moreWays.visible = false;
funnyScroll.visible = false;
txtNuts.visible = false;
funnyScroll2.visible = false;
moreWays2.visible = false;
funnyScroll3.visible = false;
2023-03-16 04:17:52 +00:00
for (grpSpr in exitMovers.keys())
2023-03-16 01:05:15 +00:00
{
2024-06-20 20:17:53 +00:00
var moveData:Null<MoveData> = exitMovers.get(grpSpr);
if (moveData == null) continue;
2023-03-16 04:17:52 +00:00
for (spr in grpSpr)
{
if (spr == null) continue;
2023-03-16 04:17:52 +00:00
var funnyMoveShit:MoveData = moveData;
2024-06-20 20:17:53 +00:00
var moveDataX = funnyMoveShit.x ?? spr.x;
var moveDataY = funnyMoveShit.y ?? spr.y;
var moveDataSpeed = funnyMoveShit.speed ?? 0.2;
var moveDataWait = funnyMoveShit.wait ?? 0;
2023-03-16 01:05:15 +00:00
2024-06-20 20:17:53 +00:00
FlxTween.tween(spr, {x: moveDataX, y: moveDataY}, moveDataSpeed, {ease: FlxEase.expoIn});
2023-03-16 04:17:52 +00:00
2024-06-20 20:17:53 +00:00
longestTimer = Math.max(longestTimer, moveDataSpeed + moveDataWait);
2023-03-16 04:17:52 +00:00
}
2023-03-16 01:05:15 +00:00
}
for (caps in grpCapsules.members)
{
caps.doJumpIn = false;
caps.doLerp = false;
caps.doJumpOut = true;
}
if (Type.getClass(_parentState) == MainMenuState)
2023-03-16 04:55:25 +00:00
{
_parentState.persistentUpdate = false;
_parentState.persistentDraw = true;
2023-03-16 04:55:25 +00:00
}
2023-03-16 01:05:15 +00:00
new FlxTimer().start(longestTimer, (_) -> {
FlxTransitionableState.skipNextTransIn = true;
FlxTransitionableState.skipNextTransOut = true;
if (Type.getClass(_parentState) == MainMenuState)
2023-03-16 04:17:52 +00:00
{
FunkinSound.playMusic('freakyMenu',
{
overrideExisting: true,
restartTrack: false
});
2024-06-02 00:36:14 +00:00
FlxG.sound.music.fadeIn(4.0, 0.0, 1.0);
2023-03-16 04:17:52 +00:00
close();
}
else
{
FlxG.switchState(() -> new MainMenuState());
2023-03-16 04:17:52 +00:00
}
2023-03-16 01:05:15 +00:00
});
2023-01-23 00:55:30 +00:00
}
if (accepted)
{
2023-08-06 20:24:34 +00:00
grpCapsules.members[curSelected].onConfirm();
2023-01-23 00:55:30 +00:00
}
}
2023-12-16 02:09:01 +00:00
public override function destroy():Void
2023-01-23 00:55:30 +00:00
{
2023-12-16 02:09:01 +00:00
super.destroy();
var daSong:Null<FreeplaySongData> = currentFilteredSongs[curSelected];
if (daSong != null)
{
clearDaCache(daSong.songName);
}
2024-05-14 00:20:23 +00:00
// remove and destroy freeplay camera
FlxG.cameras.remove(funnyCam);
2023-01-23 00:55:30 +00:00
}
function changeDiff(change:Int = 0, force:Bool = false):Void
2023-01-23 00:55:30 +00:00
{
touchTimer = 0;
var currentDifficultyIndex:Int = diffIdsCurrent.indexOf(currentDifficulty);
2023-01-23 00:55:30 +00:00
if (currentDifficultyIndex == -1) currentDifficultyIndex = diffIdsCurrent.indexOf(Constants.DEFAULT_DIFFICULTY);
2023-01-23 00:55:30 +00:00
currentDifficultyIndex += change;
if (currentDifficultyIndex < 0) currentDifficultyIndex = diffIdsCurrent.length - 1;
if (currentDifficultyIndex >= diffIdsCurrent.length) currentDifficultyIndex = 0;
currentDifficulty = diffIdsCurrent[currentDifficultyIndex];
var daSong:Null<FreeplaySongData> = grpCapsules.members[curSelected].songData;
if (daSong != null)
{
2024-06-20 20:17:53 +00:00
var targetSong:Null<Song> = SongRegistry.instance.fetchEntry(daSong.songId);
if (targetSong == null)
{
2024-06-20 20:17:53 +00:00
FlxG.log.warn('WARN: could not find song with id (${daSong.songId})');
return;
}
2024-06-20 20:17:53 +00:00
var targetVariation:String = targetSong.getFirstValidVariation(currentDifficulty) ?? '';
// TODO: This line of code makes me sad, but you can't really fix it without a breaking migration.
var suffixedDifficulty = (targetVariation != Constants.DEFAULT_VARIATION
&& targetVariation != 'erect') ? '$currentDifficulty-${targetVariation}' : currentDifficulty;
2024-06-20 20:17:53 +00:00
var songScore:Null<SaveScoreData> = Save.instance.getSongScore(daSong.songId, suffixedDifficulty);
intendedScore = songScore?.score ?? 0;
intendedCompletion = songScore == null ? 0.0 : ((songScore.tallies.sick + songScore.tallies.good) / songScore.tallies.totalNotes);
rememberedDifficulty = currentDifficulty;
}
else
{
intendedScore = 0;
intendedCompletion = 0.0;
}
2023-01-23 00:55:30 +00:00
if (intendedCompletion == Math.POSITIVE_INFINITY || intendedCompletion == Math.NEGATIVE_INFINITY || Math.isNaN(intendedCompletion))
{
intendedCompletion = 0;
}
grpDifficulties.group.forEach(function(diffSprite) {
diffSprite.visible = false;
2023-01-23 00:55:30 +00:00
});
for (diffSprite in grpDifficulties.group.members)
{
if (diffSprite == null) continue;
if (diffSprite.difficultyId == currentDifficulty)
{
if (change != 0)
{
diffSprite.visible = true;
diffSprite.offset.y += 5;
diffSprite.alpha = 0.5;
new FlxTimer().start(1 / 24, function(swag) {
diffSprite.alpha = 1;
diffSprite.updateHitbox();
});
}
else
{
diffSprite.visible = true;
}
}
}
if (change != 0 || force)
{
// Update the song capsules to reflect the new difficulty info.
for (songCapsule in grpCapsules.members)
{
if (songCapsule == null) continue;
if (songCapsule.songData != null)
{
songCapsule.songData.currentDifficulty = currentDifficulty;
songCapsule.init(null, null, songCapsule.songData);
2024-06-05 22:21:57 +00:00
songCapsule.checkClip();
}
else
{
songCapsule.init(null, null, null);
}
}
}
// Set the album graphic and play the animation if relevant.
2024-06-20 20:17:53 +00:00
var newAlbumId:Null<String> = daSong?.albumId;
if (albumRoll.albumId != newAlbumId)
{
albumRoll.albumId = newAlbumId;
2024-03-30 04:54:07 +00:00
albumRoll.skipIntro();
}
// Set difficulty star count.
albumRoll.setDifficultyStars(daSong?.difficultyRating);
2023-01-23 00:55:30 +00:00
}
// Clears the cache of songs, frees up memory, they' ll have to be loaded in later tho function clearDaCache(actualSongTho:String)
function clearDaCache(actualSongTho:String):Void
2023-01-23 00:55:30 +00:00
{
for (song in songs)
{
if (song == null) continue;
2023-01-23 00:55:30 +00:00
if (song.songName != actualSongTho)
{
trace('trying to remove: ' + song.songName);
// openfl.Assets.cache.clear(Paths.inst(song.songName));
}
}
}
function capsuleOnConfirmRandom(randomCapsule:SongMenuItem):Void
2023-08-06 20:24:34 +00:00
{
trace('RANDOM SELECTED');
2023-08-06 20:24:34 +00:00
busy = true;
letterSort.inputEnabled = false;
var availableSongCapsules:Array<SongMenuItem> = grpCapsules.members.filter(function(cap:SongMenuItem) {
// Dead capsules are ones which were removed from the list when changing filters.
return cap.alive && cap.songData != null;
});
trace('Available songs: ${availableSongCapsules.map(function(cap) {
2024-06-20 20:17:53 +00:00
return cap?.songData?.songName;
})}');
if (availableSongCapsules.length == 0)
{
trace('No songs available!');
busy = false;
letterSort.inputEnabled = true;
2024-03-23 21:50:48 +00:00
FunkinSound.playOnce(Paths.sound('cancelMenu'));
return;
}
var targetSong:SongMenuItem = FlxG.random.getObject(availableSongCapsules);
// Seeing if I can do an animation...
curSelected = grpCapsules.members.indexOf(targetSong);
changeSelection(0); // Trigger an update.
// Act like we hit Confirm on that song.
capsuleOnConfirmDefault(targetSong);
}
2023-09-29 00:29:19 +00:00
function capsuleOnConfirmDefault(cap:SongMenuItem):Void
2023-01-23 00:55:30 +00:00
{
busy = true;
letterSort.inputEnabled = false;
2023-08-06 20:24:34 +00:00
PlayStatePlaylist.isStoryMode = false;
2023-01-23 00:55:30 +00:00
2024-06-20 20:17:53 +00:00
var targetSongId:String = cap?.songData?.songId ?? 'unknown';
var targetSongNullable:Null<Song> = SongRegistry.instance.fetchEntry(targetSongId);
if (targetSongNullable == null)
{
2024-06-20 20:17:53 +00:00
FlxG.log.warn('WARN: could not find song with id (${targetSongId})');
return;
}
2024-06-20 20:17:53 +00:00
var targetSong:Song = targetSongNullable;
var targetDifficultyId:String = currentDifficulty;
2024-06-20 20:17:53 +00:00
var targetVariation:Null<String> = targetSong.getFirstValidVariation(targetDifficultyId, currentCharacter);
var targetLevelId:Null<String> = cap?.songData?.levelId;
PlayStatePlaylist.campaignId = targetLevelId ?? null;
2023-08-06 20:24:34 +00:00
2024-06-20 20:17:53 +00:00
var targetDifficulty:Null<SongDifficulty> = targetSong.getDifficulty(targetDifficultyId, targetVariation);
if (targetDifficulty == null)
{
FlxG.log.warn('WARN: could not find difficulty with id (${targetDifficultyId})');
return;
}
var baseInstrumentalId:String = targetDifficulty?.characters?.instrumental ?? '';
var altInstrumentalIds:Array<String> = targetDifficulty?.characters?.altInstrumentals ?? [];
var targetInstId:String = baseInstrumentalId;
// TODO: Make this a UI element.
#if (debug || FORCE_DEBUG_VERSION)
if (altInstrumentalIds.length > 0 && FlxG.keys.pressed.CONTROL)
{
targetInstId = altInstrumentalIds[0];
}
#end
2023-08-06 20:24:34 +00:00
// Visual and audio effects.
2024-03-23 21:50:48 +00:00
FunkinSound.playOnce(Paths.sound('confirmMenu'));
2024-06-20 20:17:53 +00:00
if (dj != null) dj.confirm();
2023-08-06 20:24:34 +00:00
grpCapsules.members[curSelected].forcePosition();
2024-06-27 23:50:38 +00:00
grpCapsules.members[curSelected].confirm();
// FlxTween.color(bgDad, 0.33, 0xFFFFFFFF, 0xFF555555, {ease: FlxEase.quadOut});
FlxTween.color(pinkBack, 0.33, 0xFFFFD0D5, 0xFF171831, {ease: FlxEase.quadOut});
orangeBackShit.visible = false;
alsoOrangeLOL.visible = false;
confirmGlow.visible = true;
confirmGlow2.visible = true;
backingTextYeah.anim.play("BF back card confirm raw", false, false, 0);
confirmGlow2.alpha = 0;
confirmGlow.alpha = 0;
FlxTween.tween(confirmGlow2, {alpha: 0.5}, 0.33,
{
ease: FlxEase.quadOut,
onComplete: function(_) {
confirmGlow2.alpha = 0.6;
confirmGlow.alpha = 1;
confirmTextGlow.visible = true;
confirmTextGlow.alpha = 1;
FlxTween.tween(confirmTextGlow, {alpha: 0.4}, 0.5);
FlxTween.tween(confirmGlow, {alpha: 0}, 0.5);
}
});
// confirmGlow
moreWays.visible = false;
funnyScroll.visible = false;
txtNuts.visible = false;
funnyScroll2.visible = false;
moreWays2.visible = false;
funnyScroll3.visible = false;
2023-08-06 20:24:34 +00:00
new FlxTimer().start(1, function(tmr:FlxTimer) {
FunkinSound.emptyPartialQueue();
2024-06-20 20:17:53 +00:00
Paths.setCurrentLevel(cap?.songData?.levelId);
LoadingState.loadPlayState(
2023-08-06 20:24:34 +00:00
{
targetSong: targetSong,
targetDifficulty: targetDifficultyId,
targetVariation: targetVariation,
targetInstrumental: targetInstId,
practiceMode: false,
minimalMode: false,
#if (debug || FORCE_DEBUG_VERSION)
botPlayMode: FlxG.keys.pressed.SHIFT,
#else
botPlayMode: false,
#end
// TODO: Make these an option! It's currently only accessible via chart editor.
// startTimestamp: 0.0,
// playbackRate: 0.5,
// botPlayMode: true,
}, true);
2023-08-06 20:24:34 +00:00
});
}
function rememberSelection():Void
{
if (rememberedSongId != null)
{
curSelected = currentFilteredSongs.findIndex(function(song) {
if (song == null) return false;
return song.songId == rememberedSongId;
});
if (curSelected == -1) curSelected = 0;
}
if (rememberedDifficulty != null)
{
currentDifficulty = rememberedDifficulty;
}
}
2024-03-12 03:42:32 +00:00
function changeSelection(change:Int = 0):Void
2023-01-23 00:55:30 +00:00
{
var prevSelected:Int = curSelected;
2023-01-23 00:55:30 +00:00
curSelected += change;
if (!prepForNewRank && curSelected != prevSelected) FunkinSound.playOnce(Paths.sound('scrollMenu'), 0.4);
2023-08-09 07:03:58 +00:00
if (curSelected < 0) curSelected = grpCapsules.countLiving() - 1;
if (curSelected >= grpCapsules.countLiving()) curSelected = 0;
2023-01-23 00:55:30 +00:00
var daSongCapsule:SongMenuItem = grpCapsules.members[curSelected];
if (daSongCapsule.songData != null)
2023-08-09 07:03:58 +00:00
{
2024-06-20 20:17:53 +00:00
var songScore:Null<SaveScoreData> = Save.instance.getSongScore(daSongCapsule.songData.songId, currentDifficulty);
intendedScore = songScore?.score ?? 0;
intendedCompletion = songScore == null ? 0.0 : ((songScore.tallies.sick + songScore.tallies.good) / songScore.tallies.totalNotes);
2023-11-02 03:20:47 +00:00
diffIdsCurrent = daSongCapsule.songData.songDifficulties;
rememberedSongId = daSongCapsule.songData.songId;
changeDiff();
2023-08-09 07:03:58 +00:00
}
else
{
intendedScore = 0;
intendedCompletion = 0.0;
diffIdsCurrent = diffIdsTotal;
rememberedSongId = null;
rememberedDifficulty = null;
albumRoll.albumId = null;
2023-08-09 07:03:58 +00:00
}
2023-01-23 00:55:30 +00:00
for (index => capsule in grpCapsules.members)
{
2023-08-04 19:59:17 +00:00
index += 1;
2023-01-23 00:55:30 +00:00
2023-09-20 03:27:07 +00:00
capsule.selected = index == curSelected + 1;
2023-01-23 00:55:30 +00:00
2023-08-04 21:10:27 +00:00
capsule.targetPos.y = capsule.intendedY(index - curSelected);
2023-01-23 00:55:30 +00:00
capsule.targetPos.x = 270 + (60 * (Math.sin(index - curSelected)));
if (index < curSelected) capsule.targetPos.y -= 100; // another 100 for good measure
2023-01-23 00:55:30 +00:00
}
2024-06-06 00:49:33 +00:00
if (grpCapsules.countLiving() > 0 && !prepForNewRank)
2023-08-14 02:12:08 +00:00
{
2024-06-06 00:49:33 +00:00
playCurSongPreview(daSongCapsule);
2023-08-14 02:12:08 +00:00
grpCapsules.members[curSelected].selected = true;
}
2023-01-23 00:55:30 +00:00
}
2024-06-06 00:49:33 +00:00
public function playCurSongPreview(daSongCapsule:SongMenuItem):Void
{
if (curSelected == 0)
{
FunkinSound.playMusic('freeplayRandom',
{
startingVolume: 0.0,
overrideExisting: true,
restartTrack: false
});
FlxG.sound.music.fadeIn(2, 0, 0.8);
}
else
{
2024-06-20 20:17:53 +00:00
var previewSongId:Null<String> = daSongCapsule?.songData?.songId;
if (previewSongId == null) return;
var previewSong:Null<Song> = SongRegistry.instance.fetchEntry(previewSongId);
var songDifficulty = previewSong?.getDifficulty(currentDifficulty,
previewSong?.getVariationsByCharacter(currentCharacter) ?? Constants.DEFAULT_VARIATION_LIST);
var baseInstrumentalId:String = songDifficulty?.characters?.instrumental ?? '';
var altInstrumentalIds:Array<String> = songDifficulty?.characters?.altInstrumentals ?? [];
var instSuffix:String = baseInstrumentalId;
// TODO: Make this a UI element.
#if (debug || FORCE_DEBUG_VERSION)
if (altInstrumentalIds.length > 0 && FlxG.keys.pressed.CONTROL)
{
instSuffix = altInstrumentalIds[0];
}
#end
instSuffix = (instSuffix != '') ? '-$instSuffix' : '';
2024-06-20 20:17:53 +00:00
trace('Attempting to play partial preview: ${previewSongId}:${instSuffix}');
FunkinSound.playMusic(previewSongId,
2024-06-06 00:49:33 +00:00
{
startingVolume: 0.0,
overrideExisting: true,
restartTrack: false,
mapTimeChanges: false, // The music metadata is not alongside the audio file so this won't work.
2024-06-06 00:49:33 +00:00
pathsFunction: INST,
suffix: instSuffix,
2024-06-06 00:49:33 +00:00
partialParams:
{
loadPartial: true,
start: 0.05,
end: 0.25
},
onLoad: function() {
FlxG.sound.music.fadeIn(2, 0, 0.4);
}
});
}
}
/**
* Build an instance of `FreeplayState` that is above the `MainMenuState`.
* @return The MainMenuState with the FreeplayState as a substate.
*/
public static function build(?params:FreeplayStateParams, ?stickers:StickerSubState):MusicBeatState
{
var result:MainMenuState;
2024-06-20 20:17:53 +00:00
if (params?.fromResults?.playRankAnim ?? false) result = new MainMenuState(true);
2024-06-01 23:25:52 +00:00
else
result = new MainMenuState(false);
result.openSubState(new FreeplayState(params, stickers));
2024-05-01 19:22:20 +00:00
result.persistentUpdate = false;
result.persistentDraw = true;
return result;
}
2021-12-08 00:29:26 +00:00
}
/**
* The difficulty selector arrows to the left and right of the difficulty.
*/
2021-12-08 00:29:26 +00:00
class DifficultySelector extends FlxSprite
{
2023-01-23 00:55:30 +00:00
var controls:Controls;
var whiteShader:PureColor;
2021-12-08 00:29:26 +00:00
2023-01-23 00:55:30 +00:00
public function new(x:Float, y:Float, flipped:Bool, controls:Controls)
{
super(x, y);
2021-12-08 00:29:26 +00:00
2023-01-23 00:55:30 +00:00
this.controls = controls;
2021-12-08 00:29:26 +00:00
2023-01-23 00:55:30 +00:00
frames = Paths.getSparrowAtlas('freeplay/freeplaySelector');
animation.addByPrefix('shine', 'arrow pointer loop', 24);
2023-01-23 00:55:30 +00:00
animation.play('shine');
2021-12-08 00:29:26 +00:00
2023-01-23 00:55:30 +00:00
whiteShader = new PureColor(FlxColor.WHITE);
2021-12-08 03:34:01 +00:00
2023-01-23 00:55:30 +00:00
shader = whiteShader;
2021-12-08 03:34:01 +00:00
2023-01-23 00:55:30 +00:00
flipX = flipped;
}
2021-04-08 21:29:31 +00:00
2024-03-12 03:42:32 +00:00
override function update(elapsed:Float):Void
2023-01-23 00:55:30 +00:00
{
if (flipX && controls.UI_RIGHT_P) moveShitDown();
if (!flipX && controls.UI_LEFT_P) moveShitDown();
2021-12-08 00:29:26 +00:00
2023-01-23 00:55:30 +00:00
super.update(elapsed);
}
2021-12-08 00:29:26 +00:00
2024-03-12 03:42:32 +00:00
function moveShitDown():Void
2023-01-23 00:55:30 +00:00
{
offset.y -= 5;
2021-04-08 21:29:31 +00:00
2023-01-23 00:55:30 +00:00
whiteShader.colorSet = true;
2021-12-08 03:34:01 +00:00
2023-08-07 02:20:18 +00:00
scale.x = scale.y = 0.5;
2023-03-16 01:05:15 +00:00
new FlxTimer().start(2 / 24, function(tmr) {
2023-08-07 02:20:18 +00:00
scale.x = scale.y = 1;
2023-01-23 00:55:30 +00:00
whiteShader.colorSet = false;
updateHitbox();
});
}
2020-10-21 18:05:27 +00:00
}
2021-02-25 01:52:59 +00:00
/**
* Structure for the current song filter.
*/
2022-09-28 06:50:53 +00:00
typedef SongFilter =
{
2023-01-23 00:55:30 +00:00
var filterType:FilterType;
var ?filterData:Dynamic;
2022-09-28 06:50:53 +00:00
}
/**
* Possible types to use for the song filter.
*/
2022-09-28 06:50:53 +00:00
enum abstract FilterType(String)
{
/**
* Filter to songs which start with a string
*/
public var STARTSWITH;
/**
* Filter to songs which match a regular expression
*/
public var REGEXP;
/**
* Filter to songs which are favorited
*/
public var FAVORITE;
/**
* Filter to all songs
*/
public var ALL;
2022-09-28 06:50:53 +00:00
}
/**
* Data about a specific song in the freeplay menu.
*/
class FreeplaySongData
2021-02-25 01:52:59 +00:00
{
/**
* Whether or not the song has been favorited.
*/
public var isFav:Bool = false;
2024-06-06 00:49:33 +00:00
public var isNew:Bool = false;
var song:Song;
public var levelId(default, null):String = '';
public var songId(default, null):String = '';
public var songDifficulties(default, null):Array<String> = [];
2023-01-23 00:55:30 +00:00
public var songName(default, null):String = '';
public var songCharacter(default, null):String = '';
public var songStartingBpm(default, null):Float = 0;
public var difficultyRating(default, null):Int = 0;
public var albumId(default, null):Null<String> = null;
public var currentDifficulty(default, set):String = Constants.DEFAULT_DIFFICULTY;
public var scoringRank:Null<ScoringRank> = null;
var displayedVariations:Array<String> = [Constants.DEFAULT_VARIATION];
function set_currentDifficulty(value:String):String
{
if (currentDifficulty == value) return value;
currentDifficulty = value;
updateValues(displayedVariations);
return value;
}
public function new(levelId:String, songId:String, song:Song, ?displayedVariations:Array<String>)
2023-01-23 00:55:30 +00:00
{
this.levelId = levelId;
this.songId = songId;
this.song = song;
this.isFav = Save.instance.isSongFavorited(songId);
if (displayedVariations != null) this.displayedVariations = displayedVariations;
updateValues(displayedVariations);
}
/**
* Toggle whether or not the song is favorited, then flush to save data.
* @return Whether or not the song is now favorited.
*/
public function toggleFavorite():Bool
{
isFav = !isFav;
if (isFav)
{
Save.instance.favoriteSong(this.songId);
}
else
{
Save.instance.unfavoriteSong(this.songId);
}
return isFav;
}
function updateValues(variations:Array<String>):Void
{
2024-06-05 21:58:22 +00:00
this.songDifficulties = song.listDifficulties(null, variations, false, false);
if (!this.songDifficulties.contains(currentDifficulty)) currentDifficulty = Constants.DEFAULT_DIFFICULTY;
2024-06-07 18:24:57 +00:00
var songDifficulty:SongDifficulty = song.getDifficulty(currentDifficulty, null, variations);
if (songDifficulty == null) return;
this.songStartingBpm = songDifficulty.getStartingBPM();
this.songName = songDifficulty.songName;
this.songCharacter = songDifficulty.characters.opponent;
this.difficultyRating = songDifficulty.difficultyRating;
if (songDifficulty.album == null)
{
FlxG.log.warn('No album for: ${songDifficulty.songName}');
this.albumId = Constants.DEFAULT_ALBUM_ID;
}
else
{
this.albumId = songDifficulty.album;
}
// TODO: This line of code makes me sad, but you can't really fix it without a breaking migration.
// `easy`, `erect`, `normal-pico`, etc.
var suffixedDifficulty = (songDifficulty.variation != Constants.DEFAULT_VARIATION
&& songDifficulty.variation != 'erect') ? '$currentDifficulty-${songDifficulty.variation}' : currentDifficulty;
this.scoringRank = Save.instance.getSongRank(songId, suffixedDifficulty);
2024-06-06 00:49:33 +00:00
this.isNew = song.isSongNew(currentDifficulty);
2023-01-23 00:55:30 +00:00
}
2021-02-25 01:52:59 +00:00
}
2023-03-16 01:05:15 +00:00
/**
* The map storing information about the exit movers.
*/
typedef ExitMoverData = Map<Array<FlxSprite>, MoveData>;
/**
* The data for an exit mover.
*/
2023-03-16 01:05:15 +00:00
typedef MoveData =
{
2023-03-16 04:17:52 +00:00
var ?x:Float;
var ?y:Float;
var ?speed:Float;
var ?wait:Float;
2023-03-16 01:05:15 +00:00
}
/**
* The sprite for the difficulty
*/
class DifficultySprite extends FlxSprite
{
/**
* The difficulty id which this sprite represents.
*/
public var difficultyId:String;
public function new(diffId:String)
{
super();
difficultyId = diffId;
if (Assets.exists(Paths.file('images/freeplay/freeplay${diffId}.xml')))
{
this.frames = Paths.getSparrowAtlas('freeplay/freeplay${diffId}');
this.animation.addByPrefix('idle', 'idle0', 24, true);
if (Preferences.flashingLights) this.animation.play('idle');
}
else
{
this.loadGraphic(Paths.image('freeplay/freeplay' + diffId));
}
}
}