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
15 changes: 15 additions & 0 deletions assets/oml.groovy
Original file line number Diff line number Diff line change
@@ -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]")
}
}
6 changes: 6 additions & 0 deletions assets/test.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public void create() {

@Override
public void resize(int width, int height) {
windowSize.set(width, height);
viewport.update(width, height, true);
}

Expand All @@ -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();
Expand Down
9 changes: 8 additions & 1 deletion funkin/src/main/java/me/stringdotjar/funkin/FunkinGame.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()));
}

Expand All @@ -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
Expand All @@ -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"));
}
}
17 changes: 16 additions & 1 deletion polyverse/src/main/java/me/stringdotjar/polyverse/Polyverse.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -107,6 +107,21 @@ public static <T extends Script> void forEachScript(Class<T> type, Consumer<T> 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 <T extends Script> void forEachScriptSuccessor(Class<T> type, Consumer<T> action) {
for (Class<? extends Script> 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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package me.stringdotjar.polyverse.script.type;

public abstract class AnotherType extends SystemScript {

public AnotherType(String id) {
super(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public void onWindowUnfocused() {}

/** Called when the game window is minimized. */
public void onWindowMinimized(boolean iconified) {}

public void rawr() {}
}