Skip to content

Commit

Permalink
add beat modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
MaybeMaru committed Jun 17, 2024
1 parent 934a716 commit 107158d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Current version is beta 2.0, beta 3.0 soon to come!
* [Midnight](https://github.com/what-is-a-git) - More accurate memory counter
* [cyn](https://twitter.com/cyn0x8) - Demon Blur Shader
* [Cracsthor](https://gamebanana.com/members/1844732) - PhantomMuff font
* [4mbr0s32](https://github.com/4mbr0s3-2) - Modifiers from Schmovin

## How to make a mod

Expand Down
8 changes: 4 additions & 4 deletions source/funkin/util/FunkMath.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import flixel.math.FlxMatrix;

class FunkMath
{
public static inline var PI:Float = 3.14159265358979323846;
public static inline var DOUBLE_PI:Float = PI * 2;
public static inline var TO_RADS:Float = PI / 180;
public static inline var TO_DEGREES:Float = 180 / PI;
@:keep public static inline var PI:Float = 3.14159265358979323846;
@:keep public static inline var DOUBLE_PI:Float = PI * 2;
@:keep public static inline var TO_RADS:Float = PI / 180;
@:keep public static inline var TO_DEGREES:Float = 180 / PI;

public static inline function isZero(value:Float):Bool {
return Math.abs(value) < 0.0001;
Expand Down
22 changes: 12 additions & 10 deletions source/funkin/util/frontend/ModchartManager.hx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,20 @@ enum abstract Modifiers(String) from String to String {
var BOOST = "BOOST";
var DRUNK = "DRUNK";
var TIPSY = "TIPSY";
var BEAT = "BEAT";
}

class ModchartManager extends EventHandler
{
var modifiers:Map<String, Void->BasicModifier> = [
COS => () -> return new CosModifier(),
SIN => () -> return new SinModifier(),
BOOST => () -> return new BoostModifier(),
DRUNK => () -> return new DrunkModifier(),
TIPSY => () -> return new TipsyModifier(),
BEAT => () -> return new BeatModifier()
];

private var strumLines:Map<Int, StrumLineGroup> = [];

var __postUpdate:Void->Void;
Expand Down Expand Up @@ -46,23 +56,15 @@ class ModchartManager extends EventHandler
return new ModchartManager();
}

// TODO: this crap

var modifiers:Map<String, Void->BasicModifier> = [
COS => () -> return new CosModifier(),
SIN => () -> return new SinModifier(),
BOOST => () -> return new BoostModifier(),
DRUNK => () -> return new DrunkModifier(),
TIPSY => () -> return new TipsyModifier()
];

function modifierFromName(name:String):BasicModifier {
if (modifiers.exists(name)) {
return modifiers.get(name)();
}
return null;
}

// TODO: add a way for scripted modifiers to get the current mod data values

public function makeModifier(name:String, defaultValues:Array<Dynamic>, callbacks:Dynamic) {
name = name.toUpperCase().trim();
modifiers.set(name, () -> {
Expand Down
37 changes: 37 additions & 0 deletions source/funkin/util/frontend/modifiers/BeatModifier.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package funkin.util.frontend.modifiers;

import funkin.util.frontend.ModchartManager.Modifiers;

class BeatModifier extends BasicModifier
{
public function new() {
super(BEAT, false);
}

function getAmplitude(currentBeat:Float)
{
var beat = currentBeat % 1;
var amp:Float = 0;
if (beat <= 0.3)
amp = FlxEase.quadIn((0.3 - beat) / 0.3) * 0.3;
else if (beat >= 0.7)
amp = -FlxEase.quadOut((beat - 0.7) / 0.3) * 0.3;
var neg = 1;
if (currentBeat % 2 >= 1)
neg = -1;
return amp / 0.3 * neg;
}

override function manageStrumUpdate(strum:NoteStrum, elapsed:Float, beat:Float) {
var size:Float = data[0];
if (FunkMath.isZero(size))
return;

strum.xModchart += scaleWidth(getAmplitude(Math.abs(beat))) * size;
}

// [size]
override function getDefaultValues() {
return [0.5];
}
}

0 comments on commit 107158d

Please sign in to comment.