From 50cbc9479b17f8f3990394084f6dd74cde92c3d6 Mon Sep 17 00:00:00 2001 From: MightyPork Date: Sat, 26 Jul 2014 23:21:30 +0200 Subject: [PATCH] reorganization --- .../lwjgl/InitTaskRedirectSlickLog.java | 2 +- src/mightypork/gamecore/core/App.java | 3 +- src/mightypork/gamecore/core/InitTask.java | 73 ------------------- .../gamecore/core/config/InitTaskConfig.java | 2 +- .../{InitTasks.java => init/InitTask.java} | 72 +++++++++++++++++- .../{ => init/impl}/InitTaskCrashHandler.java | 4 +- .../core/{ => init/impl}/InitTaskDisplay.java | 3 +- .../{ => init/impl}/InitTaskIonizables.java | 3 +- .../core/{ => init/impl}/InitTaskLog.java | 4 +- .../{ => init/impl}/InitTaskLogHeader.java | 4 +- .../core/{ => init/impl}/InitTaskWorkdir.java | 5 +- .../screenshot/InitTaskPluginScreenshot.java | 68 +++++++++++++++++ 12 files changed, 159 insertions(+), 84 deletions(-) delete mode 100644 src/mightypork/gamecore/core/InitTask.java rename src/mightypork/gamecore/core/{InitTasks.java => init/InitTask.java} (52%) rename src/mightypork/gamecore/core/{ => init/impl}/InitTaskCrashHandler.java (85%) rename src/mightypork/gamecore/core/{ => init/impl}/InitTaskDisplay.java (94%) rename src/mightypork/gamecore/core/{ => init/impl}/InitTaskIonizables.java (93%) rename src/mightypork/gamecore/core/{ => init/impl}/InitTaskLog.java (94%) rename src/mightypork/gamecore/core/{ => init/impl}/InitTaskLogHeader.java (88%) rename src/mightypork/gamecore/core/{ => init/impl}/InitTaskWorkdir.java (93%) create mode 100644 src/mightypork/gamecore/core/plugins/screenshot/InitTaskPluginScreenshot.java diff --git a/src/mightypork/gamecore/backend/lwjgl/InitTaskRedirectSlickLog.java b/src/mightypork/gamecore/backend/lwjgl/InitTaskRedirectSlickLog.java index e9a8f00..83446c3 100644 --- a/src/mightypork/gamecore/backend/lwjgl/InitTaskRedirectSlickLog.java +++ b/src/mightypork/gamecore/backend/lwjgl/InitTaskRedirectSlickLog.java @@ -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; diff --git a/src/mightypork/gamecore/core/App.java b/src/mightypork/gamecore/core/App.java index afed20d..1b49383 100644 --- a/src/mightypork/gamecore/core/App.java +++ b/src/mightypork/gamecore/core/App.java @@ -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 orderedInitializers = InitTasks.inOrder(initializers); + List orderedInitializers = InitTask.inOrder(initializers); for (InitTask initializer : orderedInitializers) { Log.f1("Running init task \"" + initializer.getName() + "\"..."); diff --git a/src/mightypork/gamecore/core/InitTask.java b/src/mightypork/gamecore/core/InitTask.java deleted file mode 100644 index 90014c2..0000000 --- a/src/mightypork/gamecore/core/InitTask.java +++ /dev/null @@ -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.
- * 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).
- * 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.
- * Depending on itself or creating a circular dependency will cause error.
- * 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[] {}; - } -} diff --git a/src/mightypork/gamecore/core/config/InitTaskConfig.java b/src/mightypork/gamecore/core/config/InitTaskConfig.java index 87bf139..c877f29 100644 --- a/src/mightypork/gamecore/core/config/InitTaskConfig.java +++ b/src/mightypork/gamecore/core/config/InitTaskConfig.java @@ -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; diff --git a/src/mightypork/gamecore/core/InitTasks.java b/src/mightypork/gamecore/core/init/InitTask.java similarity index 52% rename from src/mightypork/gamecore/core/InitTasks.java rename to src/mightypork/gamecore/core/init/InitTask.java index bf58f65..a2f939b 100644 --- a/src/mightypork/gamecore/core/InitTasks.java +++ b/src/mightypork/gamecore/core/init/InitTask.java @@ -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.
+ * 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).
+ * 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.
+ * Depending on itself or creating a circular dependency will cause error.
+ * 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 diff --git a/src/mightypork/gamecore/core/InitTaskCrashHandler.java b/src/mightypork/gamecore/core/init/impl/InitTaskCrashHandler.java similarity index 85% rename from src/mightypork/gamecore/core/InitTaskCrashHandler.java rename to src/mightypork/gamecore/core/init/impl/InitTaskCrashHandler.java index f753044..20c23fe 100644 --- a/src/mightypork/gamecore/core/InitTaskCrashHandler.java +++ b/src/mightypork/gamecore/core/init/impl/InitTaskCrashHandler.java @@ -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; diff --git a/src/mightypork/gamecore/core/InitTaskDisplay.java b/src/mightypork/gamecore/core/init/impl/InitTaskDisplay.java similarity index 94% rename from src/mightypork/gamecore/core/InitTaskDisplay.java rename to src/mightypork/gamecore/core/init/impl/InitTaskDisplay.java index b9b8fbc..7eed42d 100644 --- a/src/mightypork/gamecore/core/InitTaskDisplay.java +++ b/src/mightypork/gamecore/core/init/impl/InitTaskDisplay.java @@ -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; diff --git a/src/mightypork/gamecore/core/InitTaskIonizables.java b/src/mightypork/gamecore/core/init/impl/InitTaskIonizables.java similarity index 93% rename from src/mightypork/gamecore/core/InitTaskIonizables.java rename to src/mightypork/gamecore/core/init/impl/InitTaskIonizables.java index 38ba10a..20977f8 100644 --- a/src/mightypork/gamecore/core/InitTaskIonizables.java +++ b/src/mightypork/gamecore/core/init/impl/InitTaskIonizables.java @@ -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; diff --git a/src/mightypork/gamecore/core/InitTaskLog.java b/src/mightypork/gamecore/core/init/impl/InitTaskLog.java similarity index 94% rename from src/mightypork/gamecore/core/InitTaskLog.java rename to src/mightypork/gamecore/core/init/impl/InitTaskLog.java index 903ba63..d386d81 100644 --- a/src/mightypork/gamecore/core/InitTaskLog.java +++ b/src/mightypork/gamecore/core/init/impl/InitTaskLog.java @@ -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; diff --git a/src/mightypork/gamecore/core/InitTaskLogHeader.java b/src/mightypork/gamecore/core/init/impl/InitTaskLogHeader.java similarity index 88% rename from src/mightypork/gamecore/core/InitTaskLogHeader.java rename to src/mightypork/gamecore/core/init/impl/InitTaskLogHeader.java index 4b9161d..2de6266 100644 --- a/src/mightypork/gamecore/core/InitTaskLogHeader.java +++ b/src/mightypork/gamecore/core/init/impl/InitTaskLogHeader.java @@ -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; diff --git a/src/mightypork/gamecore/core/InitTaskWorkdir.java b/src/mightypork/gamecore/core/init/impl/InitTaskWorkdir.java similarity index 93% rename from src/mightypork/gamecore/core/InitTaskWorkdir.java rename to src/mightypork/gamecore/core/init/impl/InitTaskWorkdir.java index 8fdde07..c54c54b 100644 --- a/src/mightypork/gamecore/core/InitTaskWorkdir.java +++ b/src/mightypork/gamecore/core/init/impl/InitTaskWorkdir.java @@ -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; diff --git a/src/mightypork/gamecore/core/plugins/screenshot/InitTaskPluginScreenshot.java b/src/mightypork/gamecore/core/plugins/screenshot/InitTaskPluginScreenshot.java new file mode 100644 index 0000000..010b402 --- /dev/null +++ b/src/mightypork/gamecore/core/plugins/screenshot/InitTaskPluginScreenshot.java @@ -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" }; + } + +}