Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import me.stringdotjar.funkin.FunkinGame;
import me.stringdotjar.funkin.InitScreen;
import me.stringdotjar.funkin.InitState;
import me.stringdotjar.funkin.util.FunkinConstants;

/** Launches the Android application. */
Expand All @@ -17,7 +17,7 @@ protected void onCreate(Bundle savedInstanceState) {
FunkinConstants.WINDOW_TITLE,
FunkinConstants.WINDOW_WIDTH,
FunkinConstants.WINDOW_HEIGHT,
new InitScreen()
new InitState()
);
AndroidApplicationConfiguration configuration = new AndroidApplicationConfiguration();
configuration.useImmersiveMode = true; // Recommended, but not required.
Expand Down
2 changes: 1 addition & 1 deletion assets/another_test.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AnotherTestClass extends Script {

sprite.setPosition(randomPosX, randomPosY)

Flixel.screen.add(sprite)
Flixel.state.add(sprite)
}
}

Expand Down
6 changes: 3 additions & 3 deletions assets/test.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Color
import me.stringdotjar.flixelgdx.Flixel
import me.stringdotjar.flixelgdx.graphics.FlixelScreen
import me.stringdotjar.flixelgdx.graphics.FlixelState
import me.stringdotjar.flixelgdx.backend.FlixelPaths
import me.stringdotjar.flixelgdx.graphics.sprite.FlixelSprite
import me.stringdotjar.polyverse.script.type.SystemScript
Expand All @@ -24,7 +24,7 @@ class TestScript extends SystemScript {
super.onRender(delta)

if (Gdx.input.isKeyJustPressed(Input.Keys.Q)) {
Flixel.setScreen(new TestScreen())
Flixel.switchState(new TestState())
}
}

Expand All @@ -41,7 +41,7 @@ class TestScript extends SystemScript {
}
}

