diff --git a/source/funkin/graphics/SmartSprite.hx b/source/funkin/graphics/SmartSprite.hx index 11c8c74c..de1625b0 100644 --- a/source/funkin/graphics/SmartSprite.hx +++ b/source/funkin/graphics/SmartSprite.hx @@ -7,6 +7,13 @@ enum RenderMode { class SmartSprite extends FlxRepeatSprite { public var renderMode:RenderMode = QUAD; + public function setRenderMode(value:String) { + renderMode = switch (value.toLowerCase().trim()) { + case "quad" | "q" | "1": QUAD; + case "repeat" | "r" | "2": REPEAT; + default: QUAD; // Ill maybe add more render modes over time idk + } + } public function new(?X:Float, ?Y:Float, ?SimpleGraphic:FlxGraphicAsset) { super(X, Y, SimpleGraphic, 0, 0); @@ -26,7 +33,7 @@ class SmartSprite extends FlxRepeatSprite { updateTrig(); if (angle != 0) _matrix.rotateWithTrig(_cosAngle, _sinAngle); } - updateSkewMatrix(); + inline updateSkewMatrix(); _matrix.concat(_skewMatrix); } diff --git a/source/funkin/objects/note/BasicNote.hx b/source/funkin/objects/note/BasicNote.hx new file mode 100644 index 00000000..a8be7943 --- /dev/null +++ b/source/funkin/objects/note/BasicNote.hx @@ -0,0 +1,78 @@ +package funkin.objects.note; + +import funkin.graphics.SmartSprite; + +class BasicNote extends SmartSprite { + public var strumTime:Float = 0.0; + public var noteData:Int = 0; + public var noteSpeed:Float = 1.0; + public var targetStrum:NoteStrum; + public var parentNote:Note; + public var childNote:Sustain; + + public var isSustainNote(default, set):Bool = false; + inline function set_isSustainNote(value:Bool) { + renderMode = value ? REPEAT : QUAD; + return isSustainNote = value; + } + + private var curSkinData:SkinMapData; + public var skin(default, set):String = "default"; + inline function set_skin(?value:String) { + skin = value ?? SkinUtil.curSkin; + curSkinData = NoteUtil.getSkinSprites(skin, noteData); + updateSprites(); + return skin; + } + + public function changeSkin(?value:String) { + if (value != skin) + skin = value; + } + + public function updateSprites() { + loadFromSprite(curSkinData.baseSprite); + } + + public var approachAngle:Float = 0; + public var spawnMult:Float = 1.0; + + public function new(noteData:Int = 0, strumTime:Float = 0.0, skin:String = "default") { + super(); + this.noteData = noteData; + this.strumTime = strumTime; + this.skin = skin; + approachAngle = Preferences.getPref('downscroll') ? 180 : 0; + } + + override function update(elapsed:Float) { + super.update(elapsed); + if (targetStrum != null) { + moveToStrum(); + } + } + + inline public function moveToStrum() { + final noteMove:Float = getMillPos(Conductor.songPosition - strumTime); // Position with strumtime + y = targetStrum.y - (noteMove * getCos()); // Set Position + x = targetStrum.x - (noteMove * -getSin()); + } + + inline public function getCos() { + return FlxMath.fastCos(FlxAngle.asRadians(approachAngle)); + } + + inline public function getSin() { + return FlxMath.fastSin(FlxAngle.asRadians(approachAngle)); + } + + // Converts song milliseconds to a position on screen + inline public function getMillPos(mills:Float):Float { + return mills * (0.45 * noteSpeed); + } + + // Converts a position on screen to song milliseconds + inline public function getPosMill(pos:Float):Float { + return pos / (0.45 * noteSpeed); + } +} \ No newline at end of file diff --git a/source/funkin/objects/note/Note.hx b/source/funkin/objects/note/Note.hx index 399eaea3..3ff5ced4 100644 --- a/source/funkin/objects/note/Note.hx +++ b/source/funkin/objects/note/Note.hx @@ -8,16 +8,6 @@ interface INoteData { public var noteData:Int; } -interface INoteObject extends INoteData { - public var strumTime:Float; - public var noteSpeed:Float; - public var targetStrum:NoteStrum; - public var parentNote:Note; - public var childNote:Sustain; - - public var isSustainNote:Bool; -} - class Note extends FlxSpriteExt implements INoteData { public var noteData:Int = 0; public var strumTime:Float = 0; diff --git a/source/funkin/objects/note/Sustain.hx b/source/funkin/objects/note/Sustain.hx index a430533b..fbe60693 100644 --- a/source/funkin/objects/note/Sustain.hx +++ b/source/funkin/objects/note/Sustain.hx @@ -1,26 +1,34 @@ package funkin.objects.note; import flixel.graphics.frames.FlxFrame; -import funkin.graphics.FlxRepeatSprite; -class Sustain extends FlxRepeatSprite implements INoteData { - public var noteData:Int = 0; - public var noteSpeed:Float = 1.0; +class Sustain extends BasicNote { + public var susLength:Float = 0.0; - public function new(noteData:Int = 0) { - super(); + public function new(noteData:Int = 0, strumTime:Float = 0.0, susLength:Float = 0.0, skin:String = "default", ?parentNote:Note) { + super(noteData, strumTime, skin); // Load skin + + this.parentNote = parentNote; + isSustainNote = true; drawStyle = BOTTOM_TOP; alpha = 0.6; - this.noteData = noteData % Conductor.NOTE_DATA_LENGTH; - changeSkin("default"); + this.susLength = susLength; + setSusLength(susLength); + + //clipRect = new FlxRect(0,0,0,0); } - var skinData:SkinMapData; + function updateSusLength() { + setSusLength(susLength); + } + + function setSusLength(mills:Float = 0.0) { + repeatHeight = getMillPos(mills) + NoteUtil.swagHeight * 0.5; + } - public function changeSkin(value:String = "default") { - skinData = NoteUtil.getSkinSprites(value, noteData); - loadFromSprite(skinData.baseSprite); + override function updateSprites() { + super.updateSprites(); updateHitbox(); final holdFrame = animation.getByName("hold" + CoolUtil.directionArray[noteData]).frames[0]; @@ -34,8 +42,8 @@ class Sustain extends FlxRepeatSprite implements INoteData { override function setupTile(tileX:Int, tileY:Int, baseFrame:FlxFrame) { switch (tileY) { - case 0: playAnim("hold" + CoolUtil.directionArray[noteData] + "-end"); - case 1: playAnim("hold" + CoolUtil.directionArray[noteData]); + case 0: playAnim("hold" + CoolUtil.directionArray[noteData] + "-end"); // Tail + case 1: playAnim("hold" + CoolUtil.directionArray[noteData]); // Piece } return super.setupTile(tileX, tileY, frame); }