Skip to content

Commit 18f658d

Browse files
Merge pull request #2 from stringfromjava/base-game
Optimize signals to have custom data/parameters and modify license
2 parents d662129 + c1f5ed7 commit 18f658d

File tree

5 files changed

+88
-38
lines changed

5 files changed

+88
-38
lines changed

LICENSE renamed to LICENSE.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# Friday Night Funkin': Java Edition License
2+
3+
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.
4+
5+
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.
6+
7+
## License
8+
9+
```
110
Apache License
211
Version 2.0, January 2004
312
http://www.apache.org/licenses/
@@ -175,18 +184,7 @@ Apache License
175184
176185
END OF TERMS AND CONDITIONS
177186
178-
APPENDIX: How to apply the Apache License to your work.
179-
180-
To apply the Apache License to your work, attach the following
181-
boilerplate notice, with the fields enclosed by brackets "[]"
182-
replaced with your own identifying information. (Don't include
183-
the brackets!) The text should be enclosed in the appropriate
184-
comment syntax for the file format. We also recommend that a
185-
file or class name and description of purpose be included on the
186-
same "printed page" as the copyright notice for easier
187-
identification within third-party archives.
188-
189-
Copyright [yyyy] [name of copyright owner]
187+
Copyright 2026 String
190188
191189
Licensed under the Apache License, Version 2.0 (the "License");
192190
you may not use this file except in compliance with the License.
@@ -199,3 +197,4 @@ Apache License
199197
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200198
See the License for the specific language governing permissions and
201199
limitations under the License.
200+
```

