improved mouse controls; cleanup
This commit is contained in:
@@ -54,7 +54,9 @@ public abstract class BusEvent<HANDLER> {
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,9 @@ class EventChannel<EVENT extends BusEvent<CLIENT>, CLIENT> {
|
||||
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.eventClass = eventClass;
|
||||
|
||||
@@ -62,7 +62,9 @@ public abstract class BusNode implements BusAccess, ClientHub {
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,9 @@ public class HorizontalFixedFlowLayout extends LayoutComponent {
|
||||
this.colWidth = elementWidth;
|
||||
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.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
|
||||
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
|
||||
if (active != null) {
|
||||
|
||||
@@ -82,7 +82,9 @@ public class KeyStroke {
|
||||
|
||||
if (keys == null) {
|
||||
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;
|
||||
|
||||
|
||||
@@ -295,7 +295,9 @@ public class Log {
|
||||
|
||||
final String nl = System.getProperty("line.separator");
|
||||
|
||||
if (message.equals("\n")) { return nl; }
|
||||
if (message.equals("\n")) {
|
||||
return nl;
|
||||
}
|
||||
|
||||
if (message.charAt(0) == '\n') {
|
||||
message = nl + message.substring(1);
|
||||
@@ -357,7 +359,9 @@ public class Log {
|
||||
public static String str(Class<?> cls)
|
||||
{
|
||||
final LogAlias ln = cls.getAnnotation(LogAlias.class);
|
||||
if (ln != null) { return ln.name(); }
|
||||
if (ln != null) {
|
||||
return ln.name();
|
||||
}
|
||||
|
||||
String name = cls.getName();
|
||||
|
||||
|
||||
@@ -112,7 +112,9 @@ public class ArchivingLog extends SimpleLog {
|
||||
|
||||
// playing with fireee
|
||||
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 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
|
||||
if (txquad.isFlippedY()) {
|
||||
|
||||
@@ -70,7 +70,9 @@ public class SoundBank extends LightAppModule {
|
||||
public LoopPlayer getLoop(String 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;
|
||||
}
|
||||
|
||||
@@ -84,7 +86,9 @@ public class SoundBank extends LightAppModule {
|
||||
public EffectPlayer getEffect(String 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,9 @@ public class FontBank extends LightAppModule {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public class CachedFont implements GLFont {
|
||||
*/
|
||||
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;
|
||||
|
||||
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);
|
||||
loadResource(resource);
|
||||
|
||||
@@ -37,7 +37,9 @@ public class QuadGrid {
|
||||
*/
|
||||
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);
|
||||
}
|
||||
@@ -55,9 +57,13 @@ public class QuadGrid {
|
||||
*/
|
||||
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));
|
||||
}
|
||||
@@ -74,10 +80,13 @@ public class QuadGrid {
|
||||
*/
|
||||
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(
|
||||
"Requested invalid txsheet size (would go beyond texture size)."); }
|
||||
if (x + width > txWidth || y + height > txHeight) {
|
||||
throw new IndexOutOfBoundsException("Requested invalid txsheet size (would go beyond texture size).");
|
||||
}
|
||||
|
||||
return makeQuad(x, y).makeSheet(width, height);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,9 @@ public class FileSuffixFilter implements FileFilter {
|
||||
final String fname = pathname.getName().toLowerCase().trim();
|
||||
|
||||
for (final String suffix : suffixes) {
|
||||
if (fname.endsWith(suffix.toLowerCase().trim())) { return true; }
|
||||
if (fname.endsWith(suffix.toLowerCase().trim())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -82,7 +82,9 @@ public class FileTreeDiff {
|
||||
final int read1 = cin1.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;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,9 @@ public class FileUtils {
|
||||
if (!source.exists()) return;
|
||||
|
||||
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();
|
||||
for (final String element : children) {
|
||||
@@ -47,7 +49,9 @@ public class FileUtils {
|
||||
}
|
||||
|
||||
} else {
|
||||
if (filter != null && !filter.accept(source)) { return; }
|
||||
if (filter != null && !filter.accept(source)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (filesCopied != null) filesCopied.add(target);
|
||||
copyFile(source, target);
|
||||
@@ -72,7 +76,9 @@ public class FileUtils {
|
||||
}
|
||||
|
||||
} else {
|
||||
if (filter != null && !filter.isValid(source.getAbsolutePath())) { return; }
|
||||
if (filter != null && !filter.isValid(source.getAbsolutePath())) {
|
||||
return;
|
||||
}
|
||||
|
||||
files.add(source);
|
||||
}
|
||||
@@ -106,9 +112,13 @@ public class FileUtils {
|
||||
*/
|
||||
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];
|
||||
int len;
|
||||
@@ -127,7 +137,9 @@ public class FileUtils {
|
||||
*/
|
||||
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();
|
||||
|
||||
|
||||
@@ -56,7 +56,9 @@ public class OsUtils {
|
||||
final File f = new File(getWorkDir(dirname), subfolderName);
|
||||
|
||||
if (!f.exists() && create) {
|
||||
if (!f.mkdirs()) { throw new RuntimeException("Could not create."); }
|
||||
if (!f.mkdirs()) {
|
||||
throw new RuntimeException("Could not create.");
|
||||
}
|
||||
}
|
||||
|
||||
return f;
|
||||
@@ -135,7 +137,9 @@ public class OsUtils {
|
||||
|
||||
if (!file.exists() || !file.isDirectory()) {
|
||||
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;
|
||||
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)) {
|
||||
|
||||
@@ -263,7 +263,9 @@ public class SortedProperties extends java.util.Properties {
|
||||
private static char hexDigit(char ch, int offset)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -93,9 +93,13 @@ public class Ion {
|
||||
if (mark > 255) throw new IllegalArgumentException("Mark must be < 256.");
|
||||
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 {
|
||||
objClass.getConstructor();
|
||||
@@ -278,9 +282,13 @@ public class Ion {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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) {
|
||||
writeMark(Ion.BOOLEAN);
|
||||
|
||||
@@ -594,7 +594,9 @@ public class Calc {
|
||||
*/
|
||||
public static List<Integer> parseIntList(String list)
|
||||
{
|
||||
if (list == null) { return null; }
|
||||
if (list == null) {
|
||||
return null;
|
||||
}
|
||||
final String[] parts = list.split(",");
|
||||
|
||||
final ArrayList<Integer> intList = new ArrayList<>();
|
||||
@@ -654,7 +656,9 @@ public class Calc {
|
||||
*/
|
||||
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
|
||||
* keep the rest as is.
|
||||
* Pathfinder proxy. Can be used to override individual methods but keep the
|
||||
* rest as is.
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
|
||||
@@ -205,7 +205,9 @@ public abstract class Color {
|
||||
*/
|
||||
public static void pushAlpha(Num alpha)
|
||||
{
|
||||
if (!alphaStackEnabled) { return; }
|
||||
if (!alphaStackEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
alphaStack.push(alpha);
|
||||
}
|
||||
@@ -219,9 +221,13 @@ public abstract class Color {
|
||||
*/
|
||||
public static void popAlpha()
|
||||
{
|
||||
if (!alphaStackEnabled) { return; }
|
||||
if (!alphaStackEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (alphaStack.isEmpty()) { throw new EmptyStackException(); }
|
||||
if (alphaStack.isEmpty()) {
|
||||
throw new EmptyStackException();
|
||||
}
|
||||
|
||||
alphaStack.pop();
|
||||
}
|
||||
|
||||
@@ -1028,7 +1028,9 @@ public abstract class Rect implements RectBound, Digestable<RectDigest> {
|
||||
double rw = other.size().x();
|
||||
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 ty = this.origin().y();
|
||||
|
||||
@@ -58,9 +58,13 @@ public class TiledRect extends RectProxy {
|
||||
*/
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -29,7 +29,8 @@ public abstract class TimedTask implements Runnable, Updateable {
|
||||
}
|
||||
|
||||
|
||||
public boolean isRunning() {
|
||||
public boolean isRunning()
|
||||
{
|
||||
return !timer.isFinished();
|
||||
}
|
||||
|
||||
|
||||
@@ -64,11 +64,15 @@ public class TimerFps {
|
||||
*/
|
||||
public double getFraction()
|
||||
{
|
||||
if (getSkipped() >= 1) { return 1; }
|
||||
if (getSkipped() >= 1) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
final long time = getTime();
|
||||
|
||||
if (time <= nextFrame) { return (double) (time - lastFrame) / (double) FRAME; }
|
||||
if (time <= nextFrame) {
|
||||
return (double) (time - lastFrame) / (double) FRAME;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -137,7 +137,9 @@ public class Convert {
|
||||
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();
|
||||
}
|
||||
@@ -177,7 +179,9 @@ public class Convert {
|
||||
final double x = Double.parseDouble(parts[0].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());
|
||||
|
||||
|
||||
@@ -59,9 +59,13 @@ public class Pair<T1, T2> {
|
||||
@Override
|
||||
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;
|
||||
|
||||
|
||||
@@ -34,7 +34,9 @@ public class VarargsParser<K, V> {
|
||||
{
|
||||
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;
|
||||
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.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.closed", tiles.makeSheet(1, 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.util.math.constraints.num.Num;
|
||||
import mightypork.rogue.world.gui.MapView;
|
||||
import mightypork.rogue.world.gui.interaction.MIPClickPathfWalk;
|
||||
import mightypork.rogue.world.gui.interaction.MIPKeyWalk;
|
||||
import mightypork.rogue.world.gui.interaction.MIPMouseWalk;
|
||||
import mightypork.rogue.world.gui.interaction.MIPTileClick;
|
||||
import mightypork.rogue.world.gui.interaction.MIPKeyboard;
|
||||
import mightypork.rogue.world.gui.interaction.MIPMouse;
|
||||
|
||||
|
||||
public class WorldLayer extends ScreenLayer {
|
||||
@@ -25,10 +23,8 @@ public class WorldLayer extends ScreenLayer {
|
||||
worldView = new MapView();
|
||||
|
||||
// map input plugins
|
||||
worldView.addPlugin(new MIPKeyWalk());
|
||||
worldView.addPlugin(new MIPTileClick());
|
||||
worldView.addPlugin(new MIPClickPathfWalk());
|
||||
worldView.addPlugin(new MIPMouseWalk());
|
||||
worldView.addPlugin(new MIPKeyboard());
|
||||
worldView.addPlugin(new MIPMouse());
|
||||
|
||||
// size of lower navbar
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
public boolean clickTile(Step side)
|
||||
{
|
||||
return clickTile(getCoord().add(side));
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
@@ -121,4 +123,12 @@ public abstract class PlayerControl {
|
||||
getPlayerEntity().pos.cancelPath();
|
||||
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.rogue.world.entity.Entities;
|
||||
import mightypork.rogue.world.entity.Entity;
|
||||
import mightypork.rogue.world.entity.EntityModel;
|
||||
import mightypork.rogue.world.level.Level;
|
||||
|
||||
|
||||
@@ -95,9 +94,12 @@ public class World implements IonObjBundled, Updateable {
|
||||
return eid++;
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
final int playerEid = getNewEID();
|
||||
|
||||
@@ -32,7 +32,9 @@ public class WorldProvider extends RootBusNode {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -25,9 +25,13 @@ public final class Entities {
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -37,7 +41,9 @@ public final class Entities {
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -28,11 +28,13 @@ public final class EntityModel {
|
||||
this.tileClass = entity;
|
||||
}
|
||||
|
||||
|
||||
public Entity createEntity(World world)
|
||||
{
|
||||
return createEntity(world.getNewEID());
|
||||
}
|
||||
|
||||
|
||||
public Entity createEntity(int eid)
|
||||
{
|
||||
try {
|
||||
|
||||
@@ -27,13 +27,15 @@ public class EntityPathFinder extends PathFinder {
|
||||
|
||||
|
||||
@Override
|
||||
public int getCost(Coord from, Coord to) {
|
||||
public int getCost(Coord from, Coord to)
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getMinCost() {
|
||||
public int getMinCost()
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
|
||||
{
|
||||
if (!chasing) return;
|
||||
|
||||
Entity prey = getPreyEntity();
|
||||
final Entity prey = getPreyEntity();
|
||||
|
||||
if (prey == null || prey.isDead()) {
|
||||
//System.out.println("prey dead?");
|
||||
@@ -178,7 +178,7 @@ public class MonsterAi extends EntityModule implements EntityMoveListener {
|
||||
timerAttack.update(delta);
|
||||
|
||||
if (chasing && !entity.pos.isMoving()) {
|
||||
Entity prey = getPreyEntity();
|
||||
final Entity prey = getPreyEntity();
|
||||
|
||||
if (!isPreyInAttackRange(prey)) {
|
||||
//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.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.renderers.EntityRenderer;
|
||||
import mightypork.rogue.world.entity.renderers.EntityRendererMobLR;
|
||||
@@ -74,12 +78,12 @@ public class PlayerEntity extends Entity {
|
||||
|
||||
@Override
|
||||
public int getCost(Coord from, Coord to)
|
||||
{
|
||||
{
|
||||
if (!getLevel().getTile(pos.getCoord()).isExplored()) {
|
||||
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.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.EntityRendererMobLR;
|
||||
|
||||
|
||||
@@ -94,8 +94,8 @@ public class EntityModuleHealth extends EntityModule {
|
||||
{
|
||||
setHealth(health - attackStrength);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void fill()
|
||||
{
|
||||
setHealth(maxHealth);
|
||||
|
||||
@@ -11,7 +11,6 @@ import java.util.Set;
|
||||
import mightypork.gamecore.util.ion.IonBundle;
|
||||
import mightypork.gamecore.util.math.algo.Coord;
|
||||
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.rogue.world.entity.Entity;
|
||||
import mightypork.rogue.world.entity.EntityModule;
|
||||
@@ -202,11 +201,17 @@ public class EntityModulePosition extends EntityModule {
|
||||
{
|
||||
return entityPos.getVisualPos();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public boolean isMoving()
|
||||
{
|
||||
return walking;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasPath()
|
||||
{
|
||||
return isMoving() || !path.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package mightypork.rogue.world.entity.renderers;
|
||||
|
||||
|
||||
import mightypork.rogue.world.entity.Entity;
|
||||
import mightypork.rogue.world.level.render.MapRenderContext;
|
||||
|
||||
|
||||
public abstract class EntityRenderer {
|
||||
public abstract class EntityRenderer {
|
||||
|
||||
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.entity.Entities;
|
||||
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.themes.ThemeBrick;
|
||||
import mightypork.rogue.world.level.Level;
|
||||
@@ -45,16 +44,16 @@ public class LevelGenerator {
|
||||
// TODO tmp
|
||||
// spawn rats
|
||||
|
||||
Coord pos = Coord.make(0,0);
|
||||
for(int i=0; i<1;i++) { // 4+complexity + rand.nextInt(1+complexity)
|
||||
final Coord pos = Coord.make(0, 0);
|
||||
for (int i = 0; i < 1; i++) { // 4+complexity + rand.nextInt(1+complexity)
|
||||
|
||||
final Entity e = Entities.RAT.createEntity(world);
|
||||
|
||||
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.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 secretDoor();
|
||||
}
|
||||
|
||||
@@ -30,7 +30,9 @@ public class RoomDesc {
|
||||
int rw = amax.x - amin.x;
|
||||
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 ty = min.y;
|
||||
|
||||
@@ -41,8 +41,8 @@ public class ScratchMap {
|
||||
@Override
|
||||
public boolean isAccessible(Coord pos)
|
||||
{
|
||||
if(!isIn(pos)) return false;
|
||||
Tile t = get(pos);
|
||||
if (!isIn(pos)) return false;
|
||||
final Tile t = get(pos);
|
||||
return t.isPotentiallyWalkable() || (t.genData.protection != TileProtectLevel.STRONG);
|
||||
}
|
||||
|
||||
@@ -189,7 +189,9 @@ public class ScratchMap {
|
||||
|
||||
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];
|
||||
}
|
||||
@@ -203,7 +205,9 @@ public class ScratchMap {
|
||||
|
||||
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;
|
||||
return true;
|
||||
|
||||
@@ -21,15 +21,15 @@ public abstract class AbstractRectRoom implements RoomBuilder {
|
||||
{
|
||||
// half width, half height actually
|
||||
final Coord innerSize = getInnerSize(rand);
|
||||
final int width = 2+innerSize.x;
|
||||
final int height = 2+innerSize.y;
|
||||
final int width = 2 + innerSize.x;
|
||||
final int height = 2 + innerSize.y;
|
||||
|
||||
int wLow = width/2;
|
||||
int wHigh = width - wLow;
|
||||
int hLow = height/2;
|
||||
int hHigh = height - hLow;
|
||||
final int wLow = width / 2;
|
||||
final int wHigh = width - wLow;
|
||||
final int hLow = height / 2;
|
||||
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);
|
||||
|
||||
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)
|
||||
{
|
||||
int width = max.x - min.x;
|
||||
int height = max.y - min.y;
|
||||
final int width = max.x - min.x;
|
||||
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
|
||||
final Coord door = min.copy();
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package mightypork.rogue.world.gui;
|
||||
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -22,7 +21,6 @@ import mightypork.rogue.world.WorldProvider;
|
||||
import mightypork.rogue.world.WorldRenderer;
|
||||
import mightypork.rogue.world.entity.modules.EntityMoveListener;
|
||||
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()
|
||||
{
|
||||
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()
|
||||
{
|
||||
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()
|
||||
{
|
||||
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;
|
||||
|
||||
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();
|
||||
break;
|
||||
}
|
||||
@@ -114,7 +112,7 @@ public class MapView extends InputComponent implements KeyListener, MouseButtonL
|
||||
public void receive(KeyEvent event)
|
||||
{
|
||||
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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
+4
-4
@@ -10,7 +10,7 @@ import mightypork.rogue.world.PlayerControl;
|
||||
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 Step[] sides = { Sides.W, Sides.E, Sides.N, Sides.S };
|
||||
@@ -33,7 +33,7 @@ public class MIPKeyWalk implements MapInteractionPlugin {
|
||||
@Override
|
||||
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++) {
|
||||
if (key == keys[i]) {
|
||||
@@ -47,12 +47,12 @@ public class MIPKeyWalk implements MapInteractionPlugin {
|
||||
|
||||
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++) {
|
||||
if (InputSystem.isKeyDown(keys[i])) {
|
||||
|
||||
Step side = sides[i];
|
||||
final Step side = sides[i];
|
||||
if (pc.canGo(side)) {
|
||||
pc.go(side);
|
||||
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);
|
||||
|
||||
|
||||
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
|
||||
*
|
||||
* @param entity the entity
|
||||
* @param pos pos
|
||||
* @return true if added (false if void, wall etc)
|
||||
*/
|
||||
public boolean addEntity(Entity entity, Coord pos)
|
||||
{
|
||||
Tile t = getTile(pos);
|
||||
final Tile t = getTile(pos);
|
||||
if (!t.isWalkable()) return false;
|
||||
|
||||
addEntity(entity);
|
||||
|
||||
@@ -49,7 +49,7 @@ public abstract class Tile implements IonObjBlob {
|
||||
{
|
||||
if (!isExplored()) return;
|
||||
|
||||
TileRenderer r = getRenderer();
|
||||
final TileRenderer r = getRenderer();
|
||||
if (r == null) {
|
||||
Log.e("Tile with no renderer: " + Log.str(this));
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package mightypork.rogue.world.tile;
|
||||
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
@@ -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 UFOG_N, UFOG_S, UFOG_E, UFOG_W, UFOG_NW, UFOG_NE, UFOG_SW, UFOG_SE;
|
||||
|
||||
|
||||
private static boolean inited;
|
||||
|
||||
// data
|
||||
|
||||
|
||||
public byte shadows;
|
||||
public boolean shadowsComputed;
|
||||
|
||||
|
||||
protected final Tile tile;
|
||||
|
||||
protected Tile getTile() {
|
||||
|
||||
protected Tile getTile()
|
||||
{
|
||||
return tile;
|
||||
}
|
||||
|
||||
|
||||
public TileRenderer(Tile tile)
|
||||
{
|
||||
this.tile = tile;
|
||||
@@ -66,7 +69,7 @@ public abstract class TileRenderer implements Updateable {
|
||||
|
||||
|
||||
public void renderShadows(TileRenderContext context)
|
||||
{
|
||||
{
|
||||
if (!shadowsComputed) {
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(double delta)
|
||||
{
|
||||
|
||||
@@ -5,10 +5,7 @@ import java.io.IOException;
|
||||
|
||||
import mightypork.gamecore.util.ion.IonInput;
|
||||
import mightypork.gamecore.util.ion.IonOutput;
|
||||
import mightypork.rogue.world.tile.renderers.BasicTileRenderer;
|
||||
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.NullTile;
|
||||
import mightypork.rogue.world.tile.tiles.brick.TileBrickDoor;
|
||||
import mightypork.rogue.world.tile.tiles.brick.TileBrickFloor;
|
||||
import mightypork.rogue.world.tile.tiles.brick.TileBrickPassage;
|
||||
@@ -36,9 +33,13 @@ public final class Tiles {
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -48,7 +49,9 @@ public final class Tiles {
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -5,9 +5,7 @@ import mightypork.gamecore.render.Render;
|
||||
import mightypork.gamecore.resources.textures.TxSheet;
|
||||
import mightypork.gamecore.util.math.constraints.rect.Rect;
|
||||
import mightypork.gamecore.util.math.timing.TimedTask;
|
||||
import mightypork.rogue.Res;
|
||||
import mightypork.rogue.world.level.render.TileRenderContext;
|
||||
import mightypork.rogue.world.tile.Tile;
|
||||
import mightypork.rogue.world.tile.TileRenderer;
|
||||
import mightypork.rogue.world.tile.tiles.TileBaseDoor;
|
||||
|
||||
@@ -25,7 +23,6 @@ public class DoorTileRenderer extends TileRenderer {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
System.out.println("CLOSEDOOR + "+ ((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()) {
|
||||
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()));
|
||||
} else {
|
||||
TxSheet sheet = (((TileBaseDoor) tile).isLocked() ? locked : closed);
|
||||
final TxSheet sheet = (((TileBaseDoor) tile).isLocked() ? locked : closed);
|
||||
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.tile.Tile;
|
||||
import mightypork.rogue.world.tile.TileRenderer;
|
||||
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ public class NullTile extends Tile {
|
||||
super(model);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected TileRenderer getRenderer()
|
||||
{
|
||||
|
||||
@@ -10,15 +10,16 @@ import mightypork.rogue.world.tile.renderers.BasicTileRenderer;
|
||||
|
||||
public abstract class TileBaseFloor extends TileWalkable {
|
||||
|
||||
private BasicTileRenderer renderer;
|
||||
|
||||
|
||||
private final BasicTileRenderer renderer;
|
||||
|
||||
|
||||
public TileBaseFloor(TileModel model, TxSheet sheet)
|
||||
{
|
||||
super(model);
|
||||
this.renderer = new BasicTileRenderer(this, sheet);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected TileRenderer getRenderer()
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ import mightypork.rogue.world.tile.renderers.BasicTileRenderer;
|
||||
*/
|
||||
public abstract class TileBasePassage extends TileSolid {
|
||||
|
||||
private BasicTileRenderer renderer;
|
||||
private final BasicTileRenderer renderer;
|
||||
|
||||
|
||||
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.math.color.Color;
|
||||
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.TileRenderer;
|
||||
import mightypork.rogue.world.tile.TileType;
|
||||
import mightypork.rogue.world.tile.renderers.DoorTileRenderer;
|
||||
|
||||
|
||||
public abstract class TileBaseSecretDoor extends TileBaseDoor {
|
||||
|
||||
@@ -2,16 +2,14 @@ package mightypork.rogue.world.tile.tiles;
|
||||
|
||||
|
||||
import mightypork.gamecore.resources.textures.TxSheet;
|
||||
import mightypork.rogue.world.level.render.TileRenderContext;
|
||||
import mightypork.rogue.world.tile.TileModel;
|
||||
import mightypork.rogue.world.tile.TileRenderer;
|
||||
import mightypork.rogue.world.tile.TileType;
|
||||
import mightypork.rogue.world.tile.renderers.BasicTileRenderer;
|
||||
|
||||
|
||||
public abstract class TileBaseWall extends TileSolid {
|
||||
|
||||
private BasicTileRenderer renderer;
|
||||
private final BasicTileRenderer renderer;
|
||||
|
||||
|
||||
public TileBaseWall(TileModel model, TxSheet sheet)
|
||||
@@ -21,6 +19,7 @@ public abstract class TileBaseWall extends TileSolid {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BasicTileRenderer getRenderer()
|
||||
{
|
||||
return renderer;
|
||||
|
||||
@@ -4,7 +4,6 @@ package mightypork.rogue.world.tile.tiles;
|
||||
import mightypork.rogue.world.item.Item;
|
||||
import mightypork.rogue.world.tile.Tile;
|
||||
import mightypork.rogue.world.tile.TileModel;
|
||||
import mightypork.rogue.world.tile.TileRenderer;
|
||||
|
||||
|
||||
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.Tile;
|
||||
import mightypork.rogue.world.tile.TileModel;
|
||||
import mightypork.rogue.world.tile.TileRenderer;
|
||||
|
||||
|
||||
public abstract class TileWalkable extends Tile {
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package mightypork.rogue.world.tile.tiles.brick;
|
||||
|
||||
|
||||
import mightypork.rogue.Res;
|
||||
import mightypork.rogue.world.tile.TileModel;
|
||||
import mightypork.rogue.world.tile.tiles.TileBaseDoor;
|
||||
|
||||
|
||||
public class TileBrickDoor extends TileBaseDoor {
|
||||
|
||||
|
||||
public TileBrickDoor(TileModel model)
|
||||
{
|
||||
//@formatter:off
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package mightypork.rogue.world.tile.tiles.brick;
|
||||
|
||||
import mightypork.gamecore.resources.textures.TxSheet;
|
||||
|
||||
import mightypork.rogue.Res;
|
||||
import mightypork.rogue.world.tile.TileModel;
|
||||
import mightypork.rogue.world.tile.tiles.TileBaseFloor;
|
||||
|
||||
|
||||
public class TileBrickFloor extends TileBaseFloor {
|
||||
|
||||
|
||||
public TileBrickFloor(TileModel model)
|
||||
{
|
||||
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.world.tile.TileModel;
|
||||
import mightypork.rogue.world.tile.tiles.TileBaseDoor;
|
||||
import mightypork.rogue.world.tile.tiles.TileBasePassage;
|
||||
|
||||
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
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.world.tile.TileModel;
|
||||
import mightypork.rogue.world.tile.tiles.TileBaseDoor;
|
||||
import mightypork.rogue.world.tile.tiles.TileBaseSecretDoor;
|
||||
|
||||
|
||||
public class TileBrickSecretDoor extends TileBaseSecretDoor {
|
||||
|
||||
|
||||
public TileBrickSecretDoor(TileModel model)
|
||||
{
|
||||
//@formatter:off
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package mightypork.rogue.world.tile.tiles.brick;
|
||||
|
||||
import mightypork.gamecore.resources.textures.TxSheet;
|
||||
|
||||
import mightypork.rogue.Res;
|
||||
import mightypork.rogue.world.tile.TileModel;
|
||||
import mightypork.rogue.world.tile.tiles.TileBaseWall;
|
||||
|
||||
|
||||
public class TileBrickWall extends TileBaseWall {
|
||||
|
||||
|
||||
public TileBrickWall(TileModel model)
|
||||
{
|
||||
super(model, Res.sheet("tile.brick.wall"));
|
||||
|
||||
Reference in New Issue
Block a user