parent
cafcf78cd2
commit
50cbc9479b
@ -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,8 +1,10 @@ |
|||||||
package mightypork.gamecore.core; |
package mightypork.gamecore.core.init.impl; |
||||||
|
|
||||||
|
|
||||||
import java.lang.Thread.UncaughtExceptionHandler; |
import java.lang.Thread.UncaughtExceptionHandler; |
||||||
|
|
||||||
|
import mightypork.gamecore.core.App; |
||||||
|
import mightypork.gamecore.core.init.InitTask; |
||||||
import mightypork.utils.annotations.Stub; |
import mightypork.utils.annotations.Stub; |
||||||
import mightypork.utils.logging.Log; |
import mightypork.utils.logging.Log; |
||||||
|
|
@ -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; |
import mightypork.gamecore.render.GraphicsModule; |
||||||
|
|
||||||
|
|
@ -1,8 +1,9 @@ |
|||||||
package mightypork.gamecore.core; |
package mightypork.gamecore.core.init.impl; |
||||||
|
|
||||||
|
|
||||||
import java.io.IOException; |
import java.io.IOException; |
||||||
|
|
||||||
|
import mightypork.gamecore.core.init.InitTask; |
||||||
import mightypork.utils.ion.Ion; |
import mightypork.utils.ion.Ion; |
||||||
import mightypork.utils.ion.IonInput; |
import mightypork.utils.ion.IonInput; |
||||||
import mightypork.utils.ion.IonOutput; |
import mightypork.utils.ion.IonOutput; |
@ -1,9 +1,11 @@ |
|||||||
package mightypork.gamecore.core; |
package mightypork.gamecore.core.init.impl; |
||||||
|
|
||||||
|
|
||||||
import java.io.File; |
import java.io.File; |
||||||
import java.util.logging.Level; |
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.Log; |
||||||
import mightypork.utils.logging.writers.LogWriter; |
import mightypork.utils.logging.writers.LogWriter; |
||||||
import mightypork.utils.string.StringUtil; |
import mightypork.utils.string.StringUtil; |
@ -1,8 +1,10 @@ |
|||||||
package mightypork.gamecore.core; |
package mightypork.gamecore.core.init.impl; |
||||||
|
|
||||||
|
|
||||||
import java.io.IOException; |
import java.io.IOException; |
||||||
|
|
||||||
|
import mightypork.gamecore.core.WorkDir; |
||||||
|
import mightypork.gamecore.core.init.InitTask; |
||||||
import mightypork.utils.logging.Log; |
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" }; |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue