Skip to content

Commit

Permalink
stuff i havent commited yet
Browse files Browse the repository at this point in the history
  • Loading branch information
lemz1 committed Jun 30, 2024
1 parent 2a790aa commit 9bb62a1
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 140 deletions.
32 changes: 20 additions & 12 deletions source/funkin/play/notes/NoteSprite.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import flixel.graphics.frames.FlxAtlasFrames;
import flixel.FlxSprite;
import funkin.graphics.FunkinSprite;
import funkin.graphics.shaders.HSVShader;
import funkin.play.notes.modifier.NotePath;
import funkin.play.notes.modifier.NotePathModifier;
import funkin.play.notes.modifier.DirectionalPathModifier;
import funkin.play.notes.modifier.NotePathUtil;
import funkin.play.notes.modifier.NoteTransform;
import funkin.play.notes.Strumline;
import funkin.play.notes.StrumlineNote;

Expand All @@ -19,7 +22,12 @@ class NoteSprite extends FunkinSprite
function set_holdNoteSprite(value:SustainTrail):SustainTrail
{
this.holdNoteSprite = value;
this.holdNoteSprite.notePath = this.notePath;

if (this.holdNoteSprite != null)
{
this.holdNoteSprite.modifier = this.modifier;
}

return value;
}

Expand Down Expand Up @@ -139,21 +147,21 @@ class NoteSprite extends FunkinSprite

public var parentStrumline:Strumline;

public var notePath(default, set):NotePath;
public var modifier(default, set):NotePathModifier;

function set_notePath(value:NotePath):NotePath
function set_modifier(value:NotePathModifier):NotePathModifier
{
if (this.holdNoteSprite != null)
{
this.holdNoteSprite.notePath = value;
this.holdNoteSprite.modifier = value;
}

if (this.notePath == value)
if (this.modifier == value)
{
return value;
}

this.notePath = value;
this.modifier = value;
this.updatePosition();
return value;
}
Expand All @@ -168,18 +176,18 @@ class NoteSprite extends FunkinSprite

setupNoteGraphic(noteStyle);

this.notePath = new NotePath();
this.modifier = new DirectionalPathModifier(0.0);

// Disables the update() function for performance.
this.active = false;
}

