mirror of
https://github.com/ninjamuffin99/Funkin.git
synced 2024-11-09 16:24:42 +00:00
some cleanins with letter sorts
This commit is contained in:
parent
c3e777154e
commit
1adef48995
|
@ -550,7 +550,8 @@
|
||||||
{
|
{
|
||||||
"props": {
|
"props": {
|
||||||
"policy": "onlySingle",
|
"policy": "onlySingle",
|
||||||
"allowException": true
|
"allowException": true,
|
||||||
|
"severity": "IGNORE"
|
||||||
},
|
},
|
||||||
"type": "StringLiteral"
|
"type": "StringLiteral"
|
||||||
},
|
},
|
||||||
|
|
|
@ -539,47 +539,14 @@ class FreeplayState extends MusicBeatSubState
|
||||||
* Given the current filter, rebuild the current song list.
|
* Given the current filter, rebuild the current song list.
|
||||||
*
|
*
|
||||||
* @param filterStuff A filter to apply to the song list (regex, startswith, all, favorite)
|
* @param filterStuff A filter to apply to the song list (regex, startswith, all, favorite)
|
||||||
* @param force
|
* @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
|
* @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
|
public function generateSongList(filterStuff:Null<SongFilter>, force:Bool = false, onlyIfChanged:Bool = true):Void
|
||||||
{
|
{
|
||||||
var tempSongs:Array<FreeplaySongData> = songs;
|
var tempSongs:Array<FreeplaySongData> = songs;
|
||||||
|
|
||||||
if (filterStuff != null)
|
if (filterStuff != null) tempSongs = sortSongs(tempSongs, filterStuff);
|
||||||
{
|
|
||||||
switch (filterStuff.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('^[' + filterStuff.filterData + '].*', 'i');
|
|
||||||
tempSongs = tempSongs.filter(str -> {
|
|
||||||
if (str == null) return true; // Random
|
|
||||||
return filterRegexp.match(str.songName);
|
|
||||||
});
|
|
||||||
|
|
||||||
case STARTSWITH:
|
|
||||||
// extra note: this is essentially a "search"
|
|
||||||
|
|
||||||
tempSongs = tempSongs.filter(str -> {
|
|
||||||
if (str == null) return true; // Random
|
|
||||||
return str.songName.toLowerCase().startsWith(filterStuff.filterData);
|
|
||||||
});
|
|
||||||
case ALL:
|
|
||||||
// no filter!
|
|
||||||
case FAVORITE:
|
|
||||||
tempSongs = tempSongs.filter(str -> {
|
|
||||||
if (str == null) return true; // Random
|
|
||||||
return str.isFav;
|
|
||||||
});
|
|
||||||
default:
|
|
||||||
// return all on default
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter further by current selected difficulty.
|
// Filter further by current selected difficulty.
|
||||||
if (currentDifficulty != null)
|
if (currentDifficulty != null)
|
||||||
|
@ -657,6 +624,48 @@ class FreeplayState extends MusicBeatSubState
|
||||||
changeDiff();
|
changeDiff();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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>
|
||||||
|
*/
|
||||||
|
public function sortSongs(songsToFilter:Array<FreeplaySongData>, songFilter:SongFilter):Array<FreeplaySongData>
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
|
case STARTSWITH:
|
||||||
|
// extra note: this is essentially a "search"
|
||||||
|
|
||||||
|
songsToFilter = songsToFilter.filter(str -> {
|
||||||
|
if (str == null) return true; // Random
|
||||||
|
return str.songName.toLowerCase().startsWith(songFilter.filterData);
|
||||||
|
});
|
||||||
|
case ALL:
|
||||||
|
// no filter!
|
||||||
|
case FAVORITE:
|
||||||
|
songsToFilter = songsToFilter.filter(str -> {
|
||||||
|
if (str == null) return true; // Random
|
||||||
|
return str.isFav;
|
||||||
|
});
|
||||||
|
default:
|
||||||
|
// return all on default
|
||||||
|
}
|
||||||
|
return songsToFilter;
|
||||||
|
}
|
||||||
|
|
||||||
var touchY:Float = 0;
|
var touchY:Float = 0;
|
||||||
var touchX:Float = 0;
|
var touchX:Float = 0;
|
||||||
var dxTouch:Float = 0;
|
var dxTouch:Float = 0;
|
||||||
|
|
|
@ -39,7 +39,6 @@ class LetterSort extends FlxTypedSpriteGroup<FlxSprite>
|
||||||
var letter:FreeplayLetter = new FreeplayLetter(i * 80, 0, i);
|
var letter:FreeplayLetter = new FreeplayLetter(i * 80, 0, i);
|
||||||
letter.x += 50;
|
letter.x += 50;
|
||||||
letter.y += 50;
|
letter.y += 50;
|
||||||
letter.ogY = y;
|
|
||||||
// letter.visible = false;
|
// letter.visible = false;
|
||||||
add(letter);
|
add(letter);
|
||||||
|
|
||||||
|
@ -82,6 +81,26 @@ class LetterSort extends FlxTypedSpriteGroup<FlxSprite>
|
||||||
}
|
}
|
||||||
|
|
||||||
public function changeSelection(diff:Int = 0):Void
|
public function changeSelection(diff:Int = 0):Void
|
||||||
|
{
|
||||||
|
doLetterChangeAnims(diff);
|
||||||
|
|
||||||
|
var multiPosOrNeg:Float = diff > 0 ? 1 : -1;
|
||||||
|
|
||||||
|
// if we're moving left (diff < 0), we want control of the right arrow, and vice versa
|
||||||
|
var arrowToMove:FlxSprite = diff < 0 ? leftArrow : rightArrow;
|
||||||
|
arrowToMove.offset.x = 3 * multiPosOrNeg;
|
||||||
|
|
||||||
|
new FlxTimer().start(2 / 24, function(_) {
|
||||||
|
arrowToMove.offset.x = 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Buncho timers and stuff to move the letters and seperators
|
||||||
|
* Seperated out so we can call it again on letters with songs within them
|
||||||
|
* @param diff
|
||||||
|
*/
|
||||||
|
function doLetterChangeAnims(diff:Int):Void
|
||||||
{
|
{
|
||||||
var ezTimer:Int->FlxSprite->Float->Void = function(frameNum:Int, spr:FlxSprite, offsetNum:Float) {
|
var ezTimer:Int->FlxSprite->Float->Void = function(frameNum:Int, spr:FlxSprite, offsetNum:Float) {
|
||||||
new FlxTimer().start(frameNum / 24, function(_) {
|
new FlxTimer().start(frameNum / 24, function(_) {
|
||||||
|
@ -91,27 +110,28 @@ class LetterSort extends FlxTypedSpriteGroup<FlxSprite>
|
||||||
|
|
||||||
var positions:Array<Float> = [-10, -22, 2, 0];
|
var positions:Array<Float> = [-10, -22, 2, 0];
|
||||||
|
|
||||||
if (diff < 0)
|
// if we're moving left, we want to move the positions the same amount, but negative direciton
|
||||||
{
|
var multiPosOrNeg:Float = diff > 0 ? 1 : -1;
|
||||||
|
|
||||||
for (sep in grpSeperators)
|
for (sep in grpSeperators)
|
||||||
{
|
{
|
||||||
ezTimer(0, sep, positions[0]);
|
ezTimer(0, sep, positions[0] * multiPosOrNeg);
|
||||||
ezTimer(1, sep, positions[1]);
|
ezTimer(1, sep, positions[1] * multiPosOrNeg);
|
||||||
ezTimer(2, sep, positions[2]);
|
ezTimer(2, sep, positions[2] * multiPosOrNeg);
|
||||||
ezTimer(3, sep, positions[3]);
|
ezTimer(3, sep, positions[3] * multiPosOrNeg);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (index => letter in letters)
|
for (index => letter in letters)
|
||||||
{
|
{
|
||||||
letter.offset.x = positions[0];
|
letter.offset.x = positions[0] * multiPosOrNeg;
|
||||||
|
|
||||||
new FlxTimer().start(1 / 24, function(_) {
|
new FlxTimer().start(1 / 24, function(_) {
|
||||||
letter.offset.x = positions[1];
|
letter.offset.x = positions[1] * multiPosOrNeg;
|
||||||
if (index == 0) letter.visible = false;
|
if (index == 0) letter.visible = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
new FlxTimer().start(2 / 24, function(_) {
|
new FlxTimer().start(2 / 24, function(_) {
|
||||||
letter.offset.x = positions[2];
|
letter.offset.x = positions[2] * multiPosOrNeg;
|
||||||
if (index == 0.) letter.visible = true;
|
if (index == 0.) letter.visible = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -122,53 +142,7 @@ class LetterSort extends FlxTypedSpriteGroup<FlxSprite>
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ezTimer(3, letter, positions[3]);
|
ezTimer(3, letter, positions[3] * multiPosOrNeg);
|
||||||
}
|
|
||||||
|
|
||||||
leftArrow.offset.x = 3;
|
|
||||||
new FlxTimer().start(2 / 24, function(_) {
|
|
||||||
leftArrow.offset.x = 0;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else if (diff > 0)
|
|
||||||
{
|
|
||||||
for (sep in grpSeperators)
|
|
||||||
{
|
|
||||||
ezTimer(0, sep, -positions[0]);
|
|
||||||
ezTimer(1, sep, -positions[1]);
|
|
||||||
ezTimer(2, sep, -positions[2]);
|
|
||||||
ezTimer(3, sep, -positions[3]);
|
|
||||||
}
|
|
||||||
// same timing and functions and shit as the left one... except to the right!!
|
|
||||||
|
|
||||||
for (index => letter in letters)
|
|
||||||
{
|
|
||||||
letter.offset.x = -positions[0];
|
|
||||||
|
|
||||||
new FlxTimer().start(1 / 24, function(_) {
|
|
||||||
letter.offset.x = -positions[1];
|
|
||||||
if (index == 0) letter.visible = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
new FlxTimer().start(2 / 24, function(_) {
|
|
||||||
letter.offset.x = -positions[2];
|
|
||||||
if (index == 0) letter.visible = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (index == 2)
|
|
||||||
{
|
|
||||||
ezTimer(3, letter, 0);
|
|
||||||
// letter.offset.x = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ezTimer(3, letter, -positions[3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
rightArrow.offset.x = -3;
|
|
||||||
new FlxTimer().start(2 / 24, function(_) {
|
|
||||||
rightArrow.offset.x = 0;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
curSelection += diff;
|
curSelection += diff;
|
||||||
|
@ -182,6 +156,9 @@ class LetterSort extends FlxTypedSpriteGroup<FlxSprite>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The actual FlxAtlasSprite for the letters, with their animation code stuff and regex stuff
|
||||||
|
*/
|
||||||
class FreeplayLetter extends FlxAtlasSprite
|
class FreeplayLetter extends FlxAtlasSprite
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -201,8 +178,6 @@ class FreeplayLetter extends FlxAtlasSprite
|
||||||
*/
|
*/
|
||||||
public var curLetter:Int = 0;
|
public var curLetter:Int = 0;
|
||||||
|
|
||||||
public var ogY:Float = 0;
|
|
||||||
|
|
||||||
public function new(x:Float, y:Float, ?letterInd:Int)
|
public function new(x:Float, y:Float, ?letterInd:Int)
|
||||||
{
|
{
|
||||||
super(x, y, Paths.animateAtlas("freeplay/sortedLetters"));
|
super(x, y, Paths.animateAtlas("freeplay/sortedLetters"));
|
||||||
|
@ -231,6 +206,11 @@ class FreeplayLetter extends FlxAtlasSprite
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changes the letter graphic/anim, used in the LetterSort class above
|
||||||
|
* @param diff -1 or 1, to go left or right in the animation array
|
||||||
|
* @param curSelection what the current letter selection is, to play the bouncing anim if it matches the current letter
|
||||||
|
*/
|
||||||
public function changeLetter(diff:Int = 0, ?curSelection:Int):Void
|
public function changeLetter(diff:Int = 0, ?curSelection:Int):Void
|
||||||
{
|
{
|
||||||
curLetter += diff;
|
curLetter += diff;
|
||||||
|
@ -238,7 +218,7 @@ class FreeplayLetter extends FlxAtlasSprite
|
||||||
if (curLetter < 0) curLetter = regexLetters.length - 1;
|
if (curLetter < 0) curLetter = regexLetters.length - 1;
|
||||||
if (curLetter >= regexLetters.length) curLetter = 0;
|
if (curLetter >= regexLetters.length) curLetter = 0;
|
||||||
|
|
||||||
var animName:String = animLetters[curLetter] + " move";
|
var animName:String = animLetters[curLetter] + ' move';
|
||||||
|
|
||||||
switch (animLetters[curLetter])
|
switch (animLetters[curLetter])
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue