bugfixes, bus tweaks
This commit is contained in:
@@ -119,7 +119,7 @@ public class Config {
|
||||
public static void init(File file, String comment)
|
||||
{
|
||||
cfg = new PropertyManager(file, comment);
|
||||
cfg.cfgNewlineBeforeComments(false);
|
||||
cfg.cfgNewlineBeforeComments(true);
|
||||
cfg.cfgSeparateSections(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public abstract class BusNode implements BusAccess, ClientHub {
|
||||
|
||||
|
||||
@Override
|
||||
public final boolean isListening()
|
||||
public boolean isListening()
|
||||
{
|
||||
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;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
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.DelegatingList;
|
||||
import mightypork.gamecore.gui.components.Component;
|
||||
|
||||
|
||||
public class ClickableWrapper extends ClickableComponent implements DelegatingClient {
|
||||
|
||||
|
||||
private final Component wrapped;
|
||||
private final List<Component> list;
|
||||
private final ClientList list;
|
||||
|
||||
|
||||
public ClickableWrapper(Component wrapped)
|
||||
{
|
||||
public ClickableWrapper(Component wrapped) {
|
||||
this.wrapped = wrapped;
|
||||
wrapped.setRect(this);
|
||||
|
||||
list = new ArrayList<>(1);
|
||||
list.add(wrapped);
|
||||
list = new ClientList(wrapped);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import mightypork.gamecore.eventbus.clients.ClientList;
|
||||
import mightypork.gamecore.eventbus.clients.DelegatingClient;
|
||||
import mightypork.gamecore.gui.components.Component;
|
||||
import mightypork.gamecore.gui.components.LinearComponent;
|
||||
@@ -18,14 +19,13 @@ import mightypork.gamecore.gui.components.LinearComponent;
|
||||
public abstract class AbstractLinearWrapper extends LinearComponent implements DelegatingClient {
|
||||
|
||||
protected final Component wrapped;
|
||||
private final List<Component> list;
|
||||
private final ClientList list;
|
||||
|
||||
|
||||
/**
|
||||
* @param wrapped wrapped component. Can be null.
|
||||
*/
|
||||
public AbstractLinearWrapper(Component wrapped)
|
||||
{
|
||||
public AbstractLinearWrapper(Component wrapped) {
|
||||
this.wrapped = wrapped;
|
||||
if (wrapped != null) {
|
||||
if (wrapped instanceof LinearComponent) {
|
||||
@@ -36,8 +36,7 @@ public abstract class AbstractLinearWrapper extends LinearComponent implements D
|
||||
}
|
||||
}
|
||||
|
||||
list = new ArrayList<>(1);
|
||||
list.add(wrapped);
|
||||
list = new ClientList(wrapped);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -51,4 +51,10 @@ public abstract class ScreenLayer extends Overlay {
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isListening()
|
||||
{
|
||||
return (isVisible() || isEnabled()) && super.isListening();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,8 +32,7 @@ public class ScreenRegistry extends AppModule implements ScreenRequestListener,
|
||||
/**
|
||||
* @param app app access
|
||||
*/
|
||||
public ScreenRegistry(AppAccess app)
|
||||
{
|
||||
public ScreenRegistry(AppAccess app) {
|
||||
super(app);
|
||||
}
|
||||
|
||||
@@ -41,6 +40,7 @@ public class ScreenRegistry extends AppModule implements ScreenRequestListener,
|
||||
/**
|
||||
* Add a screen
|
||||
*
|
||||
* @param name screen key for calling
|
||||
* @param screen added 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.events.ShudownRequest;
|
||||
import mightypork.gamecore.core.events.UserQuitRequest;
|
||||
import mightypork.gamecore.eventbus.clients.RootBusNode;
|
||||
import mightypork.gamecore.eventbus.events.Updateable;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package mightypork.gamecore.input;
|
||||
|
||||
|
||||
import mightypork.gamecore.util.math.constraints.Pollable;
|
||||
import mightypork.gamecore.util.strings.StringUtils;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
@@ -22,8 +21,6 @@ public class KeyStroke { //implements Pollable
|
||||
private int mod;
|
||||
private int key;
|
||||
|
||||
// private boolean wasDown;
|
||||
|
||||
|
||||
/**
|
||||
* KeyStroke
|
||||
@@ -31,8 +28,7 @@ public class KeyStroke { //implements Pollable
|
||||
* @param key key code
|
||||
* @param mod_mask mods mask
|
||||
*/
|
||||
public KeyStroke(int key, int mod_mask)
|
||||
{
|
||||
public KeyStroke(int key, int mod_mask) {
|
||||
setTo(key, mod_mask);
|
||||
}
|
||||
|
||||
@@ -42,8 +38,7 @@ public class KeyStroke { //implements Pollable
|
||||
*
|
||||
* @param key key code
|
||||
*/
|
||||
public KeyStroke(int key)
|
||||
{
|
||||
public KeyStroke(int key) {
|
||||
this(key, Keys.MOD_NONE);
|
||||
}
|
||||
|
||||
@@ -64,43 +59,9 @@ public class KeyStroke { //implements Pollable
|
||||
{
|
||||
this.key = key;
|
||||
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()
|
||||
{
|
||||
String s = "";
|
||||
@@ -130,12 +91,10 @@ public class KeyStroke { //implements Pollable
|
||||
final String keyStr = StringUtils.fromLastChar(dataString1, '+');
|
||||
final String modStr = StringUtils.toLastChar(dataString1, '+');
|
||||
|
||||
this.key = Keys.keyFromString(keyStr);
|
||||
this.mod = Keys.modFromString(modStr);
|
||||
setTo(Keys.keyFromString(keyStr), Keys.modFromString(modStr));
|
||||
|
||||
} else {
|
||||
this.key = Keys.keyFromString(dataString1);
|
||||
this.mod = Keys.MOD_NONE;
|
||||
setTo(Keys.keyFromString(dataString1), Keys.MOD_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -166,8 +166,9 @@ public class Keys {
|
||||
loadAliasMap.put("BACKSPACE", "BACK");
|
||||
|
||||
saveAliasMap.put("RETURN", "ENTER");
|
||||
saveAliasMap.put("NEXT", "PAGE_DOWN");
|
||||
saveAliasMap.put("PRIOR", "PAGE_UP");
|
||||
saveAliasMap.put("ESCAPE", "ESC");
|
||||
saveAliasMap.put("NEXT", "PGDN");
|
||||
saveAliasMap.put("PRIOR", "PGUP");
|
||||
saveAliasMap.put("DIVIDE", "NUMPAD_DIVIDE");
|
||||
saveAliasMap.put("MULTIPLY", "NUMPAD_MULTIPLY");
|
||||
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 volatile boolean stopped;
|
||||
private BusAccess app;
|
||||
private volatile boolean mainLoopQueuing = false;
|
||||
private volatile boolean mainLoopQueuing = true;
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
@@ -292,7 +292,7 @@ public class SortedProperties extends java.util.Properties {
|
||||
sb.append(c);
|
||||
}
|
||||
|
||||
final String read = sb.toString();
|
||||
String read = sb.toString().replaceAll("(#|;|//|--)[^\n]*\n", "\n");
|
||||
|
||||
final String inputString = escapifyStr(read);
|
||||
final byte[] bs = inputString.getBytes("ISO-8859-1");
|
||||
|
||||
@@ -18,7 +18,7 @@ public class Launcher {
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Log.f3(Arrays.toString(args));
|
||||
Log.f3("Arguments: " + Arrays.toString(args));
|
||||
|
||||
File workdir = null;
|
||||
|
||||
@@ -47,7 +47,7 @@ public class Launcher {
|
||||
final BaseApp app = new RogueApp(workdir, true);
|
||||
|
||||
// configure the app
|
||||
app.opt().setBusLogging(true);
|
||||
app.opt().setBusLogging(false);
|
||||
|
||||
app.start();
|
||||
}
|
||||
|
||||
@@ -93,7 +93,6 @@ public final class RogueApp extends BaseApp {
|
||||
bindEventToKey(new ScreenshotRequest(), "global.screenshot");
|
||||
|
||||
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.KeyOpts;
|
||||
import mightypork.gamecore.Config.KeySetup;
|
||||
|
||||
|
||||
public class RogueKeys implements Config.KeySetup {
|
||||
@@ -12,12 +11,11 @@ public class RogueKeys implements Config.KeySetup {
|
||||
public void addKeys(KeyOpts keys)
|
||||
{
|
||||
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.fullscreen", "F11", "Toggle fullscreen");
|
||||
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.confirm", "ENTER", "\"Confirm\" 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.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.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.components.painters.TextPainter;
|
||||
import mightypork.gamecore.gui.screens.Overlay;
|
||||
import mightypork.gamecore.input.KeyStroke;
|
||||
import mightypork.gamecore.input.KeyStroke.Edge;
|
||||
import mightypork.gamecore.input.Keys;
|
||||
import mightypork.gamecore.resources.Res;
|
||||
import mightypork.gamecore.resources.fonts.GLFont;
|
||||
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.TextPainter;
|
||||
import mightypork.gamecore.gui.screens.ScreenLayer;
|
||||
import mightypork.gamecore.input.KeyStroke;
|
||||
import mightypork.gamecore.input.KeyStroke.Edge;
|
||||
import mightypork.gamecore.input.Keys;
|
||||
import mightypork.gamecore.logging.Log;
|
||||
import mightypork.gamecore.resources.Res;
|
||||
import mightypork.gamecore.resources.fonts.GLFont;
|
||||
@@ -131,7 +129,7 @@ public class AskSaveLayer extends ScreenLayer {
|
||||
btn2.setAction(discard);
|
||||
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.yes"), Edge.RISING, save);
|
||||
@@ -162,5 +160,4 @@ public class AskSaveLayer extends ScreenLayer {
|
||||
hideTT.stop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package mightypork.rogue.screens.game;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import mightypork.gamecore.Config;
|
||||
import mightypork.gamecore.gui.Action;
|
||||
import mightypork.gamecore.gui.AlignX;
|
||||
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.TextPainter;
|
||||
import mightypork.gamecore.gui.screens.ScreenLayer;
|
||||
import mightypork.gamecore.input.KeyStroke.Edge;
|
||||
import mightypork.gamecore.logging.Log;
|
||||
import mightypork.gamecore.resources.Res;
|
||||
import mightypork.gamecore.resources.fonts.GLFont;
|
||||
@@ -65,7 +67,7 @@ public class DeathLayer extends ScreenLayer {
|
||||
btn2.textPainter.setVPaddingPercent(25);
|
||||
linl.add(btn2);
|
||||
|
||||
btn1.setAction(new Action() {
|
||||
Action load = new Action() {
|
||||
|
||||
@Override
|
||||
protected void execute()
|
||||
@@ -77,16 +79,23 @@ public class DeathLayer extends ScreenLayer {
|
||||
Log.e(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
btn2.setAction(new Action() {
|
||||
Action quit = new Action() {
|
||||
|
||||
@Override
|
||||
protected void execute()
|
||||
{
|
||||
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.input.KeyStroke;
|
||||
import mightypork.gamecore.input.KeyStroke.Edge;
|
||||
import mightypork.gamecore.input.Keys;
|
||||
import mightypork.gamecore.resources.Res;
|
||||
import mightypork.gamecore.util.math.color.pal.RGB;
|
||||
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 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() {
|
||||
|
||||
@@ -150,9 +149,7 @@ public class InventoryLayer extends ScreenLayer {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
System.out.println("test1");
|
||||
if (isEnabled()) {
|
||||
System.out.println("test2");
|
||||
screen.actionToggleInv.run();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,7 @@ import mightypork.gamecore.core.AppAccess;
|
||||
import mightypork.gamecore.core.events.UserQuitRequest;
|
||||
import mightypork.gamecore.gui.Action;
|
||||
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.Keys;
|
||||
import mightypork.gamecore.logging.Log;
|
||||
import mightypork.gamecore.util.math.color.Color;
|
||||
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.painters.ImagePainter;
|
||||
import mightypork.gamecore.gui.components.painters.QuadPainter;
|
||||
import mightypork.gamecore.gui.screens.LayeredScreen;
|
||||
import mightypork.gamecore.gui.screens.Screen;
|
||||
import mightypork.gamecore.gui.screens.ScreenLayer;
|
||||
import mightypork.gamecore.input.KeyStroke;
|
||||
import mightypork.gamecore.input.KeyStroke.Edge;
|
||||
import mightypork.gamecore.input.Keys;
|
||||
import mightypork.gamecore.resources.Res;
|
||||
import mightypork.gamecore.resources.fonts.GLFont;
|
||||
import mightypork.gamecore.util.math.color.Color;
|
||||
@@ -121,7 +118,7 @@ public class ScreenMainMenu extends RogueScreen {
|
||||
rows.add(btn, 2);
|
||||
|
||||
|
||||
bindKey(Config.getKey("general.back"), Edge.RISING, new Runnable() {
|
||||
bindKey(Config.getKey("general.close"), Edge.RISING, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
|
||||
@@ -8,12 +8,9 @@ import mightypork.gamecore.gui.AlignX;
|
||||
import mightypork.gamecore.gui.components.layout.RowLayout;
|
||||
import mightypork.gamecore.gui.components.painters.QuadPainter;
|
||||
import mightypork.gamecore.gui.components.painters.TextPainter;
|
||||
import mightypork.gamecore.gui.screens.LayeredScreen;
|
||||
import mightypork.gamecore.gui.screens.Screen;
|
||||
import mightypork.gamecore.gui.screens.ScreenLayer;
|
||||
import mightypork.gamecore.input.KeyStroke;
|
||||
import mightypork.gamecore.input.KeyStroke.Edge;
|
||||
import mightypork.gamecore.input.Keys;
|
||||
import mightypork.gamecore.resources.Res;
|
||||
import mightypork.gamecore.util.math.color.Color;
|
||||
import mightypork.gamecore.util.math.color.pal.PAL16;
|
||||
@@ -84,7 +81,7 @@ public class ScreenSelectWorld extends RogueScreen {
|
||||
rows.add(slot3);
|
||||
|
||||
// escape to quitn from here
|
||||
bindKey(Config.getKey("general.back"), Edge.RISING, new Runnable() {
|
||||
bindKey(Config.getKey("general.close"), Edge.RISING, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
|
||||
@@ -12,6 +12,7 @@ import mightypork.gamecore.eventbus.EventBus;
|
||||
import mightypork.gamecore.eventbus.clients.DelegatingClient;
|
||||
import mightypork.gamecore.eventbus.events.Updateable;
|
||||
import mightypork.gamecore.logging.Log;
|
||||
import mightypork.gamecore.util.error.CorruptDataException;
|
||||
import mightypork.gamecore.util.ion.IonBundle;
|
||||
import mightypork.gamecore.util.ion.IonObjBundled;
|
||||
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);
|
||||
if (ent != null) {
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package mightypork.rogue.world.events;
|
||||
|
||||
|
||||
import mightypork.gamecore.eventbus.BusEvent;
|
||||
import mightypork.rogue.world.WorldProvider;
|
||||
|
||||
|
||||
public class PlayerKilledEvent extends BusEvent<PlayerDeathHandler> {
|
||||
@@ -9,6 +10,9 @@ public class PlayerKilledEvent extends BusEvent<PlayerDeathHandler> {
|
||||
@Override
|
||||
protected void handleBy(PlayerDeathHandler handler)
|
||||
{
|
||||
// not dead, discard event.
|
||||
if(!WorldProvider.get().getPlayer().isDead()) return;
|
||||
|
||||
handler.onPlayerKilled();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
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.input.InputSystem;
|
||||
import mightypork.gamecore.input.KeyBindingPool;
|
||||
import mightypork.gamecore.input.KeyStroke;
|
||||
import mightypork.gamecore.input.Keys;
|
||||
import mightypork.gamecore.input.KeyStroke.Edge;
|
||||
import mightypork.gamecore.input.events.KeyEvent;
|
||||
import mightypork.gamecore.input.events.KeyEventHandler;
|
||||
import mightypork.gamecore.util.math.algo.Move;
|
||||
@@ -14,15 +23,55 @@ import mightypork.rogue.world.events.PlayerStepEndListener;
|
||||
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 };
|
||||
//@formatter:on
|
||||
|
||||
private final KeyBindingPool kbp = new KeyBindingPool();
|
||||
private final List<Object> clients = new ArrayList<>();
|
||||
|
||||
public MIPKeyboard(MapView mapView)
|
||||
{
|
||||
clients.add(kbp);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean doesDelegate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Collection<?> getChildClients()
|
||||
{
|
||||
return clients;
|
||||
}
|
||||
|
||||
|
||||
public MIPKeyboard(MapView 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
|
||||
public void receive(KeyEvent evt)
|
||||
// @Override
|
||||
// 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()) {
|
||||
return;
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
mapView.plc.clickTile(side);
|
||||
}
|
||||
|
||||
|
||||
@@ -65,12 +119,10 @@ public class MIPKeyboard extends MapInteractionPlugin implements PlayerStepEndLi
|
||||
|
||||
if (mapView.plc.getPlayer().getMoveProgress() < 0.8) return false;
|
||||
|
||||
|
||||
if (InputSystem.getActiveModKeys() != Keys.MOD_NONE) return false;
|
||||
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (InputSystem.isKeyDown(keys[i])) {
|
||||
if (keys[i].isDown()) {
|
||||
|
||||
final Move side = sides[i];
|
||||
if (mapView.plc.canGo(side)) {
|
||||
|
||||
Reference in New Issue
Block a user