/**
* Update the notes position using its `NotePath`
* Update the notes position using its `NotePathModifier`
*/
public function updatePosition():Void
{
if (this.notePath == null)
if (this.modifier == null)
{
return;
}
Expand All @@ -188,8 +196,8 @@ class NoteSprite extends FunkinSprite
final targetX:Float = (receptor != null ? (receptor.x + (receptor.width - this.width) / 2) : this.x);
final targetY:Float = (receptor != null ? (receptor.y + (receptor.height - this.height) / 2) : this.y);

final transform:NoteTransform = this.notePath.calculateTransform(this.strumTime - Conductor.instance.songPosition, parentStrumline?.scrollSpeed ?? 1.0,
targetX, targetY);
final transform:NoteTransform = NotePathUtil.calculatePath(this.modifier, this.strumTime - Conductor.instance.songPosition,
parentStrumline?.scrollSpeed ?? 1.0, targetX, targetY);

this.x = transform.x;
this.y = transform.y;
Expand Down
21 changes: 11 additions & 10 deletions source/funkin/play/notes/SustainTrail.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package funkin.play.notes;

import lime.math.Vector2;
import flixel.graphics.frames.FlxFrame;
import funkin.play.notes.modifier.NotePathUtil;
import funkin.play.notes.modifier.NotePathModifier;
import funkin.play.notes.modifier.NoteTransform;
import funkin.play.notes.notestyle.NoteStyle;
import funkin.play.notes.NoteDirection;
import funkin.data.song.SongData.SongNoteData;
Expand All @@ -11,9 +15,6 @@ import flixel.graphics.tile.FlxDrawTrianglesItem;
import flixel.math.FlxMath;
import funkin.ui.options.PreferencesMenu;
import funkin.util.MathUtil;
import funkin.play.notes.modifier.NotePath;
import funkin.play.notes.modifier.DirectionalPathModifier;
import lime.math.Vector2;

/**
* This is based heavily on the `FlxStrip` class. It uses `drawTriangles()` to clip a sustain note
Expand All @@ -33,16 +34,16 @@ class SustainTrail extends FlxSprite
public var noteData:Null<SongNoteData>;
public var parentStrumline:Strumline;

public var notePath(default, set):NotePath;
public var modifier(default, set):NotePathModifier;

function set_notePath(value:NotePath):NotePath
function set_modifier(value:NotePathModifier):NotePathModifier
{
if (this.notePath == value)
if (this.modifier == value)
{
return value;
}

this.notePath = value;
this.modifier = value;
this.updateDrawData();
return value;
}
Expand Down Expand Up @@ -220,7 +221,7 @@ class SustainTrail extends FlxSprite
*/
public function updateClipping():Void
{
if (notePath == null)
if (modifier == null)
{
visible = false;
return;
Expand Down Expand Up @@ -293,7 +294,7 @@ class SustainTrail extends FlxSprite

var remainingTrailHeight:Float = trailHeight;

final bruhTransform:NoteTransform = notePath.calculateTransform(trailTime + 0.1, scrollSpeed, targetX, targetY);
final bruhTransform:NoteTransform = NotePathUtil.calculatePath(this.modifier, trailTime + 0.1, scrollSpeed, targetX, targetY);
var previousX:Float = bruhTransform.x;
var previousY:Float = bruhTransform.y;
while (true)
Expand All @@ -303,7 +304,7 @@ class SustainTrail extends FlxSprite

final testOffset:Float = Math.sin(trailTime * 0.01) * 0;

final transform:NoteTransform = notePath.calculateTransform(trailTime, scrollSpeed, targetX, targetY);
final transform:NoteTransform = NotePathUtil.calculatePath(this.modifier, trailTime, scrollSpeed, targetX, targetY);
var direction:Vector2 = new Vector2(transform.x - previousX, transform.y - previousY);
direction.normalize(1);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package funkin.play.notes.modifier;

import funkin.play.notes.modifier.NotePathModifier;
import funkin.play.notes.modifier.NotePath;
import funkin.play.notes.modifier.NoteTransform;
import flixel.math.FlxMath;

/**
Expand Down
114 changes: 0 additions & 114 deletions source/funkin/play/notes/modifier/NotePath.hx

This file was deleted.

2 changes: 1 addition & 1 deletion source/funkin/play/notes/modifier/NotePathModifier.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package funkin.play.notes.modifier;

import funkin.play.notes.modifier.NotePath;
import funkin.play.notes.modifier.NoteTransform;

/**
* Interface that describes how a note should move towards the strum
Expand Down
43 changes: 43 additions & 0 deletions source/funkin/play/notes/modifier/NotePathUtil.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package funkin.play.notes.modifier;

/**
* Class that contains util functions
*/
class NotePathUtil
{
/**
* Calculates the transform for the note/trail
* @param modifier The modifier to use
* @param time The delta of strumTime - songTime
* @param scrollSpeed The scrollSpeed
* @param targetPositionX Target x position
* @param targetPositionY Target y position
* @return NoteTransform
*/
public static function calculatePath(modifier:NotePathModifier, time:Float, scrollSpeed:Float, targetPositionX:Float, targetPositionY:Float):NoteTransform
{
var transform:NoteTransform = new NoteTransform(targetPositionX, targetPositionY);

final downscrollSign:Float = (Preferences.downscroll ? -1.0 : 1.0);

final modifierTransform:NoteTransform = modifier.calculateTransform(time);

transform.x += modifierTransform.x * Constants.PIXELS_PER_MS * scrollSpeed;
transform.y += modifierTransform.y * Constants.PIXELS_PER_MS * scrollSpeed * downscrollSign;

return transform;
}

/**
* Retrieve all currently rendered notes
* This assumes that player and opponent strumlines are initialized
* @return Array<NoteSprite>
*/
public static function getNotes():Array<NoteSprite>
{
var notes:Array<NoteSprite> = PlayState.instance.playerStrumline.notes.members.concat(PlayState.instance.opponentStrumline.notes.members);
return notes.filter(function(note:NoteSprite) {
return note != null;
});
}
}
59 changes: 59 additions & 0 deletions source/funkin/play/notes/modifier/NoteTransform.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package funkin.play.notes.modifier;

/**
* Class that contains note transform data
*/
class NoteTransformRaw
{
/**
* X position
*/
public var x:Float;

/**
* Y position
*/
public var y:Float;

public function new(x:Float, y:Float)
{
this.x = x;
this.y = y;
}
}

/**
* Wrapper for `NoteTransformRaw`
*/
@:forward
abstract NoteTransform(NoteTransformRaw) from NoteTransformRaw to NoteTransformRaw
{
public function new(x:Float, y:Float)
{
this = new NoteTransformRaw(x, y);
}

@:op(A + B)
public function op_add(other:NoteTransform):NoteTransform
{
return new NoteTransform(this.x + other.x, this.y + other.y);
}

@:op(A - B)
public function op_sub(other:NoteTransform):NoteTransform
{
return new NoteTransform(this.x - other.x, this.y - other.y);
}

@:op(A * B)
public function op_mul(other:NoteTransform):NoteTransform
{
return new NoteTransform(this.x * other.x, this.y * other.y);
}

@:op(A / B)
public function op_div(other:NoteTransform):NoteTransform
{
return new NoteTransform(this.x / other.x, this.y / other.y);
}
}
Loading

0 comments on commit 9bb62a1

Please sign in to comment.