improved mouse controls; cleanup

v5stable
Ondřej Hruška 11 years ago
parent fb244dc2b9
commit 45e6558d90
  1. 4
      src/mightypork/gamecore/eventbus/BusEvent.java
  2. 4
      src/mightypork/gamecore/eventbus/EventChannel.java
  3. 4
      src/mightypork/gamecore/eventbus/clients/BusNode.java
  4. 4
      src/mightypork/gamecore/gui/components/layout/HorizontalFixedFlowLayout.java
  5. 4
      src/mightypork/gamecore/gui/components/layout/VerticalFixedFlowLayout.java
  6. 4
      src/mightypork/gamecore/gui/screens/ScreenRegistry.java
  7. 4
      src/mightypork/gamecore/input/KeyStroke.java
  8. 8
      src/mightypork/gamecore/logging/Log.java
  9. 4
      src/mightypork/gamecore/logging/writers/ArchivingLog.java
  10. 4
      src/mightypork/gamecore/render/Render.java
  11. 8
      src/mightypork/gamecore/resources/audio/SoundBank.java
  12. 4
      src/mightypork/gamecore/resources/fonts/FontBank.java
  13. 2
      src/mightypork/gamecore/resources/fonts/impl/CachedFont.java
  14. 4
      src/mightypork/gamecore/resources/loading/DeferredResource.java
  15. 21
      src/mightypork/gamecore/resources/textures/QuadGrid.java
  16. 4
      src/mightypork/gamecore/util/files/FileSuffixFilter.java
  17. 4
      src/mightypork/gamecore/util/files/FileTreeDiff.java
  18. 24
      src/mightypork/gamecore/util/files/FileUtils.java
  19. 8
      src/mightypork/gamecore/util/files/OsUtils.java
  20. 4
      src/mightypork/gamecore/util/files/config/PropertyManager.java
  21. 4
      src/mightypork/gamecore/util/files/config/SortedProperties.java
  22. 16
      src/mightypork/gamecore/util/ion/Ion.java
  23. 4
      src/mightypork/gamecore/util/ion/IonOutput.java
  24. 8
      src/mightypork/gamecore/util/math/Calc.java
  25. 4
      src/mightypork/gamecore/util/math/algo/pathfinding/PathFinderProxy.java
  26. 12
      src/mightypork/gamecore/util/math/color/Color.java
  27. 4
      src/mightypork/gamecore/util/math/constraints/rect/Rect.java
  28. 8
      src/mightypork/gamecore/util/math/constraints/rect/builders/TiledRect.java
  29. 3
      src/mightypork/gamecore/util/math/timing/TimedTask.java
  30. 8
      src/mightypork/gamecore/util/math/timing/TimerFps.java
  31. 8
      src/mightypork/gamecore/util/objects/Convert.java
  32. 8
      src/mightypork/gamecore/util/objects/Pair.java
  33. 4
      src/mightypork/gamecore/util/objects/VarargsParser.java
  34. 2
      src/mightypork/rogue/Res.java
  35. 12
      src/mightypork/rogue/screens/game/WorldLayer.java
  36. 12
      src/mightypork/rogue/world/PlayerControl.java
  37. 6
      src/mightypork/rogue/world/World.java
  38. 4
      src/mightypork/rogue/world/WorldProvider.java
  39. 12
      src/mightypork/rogue/world/entity/Entities.java
  40. 2
      src/mightypork/rogue/world/entity/EntityModel.java
  41. 6
      src/mightypork/rogue/world/entity/EntityPathFinder.java
  42. 4
      src/mightypork/rogue/world/entity/entities/MonsterAi.java
  43. 10
      src/mightypork/rogue/world/entity/entities/PlayerEntity.java
  44. 5
      src/mightypork/rogue/world/entity/entities/RatEntity.java
  45. 4
      src/mightypork/rogue/world/entity/modules/EntityModuleHealth.java
  46. 11
      src/mightypork/rogue/world/entity/modules/EntityModulePosition.java
  47. 3
      src/mightypork/rogue/world/entity/renderers/EntityRenderer.java
  48. 13
      src/mightypork/rogue/world/gen/LevelGenerator.java
  49. 4
      src/mightypork/rogue/world/gen/MapTheme.java
  50. 4
      src/mightypork/rogue/world/gen/RoomDesc.java
  51. 12
      src/mightypork/rogue/world/gen/ScratchMap.java
  52. 18
      src/mightypork/rogue/world/gen/rooms/AbstractRectRoom.java
  53. 12
      src/mightypork/rogue/world/gui/MapView.java
  54. 62
      src/mightypork/rogue/world/gui/interaction/MIPClickPathfWalk.java
  55. 8
      src/mightypork/rogue/world/gui/interaction/MIPKeyboard.java
  56. 102
      src/mightypork/rogue/world/gui/interaction/MIPMouse.java
  57. 83
      src/mightypork/rogue/world/gui/interaction/MIPMouseWalk.java
  58. 44
      src/mightypork/rogue/world/gui/interaction/MIPTileClick.java
  59. 6
      src/mightypork/rogue/world/gui/interaction/MapInteractionPlugin.java
  60. 3
      src/mightypork/rogue/world/level/Level.java
  61. 2
      src/mightypork/rogue/world/tile/Tile.java
  62. 1
      src/mightypork/rogue/world/tile/TileGenData.java
  63. 2
      src/mightypork/rogue/world/tile/TileModel.java
  64. 14
      src/mightypork/rogue/world/tile/TileRenderer.java
  65. 17
      src/mightypork/rogue/world/tile/Tiles.java
  66. 9
      src/mightypork/rogue/world/tile/renderers/DoorTileRenderer.java
  67. 1
      src/mightypork/rogue/world/tile/renderers/NullTileRenderer.java
  68. 1
      src/mightypork/rogue/world/tile/tiles/NullTile.java
  69. 7
      src/mightypork/rogue/world/tile/tiles/TileBaseFloor.java
  70. 2
      src/mightypork/rogue/world/tile/tiles/TileBasePassage.java
  71. 4
      src/mightypork/rogue/world/tile/tiles/TileBaseSecretDoor.java
  72. 5
      src/mightypork/rogue/world/tile/tiles/TileBaseWall.java
  73. 1
      src/mightypork/rogue/world/tile/tiles/TileSolid.java
  74. 1
      src/mightypork/rogue/world/tile/tiles/TileWalkable.java
  75. 3
      src/mightypork/rogue/world/tile/tiles/brick/TileBrickDoor.java
  76. 4
      src/mightypork/rogue/world/tile/tiles/brick/TileBrickFloor.java
  77. 1
      src/mightypork/rogue/world/tile/tiles/brick/TileBrickPassage.java
  78. 6
      src/mightypork/rogue/world/tile/tiles/brick/TileBrickSecretDoor.java
  79. 4
      src/mightypork/rogue/world/tile/tiles/brick/TileBrickWall.java

