bugfixes, bus tweaks

v5stable
ondra 11 years ago
parent 6dad9c2302
commit f082608852
  1. 2
      src/mightypork/gamecore/Config.java
  2. 2
      src/mightypork/gamecore/eventbus/clients/BusNode.java
  3. 23
      src/mightypork/gamecore/eventbus/clients/ClientList.java
  4. 51
      src/mightypork/gamecore/eventbus/clients/DelegatingList.java
  5. 13
      src/mightypork/gamecore/gui/components/input/ClickableWrapper.java
  6. 9
      src/mightypork/gamecore/gui/components/layout/linear/AbstractLinearWrapper.java
  7. 6
      src/mightypork/gamecore/gui/screens/ScreenLayer.java
  8. 4
      src/mightypork/gamecore/gui/screens/ScreenRegistry.java
  9. 1
      src/mightypork/gamecore/input/InputSystem.java
  10. 53
      src/mightypork/gamecore/input/KeyStroke.java
  11. 5
      src/mightypork/gamecore/input/Keys.java
  12. 2
      src/mightypork/gamecore/resources/AsyncResourceLoader.java
  13. 2
      src/mightypork/gamecore/util/files/config/SortedProperties.java
  14. 4
      src/mightypork/rogue/Launcher.java
  15. 1
      src/mightypork/rogue/RogueApp.java
  16. 9
      src/mightypork/rogue/RogueKeys.java
  17. 2
      src/mightypork/rogue/screens/FpsOverlay.java
  18. 5
      src/mightypork/rogue/screens/game/AskSaveLayer.java
  19. 17
      src/mightypork/rogue/screens/game/DeathLayer.java
  20. 5
      src/mightypork/rogue/screens/game/InventoryLayer.java
  21. 3
      src/mightypork/rogue/screens/game/ScreenGame.java
  22. 5
      src/mightypork/rogue/screens/menu/ScreenMainMenu.java
  23. 5
      src/mightypork/rogue/screens/select_world/ScreenSelectWorld.java
  24. 4
      src/mightypork/rogue/world/World.java
  25. 5
      src/mightypork/rogue/world/WorldProvider.java
  26. 4
      src/mightypork/rogue/world/events/PlayerKilledEvent.java
  27. 88
      src/mightypork/rogue/world/gui/interaction/MIPKeyboard.java

