|
|
@ -1,35 +1,15 @@ |
|
|
|
package mightypork.rogue; |
|
|
|
package mightypork.rogue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import junk.AppInitOptions; |
|
|
|
|
|
|
|
import mightypork.gamecore.backends.lwjgl.LwjglBackend; |
|
|
|
import mightypork.gamecore.backends.lwjgl.LwjglBackend; |
|
|
|
import mightypork.gamecore.backends.lwjgl.LwjglInputModule; |
|
|
|
|
|
|
|
import mightypork.gamecore.core.App; |
|
|
|
import mightypork.gamecore.core.App; |
|
|
|
import mightypork.gamecore.core.config.Config; |
|
|
|
|
|
|
|
import mightypork.gamecore.core.events.MainLoopRequest; |
|
|
|
import mightypork.gamecore.core.events.MainLoopRequest; |
|
|
|
import mightypork.gamecore.core.events.ShutdownEvent; |
|
|
|
import mightypork.gamecore.core.plugins.screenshot.ScreenshotRequestListener; |
|
|
|
import mightypork.gamecore.core.plugins.screenshot.ScreenshotRequest; |
|
|
|
|
|
|
|
import mightypork.gamecore.graphics.FullscreenToggleRequest; |
|
|
|
|
|
|
|
import mightypork.gamecore.graphics.GraphicsModule; |
|
|
|
|
|
|
|
import mightypork.gamecore.gui.events.ViewportChangeEvent; |
|
|
|
import mightypork.gamecore.gui.events.ViewportChangeEvent; |
|
|
|
import mightypork.gamecore.gui.events.ViewportChangeListener; |
|
|
|
import mightypork.gamecore.gui.events.ViewportChangeListener; |
|
|
|
import mightypork.gamecore.gui.screens.ScreenRegistry; |
|
|
|
|
|
|
|
import mightypork.gamecore.input.Trigger; |
|
|
|
|
|
|
|
import mightypork.gamecore.resources.Res; |
|
|
|
import mightypork.gamecore.resources.Res; |
|
|
|
import mightypork.rogue.RogueStateManager.RogueState; |
|
|
|
import mightypork.rogue.RogueStateManager.RogueState; |
|
|
|
import mightypork.rogue.events.RogueStateRequest; |
|
|
|
import mightypork.rogue.events.RogueStateRequest; |
|
|
|
import mightypork.rogue.screens.FpsOverlay; |
|
|
|
|
|
|
|
import mightypork.rogue.screens.LoadingOverlay; |
|
|
|
|
|
|
|
import mightypork.rogue.screens.game.ScreenGame; |
|
|
|
|
|
|
|
import mightypork.rogue.screens.menu.ScreenMainMenu; |
|
|
|
|
|
|
|
import mightypork.rogue.screens.select_world.ScreenSelectWorld; |
|
|
|
|
|
|
|
import mightypork.rogue.screens.story.ScreenStory; |
|
|
|
|
|
|
|
import mightypork.rogue.world.Inventory; |
|
|
|
|
|
|
|
import mightypork.rogue.world.WorldProvider; |
|
|
|
|
|
|
|
import mightypork.rogue.world.level.Level; |
|
|
|
|
|
|
|
import mightypork.utils.eventbus.BusEvent; |
|
|
|
|
|
|
|
import mightypork.utils.ion.Ion; |
|
|
|
|
|
|
|
import mightypork.utils.logging.Log; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -37,111 +17,34 @@ import mightypork.utils.logging.Log; |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Ondřej Hruška (MightyPork) |
|
|
|
* @author Ondřej Hruška (MightyPork) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public final class RogueApp extends App implements ViewportChangeListener { |
|
|
|
public final class RogueApp extends App implements ViewportChangeListener, ScreenshotRequestListener { |
|
|
|
|
|
|
|
|
|
|
|
public RogueApp() |
|
|
|
public RogueApp() |
|
|
|
{ |
|
|
|
{ |
|
|
|
super(new LwjglBackend()); |
|
|
|
super(new LwjglBackend()); |
|
|
|
|
|
|
|
|
|
|
|
final AppInitOptions opt = getInitOptions(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
opt.addRoutes(new RogueRoutes()); |
|
|
|
|
|
|
|
opt.addResources(new RogueResources()); |
|
|
|
|
|
|
|
opt.addKeys(new RogueKeys()); |
|
|
|
|
|
|
|
opt.addConfig(new RogueConfig()); |
|
|
|
|
|
|
|
opt.setBusLogging(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
opt.setConfigFile("config.ini", "Rogue config file"); |
|
|
|
|
|
|
|
opt.setLogOptions("logs", "runtime", 5, java.util.logging.Level.ALL); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void registerIonizables() |
|
|
|
public void onScreenshotRequest() |
|
|
|
{ |
|
|
|
|
|
|
|
super.registerIonizables(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ion.register(Level.class); |
|
|
|
|
|
|
|
Ion.register(Inventory.class); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected void initDisplay(GraphicsModule gfx) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// init based on config
|
|
|
|
|
|
|
|
final int w = Config.getValue("display.width"); |
|
|
|
|
|
|
|
final int h = Config.getValue("display.height"); |
|
|
|
|
|
|
|
final boolean fs = Config.getValue("display.fullscreen"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gfx.setSize(w, h); |
|
|
|
|
|
|
|
gfx.setResizable(true); |
|
|
|
|
|
|
|
gfx.setFullscreen(fs); |
|
|
|
|
|
|
|
gfx.setTitle(Const.TITLEBAR); |
|
|
|
|
|
|
|
gfx.setTargetFps(Const.FPS_RENDER); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gfx.createDisplay(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected void initScreens(ScreenRegistry screens) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
super.initScreens(screens); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* game screen references world provider instance */ |
|
|
|
|
|
|
|
WorldProvider.setBaseDir(this); |
|
|
|
|
|
|
|
getEventBus().subscribe(new RogueStateManager(this)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
screens.addScreen("main_menu", new ScreenMainMenu(this)); |
|
|
|
|
|
|
|
screens.addScreen("select_world", new ScreenSelectWorld(this)); |
|
|
|
|
|
|
|
screens.addScreen("game", new ScreenGame(this)); |
|
|
|
|
|
|
|
screens.addScreen("story", new ScreenStory(this)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
screens.addOverlay(new FpsOverlay(this)); |
|
|
|
|
|
|
|
screens.addOverlay(new LoadingOverlay(this)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected void initInputSystem(LwjglInputModule input) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// this will work only with reusable events (such as requests)
|
|
|
|
|
|
|
|
bindEventToKey(new FullscreenToggleRequest(), "global.fullscreen"); |
|
|
|
|
|
|
|
bindEventToKey(new ScreenshotRequest(), "global.screenshot"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bindEventToKey(new ShutdownEvent(), "global.quit"); |
|
|
|
|
|
|
|
bindEventToKey(new ShutdownEvent(), "global.quit_force"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void bindEventToKey(final BusEvent<?> event, String strokeName) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
getInput().bindKey(Config.getKeyStroke(strokeName), Trigger.RISING, new Runnable() { |
|
|
|
Res.sound("gui.shutter").play(0.8); |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void run() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
getEventBus().send(event); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void postInit() |
|
|
|
protected void postInit() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
bus().send(new MainLoopRequest(new Runnable() { |
|
|
|
getEventBus().send(new MainLoopRequest(new Runnable() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void run() |
|
|
|
public void run() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (Config.getValue("opt.show_story")) { |
|
|
|
if (cfg().getValue("opt.show_story")) { |
|
|
|
Config.setValue("opt.show_story", false); |
|
|
|
cfg().setValue("opt.show_story", false); |
|
|
|
getEventBus().send(new RogueStateRequest(RogueState.STORY, true)); |
|
|
|
bus().send(new RogueStateRequest(RogueState.STORY, true)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
getEventBus().send(new RogueStateRequest(RogueState.MAIN_MENU, true)); |
|
|
|
bus().send(new RogueStateRequest(RogueState.MAIN_MENU, true)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, false)); |
|
|
|
}, false)); |
|
|
@ -154,27 +57,11 @@ public final class RogueApp extends App implements ViewportChangeListener { |
|
|
|
// save viewport size to config file
|
|
|
|
// save viewport size to config file
|
|
|
|
final boolean fs = gfx().isFullscreen(); |
|
|
|
final boolean fs = gfx().isFullscreen(); |
|
|
|
|
|
|
|
|
|
|
|
Config.setValue("display.fullscreen", fs); |
|
|
|
cfg().setValue("display.fullscreen", fs); |
|
|
|
|
|
|
|
|
|
|
|
if (!fs) { |
|
|
|
if (!fs) { |
|
|
|
Config.setValue("display.width", gfx().getWidth()); |
|
|
|
cfg().setValue("display.width", gfx().getWidth()); |
|
|
|
Config.setValue("display.height", gfx().getHeight()); |
|
|
|
cfg().setValue("display.height", gfx().getHeight()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onScreenshotRequest() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// screenshot sound
|
|
|
|
|
|
|
|
Res.sound("gui.shutter").play(0.8); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected void writeLogHeader() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Log.i("## Starting Rogue v." + Const.VERSION + " ##"); |
|
|
|
|
|
|
|
super.writeLogHeader(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|