core/src/main/java/me/stringfromjava/funkin/Funkin.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,18 @@ public static FunkinGame getGame() {
176176
*/
177177
public static class Signals {
178178

179-
public static final FunkinSignal preRender = new FunkinSignal();
180-
public static final FunkinSignal postRender = new FunkinSignal();
181-
public static final FunkinSignal preScreenSwitch = new FunkinSignal();
182-
public static final FunkinSignal postScreenSwitch = new FunkinSignal();
183-
public static final FunkinSignal preGameClose = new FunkinSignal();
184-
public static final FunkinSignal postGameClose = new FunkinSignal();
185-
public static final FunkinSignal soundPlayed = new FunkinSignal();
179+
public static final FunkinSignal<RenderSignalData> preRender = new FunkinSignal<>();
180+
public static final FunkinSignal<RenderSignalData> postRender = new FunkinSignal<>();
181+
public static final FunkinSignal<ScreenSwitchSignalData> preScreenSwitch = new FunkinSignal<>();
182+
public static final FunkinSignal<ScreenSwitchSignalData> postScreenSwitch = new FunkinSignal<>();
183+
public static final FunkinSignal<Void> preGameClose = new FunkinSignal<>();
184+
public static final FunkinSignal<Void> postGameClose = new FunkinSignal<>();
185+
public static final FunkinSignal<SoundPlayedSignalData> preSoundPlayed = new FunkinSignal<>();
186+
public static final FunkinSignal<SoundPlayedSignalData> postSoundPlayed = new FunkinSignal<>();
187+
188+
public record RenderSignalData(float delta) {}
189+
public record ScreenSwitchSignalData(FunkinScreen screen) {}
190+
public record SoundPlayedSignalData(FunkinSound sound) {}
186191

187192
private Signals() {
188193
}

core/src/main/java/me/stringfromjava/funkin/FunkinGame.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package me.stringfromjava.funkin;
22

33
import com.badlogic.gdx.Game;
4+
import com.badlogic.gdx.Gdx;
45
import com.badlogic.gdx.audio.Sound;
56
import me.stringfromjava.funkin.backend.display.cache.TextureCache;
67
import me.stringfromjava.funkin.game.InitScreen;
78

89
import java.util.Set;
910

11+
import static me.stringfromjava.funkin.Funkin.Signals.RenderSignalData;
12+
1013
/**
1114
* An enhanced version of libGDX's {@link Game} object.
1215
* <p>
@@ -24,8 +27,11 @@ public void create() {
2427
@Override
2528
public void render() {
2629
super.render();
27-
Funkin.Signals.preRender.dispatch();
28-
Funkin.Signals.postRender.dispatch();
30+
31+
float delta = Gdx.graphics.getDeltaTime();
32+
33+
Funkin.Signals.preRender.dispatch(new RenderSignalData(delta));
34+
Funkin.Signals.postRender.dispatch(new RenderSignalData(delta));
2935
}
3036

3137
@Override

core/src/main/java/me/stringfromjava/funkin/audio/FunkinSound.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
/**
1010
* An enhanced version of libGDX's {@link Sound}.
11+
* <p>
12+
* This is mostly for ensuring that a sound's volume changes when the users'
13+
* global volume changes.
1114
*/
1215
public class FunkinSound implements Sound {
1316

@@ -40,7 +43,7 @@ public FunkinSound(FileHandle path) {
4043

4144
@Override
4245
public long play() {
43-
return thisSound.play();
46+
return thisSound.play(volume, pitch, pan);
4447
}
4548

4649
@Override
@@ -54,12 +57,13 @@ public long play(float volume, float pitch) {
5457

5558
@Override
5659
public long play(float volume, float pitch, float pan) {
57-
Funkin.Signals.soundPlayed.dispatch();
60+
Funkin.Signals.preSoundPlayed.dispatch(new Funkin.Signals.SoundPlayedSignalData(this));
5861
this.volume = volume * Funkin.masterVolume;
5962
this.pitch = pitch;
6063
this.pan = pan;
6164
this.looping = false;
6265
this.isPaused = false;
66+
Funkin.Signals.postSoundPlayed.dispatch(new Funkin.Signals.SoundPlayedSignalData(this));
6367
return thisSound.play(volume, pitch, pan);
6468
}
6569

@@ -79,12 +83,13 @@ public long loop(float volume, float pitch) {
7983

8084
@Override
8185
public long loop(float volume, float pitch, float pan) {
82-
Funkin.Signals.soundPlayed.dispatch();
86+
Funkin.Signals.preSoundPlayed.dispatch(new Funkin.Signals.SoundPlayedSignalData(this));
8387
this.volume = volume * Funkin.masterVolume;
8488
this.pitch = pitch;
8589
this.pan = pan;
8690
this.looping = true;
8791
this.isPaused = false;
92+
Funkin.Signals.postSoundPlayed.dispatch(new Funkin.Signals.SoundPlayedSignalData(this));
8893
return thisSound.loop(volume, pitch, pan);
8994
}
9095

core/src/main/java/me/stringfromjava/funkin/backend/system/FunkinSignal.java

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,78 @@
44

55
/**
66
* Utility class for creating objects that can execute multiple
7-
* runnables when it is dispatched (or triggered).
7+
* callbacks when it is dispatched (or triggered).
88
*/
9-
public class FunkinSignal {
9+
public class FunkinSignal<T> {
1010

11-
private ArrayList<Runnable> runnables;
11+
private final ArrayList<SignalHandler<T>> callbacks;
12+
private final ArrayList<SignalHandler<T>> tempCallbacks; // Callbacks that are added with addOnce().
1213

1314
public FunkinSignal() {
14-
runnables = new ArrayList<>();
15+
callbacks = new ArrayList<>();
16+
tempCallbacks = new ArrayList<>();
1517
}
1618

1719
/**
1820
* Adds a new {@link Runnable} to {@code this} signal to be executed upon
1921
* {@code dispatch()} being called.
2022
*
21-
* @param runnable The new runnable to add to the signal.
23+
* @param callback The new callback to add to the signal.
2224
*/
23-
public void add(Runnable runnable) {
24-
if (runnable != null) {
25-
runnables.add(runnable);
25+
public void add(SignalHandler<T> callback) {
26+
if (callback != null) {
27+
callbacks.add(callback);
2628
}
2729
}
2830

2931
/**
30-
* Removes all runnables from {@code this} signal.
32+
* Adds a temporary {@link Runnable} that only gets ran <i>once</i>.
33+
* When {@code dispatch()} is executed, the temporary {@link Runnable} is removed.
34+
*
35+
* @param callback The new temporary callback to add.
36+
*/
37+
public void addOnce(SignalHandler<T> callback) {
38+
if (callback != null) {
39+
tempCallbacks.add(callback);
40+
}
41+
}
42+
43+
/**
44+
* Removes all callbacks from {@code this} signal.
3145
*/
3246
public void clear() {
33-
runnables.clear();
47+
callbacks.clear();
48+
tempCallbacks.clear();
3449
}
3550

3651
/**
37-
* Triggers {@code this} signal and executes all runnables.
52+
* Triggers {@code this} signal and executes all callbacks.
3853
*/
3954
public void dispatch() {
40-
for (Runnable runnable : runnables) {
41-
if (runnable != null) {
42-
runnable.run();
55+
dispatch(null);
56+
}
57+
58+
/**
59+
* Triggers {@code this} signal and executes all callbacks.
60+
*
61+
* @param data The parameters that {@code this} signal takes.
62+
*/
63+
public void dispatch(T data) {
64+
for (SignalHandler<T> callback : callbacks) {
65+
if (callback != null) {
66+
callback.execute(data);
67+
}
68+
}
69+
70+
for (SignalHandler<T> callback : tempCallbacks) {
71+
if (callback != null) {
72+
callback.execute(data);
73+
tempCallbacks.remove(callback);
4374
}
4475
}
4576
}
77+
78+
public interface SignalHandler<T> {
79+
void execute(T data);
80+
}
4681
}

0 commit comments

Comments
 (0)