Files
FNF-i486-Engine/source/NoteGroup.hx
JordanSantiagoYT 1242b43619 Revert PlayState Revamp, AGAIN.
IF YOU WANT TO WORK ON THE REWRITE, GO HERE: https://github.com/JordanSantiagoYT/FNF-JS-Engine-Rewrite
2024-03-02 14:49:24 -05:00

125 lines
2.9 KiB
Haxe

package;
import flixel.util.FlxSort;
import flixel.FlxCamera;
import Conductor;
import flixel.group.FlxGroup.FlxTypedGroup;
class NoteGroup extends FlxTypedGroup<Note> {
var __loopSprite:Note;
var i:Int = 0;
var __currentlyLooping:Bool = false;
var __time:Float = -1.0;
/**
* How many ms it should show a note before it should be hit
**/
public var limit:Float = 2000;
/**
* Preallocates the members array with nulls, but if theres anything in the array already it clears it
**/
public inline function preallocate(len:Int) {
members = cast new haxe.ds.Vector<Note>(len);
length = len;
}
public inline function addNotes(notes:Array<Note>) {
for(e in notes) add(e);
sortNotes();
}
public inline function sortNotes() {
sort(function(i, n1, n2) {
if (n1.strumTime == n2.strumTime)
return n1.isSustainNote ? 1 : -1;
return FlxSort.byValues(FlxSort.DESCENDING, n1.strumTime, n2.strumTime);
});
}
public override function update(elapsed:Float) {
i = length-1;
__loopSprite = null;
__time = Conductor.songPosition;
while(i >= 0) {
__loopSprite = members[i--];
if (__loopSprite == null || !__loopSprite.exists || !__loopSprite.active) {
continue;
}
__loopSprite.update(elapsed);
}
}
public override function draw() {
@:privateAccess var oldDefaultCameras = FlxCamera._defaultCameras;
@:privateAccess if (cameras != null) FlxCamera._defaultCameras = cameras;
var oldCur = __currentlyLooping;
__currentlyLooping = true;
i = length-1;
__loopSprite = null;
__time = Conductor.songPosition;
while(i >= 0) {
__loopSprite = members[i--];
if (__loopSprite == null || !__loopSprite.exists || !__loopSprite.visible)
continue;
//if (__loopSprite.strumTime - __time > limit) break;
__loopSprite.draw();
}
__currentlyLooping = oldCur;
@:privateAccess FlxCamera._defaultCameras = oldDefaultCameras;
}
public override function forEach(noteFunc:Note->Void, recursive:Bool = false) {
i = length-1;
__loopSprite = null;
__time = Conductor.songPosition;
var oldCur = __currentlyLooping;
__currentlyLooping = true;
while(i >= 0) {
__loopSprite = members[i--];
if (__loopSprite == null || !__loopSprite.exists)
continue;
noteFunc(__loopSprite);
}
__currentlyLooping = oldCur;
}
public override function forEachAlive(noteFunc:Note->Void, recursive:Bool = false) {
forEach(function(note) {
if (note.alive) noteFunc(note);
}, recursive);
}
public override function remove(Object:Note, Splice:Bool = false):Note
{
if (members == null)
return null;
var index:Int = members.indexOf(Object);
if (index < 0)
return null;
// doesnt prevent looping from breaking
if (Splice && __currentlyLooping && i >= index)
i++;
if (Splice)
{
members.splice(index, 1);
length--;
}
else
members[index] = null;
if (_memberRemoved != null)
_memberRemoved.dispatch(Object);
return Object;
}
}