From f76309c91ec2cd0ca4bad6163b47fefa2e57228c Mon Sep 17 00:00:00 2001
From: EliteMasterEric <ericmyllyoja@gmail.com>
Date: Fri, 12 Jul 2024 04:13:20 -0400
Subject: [PATCH] Update rendering for custom note styles

---
 source/funkin/data/notestyle/NoteStyleData.hx    |  8 ++++++++
 source/funkin/play/notes/NoteSprite.hx           | 16 +++++++++-------
 source/funkin/play/notes/Strumline.hx            |  1 +
 source/funkin/play/notes/notestyle/NoteStyle.hx  | 16 ++++++++++++++--
 .../charting/components/ChartEditorNoteSprite.hx | 10 ++++++++--
 .../toolboxes/ChartEditorNoteDataToolbox.hx      |  2 +-
 .../debug/charting/util/ChartEditorDropdowns.hx  |  6 +++---
 7 files changed, 44 insertions(+), 15 deletions(-)

diff --git a/source/funkin/data/notestyle/NoteStyleData.hx b/source/funkin/data/notestyle/NoteStyleData.hx
index 04fda67ca..fcdb3b4f9 100644
--- a/source/funkin/data/notestyle/NoteStyleData.hx
+++ b/source/funkin/data/notestyle/NoteStyleData.hx
@@ -109,6 +109,14 @@ typedef NoteStyleAssetData<T> =
   @:optional
   var isPixel:Bool;
 
+  /**
+   * If true, animations will be played on the graphic.
+   * @default `false` to save performance.
+   */
+  @:default(false)
+  @:optional
+  var animated:Bool;
+
   /**
    * The structure of this data depends on the asset.
    */