class TestScreen extends FlixelScreen {
class TestState extends FlixelState {

private FlixelSprite test

Expand Down
128 changes: 65 additions & 63 deletions flixelgdx/src/main/java/me/stringdotjar/flixelgdx/Flixel.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import games.rednblack.miniaudio.MASound;
import games.rednblack.miniaudio.MiniAudio;
import games.rednblack.miniaudio.loader.MASoundLoader;
import me.stringdotjar.flixelgdx.graphics.FlixelScreen;
import me.stringdotjar.flixelgdx.graphics.FlixelState;
import me.stringdotjar.flixelgdx.graphics.FlixelViewport;
import me.stringdotjar.flixelgdx.util.FlixelConstants;
import me.stringdotjar.flixelgdx.signal.FlixelSignal;
import me.stringdotjar.flixelgdx.signal.FlixelSignalData.MusicPlayedSignalData;
import me.stringdotjar.flixelgdx.signal.FlixelSignalData.RenderSignalData;
import me.stringdotjar.flixelgdx.signal.FlixelSignalData.ScreenSwitchSignalData;
import me.stringdotjar.flixelgdx.signal.FlixelSignalData.UpdateSignalData;
import me.stringdotjar.flixelgdx.signal.FlixelSignalData.StateSwitchSignalData;
import me.stringdotjar.flixelgdx.signal.FlixelSignalData.SoundPlayedSignalData;
import me.stringdotjar.flixelgdx.util.FlixelConstants;
import org.jetbrains.annotations.NotNull;

import java.time.LocalDateTime;
Expand All @@ -29,8 +29,8 @@
*/
public final class Flixel {

/** The current {@code FlixelScreen} being displayed. */
private static FlixelScreen screen;
/** The current {@code FlixelState} being displayed. */
private static FlixelState state;

/** The main audio object used to create, */
private static MiniAudio engine;
Expand Down Expand Up @@ -63,7 +63,7 @@ public final class Flixel {
*/
public static void initialize(FlixelGame gameInstance) {
if (initialized) {
throw new IllegalStateException("FNF:JE has already been initialized!");
throw new IllegalStateException("FlixelGDX has already been initialized!");
}
game = gameInstance;

Expand All @@ -80,24 +80,24 @@ public static void initialize(FlixelGame gameInstance) {
/**
* Sets the current screen to the provided screen.
*
* @param newScreen The new {@code FlixelScreen} to set as the current screen.
* @param newState The new {@code FlixelState} to set as the current screen.
*/
public static void setScreen(FlixelScreen newScreen) {
Signals.preScreenSwitch.dispatch(new ScreenSwitchSignalData(newScreen));
public static void switchState(FlixelState newState) {
Signals.preStateSwitch.dispatch(new StateSwitchSignalData(newState));
if (!initialized) {
throw new IllegalStateException("FNF:JE has not been initialized yet!");
throw new IllegalStateException("Polyverse has not been initialized yet!");
}
if (newScreen == null) {
throw new IllegalArgumentException("Screen cannot be null!");
if (newState == null) {
throw new IllegalArgumentException("New state cannot be null!");
}
if (screen != null) {
screen.hide();
screen.dispose();
if (state != null) {
state.hide();
state.dispose();
}
game.resetViewports();
screen = newScreen;
screen.create();
Signals.postScreenSwitch.dispatch(new ScreenSwitchSignalData(newScreen));
state = newState;
state.create();
Signals.postStateSwitch.dispatch(new StateSwitchSignalData(newState));
}

/**
Expand All @@ -112,8 +112,8 @@ public static void setScreen(FlixelScreen newScreen) {
* }</pre>
*
* @param path The path to load the sound from. Note that if you're loading an external sound
* outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a
* regular string (without {@code assets/} at the beginning).
* outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a
* regular string (without {@code assets/} at the beginning).
* @return The new sound instance.
*/
public static MASound playSound(String path) {
Expand All @@ -131,9 +131,9 @@ public static MASound playSound(String path) {
* Flixel.playSound(FlixelPaths.external("your/path/here").path(), 1);
* }</pre>
*
* @param path The path to load the sound from. Note that if you're loading an external sound
* outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a
* regular string (without {@code assets/} at the beginning).
* @param path The path to load the sound from. Note that if you're loading an external sound
* outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a
* regular string (without {@code assets/} at the beginning).
* @param volume The volume to play the new sound with.
* @return The new sound instance.
*/
Expand All @@ -152,10 +152,10 @@ public static MASound playSound(String path, float volume) {
* Flixel.playSound(FlixelPaths.external("your/path/here").path(), 1, false);
* }</pre>
*
* @param path The path to load the sound from. Note that if you're loading an external sound
* outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a
* regular string (without {@code assets/} at the beginning).
* @param volume The volume to play the new sound with.
* @param path The path to load the sound from. Note that if you're loading an external sound
* outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a
* regular string (without {@code assets/} at the beginning).
* @param volume The volume to play the new sound with.
* @param looping Should the new sound loop indefinitely?
* @return The new sound instance.
*/
Expand All @@ -175,13 +175,13 @@ public static MASound playSound(String path, float volume, boolean looping) {
* Flixel.playSound(FlixelPaths.external("your/path/here").path(), 1, false, null);
* }</pre>
*
* @param path The path to load the sound from. Note that if you're loading an external sound
* outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a
* regular string (without {@code assets/} at the beginning).
* @param volume The volume to play the new sound with.
* @param path The path to load the sound from. Note that if you're loading an external sound
* outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a
* regular string (without {@code assets/} at the beginning).
* @param volume The volume to play the new sound with.
* @param looping Should the new sound loop indefinitely?
* @param group The sound group to add the new sound to. If {@code null} is passed down, then the
* default sound group will be used.
* @param group The sound group to add the new sound to. If {@code null} is passed down, then the
* default sound group will be used.
* @return The new sound instance.
*/
public static MASound playSound(String path, float volume, boolean looping, MAGroup group) {
Expand All @@ -202,13 +202,13 @@ public static MASound playSound(String path, float volume, boolean looping, MAGr
* Flixel.playSound(FlixelPaths.external("your/path/here").path(), 1, false, null, true);
* }</pre>
*
* @param path The path to load the sound from. Note that if you're loading an external sound
* outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a
* regular string (without {@code assets/} at the beginning).
* @param volume The volume to play the new sound with.
* @param looping Should the new sound loop indefinitely?
* @param group The sound group to add the new sound to. If {@code null} is passed down, then the
* default sound group will be used.
* @param path The path to load the sound from. Note that if you're loading an external sound
* outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a
* regular string (without {@code assets/} at the beginning).
* @param volume The volume to play the new sound with.
* @param looping Should the new sound loop indefinitely?
* @param group The sound group to add the new sound to. If {@code null} is passed down, then the
* default sound group will be used.
* @param external Should this sound be loaded externally? (This is only for mobile platforms!)
* @return The new sound instance.
*/
Expand All @@ -234,8 +234,8 @@ public static MASound playSound(@NotNull String path, float volume, boolean loop
* }</pre>
*
* @param path The path to load the music from. Note that if you're loading an external sound file
* outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a
* regular string (without {@code assets/} at the beginning).
* outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a
* regular string (without {@code assets/} at the beginning).
*/
public static void playMusic(String path) {
playMusic(path, 1, true, false);
Expand All @@ -252,9 +252,9 @@ public static void playMusic(String path) {
* Flixel.playMusic(FlixelPaths.external("your/path/here").path(), 1);
* }</pre>
*
* @param path The path to load the music from. Note that if you're loading an external sound file
* outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a
* regular string (without {@code assets/} at the beginning).
* @param path The path to load the music from. Note that if you're loading an external sound file
* outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a
* regular string (without {@code assets/} at the beginning).
* @param volume The volume to play the new music with.
*/
public static void playMusic(String path, float volume) {
Expand All @@ -272,10 +272,10 @@ public static void playMusic(String path, float volume) {
* Flixel.playMusic(FlixelPaths.external("your/path/here").path(), 1, false);
* }</pre>
*
* @param path The path to load the music from. Note that if you're loading an external sound file
* outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a
* regular string (without {@code assets/} at the beginning).
* @param volume The volume to play the new music with.
* @param path The path to load the music from. Note that if you're loading an external sound file
* outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a
* regular string (without {@code assets/} at the beginning).
* @param volume The volume to play the new music with.
* @param looping Should the new music loop indefinitely?
*/
public static void playMusic(String path, float volume, boolean looping) {
Expand All @@ -295,11 +295,11 @@ public static void playMusic(String path, float volume, boolean looping) {
* Flixel.playMusic(FlixelPaths.external("your/path/here").path(), 1, false, true);
* }</pre>
*
* @param path The path to load the music from. Note that if you're loading an external sound file
* outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a
* regular string (without {@code assets/} at the beginning).
* @param volume The volume to play the new music with.
* @param looping Should the new music loop indefinitely?
* @param path The path to load the music from. Note that if you're loading an external sound file
* outside the game's assets, you should use {@link FileHandle}; otherwise, just pass down a
* regular string (without {@code assets/} at the beginning).
* @param volume The volume to play the new music with.
* @param looping Should the new music loop indefinitely?
* @param external Should this music be loaded externally? (This is only for mobile platforms!)
*/
public static void playMusic(String path, float volume, boolean looping, boolean external) {
Expand Down Expand Up @@ -369,16 +369,16 @@ public static Stage getStage() {
return game.stage;
}

public static FlixelScreen getScreen() {
return screen;
public static FlixelState getState() {
return state;
}

public static MASound getMusic() {
return music;
}

public static Vector2 getWindowSize() {
return game.windowSize;
return game.viewSize;
}

public static MiniAudio getAudioEngine() {
Expand All @@ -397,7 +397,7 @@ public static MAGroup getSoundsGroup() {
return soundsGroup;
}

public static float getDelta() {
public static float getElapsed() {
return Gdx.graphics.getDeltaTime();
}

Expand All @@ -421,10 +421,12 @@ public static boolean isFullscreen() {
*/
public static final class Signals {

public static final FlixelSignal<RenderSignalData> preRender = new FlixelSignal<>();
public static final FlixelSignal<RenderSignalData> postRender = new FlixelSignal<>();
public static final FlixelSignal<ScreenSwitchSignalData> preScreenSwitch = new FlixelSignal<>();
public static final FlixelSignal<ScreenSwitchSignalData> postScreenSwitch = new FlixelSignal<>();
public static final FlixelSignal<UpdateSignalData> preUpdate = new FlixelSignal<>();
public static final FlixelSignal<UpdateSignalData> postUpdate = new FlixelSignal<>();
public static final FlixelSignal<Void> preDraw = new FlixelSignal<>();
public static final FlixelSignal<Void> postDraw = new FlixelSignal<>();
public static final FlixelSignal<StateSwitchSignalData> preStateSwitch = new FlixelSignal<>();
public static final FlixelSignal<StateSwitchSignalData> postStateSwitch = new FlixelSignal<>();
public static final FlixelSignal<Void> preGameClose = new FlixelSignal<>();
public static final FlixelSignal<Void> postGameClose = new FlixelSignal<>();
public static final FlixelSignal<Void> windowFocused = new FlixelSignal<>();
Expand Down
Loading