mirror of
https://github.com/ninjamuffin99/Funkin.git
synced 2024-09-12 05:07:06 +00:00
Merge pull request #496 from FunkinCrew/04-16-some_cleanins_with_letter_sorts
some cleanins with letter sorts
This commit is contained in:
commit
d1c5449fa8
|
@ -550,7 +550,8 @@
|
|||
{
|
||||
"props": {
|
||||
"policy": "onlySingle",
|
||||
"allowException": true
|
||||
"allowException": true,
|
||||
"severity": "IGNORE"
|
||||
},
|
||||
"type": "StringLiteral"
|
||||
},
|
||||
|
|
|
@ -539,47 +539,14 @@ class FreeplayState extends MusicBeatSubState
|
|||
* Given the current filter, rebuild the current song list.
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
public function generateSongList(filterStuff:Null<SongFilter>, force:Bool = false, onlyIfChanged:Bool = true):Void
|
||||
{
|
||||
var tempSongs:Array<FreeplaySongData> = songs;
|
||||
|
||||
if (filterStuff != null)
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
if (filterStuff != null) tempSongs = sortSongs(tempSongs, filterStuff);
|
||||
|
||||
// Filter further by current selected difficulty.
|
||||
if (currentDifficulty != null)
|
||||
|
@ -657,6 +624,48 @@ class FreeplayState extends MusicBeatSubState
|
|||
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 touchX:Float = 0;
|
||||
var dxTouch:Float = 0;
|
||||
|
|
|
@ -39,7 +39,6 @@ class LetterSort extends FlxTypedSpriteGroup<FlxSprite>
|
|||
var letter:FreeplayLetter = new FreeplayLetter(i * 80, 0, i);
|
||||
letter.x += 50;
|
||||
letter.y += 50;
|
||||
letter.ogY = y;
|
||||
// letter.visible = false;
|
||||
add(letter);
|
||||
|
||||
|
@ -82,6 +81,26 @@ class LetterSort extends FlxTypedSpriteGroup<FlxSprite>
|
|||
}
|
||||
|
||||
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) {
|
||||
new FlxTimer().start(frameNum / 24, function(_) {
|
||||
|
@ -91,84 +110,39 @@ class LetterSort extends FlxTypedSpriteGroup<FlxSprite>
|
|||
|
||||
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(1, sep, positions[1]);
|
||||
ezTimer(2, sep, positions[2]);
|
||||
ezTimer(3, sep, positions[3]);
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
leftArrow.offset.x = 3;
|
||||
new FlxTimer().start(2 / 24, function(_) {
|
||||
leftArrow.offset.x = 0;
|
||||
});
|
||||
ezTimer(0, sep, positions[0] * multiPosOrNeg);
|
||||
ezTimer(1, sep, positions[1] * multiPosOrNeg);
|
||||
ezTimer(2, sep, positions[2] * multiPosOrNeg);
|
||||
ezTimer(3, sep, positions[3] * multiPosOrNeg);
|
||||
}
|
||||
else if (diff > 0)
|
||||
|
||||
for (index => letter in letters)
|
||||
{
|
||||
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!!
|
||||
letter.offset.x = positions[0] * multiPosOrNeg;
|
||||
|
||||
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;
|
||||
new FlxTimer().start(1 / 24, function(_) {
|
||||
letter.offset.x = positions[1] * multiPosOrNeg;
|
||||
if (index == 0) letter.visible = false;
|
||||
});
|
||||
|
||||
new FlxTimer().start(2 / 24, function(_) {
|
||||
letter.offset.x = positions[2] * multiPosOrNeg;
|
||||
if (index == 0.) letter.visible = true;
|
||||
});
|
||||
|
||||
if (index == 2)
|
||||
{
|
||||
ezTimer(3, letter, 0);
|
||||
// letter.offset.x = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
ezTimer(3, letter, positions[3] * multiPosOrNeg);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
/**
|
||||
|
@ -201,8 +178,6 @@ class FreeplayLetter extends FlxAtlasSprite
|
|||
*/
|
||||
public var curLetter:Int = 0;
|
||||
|
||||
public var ogY:Float = 0;
|
||||
|
||||
public function new(x:Float, y:Float, ?letterInd:Int)
|
||||
{
|
||||
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
|
||||
{
|
||||
curLetter += diff;
|
||||
|
@ -238,7 +218,7 @@ class FreeplayLetter extends FlxAtlasSprite
|
|||
if (curLetter < 0) curLetter = regexLetters.length - 1;
|
||||
if (curLetter >= regexLetters.length) curLetter = 0;
|
||||
|
||||
var animName:String = animLetters[curLetter] + " move";
|
||||
var animName:String = animLetters[curLetter] + ' move';
|
||||
|
||||
switch (animLetters[curLetter])
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue