From c1f5ed7723bfdf004aa9e257d4bc086ec3191f8f Mon Sep 17 00:00:00 2001 From: String Date: Mon, 22 Dec 2025 22:17:19 -0600 Subject: [PATCH] Optimize signals to have custom data/parameters and modify license --- LICENSE => LICENSE.md | 23 ++++--- .../java/me/stringfromjava/funkin/Funkin.java | 19 +++--- .../me/stringfromjava/funkin/FunkinGame.java | 10 ++- .../funkin/audio/FunkinSound.java | 11 +++- .../funkin/backend/system/FunkinSignal.java | 63 ++++++++++++++----- 5 files changed, 88 insertions(+), 38 deletions(-) rename LICENSE => LICENSE.md (94%) diff --git a/LICENSE b/LICENSE.md similarity index 94% rename from LICENSE rename to LICENSE.md index b09cd78..4a3c97d 100644 --- a/LICENSE +++ b/LICENSE.md @@ -1,3 +1,12 @@ +# Friday Night Funkin': Java Edition License + +The original game (created by Cameron Taylor and the Funkin' Crew) uses a license called the *Apache License*, which is a permissive, free software license that allows users to freely use, modify, and distribute the software for any purpose, including commercially. + +Because Friday Night Funkin': Java Edition (FNF:JE) is based off of the base game, we also adapt the same license they have to maintain consistency. + +## License + +``` Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -175,18 +184,7 @@ Apache License END OF TERMS AND CONDITIONS - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] + Copyright 2026 String Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -199,3 +197,4 @@ Apache License WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. +``` diff --git a/core/src/main/java/me/stringfromjava/funkin/Funkin.java b/core/src/main/java/me/stringfromjava/funkin/Funkin.java index f68321f..82b8548 100644 --- a/core/src/main/java/me/stringfromjava/funkin/Funkin.java +++ b/core/src/main/java/me/stringfromjava/funkin/Funkin.java @@ -176,13 +176,18 @@ public static FunkinGame getGame() { */ public static class Signals { - public static final FunkinSignal preRender = new FunkinSignal(); - public static final FunkinSignal postRender = new FunkinSignal(); - public static final FunkinSignal preScreenSwitch = new FunkinSignal(); - public static final FunkinSignal postScreenSwitch = new FunkinSignal(); - public static final FunkinSignal preGameClose = new FunkinSignal(); - public static final FunkinSignal postGameClose = new FunkinSignal(); - public static final FunkinSignal soundPlayed = new FunkinSignal(); + public static final FunkinSignal preRender = new FunkinSignal<>(); + public static final FunkinSignal postRender = new FunkinSignal<>(); + public static final FunkinSignal preScreenSwitch = new FunkinSignal<>(); + public static final FunkinSignal postScreenSwitch = new FunkinSignal<>(); + public static final FunkinSignal preGameClose = new FunkinSignal<>(); + public static final FunkinSignal postGameClose = new FunkinSignal<>(); + public static final FunkinSignal preSoundPlayed = new FunkinSignal<>(); + public static final FunkinSignal postSoundPlayed = new FunkinSignal<>(); + + public record RenderSignalData(float delta) {} + public record ScreenSwitchSignalData(FunkinScreen screen) {} + public record SoundPlayedSignalData(FunkinSound sound) {} private Signals() { } diff --git a/core/src/main/java/me/stringfromjava/funkin/FunkinGame.java b/core/src/main/java/me/stringfromjava/funkin/FunkinGame.java index 153467d..8fe0c45 100644 --- a/core/src/main/java/me/stringfromjava/funkin/FunkinGame.java +++ b/core/src/main/java/me/stringfromjava/funkin/FunkinGame.java @@ -1,12 +1,15 @@ package me.stringfromjava.funkin; import com.badlogic.gdx.Game; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.audio.Sound; import me.stringfromjava.funkin.backend.display.cache.TextureCache; import me.stringfromjava.funkin.game.InitScreen; import java.util.Set; +import static me.stringfromjava.funkin.Funkin.Signals.RenderSignalData; + /** * An enhanced version of libGDX's {@link Game} object. *

@@ -24,8 +27,11 @@ public void create() { @Override public void render() { super.render(); - Funkin.Signals.preRender.dispatch(); - Funkin.Signals.postRender.dispatch(); + + float delta = Gdx.graphics.getDeltaTime(); + + Funkin.Signals.preRender.dispatch(new RenderSignalData(delta)); + Funkin.Signals.postRender.dispatch(new RenderSignalData(delta)); } @Override diff --git a/core/src/main/java/me/stringfromjava/funkin/audio/FunkinSound.java b/core/src/main/java/me/stringfromjava/funkin/audio/FunkinSound.java index f17ef7a..cc47253 100644 --- a/core/src/main/java/me/stringfromjava/funkin/audio/FunkinSound.java +++ b/core/src/main/java/me/stringfromjava/funkin/audio/FunkinSound.java @@ -8,6 +8,9 @@ /** * An enhanced version of libGDX's {@link Sound}. + *

+ * This is mostly for ensuring that a sound's volume changes when the users' + * global volume changes. */ public class FunkinSound implements Sound { @@ -40,7 +43,7 @@ public FunkinSound(FileHandle path) { @Override public long play() { - return thisSound.play(); + return thisSound.play(volume, pitch, pan); } @Override @@ -54,12 +57,13 @@ public long play(float volume, float pitch) { @Override public long play(float volume, float pitch, float pan) { - Funkin.Signals.soundPlayed.dispatch(); + Funkin.Signals.preSoundPlayed.dispatch(new Funkin.Signals.SoundPlayedSignalData(this)); this.volume = volume * Funkin.masterVolume; this.pitch = pitch; this.pan = pan; this.looping = false; this.isPaused = false; + Funkin.Signals.postSoundPlayed.dispatch(new Funkin.Signals.SoundPlayedSignalData(this)); return thisSound.play(volume, pitch, pan); } @@ -79,12 +83,13 @@ public long loop(float volume, float pitch) { @Override public long loop(float volume, float pitch, float pan) { - Funkin.Signals.soundPlayed.dispatch(); + Funkin.Signals.preSoundPlayed.dispatch(new Funkin.Signals.SoundPlayedSignalData(this)); this.volume = volume * Funkin.masterVolume; this.pitch = pitch; this.pan = pan; this.looping = true; this.isPaused = false; + Funkin.Signals.postSoundPlayed.dispatch(new Funkin.Signals.SoundPlayedSignalData(this)); return thisSound.loop(volume, pitch, pan); } diff --git a/core/src/main/java/me/stringfromjava/funkin/backend/system/FunkinSignal.java b/core/src/main/java/me/stringfromjava/funkin/backend/system/FunkinSignal.java index 7b08090..55e8986 100644 --- a/core/src/main/java/me/stringfromjava/funkin/backend/system/FunkinSignal.java +++ b/core/src/main/java/me/stringfromjava/funkin/backend/system/FunkinSignal.java @@ -4,43 +4,78 @@ /** * Utility class for creating objects that can execute multiple - * runnables when it is dispatched (or triggered). + * callbacks when it is dispatched (or triggered). */ -public class FunkinSignal { +public class FunkinSignal { - private ArrayList runnables; + private final ArrayList> callbacks; + private final ArrayList> tempCallbacks; // Callbacks that are added with addOnce(). public FunkinSignal() { - runnables = new ArrayList<>(); + callbacks = new ArrayList<>(); + tempCallbacks = new ArrayList<>(); } /** * Adds a new {@link Runnable} to {@code this} signal to be executed upon * {@code dispatch()} being called. * - * @param runnable The new runnable to add to the signal. + * @param callback The new callback to add to the signal. */ - public void add(Runnable runnable) { - if (runnable != null) { - runnables.add(runnable); + public void add(SignalHandler callback) { + if (callback != null) { + callbacks.add(callback); } } /** - * Removes all runnables from {@code this} signal. + * Adds a temporary {@link Runnable} that only gets ran once. + * When {@code dispatch()} is executed, the temporary {@link Runnable} is removed. + * + * @param callback The new temporary callback to add. + */ + public void addOnce(SignalHandler callback) { + if (callback != null) { + tempCallbacks.add(callback); + } + } + + /** + * Removes all callbacks from {@code this} signal. */ public void clear() { - runnables.clear(); + callbacks.clear(); + tempCallbacks.clear(); } /** - * Triggers {@code this} signal and executes all runnables. + * Triggers {@code this} signal and executes all callbacks. */ public void dispatch() { - for (Runnable runnable : runnables) { - if (runnable != null) { - runnable.run(); + dispatch(null); + } + + /** + * Triggers {@code this} signal and executes all callbacks. + * + * @param data The parameters that {@code this} signal takes. + */ + public void dispatch(T data) { + for (SignalHandler callback : callbacks) { + if (callback != null) { + callback.execute(data); + } + } + + for (SignalHandler callback : tempCallbacks) { + if (callback != null) { + callback.execute(data); + tempCallbacks.remove(callback); } } } + + public interface SignalHandler { + void execute(T data); + } }