diff --git a/source/funkin/play/notes/NoteSprite.hx b/source/funkin/play/notes/NoteSprite.hx
index d8d471496..e8cacaa4d 100644
--- a/source/funkin/play/notes/NoteSprite.hx
+++ b/source/funkin/play/notes/NoteSprite.hx
@@ -91,7 +91,7 @@ class NoteSprite extends FunkinSprite
   {
     if (frames == null) return value;
 
-    animation.play(DIRECTION_COLORS[value] + 'Scroll');
+    playNoteAnimation(value);
 
     this.direction = value;
     return this.direction;
@@ -152,9 +152,6 @@ class NoteSprite extends FunkinSprite
     this.hsvShader = new HSVShader();
 
     setupNoteGraphic(noteStyle);
-
-    // Disables the update() function for performance.
-    this.active = false;
   }
 
   /**
@@ -165,10 +162,10 @@ class NoteSprite extends FunkinSprite
   {
     noteStyle.buildNoteSprite(this);
 
-    setGraphicSize(Strumline.STRUMLINE_SIZE);
-    updateHitbox();
-
     this.shader = hsvShader;
+
+    // `false` disables the update() function for performance.
+    this.active = noteStyle.isNoteAnimated();
   }
 
   /**
@@ -211,6 +208,11 @@ class NoteSprite extends FunkinSprite
   }
   #end
 
+  function playNoteAnimation(value:Int):Void
+  {
+    animation.play(DIRECTION_COLORS[value] + 'Scroll');
+  }
+
   public function desaturate():Void
   {
     this.hsvShader.saturation = 0.2;
diff --git a/source/funkin/play/notes/Strumline.hx b/source/funkin/play/notes/Strumline.hx
index 5e76afa51..1e5782ad2 100644
--- a/source/funkin/play/notes/Strumline.hx
+++ b/source/funkin/play/notes/Strumline.hx
@@ -717,6 +717,7 @@ class Strumline extends FlxSpriteGroup
 
       noteSprite.x = this.x;
       noteSprite.x += getXPos(DIRECTIONS[note.getDirection() % KEY_COUNT]);
+      noteSprite.x -= (noteSprite.width - Strumline.STRUMLINE_SIZE) / 2; // Center it
       noteSprite.x -= NUDGE;
       // noteSprite.x += INITIAL_OFFSET;
       noteSprite.y = -9999;
diff --git a/source/funkin/play/notes/notestyle/NoteStyle.hx b/source/funkin/play/notes/notestyle/NoteStyle.hx
index d0cc09f6a..3993cce52 100644
--- a/source/funkin/play/notes/notestyle/NoteStyle.hx
+++ b/source/funkin/play/notes/notestyle/NoteStyle.hx
@@ -89,12 +89,14 @@ class NoteStyle implements IRegistryEntry<NoteStyleData>
 
     target.frames = atlas;
 
-    target.scale.x = _data.assets.note.scale;
-    target.scale.y = _data.assets.note.scale;
     target.antialiasing = !_data.assets.note.isPixel;
 
     // Apply the animations.
     buildNoteAnimations(target);
+
+    // Set the scale.
+    target.setGraphicSize(Strumline.STRUMLINE_SIZE * getNoteScale());
+    target.updateHitbox();
   }
 
   var noteFrames:FlxAtlasFrames = null;
@@ -156,6 +158,16 @@ class NoteStyle implements IRegistryEntry<NoteStyleData>
     target.animation.addByPrefix('redScroll', rightData.prefix, rightData.frameRate, rightData.looped, rightData.flipX, rightData.flipY);
   }
 
+  public function isNoteAnimated():Bool
+  {
+    return _data.assets.note.animated;
+  }
+
+  public function getNoteScale():Float
+  {
+    return _data.assets.note.scale;
+  }
+
   function fetchNoteAnimationData(dir:NoteDirection):AnimationData
   {
     var result:Null<AnimationData> = switch (dir)
diff --git a/source/funkin/ui/debug/charting/components/ChartEditorNoteSprite.hx b/source/funkin/ui/debug/charting/components/ChartEditorNoteSprite.hx
index 009532401..5fd0c74aa 100644
--- a/source/funkin/ui/debug/charting/components/ChartEditorNoteSprite.hx
+++ b/source/funkin/ui/debug/charting/components/ChartEditorNoteSprite.hx
@@ -107,6 +107,12 @@ class ChartEditorNoteSprite extends FlxSprite
     var prefix:String = noteStyle.id.toTitleCase();
 
     var frameCollection:FlxAtlasFrames = Paths.getSparrowAtlas(noteStyle.getNoteAssetPath(), noteStyle.getNoteAssetLibrary());
+    if (frameCollection == null)
+    {
+      trace('Could not retrieve frame collection for ${noteStyle}: ${Paths.image(noteStyle.getNoteAssetPath(), noteStyle.getNoteAssetLibrary())}');
+      FlxG.log.error('Could not retrieve frame collection for ${noteStyle}: ${Paths.image(noteStyle.getNoteAssetPath(), noteStyle.getNoteAssetLibrary())}');
+      return;
+    }
     for (frame in frameCollection.frames)
     {
       // cloning the frame because else
@@ -221,9 +227,9 @@ class ChartEditorNoteSprite extends FlxSprite
     switch (baseAnimationName)
     {
       case 'tap':
-        this.setGraphicSize(0, ChartEditorState.GRID_SIZE);
+        this.setGraphicSize(ChartEditorState.GRID_SIZE, 0);
+        this.updateHitbox();
     }
-    this.updateHitbox();
 
     var bruhStyle:NoteStyle = fetchNoteStyle(this.noteStyle);
     this.antialiasing = !bruhStyle._data?.assets?.note?.isPixel ?? true;
diff --git a/source/funkin/ui/debug/charting/toolboxes/ChartEditorNoteDataToolbox.hx b/source/funkin/ui/debug/charting/toolboxes/ChartEditorNoteDataToolbox.hx
index ea46cf72a..12f7f7d63 100644
--- a/source/funkin/ui/debug/charting/toolboxes/ChartEditorNoteDataToolbox.hx
+++ b/source/funkin/ui/debug/charting/toolboxes/ChartEditorNoteDataToolbox.hx
@@ -283,7 +283,7 @@ class ChartEditorNoteDataToolbox extends ChartEditorBaseToolbox
       return;
     }
 
-    var heightToSet:Int = Std.int(Math.max(DIALOG_HEIGHT, toolboxNotesGrid.height + HEIGHT_OFFSET)) + MINIMIZE_FIX;
+    var heightToSet:Int = Std.int(Math.max(DIALOG_HEIGHT, (toolboxNotesGrid?.height ?? 50) + HEIGHT_OFFSET)) + MINIMIZE_FIX;
     if (this.height != heightToSet)
     {
       this.height = heightToSet;
diff --git a/source/funkin/ui/debug/charting/util/ChartEditorDropdowns.hx b/source/funkin/ui/debug/charting/util/ChartEditorDropdowns.hx
index 6a426c391..21938b005 100644
--- a/source/funkin/ui/debug/charting/util/ChartEditorDropdowns.hx
+++ b/source/funkin/ui/debug/charting/util/ChartEditorDropdowns.hx
@@ -195,11 +195,11 @@ class ChartEditorDropdowns
   {
     dropDown.dataSource.clear();
 
-    var returnValue:DropDownEntry = lookupNoteKind('~CUSTOM');
+    var returnValue:DropDownEntry = lookupNoteKind('');
 
     for (noteKindId in NOTE_KINDS.keys())
     {
-      var noteKind:String = NOTE_KINDS.get(noteKindId) ?? 'Default';
+      var noteKind:String = NOTE_KINDS.get(noteKindId) ?? 'Unknown';
 
       var value:DropDownEntry = {id: noteKindId, text: noteKind};
       if (startingKindId == noteKindId) returnValue = value;
@@ -216,7 +216,7 @@ class ChartEditorDropdowns
   {
     if (noteKindId == null) return lookupNoteKind('');
     if (!NOTE_KINDS.exists(noteKindId)) return {id: '~CUSTOM~', text: 'Custom'};
-    return {id: noteKindId ?? '', text: NOTE_KINDS.get(noteKindId) ?? 'Default'};
+    return {id: noteKindId ?? '', text: NOTE_KINDS.get(noteKindId) ?? 'Unknown'};
   }
 
   /**