Skip to content

Commit

Permalink
better modchart system to add swag modifiers later
Browse files Browse the repository at this point in the history
  • Loading branch information
MaybeMaru committed May 23, 2024
1 parent 3d53ea4 commit 46fff5a
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 67 deletions.
46 changes: 19 additions & 27 deletions source/funkin/objects/note/NoteStrum.hx
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
package funkin.objects.note;

import funkin.util.frontend.ModchartManager.ModchartData;
import funkin.objects.note.BasicNote.INoteData;

typedef ModchartValues = {
var startX:Float;
var startY:Float;

var sinOff:Float;
var sinSize:Float;
var cosOff:Float;
var cosSize:Float;
}

class NoteStrum extends FlxSpriteExt implements INoteData {
class NoteStrum extends FlxSpriteExt implements INoteData
{
public var noteData:Int = 0;
public var modchart:ModchartValues;
public var modchart:ModchartData;

public var swagWidth:Float = 110;
public var swagHeight:Float = 110;
Expand All @@ -35,25 +27,16 @@ class NoteStrum extends FlxSpriteExt implements INoteData {
super(x,y);
this.noteData = noteData;
loadSkin();

modchart = {
startX: 0.0,
startY: 0.0,

sinOff: 0.0,
sinSize: 50.0,
cosOff: 0.0,
cosSize: 50.0
}
}

override function destroy() {
super.destroy();
modchart = null;
controlFunction = null;
}

public function loadSkin(?skin:String):Void {
skin = skin ?? SkinUtil.curSkin;
skin ??= SkinUtil.curSkin;
if (curSkin != skin) {
animOffsets = new Map<String, FlxPoint>();
curSkin = skin;
Expand All @@ -73,12 +56,11 @@ class NoteStrum extends FlxSpriteExt implements INoteData {
}
}

public dynamic function applyOffsets():Void {
var curAnim = animation.curAnim;
if (curAnim != null) {
dynamic public function applyOffsets():Void {
if (animation.curAnim != null) {
updateHitbox();
centerOffsets();
var animOffset = animOffsets.get(curAnim.name);
var animOffset = animOffsets.get(animation.curAnim.name);
if (animOffset != null) {
var scaleDiff = getScaleDiff();
offset.add(animOffset.x * scaleDiff.x, animOffset.y * scaleDiff.y);
Expand All @@ -91,6 +73,16 @@ class NoteStrum extends FlxSpriteExt implements INoteData {
applyOffsets();
}

public var xModchart:Float = 0.0;
public var yModchart:Float = 0.0;

override function getScreenPosition(?result:FlxPoint, ?camera:FlxCamera):FlxPoint
{
result = super.getScreenPosition(result, camera);
result.add(xModchart, yModchart);
return result;
}

override public function update(elapsed:Float):Void {
__superUpdate(elapsed);

Expand Down
107 changes: 67 additions & 40 deletions source/funkin/util/frontend/ModchartManager.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@ package funkin.util.frontend;
import funkin.objects.note.StrumLineGroup;
import funkin.util.frontend.CutsceneManager;

class ModchartManager extends EventHandler
enum abstract ModchartModifiers(String) from String to String {
var COS = "cos";
var SIN = "sin";
}

typedef ModchartData = {
var cos:Array<Float>; // [size, offset]
var sin:Array<Float>; // [size, offset]
}

class ModchartManager extends EventHandler implements IMusicHit
{
private var strumLines:Map<Int, StrumLineGroup> = [];

Expand Down Expand Up @@ -63,72 +73,89 @@ class ModchartManager extends EventHandler
}

/**
* STRUM EFFECTS
* STRUM MODIFIERS
**/

// TODO: add the typical modchart effects like drunk, wavy n all that shit

inline public function setStrumLineSin(l:Int = 0, offPerNote:Float = 0.0, size:Float = 50.0, ?startY:Float) {
for (i in 0...getStrumLine(l).members.length)
setStrumSin(l, i, offPerNote * i, size, startY);
}

inline public function setStrumLineCos(l:Int = 0, offPerNote:Float = 0.0, size:Float = 50.0, ?startX:Float) {
for (i in 0...getStrumLine(l).members.length)
setStrumCos(l, i, offPerNote * i, size, startX);
public function setValue(value:String, data:Dynamic) {
for (strumline in strumLines.keys())
setStrumLineValue(strumline, value, data);
}

inline public function setStrumSin(l:Int = 0, s:Int = 0, off:Float = 0.0, size:Float = 50.0, ?startY:Float) {
final strum = getStrum(l, s);
sinStrums.remove(strum);

strum.modchart.startY = startY ?? strum.y;
strum.modchart.sinOff = off;
strum.modchart.sinSize = size;
sinStrums.push(strum);
inline public function setStrumLineValue(strumline:Int, value:String, data:Dynamic) {
for (i in 0...getStrumLine(strumline).members.length)
setStrumValue(strumline, i, value, data);
}

inline public function setStrumCos(l:Int = 0, s:Int = 0, off:Float = 0.0, size:Float = 50.0, ?startX:Float) {
final strum = getStrum(l, s);
cosStrums.remove(strum);

strum.modchart.startX = startX ?? strum.x;
strum.modchart.cosOff = off;
strum.modchart.cosSize = size;
cosStrums.push(strum);
inline public function setStrumValue(strumline:Int, id:Int, value:String, data:Dynamic) {
final data = resolveData(getStrum(strumline, id));
switch (value.toLowerCase().trim()) {
case COS: data.cos = cast data;
case SIN: data.sin = cast data;
}
}

var sinStrums:Array<NoteStrum> = [];
var cosStrums:Array<NoteStrum> = [];


public var speed:Float = 1.0;
var startTick:Float = 0; // Game tick the modchart started at, for cosine stuff
var timeElapsed:Float;

override function start() {
startTick = FlxG.game.ticks;
super.start();
}

override function updatePosition() {
position = Conductor.songPosition;
}

override function update(elapsed:Float)
{
super.update(elapsed);

final timeElapsed = ((FlxG.game.ticks - startTick) * speed * 0.0001) % FunkMath.DOUBLE_PI;
timeElapsed = ((FlxG.game.ticks - startTick) * speed * 0.0001) % FunkMath.DOUBLE_PI;

if (cosStrums.length > 0) {
cosStrums.fastForEach((strum, i) -> {
strum.x = (strum.modchart.startX) + (FunkMath.cos(timeElapsed + (strum.modchart.cosOff)) * (strum.modchart.cosSize));
for (key => strumline in strumLines) {
strumline.members.fastForEach((strum, i) -> {
if (strum.modchart != null)
manageStrum(strum, strum.modchart);
});
}
}

// TODO: add shit with these

public function stepHit(curStep:Int):Void {}

if (sinStrums.length > 0) {
sinStrums.fastForEach((strum, i) -> {
strum.y = (strum.modchart.startY) + (FunkMath.sin(timeElapsed + (strum.modchart.sinOff)) * (strum.modchart.sinSize));
});
public function beatHit(curBeat:Int):Void {}

public function sectionHit(curSection:Int):Void {}

// Backend crap

function resolveData(strum:NoteStrum):ModchartData
{
if (strum.modchart == null) {
strum.modchart = {
sin: [0.0, 0.0],
cos: [0.0, 0.0]
}
}

return strum.modchart;
}

override function updatePosition() {
position = Conductor.songPosition;
function manageStrum(strum:NoteStrum, data:ModchartData)
{
strum.xModchart = 0;
strum.yModchart = 0;

if (data.cos[0] != 0) {
strum.xModchart += (FunkMath.cos(timeElapsed + data.cos[1]) * data.cos[0]);
}

if (data.sin[0] != 0) {
strum.yModchart += (FunkMath.sin(timeElapsed + data.sin[1]) * data.sin[0]);
}
}
}

0 comments on commit 46fff5a

Please sign in to comment.