Skip to content

Commit

Permalink
modchart manager improvements
Browse files Browse the repository at this point in the history
fixed a bug where strumlines didnt get added correctly to the map
allow float steps, beats and sections events
modcharts now follow the conductor time to go along better with the song
WIP gonna start adding preset effects
  • Loading branch information
MaybeMaru committed May 21, 2024
1 parent f87a254 commit ebb3419
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 36 deletions.
12 changes: 8 additions & 4 deletions source/funkin/objects/NotesGroup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ class NotesGroup extends Group
boyfriend = game.boyfriend;
dad = game.dad;
}

initStrumline();

Conductor.mapBPMChanges(SONG);
Conductor.bpm = SONG.bpm;
Expand Down Expand Up @@ -205,19 +207,21 @@ class NotesGroup extends Group
});
}

public function init(startPos:Float = -5000) {
function initStrumline() {
StrumLineGroup.strumLineY = getPref('downscroll') ? FlxG.height - 150 : 50;

opponentStrums = new StrumLineGroup(0, skipStrumIntro);
opponentStrums = new StrumLineGroup(0);
add(opponentStrums);

playerStrums = new StrumLineGroup(1, skipStrumIntro);
playerStrums = new StrumLineGroup(1);
add(playerStrums);

grpNoteSplashes = new SplashGroup();
add(grpNoteSplashes);
}

//Make Song
// Make the song
public function init(startPos:Float = -5000) {
Conductor.songPosition = startPos;
generateSong();
}
Expand Down
31 changes: 17 additions & 14 deletions source/funkin/objects/note/StrumLineGroup.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,47 @@ class StrumLineGroup extends TypedSpriteGroup<NoteStrum> {
var startX:Float = 0;
var offsetY:Float = 0;

public function new(p:Int = 0, skipIntro:Bool = false, lanes:Int = Conductor.NOTE_DATA_LENGTH) {
public function new(p:Int = 0, lanes:Int = Conductor.NOTE_DATA_LENGTH) {
super(9);
startX = NoteUtil.noteWidth * 0.666 + (FlxG.width * 0.5) * p;
offsetY = Preferences.getPref('downscroll') ? 10 : -10;

final isPlayer:Bool = p == 1;
for (i in 0...lanes) {
final strumNote = addStrum(i, skipIntro);
final strumNote = addStrum(i);
ModdingUtil.addCall('generateStrum', [strumNote, isPlayer]);
}
}

public static final DEFAULT_CONTROL_CHECKS:Array<InputType->Bool> = [
function (t:InputType) return Controls.getKey('NOTE_LEFT', t),
function (t:InputType) return Controls.getKey('NOTE_DOWN', t),
function (t:InputType) return Controls.getKey('NOTE_UP', t),
function (t:InputType) return Controls.getKey('NOTE_RIGHT', t),
(t:InputType) -> return Controls.getKey('NOTE_LEFT', t),
(t:InputType) -> return Controls.getKey('NOTE_DOWN', t),
(t:InputType) -> return Controls.getKey('NOTE_UP', t),
(t:InputType) -> return Controls.getKey('NOTE_RIGHT', t)
];

static inline var seperateWidth:Int = NoteUtil.noteWidth + 5;

public function insertStrum(position:Int = 0, skipIntro:Bool = true) {
public function insertStrum(position:Int = 0) {
if (members.length >= 9) return null; // STOP
for (i in position...members.length) {
final strum = members[i];
if (strum == null) continue;
strum.x += seperateWidth;
strum.ID++;
}
return addStrum(position, skipIntro);
return addStrum(position);
}

public function addStrum(noteData:Int = 0, skipIntro:Bool = true) {
public function introStrums() {
members.fastForEach((strum, i) -> {
strum.alpha = 0;
strum.y += offsetY;
FlxTween.tween(strum, {y: strum.y - offsetY, alpha: 1}, 1, {ease: FlxEase.circOut, startDelay: 0.5 + (0.2 * strum.noteData)});
});
}

public function addStrum(noteData:Int = 0) {
if (members.length >= 9) return null; // STOP
final strumX:Float = startX + seperateWidth * noteData;
final strumNote:NoteStrum = new NoteStrum(strumX, strumLineY, noteData);
Expand All @@ -48,11 +56,6 @@ class StrumLineGroup extends TypedSpriteGroup<NoteStrum> {
strumNote.scrollFactor.set();
add(strumNote);
initPos.push(strumNote.getPosition());

if (!skipIntro) {
strumNote.alpha = 0;
strumNote.y += offsetY;
}

if (noteData < DEFAULT_CONTROL_CHECKS.length) {
strumNote.controlFunction = DEFAULT_CONTROL_CHECKS[noteData];
Expand Down
4 changes: 2 additions & 2 deletions source/funkin/states/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ class PlayState extends MusicBeatState
startedCountdown = seenCutscene = true;

if (!notesGroup.skipStrumIntro) {
notesGroup.strumLineNotes.fastForEach((strum, i) ->
FlxTween.tween(strum, {y: StrumLineGroup.strumLineY, alpha: 1}, 1, {ease: FlxEase.circOut, startDelay: 0.5 + (0.2 * strum.noteData)}));
notesGroup.opponentStrums.introStrums();
notesGroup.playerStrums.introStrums();
}

Conductor.songPosition = -Conductor.crochet * 5;
Expand Down
16 changes: 10 additions & 6 deletions source/funkin/util/frontend/CutsceneManager.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ abstract class EventHandler extends flixel.FlxBasic
events.sort((a, b) -> Std.int(a.time - b.time));
}

public function pushStep(step:Int = 0, callback:()->Void) {
public function pushStep(step:Float = 0, callback:()->Void) {
pushEvent(step * Conductor.stepCrochetMills, callback);
}

public function pushBeat(beat:Int = 0, callback:()->Void) {
public function pushBeat(beat:Float = 0, callback:()->Void) {
pushEvent(beat * Conductor.crochetMills, callback);
}

public function pushSection(section:Int = 0, callback:()->Void) {
public function pushSection(section:Float = 0, callback:()->Void) {
pushEvent(section * Conductor.sectionCrochetMills, callback);
//Song.getSectionTime(PlayState.SONG, section) TODO: maybe??
}
Expand Down Expand Up @@ -54,12 +54,16 @@ abstract class EventHandler extends flixel.FlxBasic
active = true;
}

override function update(elapsed:Float) {
super.update(elapsed);
position += elapsed * 1000;
override function update(elapsed:Float)
{
updatePosition();
callEvents();
}

function updatePosition() {
position += (FlxG.elapsed * 1000);
}

public var destroyOnComplete:Bool = true;

function callEvents():Void {
Expand Down
52 changes: 42 additions & 10 deletions source/funkin/util/frontend/ModchartManager.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package funkin.util.frontend;
import funkin.objects.note.StrumLineGroup;
import funkin.util.frontend.CutsceneManager;

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

public function new():Void {
Expand All @@ -19,6 +20,10 @@ class ModchartManager extends EventHandler {
return new ModchartManager();
}

/**
* GETTING / SETTING STRUMS
**/

inline public function setStrumLine(id:Int = 0, strumline:StrumLineGroup):Void {
strumLines.set(id, strumline);
}
Expand All @@ -31,10 +36,24 @@ class ModchartManager extends EventHandler {
return getStrumLine(strumlineID)?.members[strumID] ?? null;
}

/**
* STRUM MOVEMENT
**/

inline public function setStrumPos(l:Int = 0, s:Int = 0, ?X:Float, ?Y:Float):Void {
getStrum(l,s).setPosition(X,Y);
}

inline public function moveStrum(l:Int = 0, s:Int = 0, X:Float = 0, Y:Float = 0):Void {
var strum = getStrum(l, s);
strum.x += X;
strum.y += Y;
}

inline public function offsetStrum(l:Int = 0, s:Int = 0, X:Float = 0, Y:Float = 0):Void {
moveStrum(l, s, -X, -Y);
}

inline public function tweenStrum(l:Int = 0, s:Int = 0, ?values:Dynamic, time:Float = 1.0, ?settings:Dynamic) {
return FlxTween.tween(getStrum(l, s), values, time, settings);
}
Expand All @@ -43,18 +62,22 @@ class ModchartManager extends EventHandler {
return tweenStrum(l,s, {x: X, y:Y}, time, {ease: ease ?? FlxEase.linear});
}

/**
* STRUM EFFECTS
**/

// 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)
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)
for (i in 0...getStrumLine(l).members.length)
setStrumCos(l, i, offPerNote * i, size, startX);
}

// Requires the manager to be added to the state to work

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);
Expand All @@ -77,15 +100,20 @@ class ModchartManager extends EventHandler {

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

var timeElapsed:Float = 0.0;
var speed:Float = 1.0;

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

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

override function update(elapsed:Float)
{
super.update(elapsed);
timeElapsed = timeElapsed + (elapsed * speed);
timeElapsed = timeElapsed % FunkMath.DOUBLE_PI;

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

if (cosStrums.length > 0) {
cosStrums.fastForEach((strum, i) -> {
Expand All @@ -99,4 +127,8 @@ class ModchartManager extends EventHandler {
});
}
}

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

0 comments on commit ebb3419

Please sign in to comment.