mirror of
https://github.com/FunkinCrew/Funkin.git
synced 2024-11-30 03:25:47 -05:00
286 lines
6 KiB
Haxe
286 lines
6 KiB
Haxe
package;
|
|
|
|
import flash.text.TextField;
|
|
import flixel.FlxG;
|
|
import flixel.FlxSprite;
|
|
import flixel.addons.display.FlxGridOverlay;
|
|
import flixel.group.FlxGroup.FlxTypedGroup;
|
|
import flixel.math.FlxMath;
|
|
import flixel.text.FlxText;
|
|
import flixel.util.FlxColor;
|
|
import lime.utils.Assets;
|
|
|
|
using StringTools;
|
|
|
|
class FreeplayState extends MusicBeatState
|
|
{
|
|
var songs:Array<SongMetadata> = [];
|
|
|
|
var selector:FlxText;
|
|
var curSelected:Int = 0;
|
|
var curDifficulty:Int = 1;
|
|
|
|
var scoreText:FlxText;
|
|
var diffText:FlxText;
|
|
var lerpScore:Int = 0;
|
|
var intendedScore:Int = 0;
|
|
|
|
private var grpSongs:FlxTypedGroup<Alphabet>;
|
|
private var curPlaying:Bool = false;
|
|
|
|
override function create()
|
|
{
|
|
var initSonglist = CoolUtil.coolTextFile(Paths.txt('freeplaySonglist'));
|
|
|
|
for (i in 0...initSonglist.length)
|
|
{
|
|
songs.push(new SongMetadata(initSonglist[i], 1));
|
|
}
|
|
|
|
/*
|
|
if (FlxG.sound.music != null)
|
|
{
|
|
if (!FlxG.sound.music.playing)
|
|
FlxG.sound.playMusic(Paths.music('freakyMenu'));
|
|
}
|
|
*/
|
|
|
|
var isDebug:Bool = false;
|
|
|
|
#if debug
|
|
isDebug = true;
|
|
#end
|
|
|
|
if (StoryMenuState.weekUnlocked[2] || isDebug)
|
|
addWeek(['Spookeez', 'South', 'Monster'], 2);
|
|
|
|
if (StoryMenuState.weekUnlocked[3] || isDebug)
|
|
addWeek(['Pico', 'Philly', 'Blammed'], 3);
|
|
|
|
if (StoryMenuState.weekUnlocked[4] || isDebug)
|
|
addWeek(['Satin-Panties', 'High', 'Milf'], 4);
|
|
|
|
if (StoryMenuState.weekUnlocked[5] || isDebug)
|
|
addWeek(['Cocoa', 'Eggnog', 'Winter-Horrorland'], 5);
|
|
|
|
if (StoryMenuState.weekUnlocked[6] || isDebug)
|
|
addWeek(['Senpai', 'Roses', 'Thorns'], 6);
|
|
|
|
// LOAD MUSIC
|
|
|
|
// LOAD CHARACTERS
|
|
|
|
var bg:FlxSprite = new FlxSprite().loadGraphic(Paths.image('menuBGBlue'));
|
|
add(bg);
|
|
|
|
grpSongs = new FlxTypedGroup<Alphabet>();
|
|
add(grpSongs);
|
|
|
|
for (i in 0...songs.length)
|
|
{
|
|
var songText:Alphabet = new Alphabet(0, (70 * i) + 30, songs[i].songName, true, false);
|
|
songText.isMenuItem = true;
|
|
songText.targetY = i;
|
|
grpSongs.add(songText);
|
|
// songText.x += 40;
|
|
// DONT PUT X IN THE FIRST PARAMETER OF new ALPHABET() !!
|
|
// songText.screenCenter(X);
|
|
}
|
|
|
|
scoreText = new FlxText(FlxG.width * 0.7, 5, 0, "", 32);
|
|
// scoreText.autoSize = false;
|
|
scoreText.setFormat(Paths.font("vcr.ttf"), 32, FlxColor.WHITE, RIGHT);
|
|
// scoreText.alignment = RIGHT;
|
|
|
|
var scoreBG:FlxSprite = new FlxSprite(scoreText.x - 6, 0).makeGraphic(Std.int(FlxG.width * 0.35), 66, 0xFF000000);
|
|
scoreBG.alpha = 0.6;
|
|
add(scoreBG);
|
|
|
|
diffText = new FlxText(scoreText.x, scoreText.y + 36, 0, "", 24);
|
|
diffText.font = scoreText.font;
|
|
add(diffText);
|
|
|
|
add(scoreText);
|
|
|
|
changeSelection();
|
|
changeDiff();
|
|
|
|
// FlxG.sound.playMusic(Paths.music('title'), 0);
|
|
// FlxG.sound.music.fadeIn(2, 0, 0.8);
|
|
selector = new FlxText();
|
|
|
|
selector.size = 40;
|
|
selector.text = ">";
|
|
// add(selector);
|
|
|
|
var swag:Alphabet = new Alphabet(1, 0, "swag");
|
|
|
|
// JUST DOIN THIS SHIT FOR TESTING!!!
|
|
/*
|
|
var md:String = Markdown.markdownToHtml(Assets.getText('CHANGELOG.md'));
|
|
|
|
var texFel:TextField = new TextField();
|
|
texFel.width = FlxG.width;
|
|
texFel.height = FlxG.height;
|
|
// texFel.
|
|
texFel.htmlText = md;
|
|
|
|
FlxG.stage.addChild(texFel);
|
|
|
|
// scoreText.textField.htmlText = md;
|
|
|
|
trace(md);
|
|
*/
|
|
|
|
super.create();
|
|
}
|
|
|
|
public function addSong(songName:String, weekNum:Int)
|
|
{
|
|
songs.push(new SongMetadata(songName, weekNum));
|
|
}
|
|
|
|
public function addWeek(songs:Array<String>, weekNum:Int)
|
|
{
|
|
for (song in songs)
|
|
{
|
|
addSong(song, weekNum);
|
|
}
|
|
}
|
|
|
|
override function update(elapsed:Float)
|
|
{
|
|
super.update(elapsed);
|
|
|
|
if (FlxG.sound.music.volume < 0.7)
|
|
{
|
|
FlxG.sound.music.volume += 0.5 * FlxG.elapsed;
|
|
}
|
|
|
|
lerpScore = Math.floor(FlxMath.lerp(lerpScore, intendedScore, 0.4));
|
|
|
|
if (Math.abs(lerpScore - intendedScore) <= 10)
|
|
lerpScore = intendedScore;
|
|
|
|
scoreText.text = "PERSONAL BEST:" + lerpScore;
|
|
|
|
var upP = controls.UP_P;
|
|
var downP = controls.DOWN_P;
|
|
var accepted = controls.ACCEPT;
|
|
|
|
if (upP)
|
|
{
|
|
changeSelection(-1);
|
|
}
|
|
if (downP)
|
|
{
|
|
changeSelection(1);
|
|
}
|
|
|
|
if (controls.LEFT_P)
|
|
changeDiff(-1);
|
|
if (controls.RIGHT_P)
|
|
changeDiff(1);
|
|
|
|
if (controls.BACK)
|
|
{
|
|
FlxG.switchState(new MainMenuState());
|
|
}
|
|
|
|
if (accepted)
|
|
{
|
|
var poop:String = Highscore.formatSong(songs[curSelected].songName.toLowerCase(), curDifficulty);
|
|
|
|
trace(poop);
|
|
|
|
PlayState.SONG = Song.loadFromJson(poop, songs[curSelected].songName.toLowerCase());
|
|
PlayState.isStoryMode = false;
|
|
PlayState.storyDifficulty = curDifficulty;
|
|
|
|
PlayState.storyWeek = songs[curSelected].week;
|
|
trace('CUR WEEK' + PlayState.storyWeek);
|
|
LoadingState.loadAndSwitchState(new PlayState());
|
|
}
|
|
}
|
|
|
|
function changeDiff(change:Int = 0)
|
|
{
|
|
curDifficulty += change;
|
|
|
|
if (curDifficulty < 0)
|
|
curDifficulty = 2;
|
|
if (curDifficulty > 2)
|
|
curDifficulty = 0;
|
|
|
|
#if !switch
|
|
intendedScore = Highscore.getScore(songs[curSelected].songName, curDifficulty);
|
|
#end
|
|
|
|
switch (curDifficulty)
|
|
{
|
|
case 0:
|
|
diffText.text = "EASY";
|
|
case 1:
|
|
diffText.text = 'NORMAL';
|
|
case 2:
|
|
diffText.text = "HARD";
|
|
}
|
|
}
|
|
|
|
function changeSelection(change:Int = 0)
|
|
{
|
|
#if !switch
|
|
NGio.logEvent('Fresh');
|
|
#end
|
|
|
|
// NGio.logEvent('Fresh');
|
|
FlxG.sound.play(Paths.sound('scrollMenu'), 0.4);
|
|
|
|
curSelected += change;
|
|
|
|
if (curSelected < 0)
|
|
curSelected = songs.length - 1;
|
|
if (curSelected >= songs.length)
|
|
curSelected = 0;
|
|
|
|
// selector.y = (70 * curSelected) + 30;
|
|
|
|
#if !switch
|
|
intendedScore = Highscore.getScore(songs[curSelected].songName, curDifficulty);
|
|
// lerpScore = 0;
|
|
#end
|
|
|
|
#if PRELOAD_ALL
|
|
FlxG.sound.playMusic(Paths.inst(songs[curSelected].songName), 0);
|
|
#end
|
|
|
|
var bullShit:Int = 0;
|
|
|
|
for (item in grpSongs.members)
|
|
{
|
|
item.targetY = bullShit - curSelected;
|
|
bullShit++;
|
|
|
|
item.alpha = 0.6;
|
|
// item.setGraphicSize(Std.int(item.width * 0.8));
|
|
|
|
if (item.targetY == 0)
|
|
{
|
|
item.alpha = 1;
|
|
// item.setGraphicSize(Std.int(item.width));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
class SongMetadata
|
|
{
|
|
public var songName:String = "";
|
|
public var week:Int = 0;
|
|
|
|
public function new(song:String, week:Int)
|
|
{
|
|
this.songName = song;
|
|
this.week = week;
|
|
}
|
|
}
|