Rework note sprites to pull note style data

This commit is contained in:
EliteMasterEric 2023-07-13 20:27:45 -04:00
parent ba53957191
commit 16bcf2c767
10 changed files with 83 additions and 120 deletions

View File

@ -1,5 +1,6 @@
package funkin;
import funkin.data.notestyle.NoteStyleRegistry;
import flixel.FlxSprite;
import flixel.FlxSubState;
import flixel.group.FlxGroup;
@ -128,7 +129,7 @@ class LatencyState extends MusicBeatSubState
for (i in 0...32)
{
var note:NoteSprite = new NoteSprite(Conductor.beatLengthMs * i);
var note:NoteSprite = new NoteSprite(NoteStyleRegistry.instance.fetchDefault(), Conductor.beatLengthMs * i);
noteGrp.add(note);
}

View File

@ -107,7 +107,9 @@ class MusicBeatState extends FlxUIState implements IEventHandler
{
PolymodHandler.forceReloadAssets();
// Restart the current state, so old data is cleared.
this.destroy();
// Create a new instance of the current state, so old data is cleared.
FlxG.resetState();
}

View File

@ -65,4 +65,11 @@ class VoicesGroup extends SoundGroup
opponentVoices.clear();
super.clear();
}
public override function destroy():Void
{
playerVoices.destroy();
opponentVoices.destroy();
super.destroy();
}
}

View File