@ -119,7 +119,7 @@ public class Config {
public static void init(File file, String comment) public static void init(File file, String comment)
{ {
cfg = new PropertyManager(file, comment); cfg = new PropertyManager(file, comment);
cfg.cfgNewlineBeforeComments(false); cfg.cfgNewlineBeforeComments(true);
cfg.cfgSeparateSections(true); cfg.cfgSeparateSections(true);
} }

@ -48,7 +48,7 @@ public abstract class BusNode implements BusAccess, ClientHub {
@Override @Override
public final boolean isListening() public boolean isListening()
{ {
return listening; return listening;
} }

@ -0,0 +1,23 @@
package mightypork.gamecore.eventbus.clients;
import java.util.ArrayList;
import java.util.Collection;
import mightypork.gamecore.gui.Enableable;
/**
* Array-list with varargs constructor
*
* @author MightyPork
*/
public class ClientList extends ArrayList<Object> {
public ClientList(Object... clients) {
for (Object c : clients) {
super.add(c);
}
}
}

@ -0,0 +1,51 @@
package mightypork.gamecore.eventbus.clients;
import java.util.ArrayList;
import java.util.Collection;
import mightypork.gamecore.gui.Enableable;
/**
* Basic delegating client
*
* @author MightyPork
*/
public class DelegatingList extends ClientList implements DelegatingClient, Enableable {
private boolean enabled = true;
public DelegatingList(Object... clients) {
super(clients);
}
@Override
public Collection<?> getChildClients()
{
return this;
}
@Override
public boolean doesDelegate()
{
return isEnabled();
}
@Override
public void setEnabled(boolean yes)
{
enabled = yes;
}
@Override
public boolean isEnabled()
{
return enabled;
}
}

@ -1,28 +1,25 @@
package mightypork.gamecore.gui.components.input; package mightypork.gamecore.gui.components.input;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import mightypork.gamecore.eventbus.clients.ClientList;
import mightypork.gamecore.eventbus.clients.DelegatingClient; import mightypork.gamecore.eventbus.clients.DelegatingClient;
import mightypork.gamecore.eventbus.clients.DelegatingList;
import mightypork.gamecore.gui.components.Component; import mightypork.gamecore.gui.components.Component;
public class ClickableWrapper extends ClickableComponent implements DelegatingClient { public class ClickableWrapper extends ClickableComponent implements DelegatingClient {
private final Component wrapped; private final Component wrapped;
private final List<Component> list; private final ClientList list;
public ClickableWrapper(Component wrapped) public ClickableWrapper(Component wrapped) {
{
this.wrapped = wrapped; this.wrapped = wrapped;
wrapped.setRect(this); wrapped.setRect(this);
list = new ArrayList<>(1); list = new ClientList(wrapped);
list.add(wrapped);
} }

@ -5,6 +5,7 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import mightypork.gamecore.eventbus.clients.ClientList;
import mightypork.gamecore.eventbus.clients.DelegatingClient; import mightypork.gamecore.eventbus.clients.DelegatingClient;
import mightypork.gamecore.gui.components.Component; import mightypork.gamecore.gui.components.Component;
import mightypork.gamecore.gui.components.LinearComponent; import mightypork.gamecore.gui.components.LinearComponent;
@ -18,14 +19,13 @@ import mightypork.gamecore.gui.components.LinearComponent;
public abstract class AbstractLinearWrapper extends LinearComponent implements DelegatingClient { public abstract class AbstractLinearWrapper extends LinearComponent implements DelegatingClient {
protected final Component wrapped; protected final Component wrapped;
private final List<Component> list; private final ClientList list;
/** /**
* @param wrapped wrapped component. Can be null. * @param wrapped wrapped component. Can be null.
*/ */
public AbstractLinearWrapper(Component wrapped) public AbstractLinearWrapper(Component wrapped) {
{
this.wrapped = wrapped; this.wrapped = wrapped;
if (wrapped != null) { if (wrapped != null) {
if (wrapped instanceof LinearComponent) { if (wrapped instanceof LinearComponent) {
@ -36,8 +36,7 @@ public abstract class AbstractLinearWrapper extends LinearComponent implements D
} }
} }
list = new ArrayList<>(1); list = new ClientList(wrapped);
list.add(wrapped);
} }

@ -50,5 +50,11 @@ public abstract class ScreenLayer extends Overlay {
protected void onScreenLeave() protected void onScreenLeave()
{ {
} }
@Override
public boolean isListening()
{
return (isVisible() || isEnabled()) && super.isListening();
}
} }

@ -32,8 +32,7 @@ public class ScreenRegistry extends AppModule implements ScreenRequestListener,
/** /**
* @param app app access * @param app app access
*/ */
public ScreenRegistry(AppAccess app) public ScreenRegistry(AppAccess app) {
{
super(app); super(app);
} }
@ -41,6 +40,7 @@ public class ScreenRegistry extends AppModule implements ScreenRequestListener,
/** /**
* Add a screen * Add a screen
* *
* @param name screen key for calling
* @param screen added screen * @param screen added screen
*/ */
public void addScreen(String name, Screen screen) public void addScreen(String name, Screen screen)

@ -2,7 +2,6 @@ package mightypork.gamecore.input;
import mightypork.gamecore.core.AppAccess; import mightypork.gamecore.core.AppAccess;
import mightypork.gamecore.core.events.ShudownRequest;
import mightypork.gamecore.core.events.UserQuitRequest; import mightypork.gamecore.core.events.UserQuitRequest;
import mightypork.gamecore.eventbus.clients.RootBusNode; import mightypork.gamecore.eventbus.clients.RootBusNode;
import mightypork.gamecore.eventbus.events.Updateable; import mightypork.gamecore.eventbus.events.Updateable;

@ -1,7 +1,6 @@
package mightypork.gamecore.input; package mightypork.gamecore.input;
import mightypork.gamecore.util.math.constraints.Pollable;
import mightypork.gamecore.util.strings.StringUtils; import mightypork.gamecore.util.strings.StringUtils;
import org.lwjgl.input.Keyboard; import org.lwjgl.input.Keyboard;
@ -12,8 +11,8 @@ import org.lwjgl.input.Keyboard;
* *
* @author MightyPork * @author MightyPork
*/ */
public class KeyStroke { //implements Pollable public class KeyStroke { //implements Pollable
public static enum Edge public static enum Edge
{ {
FALLING, RISING; FALLING, RISING;
@ -22,8 +21,6 @@ public class KeyStroke { //implements Pollable
private int mod; private int mod;
private int key; private int key;
// private boolean wasDown;
/** /**
* KeyStroke * KeyStroke
@ -31,8 +28,7 @@ public class KeyStroke { //implements Pollable
* @param key key code * @param key key code
* @param mod_mask mods mask * @param mod_mask mods mask
*/ */
public KeyStroke(int key, int mod_mask) public KeyStroke(int key, int mod_mask) {
{
setTo(key, mod_mask); setTo(key, mod_mask);
} }
@ -42,8 +38,7 @@ public class KeyStroke { //implements Pollable
* *
* @param key key code * @param key key code
*/ */
public KeyStroke(int key) public KeyStroke(int key) {
{
this(key, Keys.MOD_NONE); this(key, Keys.MOD_NONE);
} }
@ -64,43 +59,9 @@ public class KeyStroke { //implements Pollable
{ {
this.key = key; this.key = key;
this.mod = mod_mask | Keys.keyToMod(key); // for mods alone this.mod = mod_mask | Keys.keyToMod(key); // for mods alone
// this.wasDown = (InputSystem.isReady() ? isDown() : false);
} }
// /**
// * Set current state as the last state (ignore it on next trigger event)
// */
// @Override
// public void poll()
// {
// wasDown = isDown();
// }
// public boolean tryTrigger(Edge edge)
// {
// final boolean down = isDown() && !wasDown;
// final boolean up = !isDown() && wasDown;
//
// boolean retval = false;
//
// switch (edge) {
// case FALLING:
// retval = !wasDown && down;
// break;
//
// case RISING:
// retval = wasDown && up;
// break;
// }
//
// wasDown = isDown();
//
// return retval;
// }
public String toDataString() public String toDataString()
{ {
String s = ""; String s = "";
@ -130,12 +91,10 @@ public class KeyStroke { //implements Pollable
final String keyStr = StringUtils.fromLastChar(dataString1, '+'); final String keyStr = StringUtils.fromLastChar(dataString1, '+');
final String modStr = StringUtils.toLastChar(dataString1, '+'); final String modStr = StringUtils.toLastChar(dataString1, '+');
this.key = Keys.keyFromString(keyStr); setTo(Keys.keyFromString(keyStr), Keys.modFromString(modStr));
this.mod = Keys.modFromString(modStr);
} else { } else {
this.key = Keys.keyFromString(dataString1); setTo(Keys.keyFromString(dataString1), Keys.MOD_NONE);
this.mod = Keys.MOD_NONE;
} }
} }

@ -166,8 +166,9 @@ public class Keys {
loadAliasMap.put("BACKSPACE", "BACK"); loadAliasMap.put("BACKSPACE", "BACK");
saveAliasMap.put("RETURN", "ENTER"); saveAliasMap.put("RETURN", "ENTER");
saveAliasMap.put("NEXT", "PAGE_DOWN"); saveAliasMap.put("ESCAPE", "ESC");
saveAliasMap.put("PRIOR", "PAGE_UP"); saveAliasMap.put("NEXT", "PGDN");
saveAliasMap.put("PRIOR", "PGUP");
saveAliasMap.put("DIVIDE", "NUMPAD_DIVIDE"); saveAliasMap.put("DIVIDE", "NUMPAD_DIVIDE");
saveAliasMap.put("MULTIPLY", "NUMPAD_MULTIPLY"); saveAliasMap.put("MULTIPLY", "NUMPAD_MULTIPLY");
saveAliasMap.put("ADD", "NUMPAD_ADD"); saveAliasMap.put("ADD", "NUMPAD_ADD");

@ -23,7 +23,7 @@ public class AsyncResourceLoader extends Thread implements ResourceLoader, Destr
private final LinkedBlockingQueue<DeferredResource> toLoad = new LinkedBlockingQueue<>(); private final LinkedBlockingQueue<DeferredResource> toLoad = new LinkedBlockingQueue<>();
private volatile boolean stopped; private volatile boolean stopped;
private BusAccess app; private BusAccess app;
private volatile boolean mainLoopQueuing = false; private volatile boolean mainLoopQueuing = true;
@Override @Override

@ -292,7 +292,7 @@ public class SortedProperties extends java.util.Properties {
sb.append(c); sb.append(c);
} }
final String read = sb.toString(); String read = sb.toString().replaceAll("(#|;|//|--)[^\n]*\n", "\n");
final String inputString = escapifyStr(read); final String inputString = escapifyStr(read);
final byte[] bs = inputString.getBytes("ISO-8859-1"); final byte[] bs = inputString.getBytes("ISO-8859-1");

@ -18,7 +18,7 @@ public class Launcher {
*/ */
public static void main(String[] args) public static void main(String[] args)
{ {
Log.f3(Arrays.toString(args)); Log.f3("Arguments: " + Arrays.toString(args));
File workdir = null; File workdir = null;
@ -47,7 +47,7 @@ public class Launcher {
final BaseApp app = new RogueApp(workdir, true); final BaseApp app = new RogueApp(workdir, true);
// configure the app // configure the app
app.opt().setBusLogging(true); app.opt().setBusLogging(false);
app.start(); app.start();
} }

@ -93,7 +93,6 @@ public final class RogueApp extends BaseApp {
bindEventToKey(new ScreenshotRequest(), "global.screenshot"); bindEventToKey(new ScreenshotRequest(), "global.screenshot");
bindEventToKey(new UserQuitRequest(), "global.quit"); bindEventToKey(new UserQuitRequest(), "global.quit");
bindEventToKey(new RogueStateRequest(RogueState.MAIN_MENU), "global.menu");
} }

@ -3,7 +3,6 @@ package mightypork.rogue;
import mightypork.gamecore.Config; import mightypork.gamecore.Config;
import mightypork.gamecore.Config.KeyOpts; import mightypork.gamecore.Config.KeyOpts;
import mightypork.gamecore.Config.KeySetup;
public class RogueKeys implements Config.KeySetup { public class RogueKeys implements Config.KeySetup {
@ -12,12 +11,11 @@ public class RogueKeys implements Config.KeySetup {
public void addKeys(KeyOpts keys) public void addKeys(KeyOpts keys)
{ {
keys.add("global.quit", "CTRL+Q", "Quit the game"); keys.add("global.quit", "CTRL+Q", "Quit the game");
keys.add("global.menu", "CTRL+M", "Direct jump to main menu");
keys.add("global.screenshot", "F2", "Take screenshot (save into working directory)"); keys.add("global.screenshot", "F2", "Take screenshot (save into working directory)");
keys.add("global.fullscreen", "F11", "Toggle fullscreen"); keys.add("global.fullscreen", "F11", "Toggle fullscreen");
keys.add("global.fps_meter", "F3", "Toggle FPS meter overlay"); keys.add("global.fps_meter", "F3", "Toggle FPS meter overlay");
keys.add("general.back", "ESC", "Leave a dialog or screen"); keys.add("general.close", "ESC", "Leave a dialog or screen");
keys.add("general.cancel", "ESC", "\"Cancel\" option in dialogs"); keys.add("general.cancel", "ESC", "\"Cancel\" option in dialogs");
keys.add("general.confirm", "ENTER", "\"Confirm\" option in dialogs"); keys.add("general.confirm", "ENTER", "\"Confirm\" option in dialogs");
keys.add("general.yes", "Y", "\"Yes\" option in dialogs"); keys.add("general.yes", "Y", "\"Yes\" option in dialogs");
@ -33,6 +31,11 @@ public class RogueKeys implements Config.KeySetup {
keys.add("game.inventory", "I", "Toggle inventory view"); keys.add("game.inventory", "I", "Toggle inventory view");
keys.add("game.pause", "P", "Pause the game"); keys.add("game.pause", "P", "Pause the game");
keys.add("game.walk.up", "UP", "Walk north");
keys.add("game.walk.down", "DOWN", "Walk south");
keys.add("game.walk.left", "LEFT", "Walk west");
keys.add("game.walk.right", "RIGHT", "Walk east");
keys.add("game.cheat.xray", "CTRL+SHIFT+X", "Cheat to see unexplored tiles"); keys.add("game.cheat.xray", "CTRL+SHIFT+X", "Cheat to see unexplored tiles");
keys.add("game.inv.use", "E", "Use (eat or equip) the selected item"); keys.add("game.inv.use", "E", "Use (eat or equip) the selected item");

@ -7,9 +7,7 @@ import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.AlignX; import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.painters.TextPainter; import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.Overlay; import mightypork.gamecore.gui.screens.Overlay;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.KeyStroke.Edge; import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.resources.Res; import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.fonts.GLFont; import mightypork.gamecore.resources.fonts.GLFont;
import mightypork.gamecore.util.math.color.pal.RGB; import mightypork.gamecore.util.math.color.pal.RGB;

@ -12,9 +12,7 @@ import mightypork.gamecore.gui.components.layout.linear.LinearLayout;
import mightypork.gamecore.gui.components.painters.QuadPainter; import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.components.painters.TextPainter; import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.KeyStroke.Edge; import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.logging.Log; import mightypork.gamecore.logging.Log;
import mightypork.gamecore.resources.Res; import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.fonts.GLFont; import mightypork.gamecore.resources.fonts.GLFont;
@ -131,7 +129,7 @@ public class AskSaveLayer extends ScreenLayer {
btn2.setAction(discard); btn2.setAction(discard);
btn3.setAction(cancel); btn3.setAction(cancel);
bindKey(Config.getKey("general.back"), Edge.RISING, cancel); bindKey(Config.getKey("general.close"), Edge.RISING, cancel);
bindKey(Config.getKey("general.cancel"), Edge.RISING, cancel); bindKey(Config.getKey("general.cancel"), Edge.RISING, cancel);
bindKey(Config.getKey("general.yes"), Edge.RISING, save); bindKey(Config.getKey("general.yes"), Edge.RISING, save);
@ -162,5 +160,4 @@ public class AskSaveLayer extends ScreenLayer {
hideTT.stop(); hideTT.stop();
} }
} }
} }

@ -3,6 +3,7 @@ package mightypork.rogue.screens.game;
import java.io.IOException; import java.io.IOException;
import mightypork.gamecore.Config;
import mightypork.gamecore.gui.Action; import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.AlignX; import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.input.TextButton; import mightypork.gamecore.gui.components.input.TextButton;
@ -13,6 +14,7 @@ import mightypork.gamecore.gui.components.painters.ImagePainter;
import mightypork.gamecore.gui.components.painters.QuadPainter; import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.components.painters.TextPainter; import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.logging.Log; import mightypork.gamecore.logging.Log;
import mightypork.gamecore.resources.Res; import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.fonts.GLFont; import mightypork.gamecore.resources.fonts.GLFont;
@ -65,7 +67,7 @@ public class DeathLayer extends ScreenLayer {
btn2.textPainter.setVPaddingPercent(25); btn2.textPainter.setVPaddingPercent(25);
linl.add(btn2); linl.add(btn2);
btn1.setAction(new Action() { Action load = new Action() {
@Override @Override
protected void execute() protected void execute()
@ -77,16 +79,23 @@ public class DeathLayer extends ScreenLayer {
Log.e(e); Log.e(e);
} }
} }
}); };
btn2.setAction(new Action() { Action quit = new Action() {
@Override @Override
protected void execute() protected void execute()
{ {
getEventBus().send(new RogueStateRequest(RogueState.MAIN_MENU)); getEventBus().send(new RogueStateRequest(RogueState.MAIN_MENU));
} }
}); };
btn1.setAction(load);
btn2.setAction(quit);
bindKey(Config.getKey("game.load"), Edge.RISING, load);
bindKey(Config.getKey("general.confirm"), Edge.RISING, load);
bindKey(Config.getKey("general.close"), Edge.RISING, quit);
} }

@ -11,7 +11,6 @@ import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.input.KeyStroke; import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.KeyStroke.Edge; import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.resources.Res; import mightypork.gamecore.resources.Res;
import mightypork.gamecore.util.math.color.pal.RGB; import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.constraints.num.Num; import mightypork.gamecore.util.math.constraints.num.Num;
@ -31,7 +30,7 @@ public class InventoryLayer extends ScreenLayer {
private final KeyStroke keyUse = Config.getKey("game.inv.use"); private final KeyStroke keyUse = Config.getKey("game.inv.use");
private final KeyStroke keyDrop = Config.getKey("game.inv.drop"); private final KeyStroke keyDrop = Config.getKey("game.inv.drop");
private final KeyStroke keyClose = Config.getKey("general.back"); private final KeyStroke keyClose = Config.getKey("general.close");
private final StringProvider contextStrProv = new StringProvider() { private final StringProvider contextStrProv = new StringProvider() {
@ -150,9 +149,7 @@ public class InventoryLayer extends ScreenLayer {
@Override @Override
public void run() public void run()
{ {
System.out.println("test1");
if (isEnabled()) { if (isEnabled()) {
System.out.println("test2");
screen.actionToggleInv.run(); screen.actionToggleInv.run();
} }
} }

@ -8,10 +8,7 @@ import mightypork.gamecore.core.AppAccess;
import mightypork.gamecore.core.events.UserQuitRequest; import mightypork.gamecore.core.events.UserQuitRequest;
import mightypork.gamecore.gui.Action; import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.ActionGroup; import mightypork.gamecore.gui.ActionGroup;
import mightypork.gamecore.gui.screens.LayeredScreen;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.KeyStroke.Edge; import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.logging.Log; import mightypork.gamecore.logging.Log;
import mightypork.gamecore.util.math.color.Color; import mightypork.gamecore.util.math.color.Color;
import mightypork.rogue.Const; import mightypork.rogue.Const;

@ -11,12 +11,9 @@ import mightypork.gamecore.gui.components.layout.RowLayout;
import mightypork.gamecore.gui.components.layout.linear.LinearLayout; import mightypork.gamecore.gui.components.layout.linear.LinearLayout;
import mightypork.gamecore.gui.components.painters.ImagePainter; import mightypork.gamecore.gui.components.painters.ImagePainter;
import mightypork.gamecore.gui.components.painters.QuadPainter; import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.screens.LayeredScreen;
import mightypork.gamecore.gui.screens.Screen; import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.KeyStroke.Edge; import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.resources.Res; import mightypork.gamecore.resources.Res;
import mightypork.gamecore.resources.fonts.GLFont; import mightypork.gamecore.resources.fonts.GLFont;
import mightypork.gamecore.util.math.color.Color; import mightypork.gamecore.util.math.color.Color;
@ -121,7 +118,7 @@ public class ScreenMainMenu extends RogueScreen {
rows.add(btn, 2); rows.add(btn, 2);
bindKey(Config.getKey("general.back"), Edge.RISING, new Runnable() { bindKey(Config.getKey("general.close"), Edge.RISING, new Runnable() {
@Override @Override
public void run() public void run()

@ -8,12 +8,9 @@ import mightypork.gamecore.gui.AlignX;
import mightypork.gamecore.gui.components.layout.RowLayout; import mightypork.gamecore.gui.components.layout.RowLayout;
import mightypork.gamecore.gui.components.painters.QuadPainter; import mightypork.gamecore.gui.components.painters.QuadPainter;
import mightypork.gamecore.gui.components.painters.TextPainter; import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.LayeredScreen;
import mightypork.gamecore.gui.screens.Screen; import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.KeyStroke.Edge; import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.input.Keys;
import mightypork.gamecore.resources.Res; import mightypork.gamecore.resources.Res;
import mightypork.gamecore.util.math.color.Color; import mightypork.gamecore.util.math.color.Color;
import mightypork.gamecore.util.math.color.pal.PAL16; import mightypork.gamecore.util.math.color.pal.PAL16;
@ -84,7 +81,7 @@ public class ScreenSelectWorld extends RogueScreen {
rows.add(slot3); rows.add(slot3);
// escape to quitn from here // escape to quitn from here
bindKey(Config.getKey("general.back"), Edge.RISING, new Runnable() { bindKey(Config.getKey("general.close"), Edge.RISING, new Runnable() {
@Override @Override
public void run() public void run()

@ -12,6 +12,7 @@ import mightypork.gamecore.eventbus.EventBus;
import mightypork.gamecore.eventbus.clients.DelegatingClient; import mightypork.gamecore.eventbus.clients.DelegatingClient;
import mightypork.gamecore.eventbus.events.Updateable; import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.logging.Log; import mightypork.gamecore.logging.Log;
import mightypork.gamecore.util.error.CorruptDataException;
import mightypork.gamecore.util.ion.IonBundle; import mightypork.gamecore.util.ion.IonBundle;
import mightypork.gamecore.util.ion.IonObjBundled; import mightypork.gamecore.util.ion.IonObjBundled;
import mightypork.gamecore.util.math.algo.Coord; import mightypork.gamecore.util.math.algo.Coord;
@ -92,10 +93,11 @@ public class World implements DelegatingClient, BusAccess, IonObjBundled, Pausea
final Entity ent = levels.get(i).getEntity(eid); final Entity ent = levels.get(i).getEntity(eid);
if (ent != null) { if (ent != null) {
Log.f3("Player entity was really on floor: " + i); Log.f3("Player entity was really on floor: " + i);
break;
} }
} }
throw new RuntimeException(); throw new CorruptDataException("Player not found in world.");
} }
} }

@ -111,6 +111,11 @@ public class WorldProvider extends RootBusNode {
if (file == null) { if (file == null) {
throw new IllegalStateException("Trying to save world to a NULL file."); throw new IllegalStateException("Trying to save world to a NULL file.");
} }
if(world.getPlayer().isDead()) {
throw new IllegalStateException("Cannot save, player is dead.");
}
Ion.toFile(file, world); Ion.toFile(file, world);
} }

@ -2,6 +2,7 @@ package mightypork.rogue.world.events;
import mightypork.gamecore.eventbus.BusEvent; import mightypork.gamecore.eventbus.BusEvent;
import mightypork.rogue.world.WorldProvider;
public class PlayerKilledEvent extends BusEvent<PlayerDeathHandler> { public class PlayerKilledEvent extends BusEvent<PlayerDeathHandler> {
@ -9,6 +10,9 @@ public class PlayerKilledEvent extends BusEvent<PlayerDeathHandler> {
@Override @Override
protected void handleBy(PlayerDeathHandler handler) protected void handleBy(PlayerDeathHandler handler)
{ {
// not dead, discard event.
if(!WorldProvider.get().getPlayer().isDead()) return;
handler.onPlayerKilled(); handler.onPlayerKilled();
} }
} }

@ -1,9 +1,18 @@
package mightypork.rogue.world.gui.interaction; package mightypork.rogue.world.gui.interaction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import mightypork.gamecore.Config;
import mightypork.gamecore.eventbus.clients.DelegatingClient;
import mightypork.gamecore.eventbus.events.Updateable; import mightypork.gamecore.eventbus.events.Updateable;
import mightypork.gamecore.input.InputSystem; import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.input.KeyBindingPool;
import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.input.Keys; import mightypork.gamecore.input.Keys;
import mightypork.gamecore.input.KeyStroke.Edge;
import mightypork.gamecore.input.events.KeyEvent; import mightypork.gamecore.input.events.KeyEvent;
import mightypork.gamecore.input.events.KeyEventHandler; import mightypork.gamecore.input.events.KeyEventHandler;
import mightypork.gamecore.util.math.algo.Move; import mightypork.gamecore.util.math.algo.Move;
@ -14,15 +23,55 @@ import mightypork.rogue.world.events.PlayerStepEndListener;
import mightypork.rogue.world.gui.MapView; import mightypork.rogue.world.gui.MapView;
public class MIPKeyboard extends MapInteractionPlugin implements PlayerStepEndListener, KeyEventHandler, Updateable { public class MIPKeyboard extends MapInteractionPlugin implements DelegatingClient, PlayerStepEndListener, Updateable {
//@formatter:off
private static final KeyStroke[] keys = {
Config.getKey("game.walk.left"),
Config.getKey("game.walk.right"),
Config.getKey("game.walk.up"),
Config.getKey("game.walk.down")
};
private static final int[] keys = { Keys.LEFT, Keys.RIGHT, Keys.UP, Keys.DOWN };
private static final Move[] sides = { Moves.W, Moves.E, Moves.N, Moves.S }; private static final Move[] sides = { Moves.W, Moves.E, Moves.N, Moves.S };
//@formatter:on
private final KeyBindingPool kbp = new KeyBindingPool();
private final List<Object> clients = new ArrayList<>();
{
clients.add(kbp);
}
public MIPKeyboard(MapView mapView) @Override
public boolean doesDelegate()
{ {
return true;
}
@Override
public Collection<?> getChildClients()
{
return clients;
}
public MIPKeyboard(MapView mapView) {
super(mapView); super(mapView);
for (int i = 0; i < 4; i++) {
final int j = i;
kbp.bindKey(keys[i], Edge.RISING, new Runnable() {
@Override
public void run()
{
clickSide(sides[j]);
}
});
}
} }
@ -40,22 +89,27 @@ public class MIPKeyboard extends MapInteractionPlugin implements PlayerStepEndLi
} }
@Override // @Override
public void receive(KeyEvent evt) // public void receive(KeyEvent evt)
// {
//
// if (evt.isDown() || mapView.plc.getPlayer().isMoving()) return; // not interested
//
// if (InputSystem.getActiveModKeys() != Keys.MOD_NONE) return;
//
// for (int i = 0; i < 4; i++) {
// if (evt.getKey() == keys[i].getKey()) {
// mapView.plc.clickTile(sides[i]);
// }
// }
// }
private void clickSide(Move side)
{ {
if (isImmobile()) { if (isImmobile()) {
return; return;
} }
mapView.plc.clickTile(side);
if (evt.isDown() || mapView.plc.getPlayer().isMoving()) return; // not interested
if (InputSystem.getActiveModKeys() != Keys.MOD_NONE) return;
for (int i = 0; i < 4; i++) {
if (evt.getKey() == keys[i]) {
mapView.plc.clickTile(sides[i]);
}
}
} }
@ -65,12 +119,10 @@ public class MIPKeyboard extends MapInteractionPlugin implements PlayerStepEndLi
if (mapView.plc.getPlayer().getMoveProgress() < 0.8) return false; if (mapView.plc.getPlayer().getMoveProgress() < 0.8) return false;
if (InputSystem.getActiveModKeys() != Keys.MOD_NONE) return false; if (InputSystem.getActiveModKeys() != Keys.MOD_NONE) return false;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (InputSystem.isKeyDown(keys[i])) { if (keys[i].isDown()) {
final Move side = sides[i]; final Move side = sides[i];
if (mapView.plc.canGo(side)) { if (mapView.plc.canGo(side)) {

Loading…
Cancel
Save