diff --git a/assets/oml.groovy b/assets/oml.groovy new file mode 100644 index 0000000..3bcee2c --- /dev/null +++ b/assets/oml.groovy @@ -0,0 +1,15 @@ +import me.stringdotjar.flixelgdx.Flixel +import me.stringdotjar.polyverse.script.type.AnotherType + +class Sob extends AnotherType { + + Sob() { + super('Sob') + } + + @Override + void onWindowFocused() { + super.onWindowFocused() + Flixel.info("i hate [insert particular ethnicity here]") + } +} diff --git a/assets/test.groovy b/assets/test.groovy index 0a291d2..fba075e 100644 --- a/assets/test.groovy +++ b/assets/test.groovy @@ -33,6 +33,12 @@ class TestScript extends SystemScript { super.onDispose() Flixel.info("TestClass", "Script has been disposed!") } + + @Override + void onWindowFocused() { + super.onWindowFocused() + Flixel.info("i like em young") + } } class TestScreen extends FlixelScreen { diff --git a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/FlixelGame.java b/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/FlixelGame.java index 36b8078..cfca1f4 100644 --- a/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/FlixelGame.java +++ b/flixelgdx/src/main/java/me/stringdotjar/flixelgdx/FlixelGame.java @@ -99,6 +99,7 @@ public void create() { @Override public void resize(int width, int height) { + windowSize.set(width, height); viewport.update(width, height, true); } @@ -109,10 +110,6 @@ public void render() { Flixel.Signals.preRender.dispatch(new RenderSignalData(delta)); - if (Flixel.keyJustPressed(Input.Keys.F11)) { - toggleFullscreen(); - } - // Update and render the current screen that's active. ScreenUtils.clear(Color.BLACK); viewport.apply(); diff --git a/funkin/src/main/java/me/stringdotjar/funkin/FunkinGame.java b/funkin/src/main/java/me/stringdotjar/funkin/FunkinGame.java index cfdce50..33ac973 100644 --- a/funkin/src/main/java/me/stringdotjar/funkin/FunkinGame.java +++ b/funkin/src/main/java/me/stringdotjar/funkin/FunkinGame.java @@ -1,5 +1,6 @@ package me.stringdotjar.funkin; +import com.badlogic.gdx.Input; import me.stringdotjar.flixelgdx.Flixel; import me.stringdotjar.flixelgdx.FlixelGame; import me.stringdotjar.flixelgdx.backend.FlixelPaths; @@ -28,6 +29,11 @@ public void create() { @Override public void render() { super.render(); + + if (Flixel.keyJustPressed(Input.Keys.F11)) { + toggleFullscreen(); + } + Polyverse.forAllScripts(script -> script.onRender(Flixel.getDelta())); } @@ -41,7 +47,7 @@ public void dispose() { public void onWindowFocused() { super.onWindowFocused(); Flixel.setMasterVolume(lastVolume); - Polyverse.forEachScript(SystemScript.class, SystemScript::onWindowFocused); + Polyverse.forEachScriptSuccessor(SystemScript.class, SystemScript::onWindowFocused); } @Override @@ -67,5 +73,6 @@ private void configurePolyverse() { Polyverse.registerScript(FlixelPaths.asset("test.groovy")); Polyverse.registerScript(FlixelPaths.asset("another_test.groovy")); + Polyverse.registerScript(FlixelPaths.asset("oml.groovy")); } } diff --git a/polyverse/src/main/java/me/stringdotjar/polyverse/Polyverse.java b/polyverse/src/main/java/me/stringdotjar/polyverse/Polyverse.java index a8383af..297105d 100644 --- a/polyverse/src/main/java/me/stringdotjar/polyverse/Polyverse.java +++ b/polyverse/src/main/java/me/stringdotjar/polyverse/Polyverse.java @@ -98,7 +98,7 @@ public static void registerScript(FileHandle handle) { } /** - * Executes an action for each script of a certain type, with error handling. + * Executes a function that pertains to a specific type for each script. * * @param type The class type of scripts to iterate over. * @param action The action to perform on each script. @@ -107,6 +107,21 @@ public static void forEachScript(Class type, Consumer a executeScriptList(getScripts(type), action); } + /** + * Executes a function for all scripts that are successors (subclasses or implementations) that are + * of a specific type. + * + * @param type The class type of scripts to iterate over, including its subtypes. + * @param action The function to perform on each script. + */ + public static void forEachScriptSuccessor(Class type, Consumer action) { + for (Class scriptType : scripts.keySet()) { + if (type.isAssignableFrom(scriptType)) { + executeScriptList(getScripts(scriptType), action); + } + } + } + /** * Executes an action for all scripts of all types, with error handling. Note that this function * is NOT recommended to be used frequently due to how generic it is. It's mainly intended for diff --git a/polyverse/src/main/java/me/stringdotjar/polyverse/script/type/AnotherType.java b/polyverse/src/main/java/me/stringdotjar/polyverse/script/type/AnotherType.java new file mode 100644 index 0000000..6e3e4fd --- /dev/null +++ b/polyverse/src/main/java/me/stringdotjar/polyverse/script/type/AnotherType.java @@ -0,0 +1,8 @@ +package me.stringdotjar.polyverse.script.type; + +public abstract class AnotherType extends SystemScript { + + public AnotherType(String id) { + super(id); + } +} diff --git a/polyverse/src/main/java/me/stringdotjar/polyverse/script/type/SystemScript.java b/polyverse/src/main/java/me/stringdotjar/polyverse/script/type/SystemScript.java index 1024e0e..0dd14fc 100644 --- a/polyverse/src/main/java/me/stringdotjar/polyverse/script/type/SystemScript.java +++ b/polyverse/src/main/java/me/stringdotjar/polyverse/script/type/SystemScript.java @@ -14,4 +14,6 @@ public void onWindowUnfocused() {} /** Called when the game window is minimized. */ public void onWindowMinimized(boolean iconified) {} + + public void rawr() {} }