@ -1,6 +1,9 @@
package funkin.play;
import haxe.Int64;
import funkin.play.notes.notestyle.NoteStyle;
import funkin.data.notestyle.NoteStyleData;
import funkin.data.notestyle.NoteStyleRegistry;
import flixel.addons.display.FlxPieDial;
import flixel.addons.transition.FlxTransitionableState;
import flixel.FlxCamera;
@ -989,6 +992,9 @@ class PlayState extends MusicBeatState
*/
override function debug_refreshModules():Void
{
// Prevent further gameplay updates, which will try to reference dead objects.
criticalFailure = true;
// Remove the current stage. If the stage gets deleted while it's still in use,
// it'll probably crash the game or something.
if (this.currentStage != null)
@ -999,8 +1005,14 @@ class PlayState extends MusicBeatState
currentStage = null;
}
// Stop the instrumental.
if (FlxG.sound.music != null)
{
FlxG.sound.music.stop();
}
// Stop the vocals.
if (vocals != null)
if (vocals != null && vocals.exists)
{
vocals.stop();
}
@ -1013,6 +1025,8 @@ class PlayState extends MusicBeatState
override function stepHit():Bool
{
if (criticalFailure) return false;
// super.stepHit() returns false if a module cancelled the event.
if (!super.stepHit()) return false;
@ -1034,6 +1048,8 @@ class PlayState extends MusicBeatState
override function beatHit():Bool
{
if (criticalFailure) return false;
// super.beatHit() returns false if a module cancelled the event.
if (!super.beatHit()) return false;
@ -1279,9 +1295,9 @@ class PlayState extends MusicBeatState
//
// OPPONENT HEALTH ICON
//
iconP2 = new HealthIcon(currentCharData.opponent, 1);
iconP2 = new HealthIcon('dad', 1);
iconP2.y = healthBar.y - (iconP2.height / 2);
dad.initHealthIcon(true);
dad.initHealthIcon(true); // Apply the character ID here
add(iconP2);
iconP2.cameras = [camHUD];
@ -1298,9 +1314,9 @@ class PlayState extends MusicBeatState
//
// PLAYER HEALTH ICON
//
iconP1 = new HealthIcon(currentPlayerId, 0);
iconP1 = new HealthIcon('bf', 0);
iconP1.y = healthBar.y - (iconP1.height / 2);
boyfriend.initHealthIcon(false);
boyfriend.initHealthIcon(false); // Apply the character ID here
add(iconP1);
iconP1.cameras = [camHUD];
@ -1350,19 +1366,17 @@ class PlayState extends MusicBeatState
*/
function initStrumlines():Void
{
// var strumlineStyle:StrumlineStyle = NORMAL;
//
//// TODO: Put this in the chart or something?
// switch (currentStageId)
// {
// case 'school':
// strumlineStyle = PIXEL;
// case 'schoolEvil':
// strumlineStyle = PIXEL;
// }
var noteStyleId:String = switch (currentStageId)
{
case 'school': 'pixel';
case 'schoolEvil': 'pixel';
default: 'funkin';
}
var noteStyle:NoteStyle = NoteStyleRegistry.instance.fetchEntry(noteStyleId);
if (noteStyle == null) noteStyle = NoteStyleRegistry.instance.fetchDefault();
playerStrumline = new Strumline(true);
opponentStrumline = new Strumline(false);
playerStrumline = new Strumline(noteStyle, true);
opponentStrumline = new Strumline(noteStyle, false);
add(playerStrumline);
add(opponentStrumline);
@ -1460,18 +1474,6 @@ class PlayState extends MusicBeatState
songEvents = currentChart.getEvents();
SongEventParser.resetEvents(songEvents);
// TODO: Put this in the chart or something?
// var strumlineStyle:StrumlineStyle = null;
// switch (currentStageId)
// {
// case 'school':
// strumlineStyle = PIXEL;
// case 'schoolEvil':
// strumlineStyle = PIXEL;
// default:
// strumlineStyle = NORMAL;
// }
// Reset the notes on each strumline.
var playerNoteData:Array<SongNoteData> = [];
var opponentNoteData:Array<SongNoteData> = [];
@ -1631,6 +1633,8 @@ class PlayState extends MusicBeatState
*/
function processNotes(elapsed:Float):Void
{
if (playerStrumline?.notes?.members == null || opponentStrumline?.notes?.members == null) return;
// Process notes on the opponent's side.
for (note in opponentStrumline.notes.members)
{

View File

@ -1,6 +1,7 @@
package funkin.play.notes;
import funkin.play.song.SongData.SongNoteData;
import funkin.play.notes.notestyle.NoteStyle;
import flixel.graphics.frames.FlxAtlasFrames;
import flixel.FlxSprite;
@ -106,7 +107,7 @@ class NoteSprite extends FlxSprite
*/
public var handledMiss:Bool;
public function new(strumTime:Float = 0, direction:Int = 0)
public function new(noteStyle:NoteStyle, strumTime:Float = 0, direction:Int = 0)
{
super(0, -9999);
this.strumTime = strumTime;
@ -114,34 +115,15 @@ class NoteSprite extends FlxSprite
if (this.strumTime < 0) this.strumTime = 0;
setupNoteGraphic();
setupNoteGraphic(noteStyle);
// Disables the update() function for performance.
this.active = false;
}
public static function buildNoteFrames(force:Bool = false):FlxAtlasFrames
function setupNoteGraphic(noteStyle:NoteStyle):Void
{
// static variables inside functions are a cool of Haxe 4.3.0.
static var noteFrames:FlxAtlasFrames = null;
if (noteFrames != null && !force) return noteFrames;
noteFrames = Paths.getSparrowAtlas('notes');
noteFrames.parent.persist = true;
return noteFrames;
}
function setupNoteGraphic():Void
{
this.frames = buildNoteFrames();
animation.addByPrefix('greenScroll', 'noteUp');
animation.addByPrefix('redScroll', 'noteRight');
animation.addByPrefix('blueScroll', 'noteDown');
animation.addByPrefix('purpleScroll', 'noteLeft');
noteStyle.buildNoteSprite(this);
setGraphicSize(Strumline.STRUMLINE_SIZE);
updateHitbox();

View File

@ -1,6 +1,7 @@
package funkin.play.notes;
import flixel.FlxG;
import funkin.play.notes.notestyle.NoteStyle;
import flixel.group.FlxSpriteGroup;
import flixel.group.FlxSpriteGroup.FlxTypedSpriteGroup;
import flixel.tweens.FlxEase;
@ -52,16 +53,19 @@ class Strumline extends FlxSpriteGroup
var noteSplashes:FlxTypedSpriteGroup<NoteSplash>;
var noteHoldCovers:FlxTypedSpriteGroup<NoteHoldCover>;
final noteStyle:NoteStyle;
var noteData:Array<SongNoteData> = [];
var nextNoteIndex:Int = -1;
var heldKeys:Array<Bool> = [];
public function new(isPlayer:Bool)
public function new(noteStyle:NoteStyle, isPlayer:Bool)
{
super();
this.isPlayer = isPlayer;
this.noteStyle = noteStyle;
this.strumlineNotes = new FlxTypedSpriteGroup<StrumlineNote>();
this.strumlineNotes.zIndex = 10;
@ -88,10 +92,11 @@ class Strumline extends FlxSpriteGroup
for (i in 0...KEY_COUNT)
{
var child:StrumlineNote = new StrumlineNote(isPlayer, DIRECTIONS[i]);
var child:StrumlineNote = new StrumlineNote(noteStyle, isPlayer, DIRECTIONS[i]);
child.x = getXPos(DIRECTIONS[i]);
child.x += INITIAL_OFFSET;
child.y = 0;
noteStyle.applyStrumlineOffsets(child);
this.strumlineNotes.add(child);
}
@ -119,20 +124,6 @@ class Strumline extends FlxSpriteGroup
super.update(elapsed);
updateNotes();
#if debug
if (!isPlayer)
{
FlxG.watch.addQuick("strumlineAnim", strumlineNotes.members[3]?.animation?.curAnim?.name);
var curFrame = strumlineNotes.members[3]?.animation?.curAnim?.curFrame;
frameMax = (curFrame > frameMax) ? curFrame : frameMax;
FlxG.watch.addQuick("strumlineFrame", strumlineNotes.members[3]?.animation?.curAnim?.curFrame);
FlxG.watch.addQuick("strumlineFrameMax", frameMax);
animFinishedEver = animFinishedEver || strumlineNotes.members[3]?.animation?.curAnim?.finished;
FlxG.watch.addQuick("strumlineFinished", strumlineNotes.members[3]?.animation?.curAnim?.finished);
FlxG.watch.addQuick("strumlineFinishedEver", animFinishedEver);
}
#end
}
var frameMax:Int;
@ -482,6 +473,7 @@ class Strumline extends FlxSpriteGroup
{
// TODO: Add a setting to disable note splashes.
// if (Settings.noSplash) return;
if (!noteStyle.isNoteSplashEnabled()) return;
var splash:NoteSplash = this.constructNoteSplash();
@ -502,6 +494,7 @@ class Strumline extends FlxSpriteGroup
{
// TODO: Add a setting to disable note splashes.
// if (Settings.noSplash) return;
if (!noteStyle.isHoldNoteCoverEnabled()) return;
var cover:NoteHoldCover = this.constructNoteHoldCover();
@ -659,7 +652,7 @@ class Strumline extends FlxSpriteGroup
{
// The note sprite pool is full and all note splashes are active.
// We have to create a new note.
result = new NoteSprite();
result = new NoteSprite(noteStyle);
this.notes.add(result);
}
@ -685,7 +678,7 @@ class Strumline extends FlxSpriteGroup
{
// The note sprite pool is full and all note splashes are active.
// We have to create a new note.
result = new SustainTrail(0, 100, Paths.image("NOTE_hold_assets"));
result = new SustainTrail(0, 100, noteStyle.getHoldNoteAssetPath(), noteStyle);
this.holdNotes.add(result);
}

View File

@ -1,5 +1,6 @@
package funkin.play.notes;
import funkin.play.notes.notestyle.NoteStyle;
import flixel.graphics.frames.FlxAtlasFrames;
import flixel.FlxSprite;
import funkin.play.notes.NoteSprite;
@ -17,24 +18,13 @@ class StrumlineNote extends FlxSprite
static final CONFIRM_HOLD_TIME:Float = 0.1;
public function updatePosition(parentNote:NoteSprite)
{
this.x = parentNote.x;
this.x += parentNote.width / 2;
this.x -= this.width / 2;
this.y = parentNote.y;
this.y += parentNote.height / 2;
}
function set_direction(value:NoteDirection):NoteDirection
{
this.direction = value;
setup();
return this.direction;
}
public function new(isPlayer:Bool, direction:NoteDirection)
public function new(noteStyle:NoteStyle, isPlayer:Bool, direction:NoteDirection)
{
super(0, 0);
@ -42,6 +32,8 @@ class StrumlineNote extends FlxSprite
this.direction = direction;
setup(noteStyle);
this.animation.callback = onAnimationFrame;
this.animation.finishCallback = onAnimationFinished;
@ -81,39 +73,15 @@ class StrumlineNote extends FlxSprite
}
}
function setup():Void
function setup(noteStyle:NoteStyle):Void
{
this.frames = Paths.getSparrowAtlas('noteStrumline');
noteStyle.applyStrumlineFrames(this);
noteStyle.applyStrumlineAnimations(this, this.direction);
switch (this.direction)
{
case NoteDirection.LEFT:
this.animation.addByPrefix('static', 'staticLeft0', 24, false, false, false);
this.animation.addByPrefix('press', 'pressLeft0', 24, false, false, false);
this.animation.addByPrefix('confirm', 'confirmLeft0', 24, false, false, false);
this.animation.addByPrefix('confirm-hold', 'confirmHoldLeft0', 24, true, false, false);
case NoteDirection.DOWN:
this.animation.addByPrefix('static', 'staticDown0', 24, false, false, false);
this.animation.addByPrefix('press', 'pressDown0', 24, false, false, false);
this.animation.addByPrefix('confirm', 'confirmDown0', 24, false, false, false);
this.animation.addByPrefix('confirm-hold', 'confirmHoldDown0', 24, true, false, false);
case NoteDirection.UP:
this.animation.addByPrefix('static', 'staticUp0', 24, false, false, false);
this.animation.addByPrefix('press', 'pressUp0', 24, false, false, false);
this.animation.addByPrefix('confirm', 'confirmUp0', 24, false, false, false);
this.animation.addByPrefix('confirm-hold', 'confirmHoldUp0', 24, true, false, false);
case NoteDirection.RIGHT:
this.animation.addByPrefix('static', 'staticRight0', 24, false, false, false);
this.animation.addByPrefix('press', 'pressRight0', 24, false, false, false);
this.animation.addByPrefix('confirm', 'confirmRight0', 24, false, false, false);
this.animation.addByPrefix('confirm-hold', 'confirmHoldRight0', 24, true, false, false);
}
this.setGraphicSize(Std.int(Strumline.STRUMLINE_SIZE * 1.55));
this.setGraphicSize(Std.int(Strumline.STRUMLINE_SIZE * noteStyle.getStrumlineScale()));
this.updateHitbox();
noteStyle.applyStrumlineOffsets(this);
this.playStatic();
}

View File

@ -1,5 +1,6 @@
package funkin.play.notes;
import funkin.play.notes.notestyle.NoteStyle;
import funkin.play.notes.NoteDirection;
import funkin.play.song.SongData.SongNoteData;
import flixel.util.FlxDirectionFlags;
@ -79,25 +80,28 @@ class SustainTrail extends FlxSprite
*/
public var bottomClip:Float = 0.9;
public var isPixel:Bool;
/**
* Normally you would take strumTime:Float, noteData:Int, sustainLength:Float, parentNote:Note (?)
* @param NoteData
* @param SustainLength Length in milliseconds.
* @param fileName
*/
public function new(noteDirection:NoteDirection, sustainLength:Float, fileName:String)
public function new(noteDirection:NoteDirection, sustainLength:Float, fileName:String, noteStyle:NoteStyle)
{
super(0, 0, fileName);
antialiasing = true;
// TODO: Why does this reference pixel stuff?
if (fileName == "arrowEnds")
this.isPixel = noteStyle.isHoldNotePixel();
if (isPixel)
{
endOffset = bottomClip = 1;
antialiasing = false;
zoom = 6;
}
zoom *= noteStyle.fetchHoldNoteScale();
// BASIC SETUP
this.sustainLength = sustainLength;
this.fullSustainLength = sustainLength;

View File

@ -1,5 +1,6 @@
package funkin.ui;
import funkin.data.notestyle.NoteStyleRegistry;
import flixel.addons.effects.chainable.FlxEffectSprite;
import flixel.addons.effects.chainable.FlxOutlineEffect;
import flixel.group.FlxGroup.FlxTypedGroup;
@ -22,7 +23,7 @@ class ColorsMenu extends Page
for (i in 0...4)
{
var note:NoteSprite = new NoteSprite(0, i);
var note:NoteSprite = new NoteSprite(NoteStyleRegistry.instance.fetchDefault(), 0, i);
note.x = (100 * i) + i;
note.screenCenter(Y);

View File

@ -1,5 +1,6 @@
package funkin.ui.debug.charting;
import funkin.data.notestyle.NoteStyleRegistry;
import funkin.ui.debug.charting.ChartEditorCommand;
import flixel.input.keyboard.FlxKey;
import funkin.input.TurboKeyHandler;
@ -2804,7 +2805,7 @@ class ChartEditorState extends HaxeUIState
// Character preview.
// NoteScriptEvent takes a sprite, ehe. Need to rework that.
var tempNote:NoteSprite = new NoteSprite();
var tempNote:NoteSprite = new NoteSprite(NoteStyleRegistry.instance.fetchDefault());
tempNote.noteData = noteData;
tempNote.scrollFactor.set(0, 0);
var event:NoteScriptEvent = new NoteScriptEvent(ScriptEvent.NOTE_HIT, tempNote, 1, true);