diff --git a/android/src/main/java/me/stringdotjar/polyverse/android/AndroidLauncher.java b/android/src/main/java/me/stringdotjar/polyverse/android/AndroidLauncher.java index b5485e5..b185a59 100644 --- a/android/src/main/java/me/stringdotjar/polyverse/android/AndroidLauncher.java +++ b/android/src/main/java/me/stringdotjar/polyverse/android/AndroidLauncher.java @@ -13,6 +13,7 @@ public class AndroidLauncher extends AndroidApplication { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + PolyverseApp app = new PolyverseApp( PolyverseConstants.WINDOW_TITLE, PolyverseConstants.WINDOW_WIDTH, @@ -22,6 +23,7 @@ protected void onCreate(Bundle savedInstanceState) { PolyverseConstants.VSYNC, PolyverseConstants.FULLSCREEN ); + AndroidApplicationConfiguration configuration = new AndroidApplicationConfiguration(); configuration.useImmersiveMode = true; // Recommended, but not required. initialize(app, configuration); diff --git a/assets/another_test.groovy b/assets/another_test.groovy index b9290b2..711365b 100644 --- a/assets/another_test.groovy +++ b/assets/another_test.groovy @@ -1,7 +1,7 @@ import com.badlogic.gdx.Gdx import com.badlogic.gdx.Input import me.stringdotjar.flixelgdx.Flixel -import me.stringdotjar.flixelgdx.graphics.FlixelSprite +import me.stringdotjar.flixelgdx.FlixelSprite import me.stringdotjar.flixelgdx.util.FlixelPathsUtil import me.stringdotjar.polyverse.util.PolyverseConstants import me.stringdotjar.polyverse.script.type.Script diff --git a/assets/test.groovy b/assets/test.groovy index 2cebc1a..3588f6e 100644 --- a/assets/test.groovy +++ b/assets/test.groovy @@ -2,8 +2,8 @@ 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.FlixelSprite -import me.stringdotjar.flixelgdx.graphics.display.FlixelState +import me.stringdotjar.flixelgdx.FlixelSprite +import me.stringdotjar.flixelgdx.display.FlixelState import me.stringdotjar.flixelgdx.util.FlixelPathsUtil import me.stringdotjar.polyverse.menus.TitleState import me.stringdotjar.polyverse.script.type.SystemScript diff --git a/flixelgdx/android/src/main/java/me/stringdotjar/flixelgdx/backend/android/FlixelAndroidLauncher.java b/flixelgdx/android/src/main/java/me/stringdotjar/flixelgdx/backend/android/FlixelAndroidLauncher.java index 3b9ee05..f440895 100644 --- a/flixelgdx/android/src/main/java/me/stringdotjar/flixelgdx/backend/android/FlixelAndroidLauncher.java +++ b/flixelgdx/android/src/main/java/me/stringdotjar/flixelgdx/backend/android/FlixelAndroidLauncher.java @@ -1,8 +1,10 @@ package me.stringdotjar.flixelgdx.backend.android; +import android.app.Activity; import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; import me.stringdotjar.flixelgdx.Flixel; import me.stringdotjar.flixelgdx.FlixelGame; +import me.stringdotjar.flixelgdx.backend.android.alert.FlixelAndroidAlerter; /** * Launches the Android version of the FlixelGDX game. @@ -17,8 +19,8 @@ public class FlixelAndroidLauncher { * * @param game The game instance to launch. This should already be initialized with the desired configuration values. */ - public static void launch(FlixelGame game) { - Flixel.initialize(game); + public static void launch(FlixelGame game, Activity activity) { + Flixel.initialize(game, new FlixelAndroidAlerter(activity)); AndroidApplicationConfiguration configuration = new AndroidApplicationConfiguration(); configuration.useImmersiveMode = true; diff --git a/flixelgdx/android/src/main/java/me/stringdotjar/flixelgdx/backend/android/alert/FlixelAndroidAlerter.java b/flixelgdx/android/src/main/java/me/stringdotjar/flixelgdx/backend/android/alert/FlixelAndroidAlerter.java new file mode 100644 index 0000000..e7ace9a --- /dev/null +++ b/flixelgdx/android/src/main/java/me/stringdotjar/flixelgdx/backend/android/alert/FlixelAndroidAlerter.java @@ -0,0 +1,44 @@ +package me.stringdotjar.flixelgdx.backend.android.alert; + +import android.app.Activity; +import android.app.AlertDialog; +import me.stringdotjar.flixelgdx.backend.Alerter; + +public class FlixelAndroidAlerter implements Alerter { + + private final Activity activity; + + public FlixelAndroidAlerter(Activity activity) { + this.activity = activity; + } + + @Override + public void showInfoAlert(String title, String message) { + showAlert(title, message, android.R.drawable.ic_dialog_info); + } + + @Override + public void showWarningAlert(String title, String message) { + showAlert(title, message, android.R.drawable.ic_dialog_alert); + } + + @Override + public void showErrorAlert(String title, String message) { + showAlert(title, message, android.R.drawable.stat_notify_error); + } + + private void showAlert(final String title, final String message, final int iconResId) { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + new AlertDialog.Builder(activity) + .setTitle(title) + .setMessage(message) + .setIcon(iconResId) + .setPositiveButton("OK", null) + .setCancelable(true) + .show(); + } + }); + } +} diff --git a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/Flixel.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/Flixel.java index d661107..9ffcd3f 100644 --- a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/Flixel.java +++ b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/Flixel.java @@ -10,8 +10,9 @@ import games.rednblack.miniaudio.MiniAudio; import games.rednblack.miniaudio.loader.MASoundLoader; import me.stringdotjar.flixelgdx.util.FlixelPathsUtil; -import me.stringdotjar.flixelgdx.graphics.display.FlixelCamera; -import me.stringdotjar.flixelgdx.graphics.display.FlixelState; +import me.stringdotjar.flixelgdx.backend.Alerter; +import me.stringdotjar.flixelgdx.display.FlixelCamera; +import me.stringdotjar.flixelgdx.display.FlixelState; import me.stringdotjar.flixelgdx.logging.FlixelLogMode; import me.stringdotjar.flixelgdx.logging.FlixelLogger; import me.stringdotjar.flixelgdx.signal.FlixelSignal; @@ -19,7 +20,6 @@ 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; /** @@ -50,12 +50,12 @@ public final class Flixel { /** The static instance used to access the core elements of the game. */ private static FlixelGame game; + /** The system to use for displaying alert notifications to the user. */ + private static Alerter alerter; + /** Has the global manager been initialized yet? */ private static boolean initialized = false; - /** When true, framework logs are emitted; when false, they are suppressed. */ - public static boolean includeFlixelLogs = false; - /** The default logger used by {@link #info}, {@link #warn}, and {@link #error}. */ private static FlixelLogger defaultLogger; @@ -66,12 +66,15 @@ public final class Flixel { * exception. * * @param gameInstance The instance of the game to use. + * @param alertSystem The system to use for displaying alert notifications to the user. + * @throws IllegalStateException If Flixel has already been initialized. */ - public static void initialize(FlixelGame gameInstance) { + public static void initialize(@NotNull FlixelGame gameInstance, @NotNull Alerter alertSystem) { if (initialized) { throw new IllegalStateException("Flixel has already been initialized!"); } game = gameInstance; + alerter = alertSystem; assetManager = new AssetManager(); @@ -334,6 +337,36 @@ public static void setMasterVolume(float volume) { masterVolume = volume; } + /** + * Shows an info alert notification to the user. + * + * @param title The title of the alert. + * @param message The message of the alert. + */ + public static void showInfoAlert(String title, String message) { + alerter.showInfoAlert(title, message); + } + + /** + * Shows a warning alert notification to the user. + * + * @param title The title of the alert. + * @param message The message of the alert. + */ + public static void showWarningAlert(String title, String message) { + alerter.showWarningAlert(title, message); + } + + /** + * Shows an error alert notification to the user. + * + * @param title The title of the alert. + * @param message The message of the alert. + */ + public static void showErrorAlert(String title, String message) { + alerter.showErrorAlert(title, message); + } + public static boolean keyPressed(int key) { return Gdx.input.isKeyPressed(key); } @@ -343,27 +376,23 @@ public static boolean keyJustPressed(int key) { } public static void info(Object message) { - info(FlixelConstants.System.LOG_TAG, message); + info(defaultLogger.getDefaultTag(), message); } public static void info(String tag, Object message) { - if (defaultLogger != null) { - defaultLogger.info(tag, message); - } + defaultLogger.info(tag, message); } public static void warn(Object message) { - warn(FlixelConstants.System.LOG_TAG, message); + warn(defaultLogger.getDefaultTag(), message); } public static void warn(String tag, Object message) { - if (defaultLogger != null) { - defaultLogger.warn(tag, message); - } + defaultLogger.warn(tag, message); } public static void error(String message) { - error(FlixelConstants.System.LOG_TAG, message, null); + error(defaultLogger.getDefaultTag(), message, null); } public static void error(String tag, Object message) { @@ -371,20 +400,21 @@ public static void error(String tag, Object message) { } public static void error(String tag, Object message, Throwable throwable) { - if (defaultLogger != null) { - defaultLogger.error(tag, message, throwable); - } + defaultLogger.error(tag, message, throwable); } public static void setLogger(@NotNull FlixelLogger logger) { defaultLogger = logger; } - /** - * Returns the current default logger used by the static logging methods. - * - * @return The current logger, or null if none has been set. - */ + public static void setDefaultLogTag(@NotNull String tag) { + defaultLogger.setDefaultTag(tag); + } + + public static Alerter getAlerter() { + return alerter; + } + public static FlixelLogger getLogger() { return defaultLogger; } @@ -450,9 +480,7 @@ public static boolean isFullscreen() { } public static void setLogMode(@NotNull FlixelLogMode mode) { - if (defaultLogger != null) { - defaultLogger.setLogMode(mode); - } + defaultLogger.setLogMode(mode); } /** diff --git a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/FlixelBasic.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/FlixelBasic.java index 49f21b2..dc411d3 100644 --- a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/FlixelBasic.java +++ b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/FlixelBasic.java @@ -2,7 +2,7 @@ import com.badlogic.gdx.graphics.g2d.Batch; -import me.stringdotjar.flixelgdx.graphics.display.FlixelCamera; +import me.stringdotjar.flixelgdx.display.FlixelCamera; /** * This is the most generic Flixel object. Both {@link FlixelObject} and {@link FlixelCamera} diff --git a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/FlixelGame.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/FlixelGame.java index 64a1401..1330fac 100644 --- a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/FlixelGame.java +++ b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/FlixelGame.java @@ -13,11 +13,10 @@ import com.badlogic.gdx.utils.ScreenUtils; import com.badlogic.gdx.utils.SnapshotArray; -import me.stringdotjar.flixelgdx.graphics.display.FlixelCamera; -import me.stringdotjar.flixelgdx.graphics.display.FlixelState; -import me.stringdotjar.flixelgdx.graphics.text.FlixelFontRegistry; -import me.stringdotjar.flixelgdx.internal.FlixelCoreLogger; +import me.stringdotjar.flixelgdx.display.FlixelCamera; +import me.stringdotjar.flixelgdx.display.FlixelState; import me.stringdotjar.flixelgdx.logging.FlixelLogger; +import me.stringdotjar.flixelgdx.text.FlixelFontRegistry; import me.stringdotjar.flixelgdx.tween.FlixelTween; import me.stringdotjar.flixelgdx.util.FlixelRuntimeUtil; import org.fusesource.jansi.AnsiConsole; @@ -26,6 +25,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; +import java.util.Arrays; import java.util.concurrent.ConcurrentLinkedQueue; /** @@ -222,7 +222,7 @@ public void create() { } batch = new SpriteBatch(); - cameras = new SnapshotArray<>(FlixelCamera.class); + cameras = new SnapshotArray<>(FlixelCamera[]::new); cameras.add(new FlixelCamera((int) viewSize.x, (int) viewSize.y)); stage = new Stage(getCamera().getViewport(), batch); @@ -309,8 +309,7 @@ public void update(float elapsed) { public void draw() { Flixel.Signals.preDraw.dispatch(); - ScreenUtils.clear(Color.BLACK); - + ScreenUtils.clear(Color.BLACK); // Clear the screen to refresh the screen. FlixelState state = Flixel.getState(); // Loop through all cameras and draw the state/substate chain onto each camera. @@ -400,7 +399,6 @@ public void resume() {} public void onWindowFocused() { isFocused = true; Flixel.Signals.windowFocused.dispatch(); - FlixelCoreLogger.info("Game window has regained focus."); } /** Called when the user loses focus on the game's window, while also not being minimized. */ @@ -410,7 +408,6 @@ public void onWindowUnfocused() { } isFocused = false; Flixel.Signals.windowUnfocused.dispatch(); - FlixelCoreLogger.info("Game window has lost focus."); } /** @@ -426,7 +423,6 @@ public void onWindowMinimized(boolean iconified) { } isFocused = false; Flixel.Signals.windowMinimized.dispatch(); - FlixelCoreLogger.info("Game window has been minimized."); } /** @@ -437,10 +433,8 @@ public void onWindowMinimized(boolean iconified) { public void setFullscreen(boolean enabled) { if (enabled) { Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode()); - FlixelCoreLogger.info("Entered fullscreen mode."); } else { Gdx.graphics.setWindowedMode((int) viewSize.x, (int) viewSize.y); - FlixelCoreLogger.info("Exited fullscreen mode."); } } @@ -459,30 +453,24 @@ protected void close() {} @Override public final void dispose() { if (isClosing) { - FlixelCoreLogger.warn("Game is already closing. Skipping dispose..."); return; } isClosing = true; - FlixelCoreLogger.warn("SHUTTING DOWN GAME AND DISPOSING ALL RESOURCES."); - Flixel.Signals.preGameClose.dispatch(); - FlixelCoreLogger.info("Disposing the screen display..."); Flixel.getState().hide(); Flixel.getState().dispose(); stage.dispose(); batch.dispose(); bgTexture.dispose(); - FlixelCoreLogger.info("Disposing all sounds from sound group and music..."); if (Flixel.getMusic() != null) { Flixel.getMusic().dispose(); } Flixel.getSoundsGroup().dispose(); Flixel.getAudioEngine().dispose(); - FlixelCoreLogger.info("Disposing all registered fonts..."); FlixelFontRegistry.dispose(); if (AnsiConsole.isInstalled()) { @@ -506,7 +494,6 @@ public final void dispose() { logThread.join(5000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); - FlixelCoreLogger.warn("Interrupted while waiting for log thread to finish."); } } @@ -521,7 +508,7 @@ protected void configureCrashHandler() { String logs = FlixelRuntimeUtil.getFullExceptionMessage(throwable); String msg = "There was an uncaught exception on thread \"" + thread.getName() + "\"!\n" + logs; Flixel.error(msg); - FlixelRuntimeUtil.showErrorAlert("Uncaught Exception", msg); + Flixel.showErrorAlert("Uncaught Exception", msg); dispose(); // Only use Gdx.app.exit() on non-iOS platforms to avoid App Store guideline violations! if (Gdx.app.getType() != Application.ApplicationType.iOS) { @@ -549,9 +536,13 @@ protected void setupLogWriterThread() { Gdx.files.absolute(logsFolder).mkdirs(); // Check if the logs folder has too many log files, and if so, delete the oldest ones. + // We prune when count >= maxLogFiles so that after creating this run's log we have at most maxLogFiles. FileHandle[] logFiles = Gdx.files.absolute(logsFolder).list(); - if (logFiles != null && logFiles.length > maxLogFiles - 1) { - for (int i = 0; i < logFiles.length - maxLogFiles - 1; i++) { + if (logFiles != null && logFiles.length >= maxLogFiles) { + // Sort by name so we delete oldest first (flixel-yyyy-MM-dd_HH-mm-ss.log is lexicographically ordered). + Arrays.sort(logFiles, (a, b) -> a.name().compareTo(b.name())); + int toDelete = logFiles.length - maxLogFiles + 1; + for (int i = 0; i < toDelete; i++) { logFiles[i].delete(); } } @@ -565,9 +556,6 @@ protected void setupLogWriterThread() { defaultLogger.setFileLineConsumer(this::enqueueLog); } - // Create and set the framework-only logger (used by FlixelCoreLogger; only logs when includeFlixelLogs is true). - FlixelCoreLogger.setInstance(logFile, Flixel.getLogMode(), this::enqueueLog); - final FileHandle logFileForThread = logFile; logThread = new Thread(() -> { try { @@ -590,15 +578,12 @@ protected void setupLogWriterThread() { } } } - } catch (Exception e) { - FlixelCoreLogger.error("Failed to setup log thread and store logs to a file.", e); - } + } catch (Exception e) {} }); logThread.setName("FlixelGDX Log Thread"); logThread.setDaemon(true); logThread.start(); } else { - FlixelCoreLogger.warn("Log storage is disabled. Logs will not be stored to a file. Deleting all existing log files..."); FileHandle[] logFiles = Gdx.files.absolute(logsFolder).list(); if (logFiles != null) { for (FileHandle logFile : logFiles) { @@ -628,12 +613,11 @@ public void enqueueLog(String log) { public FlixelCamera getCamera() { Vector2 windowSize = Flixel.getWindowSize(); if (cameras == null) { - FlixelCoreLogger.warn("Camera list is null. Re-assigning with fresh array..."); - cameras = new SnapshotArray<>(); + cameras = new SnapshotArray<>(FlixelCamera[]::new); } if (cameras.isEmpty()) { - FlixelCoreLogger.warn("Camera list is empty. Adding new fresh default camera..."); cameras.add(new FlixelCamera((int) windowSize.x, (int) windowSize.y)); + stage.setViewport(cameras.first().getViewport()); } return cameras.first(); } @@ -738,6 +722,5 @@ public boolean isFullscreen() { public void setWindowSize(Vector2 newSize) { viewSize = newSize; Gdx.graphics.setWindowedMode((int) newSize.x, (int) newSize.y); - FlixelCoreLogger.info("Set window to new size. (WIDTH=" + newSize.x + ", HEIGHT=" + newSize.y + ")"); } } diff --git a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/FlixelObject.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/FlixelObject.java index b141a64..77a62f2 100644 --- a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/FlixelObject.java +++ b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/FlixelObject.java @@ -5,7 +5,7 @@ * position ({@link #x}, {@link #y}), dimensions ({@link #width}, {@link #height}), and * rotation ({@link #angle}). * - *
Most games interact with this through {@link me.stringdotjar.flixelgdx.graphics.FlixelSprite}, + *
Most games interact with this through {@link me.stringdotjar.flixelgdx.FlixelSprite}, * which adds graphical capabilities on top of this spatial foundation. * * @see FlxObject (HaxeFlixel) diff --git a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelSprite.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/FlixelSprite.java similarity index 98% rename from flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelSprite.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/FlixelSprite.java index 3b6592c..1aef8bb 100644 --- a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/FlixelSprite.java +++ b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/FlixelSprite.java @@ -1,4 +1,4 @@ -package me.stringdotjar.flixelgdx.graphics; +package me.stringdotjar.flixelgdx; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.Color; @@ -12,9 +12,8 @@ import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Pool; import com.badlogic.gdx.utils.XmlReader; -import me.stringdotjar.flixelgdx.Flixel; -import me.stringdotjar.flixelgdx.FlixelObject; -import me.stringdotjar.flixelgdx.graphics.display.FlixelCamera; + +import me.stringdotjar.flixelgdx.display.FlixelCamera; import com.badlogic.gdx.utils.ObjectMap; diff --git a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/backend/Alerter.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/backend/Alerter.java new file mode 100644 index 0000000..d3be208 --- /dev/null +++ b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/backend/Alerter.java @@ -0,0 +1,10 @@ +package me.stringdotjar.flixelgdx.backend; + +/** + * Interface for displaying alert notifications to the user. + */ +public interface Alerter { + void showInfoAlert(String title, String message); + void showWarningAlert(String title, String message); + void showErrorAlert(String title, String message); +} diff --git a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/display/FlixelCamera.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/display/FlixelCamera.java similarity index 98% rename from flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/display/FlixelCamera.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/display/FlixelCamera.java index 8b734da..9cdc422 100644 --- a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/display/FlixelCamera.java +++ b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/display/FlixelCamera.java @@ -1,4 +1,4 @@ -package me.stringdotjar.flixelgdx.graphics.display; +package me.stringdotjar.flixelgdx.display; import com.badlogic.gdx.graphics.Camera; import com.badlogic.gdx.graphics.Color; @@ -963,7 +963,13 @@ public float getZoom() { * @param zoom The new zoom level. */ public void setZoom(float zoom) { + float oldZoom = this.zoom; this.zoom = zoom; + // Keep the center of the view fixed in world space so zoom happens from center, not from the left edge. + float centerX = scroll.x + width / (2f * oldZoom); + float centerY = scroll.y + height / (2f * oldZoom); + scroll.x = centerX - width / (2f * this.zoom); + scroll.y = centerY - height / (2f * this.zoom); applyZoom(); } diff --git a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/display/FlixelState.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/display/FlixelState.java similarity index 99% rename from flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/display/FlixelState.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/display/FlixelState.java index 845f454..57229b6 100644 --- a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/display/FlixelState.java +++ b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/display/FlixelState.java @@ -1,4 +1,4 @@ -package me.stringdotjar.flixelgdx.graphics.display; +package me.stringdotjar.flixelgdx.display; import com.badlogic.gdx.Screen; import com.badlogic.gdx.graphics.Color; diff --git a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/display/FlixelSubState.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/display/FlixelSubState.java similarity index 96% rename from flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/display/FlixelSubState.java rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/display/FlixelSubState.java index 56f819a..7ee8515 100644 --- a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/display/FlixelSubState.java +++ b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/display/FlixelSubState.java @@ -1,4 +1,4 @@ -package me.stringdotjar.flixelgdx.graphics.display; +package me.stringdotjar.flixelgdx.display; import com.badlogic.gdx.graphics.Color; diff --git a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/group/FlixelGroup.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/group/FlixelGroup.java index be35443..da62146 100644 --- a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/group/FlixelGroup.java +++ b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/group/FlixelGroup.java @@ -38,7 +38,7 @@ public FlixelGroup() { */ public FlixelGroup(int maxSize) { this.maxSize = Math.max(0, maxSize); - members = new SnapshotArray<>(FlixelBasic.class); + members = new SnapshotArray<>(FlixelBasic[]::new); } @Override diff --git a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/group/FlixelSpriteGroup.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/group/FlixelSpriteGroup.java index 528309e..a5838c8 100644 --- a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/group/FlixelSpriteGroup.java +++ b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/group/FlixelSpriteGroup.java @@ -8,7 +8,7 @@ import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.SnapshotArray; -import me.stringdotjar.flixelgdx.graphics.FlixelSprite; +import me.stringdotjar.flixelgdx.FlixelSprite; import java.util.Comparator; import java.util.Random; @@ -84,7 +84,7 @@ public FlixelSpriteGroup(int maxSize, float rotationRadius, float rotation) { this.maxSize = Math.max(0, maxSize); this.rotationRadius = rotationRadius; super.setAngle(rotation); - members = new SnapshotArray<>(FlixelSprite.class); + members = new SnapshotArray<>(FlixelSprite[]::new); } @Override diff --git a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/internal/FlixelCoreLogger.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/internal/FlixelCoreLogger.java deleted file mode 100644 index e673398..0000000 --- a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/internal/FlixelCoreLogger.java +++ /dev/null @@ -1,97 +0,0 @@ -package me.stringdotjar.flixelgdx.internal; - -import com.badlogic.gdx.files.FileHandle; - -import me.stringdotjar.flixelgdx.Flixel; -import me.stringdotjar.flixelgdx.logging.FlixelLogMode; -import me.stringdotjar.flixelgdx.logging.FlixelLogger; - -import java.util.function.Consumer; - -/** - * Logger for the internal framework code only. Logs are only emitted when - * {@link Flixel#includeFlixelLogs} is {@code true}. Access via static factory methods. - * - *
This class wraps a {@link FlixelLogger} and gates all output on {@link Flixel#includeFlixelLogs}.
- * Not exported by the module; for use only within this library.
- */
-public final class FlixelCoreLogger {
-
- private static FlixelLogger instance;
-
- /**
- * Returns the framework logger. May be null before the game has set it up.
- */
- public static FlixelLogger getInstance() {
- return instance;
- }
-
- /**
- * Sets the framework logger. Called by the framework when logging is configured.
- */
- public static void setInstance(FlixelLogger inst) {
- instance = inst;
- }
-
- /**
- * Creates and sets the framework logger with the given file location and consumer.
- * Called by {@link me.stringdotjar.flixelgdx.FlixelGame} when setting up the log writer.
- *
- * @param logFileLocation The location where the log file should be stored.
- * @param logMode The mode of the log file.
- * @param fileLineConsumer The consumer that will be used to write the log lines to the file.
- */
- public static void setInstance(FileHandle logFileLocation, FlixelLogMode logMode, Consumer This is used to get the file and method name of where the log was called from.
+ *
+ * @return The location of where the log was called from.
+ */
+ protected StackWalker.StackFrame getCaller() {
+ // TODO: Make this work for TeaVM, as call stacks aren't supported for web builds/TeaVM!
+ return StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE)
+ .walk(frames -> frames.filter(f -> {
+ // Filter packages to not log.
+ String pkg = f.getDeclaringClass().getPackageName();
+ if (pkg.startsWith(FlixelRuntimeUtil.getLibraryRoot())) return false; // Do not include FlixelGDX logs.
+ if (pkg.startsWith("org.codehaus.groovy.")) return false;
+ if (pkg.startsWith("groovy.lang.")) return false;
+ if (pkg.contains("$_run_closure")) return false;
+ if (pkg.contains("$$Lambda$")) return false;
+ if (pkg.startsWith("sun.reflect.") || pkg.startsWith("java.lang.reflect.")) return false;
+ return true;
+ })
+ .findFirst()
+ )
+ .orElse(null);
+ }
+
/**
* Wraps text with ANSI color/format codes for console output.
*/
@@ -186,4 +216,12 @@ protected String colorText(String text, String color, boolean bold, boolean ital
sb.append(FlixelConstants.AsciiCodes.RESET);
return sb.toString();
}
+
+ public String getDefaultTag() {
+ return defaultTag;
+ }
+
+ public void setDefaultTag(@NotNull String defaultTag) {
+ this.defaultTag = defaultTag;
+ }
}
diff --git a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/signal/FlixelSignalData.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/signal/FlixelSignalData.java
index 5ac1b14..289c73b 100644
--- a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/signal/FlixelSignalData.java
+++ b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/signal/FlixelSignalData.java
@@ -2,7 +2,7 @@
import games.rednblack.miniaudio.MASound;
import me.stringdotjar.flixelgdx.Flixel;
-import me.stringdotjar.flixelgdx.graphics.display.FlixelState;
+import me.stringdotjar.flixelgdx.display.FlixelState;
/**
* Convenience class for holding all signal data types used in the default signals stored in
diff --git a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/text/FlixelFontRegistry.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/text/FlixelFontRegistry.java
similarity index 91%
rename from flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/text/FlixelFontRegistry.java
rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/text/FlixelFontRegistry.java
index f1ef630..cc0dceb 100644
--- a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/text/FlixelFontRegistry.java
+++ b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/text/FlixelFontRegistry.java
@@ -1,7 +1,8 @@
-package me.stringdotjar.flixelgdx.graphics.text;
+package me.stringdotjar.flixelgdx.text;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
+import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.HashMap;
@@ -35,7 +36,7 @@
* }
*
* {@link #dispose()} must be called when the game shuts down (typically in
+ * {@link #dispose()} is called when the game shuts down (in
* {@code FlixelGame.dispose()}) to release all cached generators. Individual entries
* can be removed earlier with {@link #unregister(String)}.
*/
@@ -52,19 +53,13 @@ private FlixelFontRegistry() {}
* Registers a TrueType font under the given identifier. If an entry with the same
* ID already exists, it is replaced (and its cached generator is disposed).
*
- * @param id A unique identifier for this font (e.g. {@code "pixel"},
- * {@code "main"}, {@code "bold"}).
- * @param fontFile A libGDX {@link FileHandle} pointing to the {@code .ttf} or
- * {@code .otf} asset.
- * @throws IllegalArgumentException if {@code id} is {@code null}/empty or
- * {@code fontFile} is {@code null}.
+ * @param id A unique identifier for this font (e.g. {@code "pixel"}, {@code "main"}, {@code "bold"}).
+ * @param fontFile A libGDX {@link FileHandle} pointing to the {@code .ttf} or {@code .otf} asset.
+ * @throws IllegalArgumentException if {@code id} is {@code null}/empty or {@code fontFile} is {@code null}.
*/
- public static void register(String id, FileHandle fontFile) {
- if (id == null || id.isEmpty()) {
- throw new IllegalArgumentException("Font id must not be null or empty.");
- }
- if (fontFile == null) {
- throw new IllegalArgumentException("Font file must not be null.");
+ public static void register(@NotNull String id, @NotNull FileHandle fontFile) {
+ if (id.isEmpty()) {
+ throw new IllegalArgumentException("Font ID must not be empty.");
}
Entry existing = entries.get(id);
diff --git a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/text/FlixelText.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/text/FlixelText.java
similarity index 99%
rename from flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/text/FlixelText.java
rename to flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/text/FlixelText.java
index 1b01545..60eb4d1 100644
--- a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/graphics/text/FlixelText.java
+++ b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/text/FlixelText.java
@@ -1,4 +1,4 @@
-package me.stringdotjar.flixelgdx.graphics.text;
+package me.stringdotjar.flixelgdx.text;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
@@ -16,14 +16,14 @@
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.XmlReader;
-import me.stringdotjar.flixelgdx.graphics.FlixelSprite;
+import me.stringdotjar.flixelgdx.FlixelSprite;
import com.badlogic.gdx.utils.ObjectMap;
import org.jetbrains.annotations.NotNull;
/**
- * A display object for rendering text on screen, modeled after HaxeFlixel's {@code FlxText}.
+ * A display object for rendering text on screen.
*
* Extends {@link FlixelSprite} so that text objects can be added to sprite groups and
* states, with full support for tinting, fading, rotation, and scaling. Uses libGDX's
@@ -844,7 +844,7 @@ public final TextureRegion[][] getFrames() {
@Override
public void destroy() {
- disposeFont();
+ reset();
}
@Override
diff --git a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/tween/FlixelTweenManager.java b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/tween/FlixelTweenManager.java
index 472e3a6..1c7f0b8 100644
--- a/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/tween/FlixelTweenManager.java
+++ b/flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/tween/FlixelTweenManager.java
@@ -1,13 +1,13 @@
package me.stringdotjar.flixelgdx.tween;
-import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Pool;
+import com.badlogic.gdx.utils.SnapshotArray;
/** Manager class for handling a list of active {@link FlixelTween}s. */
public class FlixelTweenManager {
/** Array where all current active tweens are stored. */
- protected final ArrayLifecycle
- *