@ -54,7 +54,9 @@ public abstract class BusEvent<HANDLER> {
{ {
if (consumed) throw new IllegalStateException("Already consumed."); if (consumed) throw new IllegalStateException("Already consumed.");
if (getClass().isAnnotationPresent(NonConsumableEvent.class)) { throw new UnsupportedOperationException("Not consumable."); } if (getClass().isAnnotationPresent(NonConsumableEvent.class)) {
throw new UnsupportedOperationException("Not consumable.");
}
consumed = true; consumed = true;
} }

@ -31,7 +31,9 @@ class EventChannel<EVENT extends BusEvent<CLIENT>, CLIENT> {
public EventChannel(Class<EVENT> eventClass, Class<CLIENT> clientClass) public EventChannel(Class<EVENT> eventClass, Class<CLIENT> clientClass)
{ {
if (eventClass == null || clientClass == null) { throw new NullPointerException("Null Event or Client class."); } if (eventClass == null || clientClass == null) {
throw new NullPointerException("Null Event or Client class.");
}
this.clientClass = clientClass; this.clientClass = clientClass;
this.eventClass = eventClass; this.eventClass = eventClass;

@ -62,7 +62,9 @@ public abstract class BusNode implements BusAccess, ClientHub {
@Override @Override
public void addChildClient(Object client) public void addChildClient(Object client)
{ {
if (client instanceof RootBusNode) { throw new IllegalArgumentException("Cannot nest RootBusNode."); } if (client instanceof RootBusNode) {
throw new IllegalArgumentException("Cannot nest RootBusNode.");
}
clients.add(client); clients.add(client);
} }

@ -34,7 +34,9 @@ public class HorizontalFixedFlowLayout extends LayoutComponent {
this.colWidth = elementWidth; this.colWidth = elementWidth;
this.align = align; this.align = align;
if (align != AlignX.LEFT && align != AlignX.RIGHT) { throw new IllegalArgumentException("Can align only left or right."); } if (align != AlignX.LEFT && align != AlignX.RIGHT) {
throw new IllegalArgumentException("Can align only left or right.");
}
} }

@ -34,7 +34,9 @@ public class VerticalFixedFlowLayout extends LayoutComponent {
this.rowHeight = elementHeight; this.rowHeight = elementHeight;
this.align = align; this.align = align;
if (align != AlignY.TOP && align != AlignY.BOTTOM) { throw new IllegalArgumentException("Can align only to top or bottom."); } if (align != AlignY.TOP && align != AlignY.BOTTOM) {
throw new IllegalArgumentException("Can align only to top or bottom.");
}
} }

@ -69,7 +69,9 @@ public class ScreenRegistry extends AppModule implements ScreenRequestListener,
// find screen to show // find screen to show
final Screen toShow = screens.get(key); final Screen toShow = screens.get(key);
if (toShow == null) { throw new RuntimeException("Screen " + key + " not defined."); } if (toShow == null) {
throw new RuntimeException("Screen " + key + " not defined.");
}
// deactivate last screen // deactivate last screen
if (active != null) { if (active != null) {

@ -82,7 +82,9 @@ public class KeyStroke {
if (keys == null) { if (keys == null) {
if (other.keys != null) return false; if (other.keys != null) return false;
} else if (!keys.equals(other.keys)) { return false; } } else if (!keys.equals(other.keys)) {
return false;
}
if (fallingEdge != other.fallingEdge) return false; if (fallingEdge != other.fallingEdge) return false;

@ -295,7 +295,9 @@ public class Log {
final String nl = System.getProperty("line.separator"); final String nl = System.getProperty("line.separator");
if (message.equals("\n")) { return nl; } if (message.equals("\n")) {
return nl;
}
if (message.charAt(0) == '\n') { if (message.charAt(0) == '\n') {
message = nl + message.substring(1); message = nl + message.substring(1);
@ -357,7 +359,9 @@ public class Log {
public static String str(Class<?> cls) public static String str(Class<?> cls)
{ {
final LogAlias ln = cls.getAnnotation(LogAlias.class); final LogAlias ln = cls.getAnnotation(LogAlias.class);
if (ln != null) { return ln.name(); } if (ln != null) {
return ln.name();
}
String name = cls.getName(); String name = cls.getName();

@ -112,7 +112,9 @@ public class ArchivingLog extends SimpleLog {
// playing with fireee // playing with fireee
for (int i = 0; i < oldLogs.size() - logs_to_keep; i++) { for (int i = 0; i < oldLogs.size() - logs_to_keep; i++) {
if (!oldLogs.get(i).delete()) { throw new RuntimeException("Could not delete old log file."); } if (!oldLogs.get(i).delete()) {
throw new RuntimeException("Could not delete old log file.");
}
} }
} }

@ -455,9 +455,9 @@ public class Render {
final RectDigest q = quad.digest(); final RectDigest q = quad.digest();
final RectDigest u = txquad.uvs.digest(); final RectDigest u = txquad.uvs.digest();
double offs = 0.0001;// hack to avoid white stitching final double offs = 0.0001;// hack to avoid white stitching
double tL = u.left+offs, tR = u.right-offs, tT = u.top+offs, tB = u.bottom-offs; double tL = u.left + offs, tR = u.right - offs, tT = u.top + offs, tB = u.bottom - offs;
// handle flip // handle flip
if (txquad.isFlippedY()) { if (txquad.isFlippedY()) {

@ -70,7 +70,9 @@ public class SoundBank extends LightAppModule {
public LoopPlayer getLoop(String key) public LoopPlayer getLoop(String key)
{ {
final LoopPlayer p = loops.get(key); final LoopPlayer p = loops.get(key);
if (p == null) { throw new RuntimeException("Unknown sound loop \"" + key + "\"."); } if (p == null) {
throw new RuntimeException("Unknown sound loop \"" + key + "\".");
}
return p; return p;
} }
@ -84,7 +86,9 @@ public class SoundBank extends LightAppModule {
public EffectPlayer getEffect(String key) public EffectPlayer getEffect(String key)
{ {
final EffectPlayer p = effects.get(key); final EffectPlayer p = effects.get(key);
if (p == null) { throw new RuntimeException("Unknown sound effect \"" + key + "\"."); } if (p == null) {
throw new RuntimeException("Unknown sound effect \"" + key + "\".");
}
return p; return p;
} }
} }

@ -80,7 +80,9 @@ public class FontBank extends LightAppModule {
if (f == null) f = fonts.get(aliases.get(key)); if (f == null) f = fonts.get(aliases.get(key));
if (f == null) { throw new RuntimeException("There's no font called " + key + "!"); } if (f == null) {
throw new RuntimeException("There's no font called " + key + "!");
}
return f; return f;
} }

@ -88,7 +88,7 @@ public class CachedFont implements GLFont {
*/ */
public CachedFont(java.awt.Font font, boolean antialias, FilterMode filter, String chars) public CachedFont(java.awt.Font font, boolean antialias, FilterMode filter, String chars)
{ {
this(font, antialias, filter, (" "+chars).toCharArray()); this(font, antialias, filter, (" " + chars).toCharArray());
} }

@ -41,7 +41,9 @@ public abstract class DeferredResource implements Deferred, Destroyable {
loadFailed = false; loadFailed = false;
try { try {
if (resource == null) { throw new NullPointerException("Resource string cannot be null for non-null resource."); } if (resource == null) {
throw new NullPointerException("Resource string cannot be null for non-null resource.");
}
Log.f3("<RES> Loading: " + this); Log.f3("<RES> Loading: " + this);
loadResource(resource); loadResource(resource);

@ -37,7 +37,9 @@ public class QuadGrid {
*/ */
public TxQuad makeQuad(int x, int y) public TxQuad makeQuad(int x, int y)
{ {
if (x < 0 || x >= txWidth || y < 0 || y >= txHeight) { throw new IndexOutOfBoundsException("Requested invalid txquad coordinates."); } if (x < 0 || x >= txWidth || y < 0 || y >= txHeight) {
throw new IndexOutOfBoundsException("Requested invalid txquad coordinates.");
}
return makeQuad(x, y, 1, 1); return makeQuad(x, y, 1, 1);
} }
@ -55,9 +57,13 @@ public class QuadGrid {
*/ */
public TxQuad makeQuad(double x, double y, double width, double height) public TxQuad makeQuad(double x, double y, double width, double height)
{ {
if (x < 0 || x >= txWidth || y < 0 || y >= txHeight) { throw new IndexOutOfBoundsException("Requested invalid txquad coordinates."); } if (x < 0 || x >= txWidth || y < 0 || y >= txHeight) {
throw new IndexOutOfBoundsException("Requested invalid txquad coordinates.");
}
if (x + width > txWidth || y + height > txHeight) { throw new IndexOutOfBoundsException("Requested invalid txquad size (would go beyond texture size)."); } if (x + width > txWidth || y + height > txHeight) {
throw new IndexOutOfBoundsException("Requested invalid txquad size (would go beyond texture size).");
}
return tx.makeQuad(Rect.make(tileW * x, tileH * y, tileW * width, tileH * height)); return tx.makeQuad(Rect.make(tileW * x, tileH * y, tileW * width, tileH * height));
} }
@ -74,10 +80,13 @@ public class QuadGrid {
*/ */
public TxSheet makeSheet(int x, int y, int width, int height) public TxSheet makeSheet(int x, int y, int width, int height)
{ {
if (x < 0 || x >= txWidth || y < 0 || y >= txHeight) { throw new IndexOutOfBoundsException("Requested invalid txquad coordinates."); } if (x < 0 || x >= txWidth || y < 0 || y >= txHeight) {
throw new IndexOutOfBoundsException("Requested invalid txquad coordinates.");
}
if (x + width > txWidth || y + height > txHeight) { throw new IndexOutOfBoundsException( if (x + width > txWidth || y + height > txHeight) {
"Requested invalid txsheet size (would go beyond texture size)."); } throw new IndexOutOfBoundsException("Requested invalid txsheet size (would go beyond texture size).");
}
return makeQuad(x, y).makeSheet(width, height); return makeQuad(x, y).makeSheet(width, height);
} }

@ -35,7 +35,9 @@ public class FileSuffixFilter implements FileFilter {
final String fname = pathname.getName().toLowerCase().trim(); final String fname = pathname.getName().toLowerCase().trim();
for (final String suffix : suffixes) { for (final String suffix : suffixes) {
if (fname.endsWith(suffix.toLowerCase().trim())) { return true; } if (fname.endsWith(suffix.toLowerCase().trim())) {
return true;
}
} }
return false; return false;

@ -82,7 +82,9 @@ public class FileTreeDiff {
final int read1 = cin1.read(BUFFER); final int read1 = cin1.read(BUFFER);
final int read2 = cin2.read(BUFFER); final int read2 = cin2.read(BUFFER);
if (read1 != read2 || ck1.getValue() != ck2.getValue()) { throw new NotEqualException("Bytes differ:\n" + pair.a + "\n" + pair.b); } if (read1 != read2 || ck1.getValue() != ck2.getValue()) {
throw new NotEqualException("Bytes differ:\n" + pair.a + "\n" + pair.b);
}
if (read1 == -1) break; if (read1 == -1) break;
} }

@ -39,7 +39,9 @@ public class FileUtils {
if (!source.exists()) return; if (!source.exists()) return;
if (source.isDirectory()) { if (source.isDirectory()) {
if (!target.exists() && !target.mkdir()) { throw new IOException("Could not open destination directory."); } if (!target.exists() && !target.mkdir()) {
throw new IOException("Could not open destination directory.");
}
final String[] children = source.list(); final String[] children = source.list();
for (final String element : children) { for (final String element : children) {
@ -47,7 +49,9 @@ public class FileUtils {
} }
} else { } else {
if (filter != null && !filter.accept(source)) { return; } if (filter != null && !filter.accept(source)) {
return;
}
if (filesCopied != null) filesCopied.add(target); if (filesCopied != null) filesCopied.add(target);
copyFile(source, target); copyFile(source, target);
@ -72,7 +76,9 @@ public class FileUtils {
} }
} else { } else {
if (filter != null && !filter.isValid(source.getAbsolutePath())) { return; } if (filter != null && !filter.isValid(source.getAbsolutePath())) {
return;
}
files.add(source); files.add(source);
} }
@ -106,9 +112,13 @@ public class FileUtils {
*/ */
public static void copyStream(InputStream in, OutputStream out) throws IOException public static void copyStream(InputStream in, OutputStream out) throws IOException
{ {
if (in == null) { throw new NullPointerException("Input stream is null"); } if (in == null) {
throw new NullPointerException("Input stream is null");
}
if (out == null) { throw new NullPointerException("Output stream is null"); } if (out == null) {
throw new NullPointerException("Output stream is null");
}
final byte[] buf = new byte[2048]; final byte[] buf = new byte[2048];
int len; int len;
@ -127,7 +137,9 @@ public class FileUtils {
*/ */
public static boolean delete(File path, boolean recursive) public static boolean delete(File path, boolean recursive)
{ {
if (!path.exists()) { return true; } if (!path.exists()) {
return true;
}
if (!recursive || !path.isDirectory()) return path.delete(); if (!recursive || !path.isDirectory()) return path.delete();

@ -56,7 +56,9 @@ public class OsUtils {
final File f = new File(getWorkDir(dirname), subfolderName); final File f = new File(getWorkDir(dirname), subfolderName);
if (!f.exists() && create) { if (!f.exists() && create) {
if (!f.mkdirs()) { throw new RuntimeException("Could not create."); } if (!f.mkdirs()) {
throw new RuntimeException("Could not create.");
}
} }
return f; return f;
@ -135,7 +137,9 @@ public class OsUtils {
if (!file.exists() || !file.isDirectory()) { if (!file.exists() || !file.isDirectory()) {
if (create) { if (create) {
if (!file.mkdirs()) { throw new RuntimeException("Could not create working directory."); } if (!file.mkdirs()) {
throw new RuntimeException("Could not create working directory.");
}
} }
} }

@ -182,7 +182,9 @@ public class PropertyManager {
{ {
boolean needsSave = false; boolean needsSave = false;
if (!file.getParentFile().mkdirs()) { if (!file.getParentFile().mkdirs()) {
if (!file.getParentFile().exists()) { throw new RuntimeException("Cound not create config file."); } if (!file.getParentFile().exists()) {
throw new RuntimeException("Cound not create config file.");
}
} }
try(FileInputStream fis = new FileInputStream(file)) { try(FileInputStream fis = new FileInputStream(file)) {

@ -263,7 +263,9 @@ public class SortedProperties extends java.util.Properties {
private static char hexDigit(char ch, int offset) private static char hexDigit(char ch, int offset)
{ {
final int val = (ch >> offset) & 0xF; final int val = (ch >> offset) & 0xF;
if (val <= 9) { return (char) ('0' + val); } if (val <= 9) {
return (char) ('0' + val);
}
return (char) ('A' + val - 10); return (char) ('A' + val - 10);
} }

@ -93,9 +93,13 @@ public class Ion {
if (mark > 255) throw new IllegalArgumentException("Mark must be < 256."); if (mark > 255) throw new IllegalArgumentException("Mark must be < 256.");
if (mark < 0) throw new IllegalArgumentException("Mark must be positive."); if (mark < 0) throw new IllegalArgumentException("Mark must be positive.");
if (reservedMarkChecking && mark < 50) { throw new IllegalArgumentException("Marks 0..49 are reserved."); } if (reservedMarkChecking && mark < 50) {
throw new IllegalArgumentException("Marks 0..49 are reserved.");
}
if (registered[mark] != null) { throw new IllegalArgumentException("Mark " + mark + " is already in use."); } if (registered[mark] != null) {
throw new IllegalArgumentException("Mark " + mark + " is already in use.");
}
try { try {
objClass.getConstructor(); objClass.getConstructor();
@ -278,9 +282,13 @@ public class Ion {
final Class<? extends IonObjBinary> clz = Ion.getClassForMark(mark); final Class<? extends IonObjBinary> clz = Ion.getClassForMark(mark);
if (clz == null) { throw new IOException("Not registered - mark: " + mark + ", class: " + Log.str(obj.getClass())); } if (clz == null) {
throw new IOException("Not registered - mark: " + mark + ", class: " + Log.str(obj.getClass()));
}
if (clz != obj.getClass()) { throw new IOException("Class mismatch - mark: " + mark + ", class: " + Log.str(obj.getClass())); } if (clz != obj.getClass()) {
throw new IOException("Class mismatch - mark: " + mark + ", class: " + Log.str(obj.getClass()));
}
} }
} }

@ -281,7 +281,9 @@ public class IonOutput {
return; return;
} }
if (obj instanceof IonObjBundled) { throw new IOException("Bundled objects cannot be written to ION stream directly at " + obj); } if (obj instanceof IonObjBundled) {
throw new IOException("Bundled objects cannot be written to ION stream directly at " + obj);
}
if (obj instanceof Boolean) { if (obj instanceof Boolean) {
writeMark(Ion.BOOLEAN); writeMark(Ion.BOOLEAN);

@ -594,7 +594,9 @@ public class Calc {
*/ */
public static List<Integer> parseIntList(String list) public static List<Integer> parseIntList(String list)
{ {
if (list == null) { return null; } if (list == null) {
return null;
}
final String[] parts = list.split(","); final String[] parts = list.split(",");
final ArrayList<Integer> intList = new ArrayList<>(); final ArrayList<Integer> intList = new ArrayList<>();
@ -654,7 +656,9 @@ public class Calc {
*/ */
public static void assertValidIndex(int index, int length) public static void assertValidIndex(int index, int length)
{ {
if (!inRange(index, 0, length - 1)) { throw new IndexOutOfBoundsException(); } if (!inRange(index, 0, length - 1)) {
throw new IndexOutOfBoundsException();
}
} }

@ -6,8 +6,8 @@ import mightypork.gamecore.util.math.algo.Step;
/** /**
* Pathfinder proxy. Can be used to override individual methods but * Pathfinder proxy. Can be used to override individual methods but keep the
* keep the rest as is. * rest as is.
* *
* @author MightyPork * @author MightyPork
*/ */

@ -205,7 +205,9 @@ public abstract class Color {
*/ */
public static void pushAlpha(Num alpha) public static void pushAlpha(Num alpha)
{ {
if (!alphaStackEnabled) { return; } if (!alphaStackEnabled) {
return;
}
alphaStack.push(alpha); alphaStack.push(alpha);
} }
@ -219,9 +221,13 @@ public abstract class Color {
*/ */
public static void popAlpha() public static void popAlpha()
{ {
if (!alphaStackEnabled) { return; } if (!alphaStackEnabled) {
return;
}
if (alphaStack.isEmpty()) { throw new EmptyStackException(); } if (alphaStack.isEmpty()) {
throw new EmptyStackException();
}
alphaStack.pop(); alphaStack.pop();
} }

@ -1028,7 +1028,9 @@ public abstract class Rect implements RectBound, Digestable<RectDigest> {
double rw = other.size().x(); double rw = other.size().x();
double rh = other.size().y(); double rh = other.size().y();
if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) { return false; } if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) {
return false;
}
final double tx = this.origin().x(); final double tx = this.origin().x();
final double ty = this.origin().y(); final double ty = this.origin().y();

@ -58,9 +58,13 @@ public class TiledRect extends RectProxy {
*/ */
public Rect tile(int x, int y) public Rect tile(int x, int y)
{ {
if (x >= tilesX || x < 0) { throw new IndexOutOfBoundsException("X coordinate out fo range: " + x); } if (x >= tilesX || x < 0) {
throw new IndexOutOfBoundsException("X coordinate out fo range: " + x);
}
if (y >= tilesY || y < 0) { throw new IndexOutOfBoundsException("Y coordinate out of range: " + y); } if (y >= tilesY || y < 0) {
throw new IndexOutOfBoundsException("Y coordinate out of range: " + y);
}
return aTile.move(perCol.mul(x), perRow.mul(y)); return aTile.move(perCol.mul(x), perRow.mul(y));
} }

@ -29,7 +29,8 @@ public abstract class TimedTask implements Runnable, Updateable {
} }
public boolean isRunning() { public boolean isRunning()
{
return !timer.isFinished(); return !timer.isFinished();
} }

@ -64,11 +64,15 @@ public class TimerFps {
*/ */
public double getFraction() public double getFraction()
{ {
if (getSkipped() >= 1) { return 1; } if (getSkipped() >= 1) {
return 1;
}
final long time = getTime(); final long time = getTime();
if (time <= nextFrame) { return (double) (time - lastFrame) / (double) FRAME; } if (time <= nextFrame) {
return (double) (time - lastFrame) / (double) FRAME;
}
return 1; return 1;
} }

@ -137,7 +137,9 @@ public class Convert {
return String.format("{%f|%f}", c.getMin(), c.getMax()); return String.format("{%f|%f}", c.getMin(), c.getMax());
} }
if (o instanceof Class<?>) { return Log.str(o); } if (o instanceof Class<?>) {
return Log.str(o);
}
return o.toString(); return o.toString();
} }
@ -177,7 +179,9 @@ public class Convert {
final double x = Double.parseDouble(parts[0].trim()); final double x = Double.parseDouble(parts[0].trim());
final double y = Double.parseDouble(parts[1].trim()); final double y = Double.parseDouble(parts[1].trim());
if (parts.length == 2) { return Vect.make(x, y); } if (parts.length == 2) {
return Vect.make(x, y);
}
final double z = Double.parseDouble(parts[2].trim()); final double z = Double.parseDouble(parts[2].trim());

@ -59,9 +59,13 @@ public class Pair<T1, T2> {
@Override @Override
public boolean equals(Object obj) public boolean equals(Object obj)
{ {
if (obj == null) { return false; } if (obj == null) {
return false;
}
if (!this.getClass().equals(obj.getClass())) { return false; } if (!this.getClass().equals(obj.getClass())) {
return false;
}
final Pair<?, ?> t = (Pair<?, ?>) obj; final Pair<?, ?> t = (Pair<?, ?>) obj;

@ -34,7 +34,9 @@ public class VarargsParser<K, V> {
{ {
final LinkedHashMap<K, V> attrs = new LinkedHashMap<>(); final LinkedHashMap<K, V> attrs = new LinkedHashMap<>();
if (args.length % 2 != 0) { throw new IllegalArgumentException("Odd number of elements in varargs map!"); } if (args.length % 2 != 0) {
throw new IllegalArgumentException("Odd number of elements in varargs map!");
}
K key = null; K key = null;
for (final Object o : args) { for (final Object o : args) {

@ -86,7 +86,7 @@ public final class Res {
textures.addSheet("tile.brick.floor", tiles.makeSheet(0, 1, 5, 1)); textures.addSheet("tile.brick.floor", tiles.makeSheet(0, 1, 5, 1));
textures.addSheet("tile.brick.wall", tiles.makeSheet(0, 0, 8, 1)); textures.addSheet("tile.brick.wall", tiles.makeSheet(0, 0, 8, 1));
textures.addSheet("tile.brick.door.locked", tiles.makeSheet(1, 2, 1, 1));//TODO unique tx textures.addSheet("tile.brick.door.locked", tiles.makeSheet(1, 2, 1, 1));//TODO unique tx
textures.addSheet("tile.brick.door.closed", tiles.makeSheet(1, 2, 1, 1)); textures.addSheet("tile.brick.door.closed", tiles.makeSheet(1, 2, 1, 1));
textures.addSheet("tile.brick.door.open", tiles.makeSheet(2, 2, 1, 1)); textures.addSheet("tile.brick.door.open", tiles.makeSheet(2, 2, 1, 1));

@ -5,10 +5,8 @@ import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.util.math.constraints.num.Num; import mightypork.gamecore.util.math.constraints.num.Num;
import mightypork.rogue.world.gui.MapView; import mightypork.rogue.world.gui.MapView;
import mightypork.rogue.world.gui.interaction.MIPClickPathfWalk; import mightypork.rogue.world.gui.interaction.MIPKeyboard;
import mightypork.rogue.world.gui.interaction.MIPKeyWalk; import mightypork.rogue.world.gui.interaction.MIPMouse;
import mightypork.rogue.world.gui.interaction.MIPMouseWalk;
import mightypork.rogue.world.gui.interaction.MIPTileClick;
public class WorldLayer extends ScreenLayer { public class WorldLayer extends ScreenLayer {
@ -25,10 +23,8 @@ public class WorldLayer extends ScreenLayer {
worldView = new MapView(); worldView = new MapView();
// map input plugins // map input plugins
worldView.addPlugin(new MIPKeyWalk()); worldView.addPlugin(new MIPKeyboard());
worldView.addPlugin(new MIPTileClick()); worldView.addPlugin(new MIPMouse());
worldView.addPlugin(new MIPClickPathfWalk());
worldView.addPlugin(new MIPMouseWalk());
// size of lower navbar // size of lower navbar
final Num lownav = root.width().min(root.height()).max(700).perc(7); final Num lownav = root.width().min(root.height()).max(700).perc(7);

@ -103,14 +103,16 @@ public abstract class PlayerControl {
return getLevel().getTile(getCoord().add(side)).isWalkable(); return getLevel().getTile(getCoord().add(side)).isWalkable();
} }
public boolean clickTile(Step side) public boolean clickTile(Step side)
{ {
return clickTile(getCoord().add(side)); return clickTile(getCoord().add(side));
} }
public boolean clickTile(Coord pos) public boolean clickTile(Coord pos)
{ {
if(pos.dist(getCoord()) > 8) return false; // too far if (pos.dist(getCoord()) > 8) return false; // too far
return getLevel().getTile(pos).onClick(); return getLevel().getTile(pos).onClick();
} }
@ -121,4 +123,12 @@ public abstract class PlayerControl {
getPlayerEntity().pos.cancelPath(); getPlayerEntity().pos.cancelPath();
getPlayerEntity().pos.addStep(side); getPlayerEntity().pos.addStep(side);
} }
public boolean tryGo(Step e)
{
if (!canGo(e)) return false;
go(e);
return true;
}
} }

@ -9,7 +9,6 @@ import mightypork.gamecore.util.ion.IonBundle;
import mightypork.gamecore.util.ion.IonObjBundled; import mightypork.gamecore.util.ion.IonObjBundled;
import mightypork.rogue.world.entity.Entities; import mightypork.rogue.world.entity.Entities;
import mightypork.rogue.world.entity.Entity; import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.EntityModel;
import mightypork.rogue.world.level.Level; import mightypork.rogue.world.level.Level;
@ -95,9 +94,12 @@ public class World implements IonObjBundled, Updateable {
return eid++; return eid++;
} }
public void createPlayer(int level) public void createPlayer(int level)
{ {
if (playerInfo.isInitialized()) { throw new RuntimeException("Player already created."); } if (playerInfo.isInitialized()) {
throw new RuntimeException("Player already created.");
}
// make entity // make entity
final int playerEid = getNewEID(); final int playerEid = getNewEID();

@ -32,7 +32,9 @@ public class WorldProvider extends RootBusNode {
public static WorldProvider get() public static WorldProvider get()
{ {
if (inst == null) { throw new IllegalStateException("World provider not initialized."); } if (inst == null) {
throw new IllegalStateException("World provider not initialized.");
}
return inst; return inst;
} }

@ -25,9 +25,13 @@ public final class Entities {
public static void register(int id, EntityModel model) public static void register(int id, EntityModel model)
{ {
if (id < 0 || id >= entities.length) { throw new IllegalArgumentException("Entity model ID " + id + " is out of range."); } if (id < 0 || id >= entities.length) {
throw new IllegalArgumentException("Entity model ID " + id + " is out of range.");
}
if (entities[id] != null) { throw new IllegalArgumentException("Entity model ID " + id + " already in use."); } if (entities[id] != null) {
throw new IllegalArgumentException("Entity model ID " + id + " already in use.");
}
entities[id] = model; entities[id] = model;
} }
@ -37,7 +41,9 @@ public final class Entities {
{ {
final EntityModel e = entities[id]; final EntityModel e = entities[id];
if (e == null) { throw new IllegalArgumentException("No entity model with ID " + id + "."); } if (e == null) {
throw new IllegalArgumentException("No entity model with ID " + id + ".");
}
return e; return e;
} }

@ -28,11 +28,13 @@ public final class EntityModel {
this.tileClass = entity; this.tileClass = entity;
} }
public Entity createEntity(World world) public Entity createEntity(World world)
{ {
return createEntity(world.getNewEID()); return createEntity(world.getNewEID());
} }
public Entity createEntity(int eid) public Entity createEntity(int eid)
{ {
try { try {

@ -27,13 +27,15 @@ public class EntityPathFinder extends PathFinder {
@Override @Override
public int getCost(Coord from, Coord to) { public int getCost(Coord from, Coord to)
{
return 10; return 10;
} }
@Override @Override
public int getMinCost() { public int getMinCost()
{
return 10; return 10;
} }

@ -52,7 +52,7 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
{ {
if (!chasing) return; if (!chasing) return;
Entity prey = getPreyEntity(); final Entity prey = getPreyEntity();
if (prey == null || prey.isDead()) { if (prey == null || prey.isDead()) {
//System.out.println("prey dead?"); //System.out.println("prey dead?");
@ -178,7 +178,7 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
timerAttack.update(delta); timerAttack.update(delta);
if (chasing && !entity.pos.isMoving()) { if (chasing && !entity.pos.isMoving()) {
Entity prey = getPreyEntity(); final Entity prey = getPreyEntity();
if (!isPreyInAttackRange(prey)) { if (!isPreyInAttackRange(prey)) {
//System.out.println("-upd STEP--"); //System.out.println("-upd STEP--");

@ -3,7 +3,11 @@ package mightypork.rogue.world.entity.entities;
import mightypork.gamecore.util.math.algo.Coord; import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.algo.pathfinding.PathFinder; import mightypork.gamecore.util.math.algo.pathfinding.PathFinder;
import mightypork.rogue.world.entity.*; import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.EntityModel;
import mightypork.rogue.world.entity.EntityModule;
import mightypork.rogue.world.entity.EntityPathFinder;
import mightypork.rogue.world.entity.EntityType;
import mightypork.rogue.world.entity.modules.EntityMoveListener; import mightypork.rogue.world.entity.modules.EntityMoveListener;
import mightypork.rogue.world.entity.renderers.EntityRenderer; import mightypork.rogue.world.entity.renderers.EntityRenderer;
import mightypork.rogue.world.entity.renderers.EntityRendererMobLR; import mightypork.rogue.world.entity.renderers.EntityRendererMobLR;
@ -74,12 +78,12 @@ public class PlayerEntity extends Entity {
@Override @Override
public int getCost(Coord from, Coord to) public int getCost(Coord from, Coord to)
{ {
if (!getLevel().getTile(pos.getCoord()).isExplored()) { if (!getLevel().getTile(pos.getCoord()).isExplored()) {
return 1000; return 1000;
} }
return super.getCost(from, to); return super.getCost(from, to);
}; };
}; };
} }

@ -2,7 +2,10 @@ package mightypork.rogue.world.entity.entities;
import mightypork.gamecore.util.math.algo.pathfinding.PathFinder; import mightypork.gamecore.util.math.algo.pathfinding.PathFinder;
import mightypork.rogue.world.entity.*; import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.EntityModel;
import mightypork.rogue.world.entity.EntityPathFinder;
import mightypork.rogue.world.entity.EntityType;
import mightypork.rogue.world.entity.renderers.EntityRenderer; import mightypork.rogue.world.entity.renderers.EntityRenderer;
import mightypork.rogue.world.entity.renderers.EntityRendererMobLR; import mightypork.rogue.world.entity.renderers.EntityRendererMobLR;

@ -94,8 +94,8 @@ public class EntityModuleHealth extends EntityModule {
{ {
setHealth(health - attackStrength); setHealth(health - attackStrength);
} }
public void fill() public void fill()
{ {
setHealth(maxHealth); setHealth(maxHealth);

@ -11,7 +11,6 @@ import java.util.Set;
import mightypork.gamecore.util.ion.IonBundle; import mightypork.gamecore.util.ion.IonBundle;
import mightypork.gamecore.util.math.algo.Coord; import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.algo.Step; import mightypork.gamecore.util.math.algo.Step;
import mightypork.gamecore.util.math.algo.pathfinding.PathFinder;
import mightypork.gamecore.util.math.constraints.vect.VectConst; import mightypork.gamecore.util.math.constraints.vect.VectConst;
import mightypork.rogue.world.entity.Entity; import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.entity.EntityModule; import mightypork.rogue.world.entity.EntityModule;
@ -202,11 +201,17 @@ public class EntityModulePosition extends EntityModule {
{ {
return entityPos.getVisualPos(); return entityPos.getVisualPos();
} }
public boolean isMoving() public boolean isMoving()
{ {
return walking; return walking;
} }
public boolean hasPath()
{
return isMoving() || !path.isEmpty();
}
} }

@ -1,11 +1,10 @@
package mightypork.rogue.world.entity.renderers; package mightypork.rogue.world.entity.renderers;
import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.level.render.MapRenderContext; import mightypork.rogue.world.level.render.MapRenderContext;
public abstract class EntityRenderer { public abstract class EntityRenderer {
public abstract void render(MapRenderContext context); public abstract void render(MapRenderContext context);

@ -7,7 +7,6 @@ import mightypork.gamecore.util.math.algo.Coord;
import mightypork.rogue.world.World; import mightypork.rogue.world.World;
import mightypork.rogue.world.entity.Entities; import mightypork.rogue.world.entity.Entities;
import mightypork.rogue.world.entity.Entity; import mightypork.rogue.world.entity.Entity;
import mightypork.rogue.world.gen.rooms.DeadEndRoom;
import mightypork.rogue.world.gen.rooms.Rooms; import mightypork.rogue.world.gen.rooms.Rooms;
import mightypork.rogue.world.gen.themes.ThemeBrick; import mightypork.rogue.world.gen.themes.ThemeBrick;
import mightypork.rogue.world.level.Level; import mightypork.rogue.world.level.Level;
@ -45,16 +44,16 @@ public class LevelGenerator {
// TODO tmp // TODO tmp
// spawn rats // spawn rats
Coord pos = Coord.make(0,0); final Coord pos = Coord.make(0, 0);
for(int i=0; i<1;i++) { // 4+complexity + rand.nextInt(1+complexity) for (int i = 0; i < 1; i++) { // 4+complexity + rand.nextInt(1+complexity)
Entity e = Entities.RAT.createEntity(world); final Entity e = Entities.RAT.createEntity(world);
for(int j=0; j<20;j++) { for (int j = 0; j < 20; j++) {
pos.x = rand.nextInt(lvl.getWidth()); pos.x = rand.nextInt(lvl.getWidth());
pos.y = rand.nextInt(lvl.getHeight()); pos.y = rand.nextInt(lvl.getHeight());
if(lvl.addEntity(e, pos)) break; if (lvl.addEntity(e, pos)) break;
} }
} }

@ -21,7 +21,7 @@ public interface MapTheme {
TileModel passage(); TileModel passage();
TileModel secretDoor(); TileModel secretDoor();
} }

@ -30,7 +30,9 @@ public class RoomDesc {
int rw = amax.x - amin.x; int rw = amax.x - amin.x;
int rh = amax.y - amin.y; int rh = amax.y - amin.y;
if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) { return false; } if (rw <= 0 || rh <= 0 || tw <= 0 || th <= 0) {
return false;
}
final int tx = min.x; final int tx = min.x;
final int ty = min.y; final int ty = min.y;

@ -41,8 +41,8 @@ public class ScratchMap {
@Override @Override
public boolean isAccessible(Coord pos) public boolean isAccessible(Coord pos)
{ {
if(!isIn(pos)) return false; if (!isIn(pos)) return false;
Tile t = get(pos); final Tile t = get(pos);
return t.isPotentiallyWalkable() || (t.genData.protection != TileProtectLevel.STRONG); return t.isPotentiallyWalkable() || (t.genData.protection != TileProtectLevel.STRONG);
} }
@ -189,7 +189,9 @@ public class ScratchMap {
public Tile get(Coord pos) public Tile get(Coord pos)
{ {
if (!isIn(pos)) { throw new IndexOutOfBoundsException("Tile not in map: " + pos); } if (!isIn(pos)) {
throw new IndexOutOfBoundsException("Tile not in map: " + pos);
}
return map[pos.y][pos.x]; return map[pos.y][pos.x];
} }
@ -203,7 +205,9 @@ public class ScratchMap {
public boolean set(Coord pos, Tile tile) public boolean set(Coord pos, Tile tile)
{ {
if (!isIn(pos)) { throw new IndexOutOfBoundsException("Tile not in map: " + pos); } if (!isIn(pos)) {
throw new IndexOutOfBoundsException("Tile not in map: " + pos);
}
map[pos.y][pos.x] = tile; map[pos.y][pos.x] = tile;
return true; return true;

@ -21,15 +21,15 @@ public abstract class AbstractRectRoom implements RoomBuilder {
{ {
// half width, half height actually // half width, half height actually
final Coord innerSize = getInnerSize(rand); final Coord innerSize = getInnerSize(rand);
final int width = 2+innerSize.x; final int width = 2 + innerSize.x;
final int height = 2+innerSize.y; final int height = 2 + innerSize.y;
int wLow = width/2; final int wLow = width / 2;
int wHigh = width - wLow; final int wHigh = width - wLow;
int hLow = height/2; final int hLow = height / 2;
int hHigh = height - hLow; final int hHigh = height - hLow;
final Coord min = new Coord(center.x-wLow, center.y-hLow); final Coord min = new Coord(center.x - wLow, center.y - hLow);
final Coord max = new Coord(center.x + wHigh, center.y + hHigh); final Coord max = new Coord(center.x + wHigh, center.y + hHigh);
if (!map.isClear(min.add(-1, -1), max)) return null; if (!map.isClear(min.add(-1, -1), max)) return null;
@ -48,8 +48,8 @@ public abstract class AbstractRectRoom implements RoomBuilder {
protected void placeDoors(ScratchMap map, MapTheme theme, Random rand, Coord min, Coord max) protected void placeDoors(ScratchMap map, MapTheme theme, Random rand, Coord min, Coord max)
{ {
int width = max.x - min.x; final int width = max.x - min.x;
int height = max.y - min.y; final int height = max.y - min.y;
for (int i = 0, j = 0; i <= getDoorCount(rand) && j < 100; j++) { // j is to prevent inf loop for (int i = 0, j = 0; i <= getDoorCount(rand) && j < 100; j++) { // j is to prevent inf loop
final Coord door = min.copy(); final Coord door = min.copy();

@ -1,7 +1,6 @@
package mightypork.rogue.world.gui; package mightypork.rogue.world.gui;
import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Set; import java.util.Set;
@ -22,7 +21,6 @@ import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.WorldRenderer; import mightypork.rogue.world.WorldRenderer;
import mightypork.rogue.world.entity.modules.EntityMoveListener; import mightypork.rogue.world.entity.modules.EntityMoveListener;
import mightypork.rogue.world.gui.interaction.MapInteractionPlugin; import mightypork.rogue.world.gui.interaction.MapInteractionPlugin;
import mightypork.rogue.world.tile.Tile;
/** /**
@ -73,7 +71,7 @@ public class MapView extends InputComponent implements KeyListener, MouseButtonL
public void onStepFinished() public void onStepFinished()
{ {
for (final MapInteractionPlugin p : plugins) { for (final MapInteractionPlugin p : plugins) {
if(p.onStepEnd(this, pc)) break; if (p.onStepEnd(this, pc)) break;
} }
} }
@ -82,7 +80,7 @@ public class MapView extends InputComponent implements KeyListener, MouseButtonL
public void onPathFinished() public void onPathFinished()
{ {
for (final MapInteractionPlugin p : plugins) { for (final MapInteractionPlugin p : plugins) {
if(p.onStepEnd(this, pc)) break; if (p.onStepEnd(this, pc)) break;
} }
} }
@ -91,7 +89,7 @@ public class MapView extends InputComponent implements KeyListener, MouseButtonL
public void onPathInterrupted() public void onPathInterrupted()
{ {
for (final MapInteractionPlugin p : plugins) { for (final MapInteractionPlugin p : plugins) {
if(p.onStepEnd(this, pc)) break; if (p.onStepEnd(this, pc)) break;
} }
} }
@ -102,7 +100,7 @@ public class MapView extends InputComponent implements KeyListener, MouseButtonL
if (!event.isOver(this)) return; if (!event.isOver(this)) return;
for (final MapInteractionPlugin p : plugins) { for (final MapInteractionPlugin p : plugins) {
if(p.onClick(this, pc, event.getPos(), event.getButton(), event.isDown())) { if (p.onClick(this, pc, event.getPos(), event.getButton(), event.isDown())) {
event.consume(); event.consume();
break; break;
} }
@ -114,7 +112,7 @@ public class MapView extends InputComponent implements KeyListener, MouseButtonL
public void receive(KeyEvent event) public void receive(KeyEvent event)
{ {
for (final MapInteractionPlugin p : plugins) { for (final MapInteractionPlugin p : plugins) {
if(p.onKey(this, pc, event.getKey(), event.isDown())) break; if (p.onKey(this, pc, event.getKey(), event.isDown())) break;
} }
if (event.getKey() == Keys.Z) { if (event.getKey() == Keys.Z) {

@ -1,62 +0,0 @@
package mightypork.rogue.world.gui.interaction;
import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.rogue.world.PlayerControl;
import mightypork.rogue.world.gui.MapView;
import mightypork.rogue.world.tile.Tile;
public class MIPClickPathfWalk implements MapInteractionPlugin {
private static final int BTN = 0; // left
@Override
public void update(MapView view, PlayerControl pc, double delta)
{
if(pc.getPlayerEntity().pos.isMoving()) return;
if (InputSystem.isMouseButtonDown(BTN)) {
troToNav(view, pc, InputSystem.getMousePos());
}
}
@Override
public boolean onClick(MapView view, PlayerControl player, Vect mouse, int button, boolean down)
{
if (down || button != BTN) return false;
return troToNav(view, player, mouse);
}
private boolean troToNav(MapView view, PlayerControl player, Vect mouse)
{
final Coord clicked = view.toWorldPos(mouse);
Tile t = player.getLevel().getTile(clicked);
if (!t.isWalkable() || !t.isExplored()) return false;
player.navigateTo(clicked);
return true;
}
@Override
public boolean onKey(MapView view, PlayerControl player, int key, boolean down)
{
return false;
}
@Override
public boolean onStepEnd(MapView mapView, PlayerControl player)
{
return false;
}
}

@ -10,7 +10,7 @@ import mightypork.rogue.world.PlayerControl;
import mightypork.rogue.world.gui.MapView; import mightypork.rogue.world.gui.MapView;
public class MIPKeyWalk implements MapInteractionPlugin { public class MIPKeyboard implements MapInteractionPlugin {
private static final int[] keys = { Keys.LEFT, Keys.RIGHT, Keys.UP, Keys.DOWN }; private static final int[] keys = { Keys.LEFT, Keys.RIGHT, Keys.UP, Keys.DOWN };
private static final Step[] sides = { Sides.W, Sides.E, Sides.N, Sides.S }; private static final Step[] sides = { Sides.W, Sides.E, Sides.N, Sides.S };
@ -33,7 +33,7 @@ public class MIPKeyWalk implements MapInteractionPlugin {
@Override @Override
public boolean onKey(MapView view, PlayerControl player, int key, boolean down) public boolean onKey(MapView view, PlayerControl player, int key, boolean down)
{ {
if(down) return false; // not interested if (down) return false; // not interested
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (key == keys[i]) { if (key == keys[i]) {
@ -47,12 +47,12 @@ public class MIPKeyWalk implements MapInteractionPlugin {
private boolean walkByKey(PlayerControl pc) private boolean walkByKey(PlayerControl pc)
{ {
if(pc.getPlayerEntity().pos.isMoving()) return false; if (pc.getPlayerEntity().pos.isMoving()) return false;
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (InputSystem.isKeyDown(keys[i])) { if (InputSystem.isKeyDown(keys[i])) {
Step side = sides[i]; final Step side = sides[i];
if (pc.canGo(side)) { if (pc.canGo(side)) {
pc.go(side); pc.go(side);
return true; return true;

@ -0,0 +1,102 @@
package mightypork.rogue.world.gui.interaction;
import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.util.math.Calc.Deg;
import mightypork.gamecore.util.math.Polar;
import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.algo.Sides;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.rogue.world.PlayerControl;
import mightypork.rogue.world.gui.MapView;
import mightypork.rogue.world.tile.Tile;
public class MIPMouse implements MapInteractionPlugin {
private static final int BTN = 0; // left
@Override
public void update(MapView view, PlayerControl pc, double delta)
{
if (pc.getPlayerEntity().pos.hasPath()) return;
final Vect pos = InputSystem.getMousePos();
if (InputSystem.isMouseButtonDown(BTN)) {
if (mouseWalk(view, pc, pos)) return;
if (troToNav(view, pc, pos)) return;
}
}
@Override
public boolean onClick(MapView view, PlayerControl pc, Vect mouse, int button, boolean down)
{
if (!down && button == BTN) {
final Coord pos = view.toWorldPos(mouse);
final Tile t = pc.getLevel().getTile(pos);
if (t.onClick()) return true;
if (troToNav(view, pc, mouse)) return true;
}
return false;
}
private boolean troToNav(MapView view, PlayerControl pc, Vect mouse)
{
final Coord clicked = view.toWorldPos(mouse);
final Tile t = pc.getLevel().getTile(clicked);
if (!t.isWalkable() || !t.isExplored()) return false;
pc.navigateTo(clicked);
return true;
}
private boolean mouseWalk(MapView view, PlayerControl pc, Vect pos)
{
final Coord plpos = pc.getCoord();
final Coord clicked = view.toWorldPos(pos);
final Polar p = Polar.fromCoord(clicked.x - plpos.x, clicked.y - plpos.y);
final int dir = Deg.round90(p.getAngleDeg()) / 90;
switch (dir) {
case 0:
return pc.tryGo(Sides.E);
case 1:
return pc.tryGo(Sides.S);
case 2:
return pc.tryGo(Sides.W);
case 3:
return pc.tryGo(Sides.N);
}
return false;
}
@Override
public boolean onKey(MapView view, PlayerControl player, int key, boolean down)
{
return false;
}
@Override
public boolean onStepEnd(MapView mapView, PlayerControl player)
{
return false;
}
}

@ -1,83 +0,0 @@
package mightypork.rogue.world.gui.interaction;
import mightypork.gamecore.input.InputSystem;
import mightypork.gamecore.util.math.Calc.Deg;
import mightypork.gamecore.util.math.Polar;
import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.rogue.world.PlayerControl;
import mightypork.rogue.world.gui.MapView;
import mightypork.rogue.world.tile.Tile;
public class MIPMouseWalk implements MapInteractionPlugin {
@Override
public void update(MapView view, PlayerControl pc, double delta)
{
if (InputSystem.isMouseButtonDown(0)) {
// walk by holding btn
tryWalk(view, pc, InputSystem.getMousePos());
}
}
@Override
public boolean onClick(MapView view, PlayerControl pc, Vect mouse, int button, boolean down)
{
if (!down || button != 0) return false;
tryWalk(view, pc, mouse);
return true;
}
private void tryWalk(MapView view, PlayerControl pc, Vect pos)
{
if (pc.getPlayerEntity().pos.isMoving()) return;
final Coord plpos = pc.getCoord();
final Coord clicked = view.toWorldPos(pos);
final Polar p = Polar.fromCoord(clicked.x - plpos.x, clicked.y - plpos.y);
final int dir = Deg.round90(p.getAngleDeg()) / 90;
switch (dir) {
case 0:
pc.goEast();
break;
case 1:
pc.goSouth();
break;
case 2:
pc.goWest();
break;
case 3:
pc.goNorth();
break;
}
}
@Override
public boolean onKey(MapView world, PlayerControl player, int key, boolean down)
{
return false;
}
@Override
public boolean onStepEnd(MapView view, PlayerControl pc)
{
if(!InputSystem.isMouseButtonDown(0)) return false;
tryWalk(view, pc, InputSystem.getMousePos());
return true;
}
}

@ -1,44 +0,0 @@
package mightypork.rogue.world.gui.interaction;
import mightypork.gamecore.util.math.algo.Coord;
import mightypork.gamecore.util.math.constraints.vect.Vect;
import mightypork.rogue.world.PlayerControl;
import mightypork.rogue.world.WorldProvider;
import mightypork.rogue.world.gui.MapView;
public class MIPTileClick implements MapInteractionPlugin {
@Override
public boolean onStepEnd(MapView wv, PlayerControl player)
{
return false;
}
@Override
public boolean onClick(MapView wv, PlayerControl player, Vect mouse, int button, boolean down)
{
if (!down && button == 0) {
Coord pos = wv.toWorldPos(mouse);
player.clickTile(pos);
System.out.println("~");
return true;
}
return false;
}
@Override
public boolean onKey(MapView wv, PlayerControl player, int key, boolean down)
{
return false;
}
@Override
public void update(MapView mapView, PlayerControl pc, double delta)
{
}
}

@ -15,8 +15,8 @@ public interface MapInteractionPlugin {
boolean onKey(MapView mapView, PlayerControl player, int key, boolean down); boolean onKey(MapView mapView, PlayerControl player, int key, boolean down);
void update(MapView mapView, PlayerControl pc, double delta); void update(MapView mapView, PlayerControl pc, double delta);
} }

@ -243,13 +243,14 @@ public class Level implements MapAccess, IonObjBinary {
/** /**
* Try to add entity at given pos * Try to add entity at given pos
*
* @param entity the entity * @param entity the entity
* @param pos pos * @param pos pos
* @return true if added (false if void, wall etc) * @return true if added (false if void, wall etc)
*/ */
public boolean addEntity(Entity entity, Coord pos) public boolean addEntity(Entity entity, Coord pos)
{ {
Tile t = getTile(pos); final Tile t = getTile(pos);
if (!t.isWalkable()) return false; if (!t.isWalkable()) return false;
addEntity(entity); addEntity(entity);

@ -49,7 +49,7 @@ public abstract class Tile implements IonObjBlob {
{ {
if (!isExplored()) return; if (!isExplored()) return;
TileRenderer r = getRenderer(); final TileRenderer r = getRenderer();
if (r == null) { if (r == null) {
Log.e("Tile with no renderer: " + Log.str(this)); Log.e("Tile with no renderer: " + Log.str(this));
return; return;

@ -1,5 +1,6 @@
package mightypork.rogue.world.tile; package mightypork.rogue.world.tile;
import mightypork.rogue.world.gen.TileProtectLevel; import mightypork.rogue.world.gen.TileProtectLevel;

@ -8,7 +8,7 @@ import mightypork.gamecore.util.ion.IonOutput;
/** /**
* Tile model (logic of a tile) * Tile model (builder)
* *
* @author MightyPork * @author MightyPork
*/ */

@ -22,20 +22,23 @@ public abstract class TileRenderer implements Updateable {
private static TxQuad SH_N, SH_S, SH_E, SH_W, SH_NW, SH_NE, SH_SW, SH_SE; private static TxQuad SH_N, SH_S, SH_E, SH_W, SH_NW, SH_NE, SH_SW, SH_SE;
private static TxQuad UFOG_N, UFOG_S, UFOG_E, UFOG_W, UFOG_NW, UFOG_NE, UFOG_SW, UFOG_SE; private static TxQuad UFOG_N, UFOG_S, UFOG_E, UFOG_W, UFOG_NW, UFOG_NE, UFOG_SW, UFOG_SE;
private static boolean inited; private static boolean inited;
// data // data
public byte shadows; public byte shadows;
public boolean shadowsComputed; public boolean shadowsComputed;
protected final Tile tile; protected final Tile tile;
protected Tile getTile() {
protected Tile getTile()
{
return tile; return tile;
} }
public TileRenderer(Tile tile) public TileRenderer(Tile tile)
{ {
this.tile = tile; this.tile = tile;
@ -66,7 +69,7 @@ public abstract class TileRenderer implements Updateable {
public void renderShadows(TileRenderContext context) public void renderShadows(TileRenderContext context)
{ {
if (!shadowsComputed) { if (!shadowsComputed) {
// no shadows computed yet // no shadows computed yet
@ -126,6 +129,7 @@ public abstract class TileRenderer implements Updateable {
if ((ufog & Sides.SE_CORNER) == Sides.MASK_SE) Render.quadTextured(rect, UFOG_SE); if ((ufog & Sides.SE_CORNER) == Sides.MASK_SE) Render.quadTextured(rect, UFOG_SE);
} }
@Override @Override
public void update(double delta) public void update(double delta)
{ {

@ -5,10 +5,7 @@ import java.io.IOException;
import mightypork.gamecore.util.ion.IonInput; import mightypork.gamecore.util.ion.IonInput;
import mightypork.gamecore.util.ion.IonOutput; import mightypork.gamecore.util.ion.IonOutput;
import mightypork.rogue.world.tile.renderers.BasicTileRenderer; import mightypork.rogue.world.tile.tiles.NullTile;
import mightypork.rogue.world.tile.renderers.DoorTileRenderer;
import mightypork.rogue.world.tile.renderers.NullTileRenderer;
import mightypork.rogue.world.tile.tiles.*;
import mightypork.rogue.world.tile.tiles.brick.TileBrickDoor; import mightypork.rogue.world.tile.tiles.brick.TileBrickDoor;
import mightypork.rogue.world.tile.tiles.brick.TileBrickFloor; import mightypork.rogue.world.tile.tiles.brick.TileBrickFloor;
import mightypork.rogue.world.tile.tiles.brick.TileBrickPassage; import mightypork.rogue.world.tile.tiles.brick.TileBrickPassage;
@ -36,9 +33,13 @@ public final class Tiles {
public static void register(int id, TileModel model) public static void register(int id, TileModel model)
{ {
if (id < 0 || id >= tiles.length) { throw new IllegalArgumentException("Tile ID " + id + " is out of range."); } if (id < 0 || id >= tiles.length) {
throw new IllegalArgumentException("Tile ID " + id + " is out of range.");
}
if (tiles[id] != null) { throw new IllegalArgumentException("Tile ID " + id + " already in use."); } if (tiles[id] != null) {
throw new IllegalArgumentException("Tile ID " + id + " already in use.");
}
tiles[id] = model; tiles[id] = model;
} }
@ -48,7 +49,9 @@ public final class Tiles {
{ {
final TileModel m = tiles[id]; final TileModel m = tiles[id];
if (m == null) { throw new IllegalArgumentException("No tile with ID " + id + "."); } if (m == null) {
throw new IllegalArgumentException("No tile with ID " + id + ".");
}
return m; return m;
} }

@ -5,9 +5,7 @@ import mightypork.gamecore.render.Render;
import mightypork.gamecore.resources.textures.TxSheet; import mightypork.gamecore.resources.textures.TxSheet;
import mightypork.gamecore.util.math.constraints.rect.Rect; import mightypork.gamecore.util.math.constraints.rect.Rect;
import mightypork.gamecore.util.math.timing.TimedTask; import mightypork.gamecore.util.math.timing.TimedTask;
import mightypork.rogue.Res;
import mightypork.rogue.world.level.render.TileRenderContext; import mightypork.rogue.world.level.render.TileRenderContext;
import mightypork.rogue.world.tile.Tile;
import mightypork.rogue.world.tile.TileRenderer; import mightypork.rogue.world.tile.TileRenderer;
import mightypork.rogue.world.tile.tiles.TileBaseDoor; import mightypork.rogue.world.tile.tiles.TileBaseDoor;
@ -25,7 +23,6 @@ public class DoorTileRenderer extends TileRenderer {
@Override @Override
public void run() public void run()
{ {
System.out.println("CLOSEDOOR + "+ ((TileBaseDoor) tile).isOpen());
visuallyOpen = ((TileBaseDoor) tile).isOpen(); visuallyOpen = ((TileBaseDoor) tile).isOpen();
} }
}; };
@ -49,13 +46,13 @@ public class DoorTileRenderer extends TileRenderer {
if (!visuallyOpen && ((TileBaseDoor) tile).isOpen()) visuallyOpen = true; if (!visuallyOpen && ((TileBaseDoor) tile).isOpen()) visuallyOpen = true;
if (visuallyOpen && !((TileBaseDoor) tile).isOpen()) { if (visuallyOpen && !((TileBaseDoor) tile).isOpen()) {
if(!closeTask.isRunning()) closeTask.start(0.4); if (!closeTask.isRunning()) closeTask.start(0.4);
} }
if (visuallyOpen) { if (visuallyOpen) {
Render.quadTextured(rect, open.getRandomQuad(context.getTileNoise())); Render.quadTextured(rect, open.getRandomQuad(context.getTileNoise()));
} else { } else {
TxSheet sheet = (((TileBaseDoor) tile).isLocked() ? locked : closed); final TxSheet sheet = (((TileBaseDoor) tile).isLocked() ? locked : closed);
Render.quadTextured(rect, sheet.getRandomQuad(context.getTileNoise())); Render.quadTextured(rect, sheet.getRandomQuad(context.getTileNoise()));
} }
} }

@ -2,7 +2,6 @@ package mightypork.rogue.world.tile.renderers;
import mightypork.rogue.world.level.render.TileRenderContext; import mightypork.rogue.world.level.render.TileRenderContext;
import mightypork.rogue.world.tile.Tile;
import mightypork.rogue.world.tile.TileRenderer; import mightypork.rogue.world.tile.TileRenderer;

@ -17,6 +17,7 @@ public class NullTile extends Tile {
super(model); super(model);
} }
@Override @Override
protected TileRenderer getRenderer() protected TileRenderer getRenderer()
{ {

@ -10,15 +10,16 @@ import mightypork.rogue.world.tile.renderers.BasicTileRenderer;
public abstract class TileBaseFloor extends TileWalkable { public abstract class TileBaseFloor extends TileWalkable {
private BasicTileRenderer renderer; private final BasicTileRenderer renderer;
public TileBaseFloor(TileModel model, TxSheet sheet) public TileBaseFloor(TileModel model, TxSheet sheet)
{ {
super(model); super(model);
this.renderer = new BasicTileRenderer(this, sheet); this.renderer = new BasicTileRenderer(this, sheet);
} }
@Override @Override
protected TileRenderer getRenderer() protected TileRenderer getRenderer()
{ {

@ -15,7 +15,7 @@ import mightypork.rogue.world.tile.renderers.BasicTileRenderer;
*/ */
public abstract class TileBasePassage extends TileSolid { public abstract class TileBasePassage extends TileSolid {
private BasicTileRenderer renderer; private final BasicTileRenderer renderer;
public TileBasePassage(TileModel model, TxSheet sheet) public TileBasePassage(TileModel model, TxSheet sheet)

@ -8,12 +8,8 @@ import mightypork.gamecore.util.ion.IonInput;
import mightypork.gamecore.util.ion.IonOutput; import mightypork.gamecore.util.ion.IonOutput;
import mightypork.gamecore.util.math.color.Color; import mightypork.gamecore.util.math.color.Color;
import mightypork.gamecore.util.math.color.pal.RGB; import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.gamecore.util.math.timing.TimedTask;
import mightypork.rogue.world.level.Level;
import mightypork.rogue.world.tile.TileModel; import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.TileRenderer;
import mightypork.rogue.world.tile.TileType; import mightypork.rogue.world.tile.TileType;
import mightypork.rogue.world.tile.renderers.DoorTileRenderer;
public abstract class TileBaseSecretDoor extends TileBaseDoor { public abstract class TileBaseSecretDoor extends TileBaseDoor {

@ -2,16 +2,14 @@ package mightypork.rogue.world.tile.tiles;
import mightypork.gamecore.resources.textures.TxSheet; import mightypork.gamecore.resources.textures.TxSheet;
import mightypork.rogue.world.level.render.TileRenderContext;
import mightypork.rogue.world.tile.TileModel; import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.TileRenderer;
import mightypork.rogue.world.tile.TileType; import mightypork.rogue.world.tile.TileType;
import mightypork.rogue.world.tile.renderers.BasicTileRenderer; import mightypork.rogue.world.tile.renderers.BasicTileRenderer;
public abstract class TileBaseWall extends TileSolid { public abstract class TileBaseWall extends TileSolid {
private BasicTileRenderer renderer; private final BasicTileRenderer renderer;
public TileBaseWall(TileModel model, TxSheet sheet) public TileBaseWall(TileModel model, TxSheet sheet)
@ -21,6 +19,7 @@ public abstract class TileBaseWall extends TileSolid {
} }
@Override
public BasicTileRenderer getRenderer() public BasicTileRenderer getRenderer()
{ {
return renderer; return renderer;

@ -4,7 +4,6 @@ package mightypork.rogue.world.tile.tiles;
import mightypork.rogue.world.item.Item; import mightypork.rogue.world.item.Item;
import mightypork.rogue.world.tile.Tile; import mightypork.rogue.world.tile.Tile;
import mightypork.rogue.world.tile.TileModel; import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.TileRenderer;
public abstract class TileSolid extends Tile { public abstract class TileSolid extends Tile {

@ -12,7 +12,6 @@ import mightypork.rogue.world.level.render.TileRenderContext;
import mightypork.rogue.world.tile.DroppedItemRenderer; import mightypork.rogue.world.tile.DroppedItemRenderer;
import mightypork.rogue.world.tile.Tile; import mightypork.rogue.world.tile.Tile;
import mightypork.rogue.world.tile.TileModel; import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.TileRenderer;
public abstract class TileWalkable extends Tile { public abstract class TileWalkable extends Tile {

@ -1,12 +1,13 @@
package mightypork.rogue.world.tile.tiles.brick; package mightypork.rogue.world.tile.tiles.brick;
import mightypork.rogue.Res; import mightypork.rogue.Res;
import mightypork.rogue.world.tile.TileModel; import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.tiles.TileBaseDoor; import mightypork.rogue.world.tile.tiles.TileBaseDoor;
public class TileBrickDoor extends TileBaseDoor { public class TileBrickDoor extends TileBaseDoor {
public TileBrickDoor(TileModel model) public TileBrickDoor(TileModel model)
{ {
//@formatter:off //@formatter:off

@ -1,13 +1,13 @@
package mightypork.rogue.world.tile.tiles.brick; package mightypork.rogue.world.tile.tiles.brick;
import mightypork.gamecore.resources.textures.TxSheet;
import mightypork.rogue.Res; import mightypork.rogue.Res;
import mightypork.rogue.world.tile.TileModel; import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.tiles.TileBaseFloor; import mightypork.rogue.world.tile.tiles.TileBaseFloor;
public class TileBrickFloor extends TileBaseFloor { public class TileBrickFloor extends TileBaseFloor {
public TileBrickFloor(TileModel model) public TileBrickFloor(TileModel model)
{ {
super(model, Res.sheet("tile.brick.floor")); super(model, Res.sheet("tile.brick.floor"));

@ -3,7 +3,6 @@ package mightypork.rogue.world.tile.tiles.brick;
import mightypork.rogue.Res; import mightypork.rogue.Res;
import mightypork.rogue.world.tile.TileModel; import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.tiles.TileBaseDoor;
import mightypork.rogue.world.tile.tiles.TileBasePassage; import mightypork.rogue.world.tile.tiles.TileBasePassage;

@ -1,15 +1,13 @@
package mightypork.rogue.world.tile.tiles.brick; package mightypork.rogue.world.tile.tiles.brick;
import mightypork.gamecore.util.math.color.Color;
import mightypork.gamecore.util.math.color.pal.RGB;
import mightypork.rogue.Res; import mightypork.rogue.Res;
import mightypork.rogue.world.tile.TileModel; import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.tiles.TileBaseDoor;
import mightypork.rogue.world.tile.tiles.TileBaseSecretDoor; import mightypork.rogue.world.tile.tiles.TileBaseSecretDoor;
public class TileBrickSecretDoor extends TileBaseSecretDoor { public class TileBrickSecretDoor extends TileBaseSecretDoor {
public TileBrickSecretDoor(TileModel model) public TileBrickSecretDoor(TileModel model)
{ {
//@formatter:off //@formatter:off

@ -1,13 +1,13 @@
package mightypork.rogue.world.tile.tiles.brick; package mightypork.rogue.world.tile.tiles.brick;
import mightypork.gamecore.resources.textures.TxSheet;
import mightypork.rogue.Res; import mightypork.rogue.Res;
import mightypork.rogue.world.tile.TileModel; import mightypork.rogue.world.tile.TileModel;
import mightypork.rogue.world.tile.tiles.TileBaseWall; import mightypork.rogue.world.tile.tiles.TileBaseWall;
public class TileBrickWall extends TileBaseWall { public class TileBrickWall extends TileBaseWall {
public TileBrickWall(TileModel model) public TileBrickWall(TileModel model)
{ {
super(model, Res.sheet("tile.brick.wall")); super(model, Res.sheet("tile.brick.wall"));

Loading…
Cancel
Save