Skip to content
This repository has been archived by the owner on Jan 26, 2025. It is now read-only.

Commit

Permalink
improved note remove system
Browse files Browse the repository at this point in the history
  • Loading branch information
MaybeMaru committed Dec 29, 2023
1 parent 1129ffa commit 80a9b8e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 25 deletions.
36 changes: 18 additions & 18 deletions source/funkin/objects/NotesGroup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import flixel.util.FlxArrayUtil;
import funkin.objects.note.StrumLineGroup;

class NotesGroup extends FlxGroup
{
{
public static var instance:NotesGroup = null;
public var SONG:SwagSong;

public static var songSpeed:Float = 1.0;
Expand Down Expand Up @@ -92,6 +93,7 @@ class NotesGroup extends FlxGroup

public function new(_SONG:SwagSong, isPlayState:Bool = true) {
super();
instance = this;
this.isPlayState = isPlayState;
SONG = Song.checkSong(_SONG, null, false); //Double check null values
Conductor.mapBPMChanges(SONG);
Expand Down Expand Up @@ -290,10 +292,9 @@ class NotesGroup extends FlxGroup
public var scrollSpeed(default, set):Float = 1.0; // Shortcut to change all notes scroll speed
public function set_scrollSpeed(value:Float = 1.0) {
if (value != scrollSpeed) {
for (i in unspawnNotes.concat(notes.members)) {
i.noteSpeed = value;
}
spawnNotes();
for (i in 0...unspawnNotes.length) unspawnNotes[i].noteSpeed = value;
for (i in 0...notes.members.length) notes.members[i].noteSpeed = value;
if (value < scrollSpeed) spawnNotes();
}
return scrollSpeed = value;
}
Expand All @@ -306,13 +307,12 @@ class NotesGroup extends FlxGroup
public var opponentNoteHit:Dynamic = null;
public var opponentSustainPress:Dynamic = null;

public function checkCallback(callback:Dynamic, ?args:Array<Dynamic>) {
public inline function checkCallback(callback:Dynamic, ?args:Array<Dynamic>) {
if (callback != null) Reflect.callMethod(this, callback, args ?? []); // Prevent null
}

public inline function removeNote(note:BasicNote) {
notes.remove(note, true);
note.destroy();
note.removeNote();
}

//Makes the conductor song go vroom vroom
Expand Down Expand Up @@ -376,7 +376,7 @@ class NotesGroup extends FlxGroup
return (note.mustPress && inBotplay) || (!note.mustPress && dadBotplay);
}

public inline function checkCpuNote(note:BasicNote) {
public function checkCpuNote(note:BasicNote) {
if (!isCpuNote(note)) return;
if (Conductor.songPosition >= note.strumTime && note.mustHit) {
if (note.isSustainNote) {
Expand All @@ -390,9 +390,9 @@ class NotesGroup extends FlxGroup
}
}

public inline function checkMissNote(note:BasicNote) {
if (note.active || Conductor.songPosition < note.strumTime) return;
if (!isCpuNote(note) && !note.isSustainNote && note.mustHit)
public function checkMissNote(note:BasicNote) {
if (note.activeNote || note.isSustainNote) return;
if (!isCpuNote(note) && note.mustHit)
checkCallback(noteMiss, [note.noteData%Conductor.NOTE_DATA_LENGTH, note]);
removeNote(note);
}
Expand All @@ -405,21 +405,21 @@ class NotesGroup extends FlxGroup

override function update(elapsed:Float) {
super.update(elapsed);
updateConductor(elapsed);
inline updateConductor(elapsed);

if (!generatedMusic) return; // Stuff that needs notes / events
spawnNotes();
checkEvents();
inline spawnNotes();
inline checkEvents();
notes.forEachAlive(function(note:BasicNote) {
checkCpuNote(note);
checkMissNote(note);
inline checkCpuNote(note);
inline checkMissNote(note);
});

if (isPlayState) {
if (PlayState.instance.inCutscene) return; // No controls in cutscenes >:(
}
controls();
checkStrumAnims();
inline checkStrumAnims();
}

public var holdingArray:Array<Bool> = [];
Expand Down
12 changes: 11 additions & 1 deletion source/funkin/objects/note/BasicNote.hx
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,21 @@ class BasicNote extends SmartSprite implements INoteData {
public var moving:Bool = true;
public var susLength:Float = 0.0;

public inline function removeNote() {
alive = exists = false;
FlxG.signals.preUpdate.addOnce(function () {
if (NotesGroup.instance != null) NotesGroup.instance.notes.remove(this, true);
this.destroy();
});
}

public var activeNote:Bool = true;

override function update(elapsed:Float):Void {
super.update(elapsed);
if (targetStrum != null) {
if (moving) moveToStrum();
active = Conductor.songPosition < (strumTime + susLength + getPosMill(NoteUtil.swagHeight * 2));
activeNote = Conductor.songPosition < (strumTime + susLength + getPosMill(NoteUtil.swagHeight * 2));
}
}

Expand Down
23 changes: 17 additions & 6 deletions source/funkin/objects/note/Sustain.hx
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,25 @@ class Sustain extends BasicNote {
public var startedPress:Bool = false;
public var missedPress(default, set):Bool = false;
inline function set_missedPress(value:Bool):Bool {
color = (value && mustHit) ? MISS_COLOR : FlxColor.WHITE;
pressed = false;
moving = true;
offset.y = cutHeight * getCos();

FlxG.signals.preDraw.addOnce(function () {
color = (value && mustHit) ? MISS_COLOR : FlxColor.WHITE;
offset.y = cutHeight * getCos();
});

return missedPress = value;
}

override function update(elapsed:Float) {
super.update(elapsed);

if (missedPress && !activeNote) {
removeNote();
}
}

public var percentLeft(default, null):Float = 0.0;
public var cutHeight(default, null):Float = 0.0;
public var susEndHeight:Int = 15;
Expand All @@ -57,9 +69,8 @@ class Sustain extends BasicNote {
clipRect.y = cutHeight;

// Sustain is finished
if (cutHeight <= (-repeatHeight + (susEndHeight * noteSpeed * 0.45))) {
kill();
}
if (cutHeight <= (-repeatHeight + (susEndHeight * noteSpeed * 0.45)))
removeNote();
}
}

Expand All @@ -77,7 +88,7 @@ class Sustain extends BasicNote {

// Kill too short sustains
if (Std.int(repeatHeight) <= Std.int(NoteUtil.swagHeight * 0.51))
kill();
removeNote();

return repeatHeight;
}
Expand Down

0 comments on commit 80a9b8e

Please sign in to comment.