1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-12-01 11:13:06 +00:00

alphabetical sorting stuuuuf

This commit is contained in:
Cameron Taylor 2022-09-27 04:37:42 -04:00
parent 09a037b20b
commit 4918c4f645
2 changed files with 163 additions and 20 deletions

View file

@ -25,6 +25,7 @@ import funkin.Controls.Control;
import funkin.freeplayStuff.BGScrollingText;
import funkin.freeplayStuff.DJBoyfriend;
import funkin.freeplayStuff.FreeplayScore;
import funkin.freeplayStuff.LetterSort;
import funkin.freeplayStuff.SongMenuItem;
import funkin.play.HealthIcon;
import funkin.play.PlayState;
@ -242,6 +243,14 @@ class FreeplayState extends MusicBeatSubstate
add(new DifficultySelector(20, grpDifficulties.y - 10, false, controls));
add(new DifficultySelector(325, grpDifficulties.y - 10, true, controls));
var letterSort:LetterSort = new LetterSort(300, 100);
add(letterSort);
letterSort.changeSelectionCallback = (str) ->
{
generateSongList(str, true);
};
new FlxTimer().start(1 / 24, function(handShit)
{
fnfFreeplay.visible = true;
@ -299,7 +308,7 @@ class FreeplayState extends MusicBeatSubstate
typing.callback = function(txt, action)
{
generateSongList(new EReg(txt.trim(), "ig"));
// generateSongList(new EReg(txt.trim(), "ig"));
trace(action);
};
@ -311,29 +320,48 @@ class FreeplayState extends MusicBeatSubstate
super.create();
}
public function generateSongList(?regexp:EReg)
public function generateSongList(?startsWith:String, ?force:Bool = false)
{
curSelected = 0;
grpCapsules.clear();
var regexp:EReg = regexp;
// var regexp:EReg = regexp;
var tempSongs:Array<SongMetadata> = songs;
if (regexp != null)
tempSongs = songs.filter(item -> regexp.match(item.songName));
tempSongs.sort(function(a, b):Int
if (startsWith != null)
{
var tempA = a.songName.toUpperCase();
var tempB = b.songName.toUpperCase();
trace("STARTS WITH: " + startsWith);
switch (startsWith)
{
case "ALL":
case "#":
default:
trace(tempSongs.length);
if (tempA < tempB)
return -1;
else if (tempA > tempB)
return 1;
else
return 0;
});
tempSongs = tempSongs.filter(str ->
{
return str.songName.toLowerCase().startsWith(startsWith);
});
trace(tempSongs.length);
}
}
// if (regexp != null)
// tempSongs = songs.filter(item -> regexp.match(item.songName));
// tempSongs.sort(function(a, b):Int
// {
// var tempA = a.songName.toUpperCase();
// var tempB = b.songName.toUpperCase();
// if (tempA < tempB)
// return -1;
// else if (tempA > tempB)
// return 1;
// else
// return 0;
// });
for (i in 0...tempSongs.length)
{
@ -355,11 +383,19 @@ class FreeplayState extends MusicBeatSubstate
funnyMenu.doLerp = true;
});
new FlxTimer().start(((0.20 * i) / (1 + i)) + 0.75, function(swagShi)
if (!force)
{
new FlxTimer().start(((0.20 * i) / (1 + i)) + 0.75, function(swagShi)
{
funnyMenu.songText.visible = true;
funnyMenu.alpha = 1;
});
}
else
{
funnyMenu.songText.visible = true;
funnyMenu.alpha = 1;
});
}
grpCapsules.add(funnyMenu);
@ -649,8 +685,8 @@ class FreeplayState extends MusicBeatSubstate
curSelected += change;
if (curSelected < 0)
curSelected = songs.length - 1;
if (curSelected >= songs.length)
curSelected = grpCapsules.members.length - 1;
if (curSelected >= grpCapsules.members.length)
curSelected = 0;
// selector.y = (70 * curSelected) + 30;
@ -684,7 +720,8 @@ class FreeplayState extends MusicBeatSubstate
capsule.targetPos.y -= 100; // another 100 for good measure
}
grpCapsules.members[curSelected].selected = true;
if (grpCapsules.members.length > 0)
grpCapsules.members[curSelected].selected = true;
}
}

View file

@ -0,0 +1,106 @@
package funkin.freeplayStuff;
import flixel.FlxSprite;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.group.FlxGroup;
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
class LetterSort extends FlxTypedSpriteGroup<FreeplayLetter>
{
public var letters:Array<FreeplayLetter> = [];
var curSelection:Int = 0;
public var changeSelectionCallback:String->Void;
public function new(x, y)
{
super(x, y);
var leftArrow:FreeplayLetter = new FreeplayLetter(-20, 0);
leftArrow.animation.play("arrow");
add(leftArrow);
for (i in 0...6)
{
var letter:FreeplayLetter = new FreeplayLetter(i * 80, 0, i);
add(letter);
letters.push(letter);
if (i == 3)
letter.alpha = 0.6;
var sep:FreeplayLetter = new FreeplayLetter((i * 80) + 50, 0);
sep.animation.play("seperator");
add(sep);
}
// changeSelection(-3);
}
override function update(elapsed:Float)
{
super.update(elapsed);
if (FlxG.keys.justPressed.E)
changeSelection(1);
if (FlxG.keys.justPressed.Q)
changeSelection(-1);
}
public function changeSelection(diff:Int = 0)
{
for (letter in letters)
letter.changeLetter(diff);
if (changeSelectionCallback != null)
changeSelectionCallback(letters[3].arr[letters[3].curLetter]); // bullshit and long lol!
}
}
class FreeplayLetter extends FlxSprite
{
public var arr:Array<String> = [];
public var curLetter:Int = 0;
public function new(x:Float, y:Float, ?letterInd:Int)
{
super(x, y);
frames = Paths.getSparrowAtlas("freeplay/letterStuff");
var alphabet:String = "abcdefghijklmnopqrstuvwxyz";
arr = alphabet.split("");
arr.insert(0, "#");
arr.insert(0, "ALL");
arr.insert(0, "fav");
for (str in arr)
{
animation.addByPrefix(str, str + " "); // string followed by a space! intentional!
}
animation.addByPrefix("arrow", "mini arrow");
animation.addByPrefix("seperator", "seperator");
if (letterInd != null)
{
animation.play(arr[letterInd]);
curLetter = letterInd;
}
}
public function changeLetter(diff:Int = 0)
{
curLetter += diff;
if (curLetter < 0)
curLetter = arr.length - 1;
if (curLetter >= arr.length)
curLetter = 0;
animation.play(arr[curLetter]);
}
}