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
2 changes: 1 addition & 1 deletion assets/another_test.groovy
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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.util.FlixelPathsUtil
import me.stringdotjar.flixelgdx.graphics.sprite.FlixelSprite
import me.stringdotjar.polyverse.util.PolyverseConstants
import me.stringdotjar.polyverse.script.type.Script

Expand Down
4 changes: 2 additions & 2 deletions assets/test.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ 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.FlixelState
import me.stringdotjar.flixelgdx.graphics.FlixelSprite
import me.stringdotjar.flixelgdx.graphics.display.FlixelState
import me.stringdotjar.flixelgdx.util.FlixelPathsUtil
import me.stringdotjar.flixelgdx.graphics.sprite.FlixelSprite
import me.stringdotjar.polyverse.menus.TitleState
import me.stringdotjar.polyverse.script.type.SystemScript

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package me.stringdotjar.flixelgdx.backend.android;

import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import me.stringdotjar.flixelgdx.Flixel;
import me.stringdotjar.flixelgdx.FlixelGame;

/**
* Launches the Android version of a FlixelGDX game.
* Launches the Android version of the FlixelGDX game.
*/
public class FlixelAndroidLauncher {

Expand All @@ -15,5 +17,10 @@ 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) {}
public static void launch(FlixelGame game) {
Flixel.initialize(game);

AndroidApplicationConfiguration configuration = new AndroidApplicationConfiguration();
configuration.useImmersiveMode = true;
}
}
25 changes: 25 additions & 0 deletions flixelgdx/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,31 @@ java {
targetCompatibility = 17
}

// Put dependencies on module path so module-info.java can resolve requires (automatic modules).
tasks.named('compileJava') {
doFirst {
options.compilerArgs = [
'--module-path', classpath.asPath,
]
classpath = files()
}
}

// Require Eclipse (and IDEs that use Eclipse project model) to put dependencies on the module path,
// making "requires gdx" etc. resolve. Without this, only Gradle's compileJava sees them as modules.
eclipse.classpath.file {
whenMerged {
entries.findAll { it instanceof org.gradle.plugins.ide.eclipse.model.Library }.each {
it.entryAttributes['module'] = 'true'
}
}
}

// Avoid JPMS split-package error: gdx and gdx-jnigen-loader both expose com.badlogic.gdx.utils.
configurations.all {
exclude group: 'com.badlogicgames.gdx', module: 'gdx-jnigen-loader'
}

dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
api "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
Expand Down
137 changes: 36 additions & 101 deletions flixelgdx/core/src/main/java/me/stringdotjar/flixelgdx/Flixel.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import games.rednblack.miniaudio.MiniAudio;
import games.rednblack.miniaudio.loader.MASoundLoader;
import me.stringdotjar.flixelgdx.util.FlixelPathsUtil;
import me.stringdotjar.flixelgdx.graphics.FlixelState;
import me.stringdotjar.flixelgdx.graphics.FlixelCamera;
import me.stringdotjar.flixelgdx.graphics.display.FlixelCamera;
import me.stringdotjar.flixelgdx.graphics.display.FlixelState;
import me.stringdotjar.flixelgdx.logging.FlixelLogMode;
import me.stringdotjar.flixelgdx.logging.FlixelLogger;
import me.stringdotjar.flixelgdx.signal.FlixelSignal;
import me.stringdotjar.flixelgdx.signal.FlixelSignalData.MusicPlayedSignalData;
import me.stringdotjar.flixelgdx.signal.FlixelSignalData.UpdateSignalData;
Expand All @@ -20,9 +22,6 @@
import me.stringdotjar.flixelgdx.util.FlixelConstants;
import org.jetbrains.annotations.NotNull;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
* Global manager and utility class for Flixel.
*
Expand Down Expand Up @@ -54,8 +53,11 @@ public final class Flixel {
/** Has the global manager been initialized yet? */
private static boolean initialized = false;

/** The active logging mode used by the global logger. */
private static FlixelLogMode logMode = FlixelLogMode.SIMPLE;
/** 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;

/**
* Initializes the global manager.
Expand All @@ -78,6 +80,7 @@ public static void initialize(FlixelGame gameInstance) {
soundsGroup = engine.createGroup();
assetManager.setLoader(MASound.class, new MASoundLoader(engine, assetManager.getFileHandleResolver()));

defaultLogger = new FlixelLogger(FlixelLogMode.SIMPLE);
initialized = true;
}

Expand Down Expand Up @@ -344,15 +347,19 @@ public static void info(Object message) {
}

public static void info(String tag, Object message) {
outputLog(tag, message, FlixelLogLevel.INFO);
if (defaultLogger != null) {
defaultLogger.info(tag, message);
}
}

public static void warn(Object message) {
warn(FlixelConstants.System.LOG_TAG, message);
}

public static void warn(String tag, Object message) {
outputLog(tag, message, FlixelLogLevel.WARN);
if (defaultLogger != null) {
defaultLogger.warn(tag, message);
}
}

public static void error(String message) {
Expand All @@ -364,12 +371,26 @@ public static void error(String tag, Object message) {
}

public static void error(String tag, Object message, Throwable throwable) {
String msg = (throwable != null) ? (message + " | Exception: " + throwable) : message.toString();
outputLog(tag, msg, FlixelLogLevel.ERROR);
if (defaultLogger != null) {
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 FlixelLogger getLogger() {
return defaultLogger;
}

public static FlixelLogMode getLogMode() {
return logMode;
return defaultLogger.getLogMode();
}

public static FlixelGame getGame() {
Expand Down Expand Up @@ -429,7 +450,9 @@ public static boolean isFullscreen() {
}

public static void setLogMode(@NotNull FlixelLogMode mode) {
logMode = mode;
if (defaultLogger != null) {
defaultLogger.setLogMode(mode);
}
}

/**
Expand Down Expand Up @@ -463,93 +486,5 @@ public static final class Signals {
private Signals() {}
}

private static void outputLog(String tag, Object message, FlixelLogLevel level) {
StackWalker.StackFrame caller = StackWalker.getInstance()
.walk(s -> s.skip(3).findFirst())
.orElse(null);

String file = "UnknownFile.java:0";
String simpleFile = "UnknownFile.java:0";
String method = "unknownMethod()";
if (caller != null) {
file = caller.getFileName() + ":" + caller.getLineNumber();
String className = caller.getClassName();
int lastDot = className.lastIndexOf('.');
String packagePath = (lastDot > 0) ? className.substring(0, lastDot).replace('.', '/') : "";
simpleFile = packagePath.isEmpty()
? caller.getFileName() + ":" + caller.getLineNumber()
: packagePath + "/" + caller.getFileName() + ":" + caller.getLineNumber();
method = caller.getMethodName() + "()";
}

String rawMessage = (message != null) ? message.toString() : "null";
String color = switch (level) {
case INFO -> FlixelConstants.AsciiCodes.WHITE;
case WARN -> FlixelConstants.AsciiCodes.YELLOW;
case ERROR -> FlixelConstants.AsciiCodes.RED;
};
boolean underlineFile = (level == FlixelLogLevel.ERROR);
String plainLog;
String coloredLog;

if (logMode == FlixelLogMode.SIMPLE) {
plainLog = simpleFile + ": " + rawMessage;
coloredLog = colorText(simpleFile, color, true, false, underlineFile)
+ ": "
+ colorText(rawMessage, color, false, true, false);
} else {
String timestamp = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
String levelTag = "[" + level + "]";
String tagPart = "[" + tag + "]";
String filePart = "[" + file + "]";
String methodPart = "[" + method + "]";

// Plain text for the log file, no ANSI codes.
plainLog = timestamp + " " + levelTag + " " + tagPart + " " + filePart + " " + methodPart + " " + rawMessage;

// ANSI-colored version for the console.
coloredLog = colorText(timestamp + " ", color, false, false, false)
+ colorText(levelTag + " ", color, true, false, false)
+ colorText(tagPart + " ", color, true, false, false)
+ colorText(filePart + " ", color, true, false, underlineFile)
+ colorText(methodPart + " ", color, false, false, false)
+ colorText(rawMessage, color, false, true, false);
}

// Output and store the log message.
System.out.println(coloredLog);
if (game.canStoreLogs()) {
game.enqueueLog(plainLog);
}
}

private static String colorText(String text, String color, boolean bold, boolean italic, boolean underline) {
StringBuilder sb = new StringBuilder();
if (bold) {
sb.append(FlixelConstants.AsciiCodes.BOLD);
}
if (italic) {
sb.append(FlixelConstants.AsciiCodes.ITALIC);
}
if (underline) {
sb.append(FlixelConstants.AsciiCodes.UNDERLINE);
}
sb.append(color);
sb.append(text);
sb.append(FlixelConstants.AsciiCodes.RESET);
return sb.toString();
}

private Flixel() {}
}

enum FlixelLogLevel {
INFO,
WARN,
ERROR
}

enum FlixelLogMode {
SIMPLE,
DETAILED
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package me.stringdotjar.flixelgdx.graphics;
package me.stringdotjar.flixelgdx;

import com.badlogic.gdx.graphics.g2d.Batch;

import me.stringdotjar.flixelgdx.graphics.display.FlixelCamera;

/**
* This is the most generic Flixel object. Both {@link FlixelObject} and {@link FlixelCamera}
* extend this class. It has no size, position, or graphical data, only lifecycle flags and
Expand Down
Loading