1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-08-19 23:15:15 +00:00

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; package funkin;
import funkin.data.notestyle.NoteStyleRegistry;
import flixel.FlxSprite; import flixel.FlxSprite;
import flixel.FlxSubState; import flixel.FlxSubState;
import flixel.group.FlxGroup; import flixel.group.FlxGroup;
@ -128,7 +129,7 @@ class LatencyState extends MusicBeatSubState
for (i in 0...32) 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); noteGrp.add(note);
} }

View file

@ -107,7 +107,9 @@ class MusicBeatState extends FlxUIState implements IEventHandler
{ {
PolymodHandler.forceReloadAssets(); 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(); FlxG.resetState();
} }

View file

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

View file

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

View file

@ -1,6 +1,7 @@
package funkin.play.notes; package funkin.play.notes;
import funkin.play.song.SongData.SongNoteData; import funkin.play.song.SongData.SongNoteData;
import funkin.play.notes.notestyle.NoteStyle;
import flixel.graphics.frames.FlxAtlasFrames; import flixel.graphics.frames.FlxAtlasFrames;
import flixel.FlxSprite; import flixel.FlxSprite;
@ -106,7 +107,7 @@ class NoteSprite extends FlxSprite
*/ */
public var handledMiss:Bool; 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); super(0, -9999);
this.strumTime = strumTime; this.strumTime = strumTime;
@ -114,34 +115,15 @@ class NoteSprite extends FlxSprite
if (this.strumTime < 0) this.strumTime = 0; if (this.strumTime < 0) this.strumTime = 0;
setupNoteGraphic(); setupNoteGraphic(noteStyle);
// Disables the update() function for performance. // Disables the update() function for performance.
this.active = false; 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. noteStyle.buildNoteSprite(this);
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');
setGraphicSize(Strumline.STRUMLINE_SIZE); setGraphicSize(Strumline.STRUMLINE_SIZE);
updateHitbox(); updateHitbox();

View file

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

View file

@ -1,5 +1,6 @@
package funkin.play.notes; package funkin.play.notes;
import funkin.play.notes.notestyle.NoteStyle;
import flixel.graphics.frames.FlxAtlasFrames; import flixel.graphics.frames.FlxAtlasFrames;
import flixel.FlxSprite; import flixel.FlxSprite;
import funkin.play.notes.NoteSprite; import funkin.play.notes.NoteSprite;
@ -17,24 +18,13 @@ class StrumlineNote extends FlxSprite
static final CONFIRM_HOLD_TIME:Float = 0.1; 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 function set_direction(value:NoteDirection):NoteDirection
{ {
this.direction = value; this.direction = value;
setup();
return this.direction; return this.direction;
} }
public function new(isPlayer:Bool, direction:NoteDirection) public function new(noteStyle:NoteStyle, isPlayer:Bool, direction:NoteDirection)
{ {
super(0, 0); super(0, 0);
@ -42,6 +32,8 @@ class StrumlineNote extends FlxSprite
this.direction = direction; this.direction = direction;
setup(noteStyle);
this.animation.callback = onAnimationFrame; this.animation.callback = onAnimationFrame;
this.animation.finishCallback = onAnimationFinished; 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) this.setGraphicSize(Std.int(Strumline.STRUMLINE_SIZE * noteStyle.getStrumlineScale()));
{
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.updateHitbox(); this.updateHitbox();
noteStyle.applyStrumlineOffsets(this);
this.playStatic(); this.playStatic();
} }

View file

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

View file

@ -1,5 +1,6 @@
package funkin.ui; package funkin.ui;
import funkin.data.notestyle.NoteStyleRegistry;
import flixel.addons.effects.chainable.FlxEffectSprite; import flixel.addons.effects.chainable.FlxEffectSprite;
import flixel.addons.effects.chainable.FlxOutlineEffect; import flixel.addons.effects.chainable.FlxOutlineEffect;
import flixel.group.FlxGroup.FlxTypedGroup; import flixel.group.FlxGroup.FlxTypedGroup;
@ -22,7 +23,7 @@ class ColorsMenu extends Page
for (i in 0...4) 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.x = (100 * i) + i;
note.screenCenter(Y); note.screenCenter(Y);

View file

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