From 107158d1a96e5d886b5cefa767ca35b816a41857 Mon Sep 17 00:00:00 2001 From: MaybeMaru <97055307+MaybeMaru@users.noreply.github.com> Date: Tue, 18 Jun 2024 00:54:57 +0200 Subject: [PATCH] add beat modifier --- README.md | 1 + source/funkin/util/FunkMath.hx | 8 ++-- .../funkin/util/frontend/ModchartManager.hx | 22 ++++++----- .../util/frontend/modifiers/BeatModifier.hx | 37 +++++++++++++++++++ 4 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 source/funkin/util/frontend/modifiers/BeatModifier.hx diff --git a/README.md b/README.md index 688b39be..8bdac36f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/source/funkin/util/FunkMath.hx b/source/funkin/util/FunkMath.hx index 845dde30..062a12b0 100644 --- a/source/funkin/util/FunkMath.hx +++ b/source/funkin/util/FunkMath.hx @@ -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; diff --git a/source/funkin/util/frontend/ModchartManager.hx b/source/funkin/util/frontend/ModchartManager.hx index fec3055e..86d05c3e 100644 --- a/source/funkin/util/frontend/ModchartManager.hx +++ b/source/funkin/util/frontend/ModchartManager.hx @@ -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:MapBasicModifier> = [ + 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 = []; var __postUpdate:Void->Void; @@ -46,16 +56,6 @@ class ModchartManager extends EventHandler return new ModchartManager(); } - // TODO: this crap - - var modifiers:MapBasicModifier> = [ - 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)(); @@ -63,6 +63,8 @@ class ModchartManager extends EventHandler return null; } + // TODO: add a way for scripted modifiers to get the current mod data values + public function makeModifier(name:String, defaultValues:Array, callbacks:Dynamic) { name = name.toUpperCase().trim(); modifiers.set(name, () -> { diff --git a/source/funkin/util/frontend/modifiers/BeatModifier.hx b/source/funkin/util/frontend/modifiers/BeatModifier.hx new file mode 100644 index 00000000..d2d868f9 --- /dev/null +++ b/source/funkin/util/frontend/modifiers/BeatModifier.hx @@ -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]; + } +} \ No newline at end of file