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
8 changes: 5 additions & 3 deletions assets/test.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ class TestScreen extends FlixelScreen {
void create() {
super.create()

test = new FlixelSprite().loadGraphic(FlixelPaths.sharedImageAsset('NOTE_hold_assets'))
add(test)

bgColor = new Color(0, 1, 0, 1)

Flixel.playMusic('songs/darnell/Inst.ogg')

// test.changeX(-30)

test = new FlixelSprite().loadGraphic(FlixelPaths.sharedImageAsset('NOTE_hold_assets'))
add(test)
}

@Override
Expand Down
3 changes: 0 additions & 3 deletions flixelgdx/src/main/java/me/stringdotjar/flixelgdx/Flixel.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,6 @@ public static void playMusic(String path, float volume, boolean looping, boolean
/**
* Sets the game master/global volume, which is automatically applied to all current sounds.
*
* <p>(This is just a helper method for creating a faster version of {@code
* Flixel.getAudioEngine().setMasterVolume(float)}).
*
* @param volume The new master volume to set.
*/
public static void setMasterVolume(float volume) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package me.stringdotjar.flixelgdx.util;

import me.stringdotjar.flixelgdx.Flixel;

import javax.swing.JOptionPane;
import java.awt.EventQueue;
import java.lang.reflect.InvocationTargetException;

/**
* Utility class for handling operation related to the runtime environment, including OS detection,
Expand Down Expand Up @@ -93,9 +96,18 @@ public static void showErrorAlert(String title, Object message) {
* @param type The type of alert (e.g., JOptionPane.INFORMATION_MESSAGE).
*/
public static void showAlert(String title, Object message, int type) {
EventQueue.invokeLater(() -> {
JOptionPane.showMessageDialog(null, message, title, type);
});
String msg = message != null ? message.toString() : "null";
if (EventQueue.isDispatchThread()) {
JOptionPane.showMessageDialog(null, msg, title, type);
} else {
try {
EventQueue.invokeAndWait(() -> {
JOptionPane.showMessageDialog(null, msg, title, type);
});
} catch (InterruptedException | InvocationTargetException e) {
Flixel.error(FlixelConstants.System.LOG_TAG, "Failed to show alert message.", e);
}
}
}

private FlixelRuntimeUtil() {}
Expand Down
28 changes: 18 additions & 10 deletions polyverse/src/main/java/me/stringdotjar/polyverse/Polyverse.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.badlogic.gdx.files.FileHandle;
import groovy.lang.GroovyClassLoader;
import me.stringdotjar.flixelgdx.Flixel;
import me.stringdotjar.flixelgdx.util.FlixelRuntimeUtil;
import me.stringdotjar.polyverse.script.type.Script;

import java.util.ArrayList;
Expand Down Expand Up @@ -81,10 +82,7 @@ public static void registerScript(FileHandle handle) {
var typeScripts = scripts.get(mostSpecificType);
if (!typeScripts.contains(script)) {
typeScripts.add(script);
Flixel.info(
"Polyverse",
"Registered Polyverse script \""
+ script.getClass().getSimpleName()
Flixel.info("Polyverse", "Registered Polyverse script \"" + script.getClass().getSimpleName()
+ "\" of script type \""
+ mostSpecificType.getSimpleName()
+ "\".");
Expand All @@ -93,7 +91,12 @@ public static void registerScript(FileHandle handle) {
script.onCreate();
}
} catch (Exception e) {
Flixel.error("Polyverse", "Failed to load script: " + handle.path(), e);
StringBuilder errorWindowMessage = new StringBuilder();
errorWindowMessage.append("There was an uncaught exception for a script during compilation.\n");
errorWindowMessage.append("Location: ").append(handle.path()).append("\n");
errorWindowMessage.append("Exception: ").append(e);
Flixel.error("Polyverse", "Failed to compile script: " + handle.path(), e);
FlixelRuntimeUtil.showErrorAlert("Polyverse Script Exception", errorWindowMessage);
}
}

Expand Down Expand Up @@ -136,18 +139,23 @@ public static <T extends Script> void forAllScripts(Consumer<T> action) {
}
}

private static <T extends Script> void executeScriptList(
List<? extends Script> scriptList, Consumer<T> action) {
// Use a standard for-loop to prevent ConcurrentModificationException
// and ensure we are iterating over the current snapshot of scripts.
private static <T extends Script> void executeScriptList(List<? extends Script> scriptList, Consumer<T> action) {
// Use a standard for-loop to prevent ConcurrentModificationException and ensure we are
// iterating over the current snapshot of scripts. Plus, it's also to prevent stuttering since we are using
// ArrayLists for storing scripts.
for (int i = 0; i < scriptList.size(); i++) {
@SuppressWarnings("unchecked")
T script = (T) scriptList.get(i);
if (script != null) {
try {
action.accept(script);
} catch (Exception e) {
Flixel.error("Polyverse", "Error in " + script.getClass().getSimpleName(), e);
StringBuilder errorMsg = new StringBuilder();
errorMsg.append("There was an uncaught exception for a script when executing it.\n");
errorMsg.append("Script ID: \"").append(script.getId()).append("\"\n");
errorMsg.append("Exception: ").append(e);
Flixel.error("Polyverse", errorMsg, e);
FlixelRuntimeUtil.showErrorAlert("Polyverse Script Exception", errorMsg);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
public abstract class Script {

/** The unique identifier {@code this} script. */
protected String id;
private final String id;

public Script(String id) {
this.id = id;
Expand Down