reorganization
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package mightypork.gamecore.backend.lwjgl;
|
||||
|
||||
|
||||
import mightypork.gamecore.core.InitTask;
|
||||
import mightypork.gamecore.core.init.InitTask;
|
||||
import mightypork.utils.logging.writers.LogWriter;
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.util.Map;
|
||||
|
||||
import mightypork.gamecore.backend.Backend;
|
||||
import mightypork.gamecore.core.config.Config;
|
||||
import mightypork.gamecore.core.init.InitTask;
|
||||
import mightypork.gamecore.core.plugins.AppPlugin;
|
||||
import mightypork.gamecore.render.GraphicsModule;
|
||||
import mightypork.gamecore.resources.audio.AudioModule;
|
||||
@@ -124,7 +125,7 @@ public class App extends BusNode {
|
||||
Log.i("=== Starting initialization sequence ===");
|
||||
|
||||
// sort initializers by order.
|
||||
List<InitTask> orderedInitializers = InitTasks.inOrder(initializers);
|
||||
List<InitTask> orderedInitializers = InitTask.inOrder(initializers);
|
||||
|
||||
for (InitTask initializer : orderedInitializers) {
|
||||
Log.f1("Running init task \"" + initializer.getName() + "\"...");
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
package mightypork.gamecore.core;
|
||||
|
||||
|
||||
import mightypork.utils.annotations.Stub;
|
||||
|
||||
|
||||
/**
|
||||
* App initializer. A sequence of initializers is executed once the start()
|
||||
* method on App is called. Adding initializers is one way to customize the App
|
||||
* behavior and features.
|
||||
*
|
||||
* @author Ondřej Hruška (MightyPork)
|
||||
*/
|
||||
public abstract class InitTask {
|
||||
|
||||
protected App app;
|
||||
|
||||
|
||||
/**
|
||||
* Assign the initialized app instance to a protected "app" field.
|
||||
*
|
||||
* @param app app
|
||||
*/
|
||||
public void bind(App app)
|
||||
{
|
||||
if (this.app != null) {
|
||||
throw new IllegalStateException("App instance is already set.");
|
||||
}
|
||||
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An intialization method that is called before the run() method.<br>
|
||||
* This method should be left unimplemented in the task, and can be used to
|
||||
* configure the init task when using it as anonymous inner type.
|
||||
*/
|
||||
@Stub
|
||||
public void init()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run the initalizer on app.
|
||||
*/
|
||||
public abstract void run();
|
||||
|
||||
|
||||
/**
|
||||
* Get name of this initializer (for dependency resolver).<br>
|
||||
* The name should be short, snake_case and precise.
|
||||
*
|
||||
* @return name
|
||||
*/
|
||||
public abstract String getName();
|
||||
|
||||
|
||||
/**
|
||||
* Get what other initializers must be already loaded before this can load.<br>
|
||||
* Depending on itself or creating a circular dependency will cause error.<br>
|
||||
* If the dependencies cannot be satisfied, the initialization sequence will
|
||||
* be aborted.
|
||||
*
|
||||
* @return array of names of required initializers.
|
||||
*/
|
||||
@Stub
|
||||
public String[] getDependencies()
|
||||
{
|
||||
return new String[] {};
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package mightypork.gamecore.core.config;
|
||||
|
||||
|
||||
import mightypork.gamecore.core.InitTask;
|
||||
import mightypork.gamecore.core.init.InitTask;
|
||||
import mightypork.utils.annotations.Stub;
|
||||
import mightypork.utils.exceptions.IllegalValueException;
|
||||
|
||||
|
||||
+70
-2
@@ -1,4 +1,4 @@
|
||||
package mightypork.gamecore.core;
|
||||
package mightypork.gamecore.core.init;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -7,10 +7,78 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import mightypork.gamecore.core.App;
|
||||
import mightypork.utils.annotations.Stub;
|
||||
import mightypork.utils.logging.Log;
|
||||
|
||||
|
||||
public class InitTasks {
|
||||
/**
|
||||
* App initializer. A sequence of initializers is executed once the start()
|
||||
* method on App is called. Adding initializers is one way to customize the App
|
||||
* behavior and features.
|
||||
*
|
||||
* @author Ondřej Hruška (MightyPork)
|
||||
*/
|
||||
public abstract class InitTask {
|
||||
|
||||
protected App app;
|
||||
|
||||
|
||||
/**
|
||||
* Assign the initialized app instance to a protected "app" field.
|
||||
*
|
||||
* @param app app
|
||||
*/
|
||||
public void bind(App app)
|
||||
{
|
||||
if (this.app != null) {
|
||||
throw new IllegalStateException("App instance is already set.");
|
||||
}
|
||||
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An intialization method that is called before the run() method.<br>
|
||||
* This method should be left unimplemented in the task, and can be used to
|
||||
* configure the init task when using it as anonymous inner type.
|
||||
*/
|
||||
@Stub
|
||||
public void init()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run the initalizer on app.
|
||||
*/
|
||||
public abstract void run();
|
||||
|
||||
|
||||
/**
|
||||
* Get name of this initializer (for dependency resolver).<br>
|
||||
* The name should be short, snake_case and precise.
|
||||
*
|
||||
* @return name
|
||||
*/
|
||||
public abstract String getName();
|
||||
|
||||
|
||||
/**
|
||||
* Get what other initializers must be already loaded before this can load.<br>
|
||||
* Depending on itself or creating a circular dependency will cause error.<br>
|
||||
* If the dependencies cannot be satisfied, the initialization sequence will
|
||||
* be aborted.
|
||||
*
|
||||
* @return array of names of required initializers.
|
||||
*/
|
||||
@Stub
|
||||
public String[] getDependencies()
|
||||
{
|
||||
return new String[] {};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Order init tasks so that all dependencies are loaded before thye are
|
||||
+3
-1
@@ -1,8 +1,10 @@
|
||||
package mightypork.gamecore.core;
|
||||
package mightypork.gamecore.core.init.impl;
|
||||
|
||||
|
||||
import java.lang.Thread.UncaughtExceptionHandler;
|
||||
|
||||
import mightypork.gamecore.core.App;
|
||||
import mightypork.gamecore.core.init.InitTask;
|
||||
import mightypork.utils.annotations.Stub;
|
||||
import mightypork.utils.logging.Log;
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package mightypork.gamecore.core;
|
||||
package mightypork.gamecore.core.init.impl;
|
||||
|
||||
|
||||
import mightypork.gamecore.core.init.InitTask;
|
||||
import mightypork.gamecore.render.GraphicsModule;
|
||||
|
||||
|
||||
+2
-1
@@ -1,8 +1,9 @@
|
||||
package mightypork.gamecore.core;
|
||||
package mightypork.gamecore.core.init.impl;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import mightypork.gamecore.core.init.InitTask;
|
||||
import mightypork.utils.ion.Ion;
|
||||
import mightypork.utils.ion.IonInput;
|
||||
import mightypork.utils.ion.IonOutput;
|
||||
+3
-1
@@ -1,9 +1,11 @@
|
||||
package mightypork.gamecore.core;
|
||||
package mightypork.gamecore.core.init.impl;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import mightypork.gamecore.core.WorkDir;
|
||||
import mightypork.gamecore.core.init.InitTask;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.logging.writers.LogWriter;
|
||||
import mightypork.utils.string.StringUtil;
|
||||
+3
-1
@@ -1,8 +1,10 @@
|
||||
package mightypork.gamecore.core;
|
||||
package mightypork.gamecore.core.init.impl;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import mightypork.gamecore.core.WorkDir;
|
||||
import mightypork.gamecore.core.init.InitTask;
|
||||
import mightypork.utils.logging.Log;
|
||||
|
||||
|
||||
+4
-1
@@ -1,4 +1,4 @@
|
||||
package mightypork.gamecore.core;
|
||||
package mightypork.gamecore.core.init.impl;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
@@ -8,6 +8,9 @@ import java.util.Map.Entry;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import mightypork.gamecore.core.App;
|
||||
import mightypork.gamecore.core.WorkDir;
|
||||
import mightypork.gamecore.core.init.InitTask;
|
||||
import mightypork.utils.annotations.Stub;
|
||||
import mightypork.utils.files.InstanceLock;
|
||||
import mightypork.utils.logging.Log;
|
||||
@@ -0,0 +1,68 @@
|
||||
package mightypork.gamecore.core.plugins.screenshot;
|
||||
|
||||
|
||||
import mightypork.gamecore.core.WorkDir;
|
||||
import mightypork.gamecore.core.init.InitTask;
|
||||
|
||||
|
||||
/**
|
||||
* Register screenshot plugin to the App.
|
||||
*
|
||||
* @author Ondřej Hruška (MightyPork)
|
||||
*/
|
||||
public class InitTaskPluginScreenshot extends InitTask {
|
||||
|
||||
private String screenshotDir;
|
||||
|
||||
|
||||
/**
|
||||
* Initialize to use the "screenshots" directory
|
||||
*/
|
||||
public InitTaskPluginScreenshot() {
|
||||
this("screenshots");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize to use the given directory for saving.
|
||||
*
|
||||
* @param dir screenshot dir (relative to workdir)
|
||||
*/
|
||||
public InitTaskPluginScreenshot(String dir) {
|
||||
this.screenshotDir = dir;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set screenshot directory
|
||||
*
|
||||
* @param dir screenshot dir (relative to workdir)
|
||||
*/
|
||||
public void setScreenshotDir(String dir)
|
||||
{
|
||||
this.screenshotDir = dir;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
WorkDir.addPath("_screenshot_dir", screenshotDir);
|
||||
app.addPlugin(new ScreenshotPlugin());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "plugin_screenshot";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String[] getDependencies()
|
||||
{
|
||||
return new String[] { "workdir" };
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user