From 7d3695d0a91679662fa8588efe6e54ba2d21d788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Thu, 1 May 2014 01:16:59 +0200 Subject: [PATCH] cleanup & format --- src/mightypork/gamecore/app/BaseApp.java | 5 ++- src/mightypork/gamecore/gui/Action.java | 1 - .../gamecore/gui/events/CrossfadeRequest.java | 2 + .../gamecore/gui/screens/Screen.java | 3 +- .../gui/screens/impl/CrossfadeOverlay.java | 3 +- .../gamecore/gui/screens/impl/LayerColor.java | 6 +-- .../gamecore/logging/SlickLogRedirector.java | 1 + src/mightypork/gamecore/util/ion/Ion.java | 22 ++++------- .../gamecore/util/ion/IonBundle.java | 4 +- .../gamecore/util/math/algo/Coord.java | 13 +++++-- .../gamecore/util/math/algo/Sides.java | 2 +- .../gamecore/util/math/algo/Step.java | 14 ++++--- .../pathfinding/PathFindingContextProxy.java | 5 ++- .../gamecore/util/math/color/pal/CGA.java | 1 + .../util/math/color/pal/COMMODORE.java | 1 + .../gamecore/util/math/color/pal/PAL16.java | 1 + .../gamecore/util/math/color/pal/RGB.java | 1 + .../gamecore/util/math/color/pal/ZX.java | 1 + .../gamecore/util/math/timing/Animator.java | 24 ++++++++---- .../util/math/timing/TaskRepeater.java | 9 ++++- .../gamecore/util/strings/StringWrapper.java | 3 +- .../rogue/screens/game/ScreenGame.java | 8 ++-- .../rogue/screens/menu/MenuButton.java | 5 ++- .../rogue/screens/menu/MenuLayer.java | 5 ++- .../test_bouncyboxes/ScreenTestBouncy.java | 3 +- .../rogue/world/entity/AiTimer.java | 18 +++++---- src/mightypork/rogue/world/entity/Entity.java | 15 ++++---- .../rogue/world/entity/EntityModule.java | 4 +- .../world/entity/entities/MonsterAi.java | 37 ++++++++++--------- .../world/entity/entities/PlayerEntity.java | 13 ++++--- .../world/entity/entities/SimpleMonster.java | 11 ++++-- .../entity/modules/EntityModuleHealth.java | 3 +- .../entity/modules/EntityModulePosition.java | 3 +- .../entity/modules/EntityMoveListener.java | 2 - src/mightypork/rogue/world/gen/MapTheme.java | 1 + .../rogue/world/gen/rooms/DeadEndRoom.java | 7 ++-- .../rogue/world/gen/rooms/SimpleRectRoom.java | 4 +- src/mightypork/rogue/world/level/Level.java | 30 +++++++++------ .../tile/renderers/DoorTileRenderer.java | 1 - .../world/tile/tiles/WallPassageTile.java | 10 +++-- 40 files changed, 176 insertions(+), 126 deletions(-) diff --git a/src/mightypork/gamecore/app/BaseApp.java b/src/mightypork/gamecore/app/BaseApp.java index d7bc01f..ffab61a 100644 --- a/src/mightypork/gamecore/app/BaseApp.java +++ b/src/mightypork/gamecore/app/BaseApp.java @@ -148,14 +148,15 @@ public abstract class BaseApp implements AppAccess, UncaughtExceptionHandler { Log.i("=== Initialized sequence completed ==="); } + @DefaultImpl protected void registerIonizables() { Ion.registerType(Coord.ION_MARK, Coord.class); Ion.registerType(Step.ION_MARK, Step.class); } - - + + /** * Called at the beginning of the initialization sequence, right after lock * was obtained. diff --git a/src/mightypork/gamecore/gui/Action.java b/src/mightypork/gamecore/gui/Action.java index 0c8952a..1b468d6 100644 --- a/src/mightypork/gamecore/gui/Action.java +++ b/src/mightypork/gamecore/gui/Action.java @@ -1,7 +1,6 @@ package mightypork.gamecore.gui; - /** * Triggered action * diff --git a/src/mightypork/gamecore/gui/events/CrossfadeRequest.java b/src/mightypork/gamecore/gui/events/CrossfadeRequest.java index 4866121..da053c8 100644 --- a/src/mightypork/gamecore/gui/events/CrossfadeRequest.java +++ b/src/mightypork/gamecore/gui/events/CrossfadeRequest.java @@ -13,6 +13,7 @@ public class CrossfadeRequest extends BusEvent { private final String screen; private final boolean fromDark; + /** * @param screen screen key to show. Null = exit the app. * @param fromDark true to fade from full black (ie. start of the game) @@ -24,6 +25,7 @@ public class CrossfadeRequest extends BusEvent { this.fromDark = fromDark; } + /** * @param screen screen key to show. Null = exit the app. */ diff --git a/src/mightypork/gamecore/gui/screens/Screen.java b/src/mightypork/gamecore/gui/screens/Screen.java index 06db934..8409727 100644 --- a/src/mightypork/gamecore/gui/screens/Screen.java +++ b/src/mightypork/gamecore/gui/screens/Screen.java @@ -32,7 +32,8 @@ public abstract class Screen extends AppSubModule implements Renderable, RectBou /** * @param app app access */ - public Screen(AppAccess app) { + public Screen(AppAccess app) + { super(app); // disable events initially diff --git a/src/mightypork/gamecore/gui/screens/impl/CrossfadeOverlay.java b/src/mightypork/gamecore/gui/screens/impl/CrossfadeOverlay.java index 79855f0..ff86bc8 100644 --- a/src/mightypork/gamecore/gui/screens/impl/CrossfadeOverlay.java +++ b/src/mightypork/gamecore/gui/screens/impl/CrossfadeOverlay.java @@ -39,7 +39,8 @@ public class CrossfadeOverlay extends Overlay { }; - public CrossfadeOverlay(AppAccess app) { + public CrossfadeOverlay(AppAccess app) + { super(app); final QuadPainter qp = new QuadPainter(color); diff --git a/src/mightypork/gamecore/gui/screens/impl/LayerColor.java b/src/mightypork/gamecore/gui/screens/impl/LayerColor.java index 5e65ee9..f41d3d4 100644 --- a/src/mightypork/gamecore/gui/screens/impl/LayerColor.java +++ b/src/mightypork/gamecore/gui/screens/impl/LayerColor.java @@ -9,9 +9,9 @@ import mightypork.gamecore.util.math.color.Color; public class LayerColor extends ScreenLayer { - private int zIndex; - - + private final int zIndex; + + public LayerColor(Screen screen, Color color, int zIndex) { super(screen); diff --git a/src/mightypork/gamecore/logging/SlickLogRedirector.java b/src/mightypork/gamecore/logging/SlickLogRedirector.java index 3a37820..b6687d5 100644 --- a/src/mightypork/gamecore/logging/SlickLogRedirector.java +++ b/src/mightypork/gamecore/logging/SlickLogRedirector.java @@ -5,6 +5,7 @@ import java.util.logging.Level; import mightypork.gamecore.logging.writers.LogWriter; + /** * Used to redirect slick log into main logger. * diff --git a/src/mightypork/gamecore/util/ion/Ion.java b/src/mightypork/gamecore/util/ion/Ion.java index ca3dbf8..c0c88ef 100644 --- a/src/mightypork/gamecore/util/ion/Ion.java +++ b/src/mightypork/gamecore/util/ion/Ion.java @@ -93,13 +93,9 @@ 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(); @@ -125,7 +121,7 @@ public class Ion { */ public static T fromFile(File file) throws IOException { - try (InputStream in = new FileInputStream(file)) { + try(InputStream in = new FileInputStream(file)) { return fromStream(in); } } @@ -145,7 +141,7 @@ public class Ion { */ public static T fromFile(File file, Class objClass) throws IOException { - try (InputStream in = new FileInputStream(file)) { + try(InputStream in = new FileInputStream(file)) { return fromStream(in, objClass); @@ -182,7 +178,7 @@ public class Ion { */ public static void toFile(File file, IonObjBinary obj) throws IOException { - try (OutputStream out = new FileOutputStream(file)) { + try(OutputStream out = new FileOutputStream(file)) { toStream(out, obj); @@ -282,13 +278,9 @@ public class Ion { final Class 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())); } } } diff --git a/src/mightypork/gamecore/util/ion/IonBundle.java b/src/mightypork/gamecore/util/ion/IonBundle.java index 759b77b..48b065e 100644 --- a/src/mightypork/gamecore/util/ion/IonBundle.java +++ b/src/mightypork/gamecore/util/ion/IonBundle.java @@ -137,12 +137,14 @@ public class IonBundle implements IonObjBinary { { backingMap.put(key, value); } - + + public void put(String key, byte value) { backingMap.put(key, value); } + public void put(String key, char value) { backingMap.put(key, value); diff --git a/src/mightypork/gamecore/util/math/algo/Coord.java b/src/mightypork/gamecore/util/math/algo/Coord.java index 22f4c5e..9a33e62 100644 --- a/src/mightypork/gamecore/util/math/algo/Coord.java +++ b/src/mightypork/gamecore/util/math/algo/Coord.java @@ -46,19 +46,24 @@ public class Coord implements IonObjBundled, IonObjBinary { { return make(0, 0); } - - public Coord() { + + + public Coord() + { // for ion } - public Coord(int x, int y) { + + public Coord(int x, int y) + { super(); this.x = x; this.y = y; } - public Coord(Coord other) { + public Coord(Coord other) + { this.x = other.x; this.y = other.y; } diff --git a/src/mightypork/gamecore/util/math/algo/Sides.java b/src/mightypork/gamecore/util/math/algo/Sides.java index b142fb5..a0442d3 100644 --- a/src/mightypork/gamecore/util/math/algo/Sides.java +++ b/src/mightypork/gamecore/util/math/algo/Sides.java @@ -19,7 +19,7 @@ public class Sides { public static final byte NE_CORNER = MASK_E | MASK_NE | MASK_N; public static final byte SW_CORNER = MASK_W | MASK_SW | MASK_S; public static final byte SE_CORNER = MASK_E | MASK_SE | MASK_S; - + public static final Step NW = Step.make(-1, -1); public static final Step N = Step.make(0, -1); public static final Step NE = Step.make(1, -1); diff --git a/src/mightypork/gamecore/util/math/algo/Step.java b/src/mightypork/gamecore/util/math/algo/Step.java index 0d5f274..ce20118 100644 --- a/src/mightypork/gamecore/util/math/algo/Step.java +++ b/src/mightypork/gamecore/util/math/algo/Step.java @@ -43,12 +43,16 @@ public class Step implements IonObjBinary, IonObjBundled { private byte x; private byte y; - - public Step() { + + + public Step() + { // for ion } - public Step(int x, int y) { + + public Step(int x, int y) + { this.x = (byte) (x < 0 ? -1 : x > 0 ? 1 : 0); this.y = (byte) (y < 0 ? -1 : y > 0 ? 1 : 0); } @@ -66,7 +70,6 @@ public class Step implements IonObjBinary, IonObjBundled { } - public Coord toCoord() { return Coord.make(x, y); @@ -85,7 +88,7 @@ public class Step implements IonObjBinary, IonObjBundled { { return "(" + x + ";" + y + ")"; } - + @Override public void load(IonInput in) throws IOException @@ -102,6 +105,7 @@ public class Step implements IonObjBinary, IonObjBundled { out.writeByte(y); } + @Override public void load(IonBundle bundle) throws IOException { diff --git a/src/mightypork/gamecore/util/math/algo/pathfinding/PathFindingContextProxy.java b/src/mightypork/gamecore/util/math/algo/pathfinding/PathFindingContextProxy.java index 64fad5d..6ec31da 100644 --- a/src/mightypork/gamecore/util/math/algo/pathfinding/PathFindingContextProxy.java +++ b/src/mightypork/gamecore/util/math/algo/pathfinding/PathFindingContextProxy.java @@ -13,10 +13,11 @@ import mightypork.gamecore.util.math.algo.Step; */ public class PathFindingContextProxy implements PathFindingContext { - private PathFindingContext source; + private final PathFindingContext source; - public PathFindingContextProxy(PathFindingContext other) { + public PathFindingContextProxy(PathFindingContext other) + { this.source = other; } diff --git a/src/mightypork/gamecore/util/math/color/pal/CGA.java b/src/mightypork/gamecore/util/math/color/pal/CGA.java index 683f9e2..aa525a9 100644 --- a/src/mightypork/gamecore/util/math/color/pal/CGA.java +++ b/src/mightypork/gamecore/util/math/color/pal/CGA.java @@ -1,5 +1,6 @@ package mightypork.gamecore.util.math.color.pal; + import mightypork.gamecore.util.math.color.Color; diff --git a/src/mightypork/gamecore/util/math/color/pal/COMMODORE.java b/src/mightypork/gamecore/util/math/color/pal/COMMODORE.java index 7bb687d..ffb0166 100644 --- a/src/mightypork/gamecore/util/math/color/pal/COMMODORE.java +++ b/src/mightypork/gamecore/util/math/color/pal/COMMODORE.java @@ -1,5 +1,6 @@ package mightypork.gamecore.util.math.color.pal; + import mightypork.gamecore.util.math.color.Color; diff --git a/src/mightypork/gamecore/util/math/color/pal/PAL16.java b/src/mightypork/gamecore/util/math/color/pal/PAL16.java index 6d581c7..08d500c 100644 --- a/src/mightypork/gamecore/util/math/color/pal/PAL16.java +++ b/src/mightypork/gamecore/util/math/color/pal/PAL16.java @@ -1,5 +1,6 @@ package mightypork.gamecore.util.math.color.pal; + import mightypork.gamecore.util.math.color.Color; diff --git a/src/mightypork/gamecore/util/math/color/pal/RGB.java b/src/mightypork/gamecore/util/math/color/pal/RGB.java index 06dd14e..36a84c8 100644 --- a/src/mightypork/gamecore/util/math/color/pal/RGB.java +++ b/src/mightypork/gamecore/util/math/color/pal/RGB.java @@ -1,5 +1,6 @@ package mightypork.gamecore.util.math.color.pal; + import mightypork.gamecore.util.math.color.Color; diff --git a/src/mightypork/gamecore/util/math/color/pal/ZX.java b/src/mightypork/gamecore/util/math/color/pal/ZX.java index ac8f94a..5ed4ca2 100644 --- a/src/mightypork/gamecore/util/math/color/pal/ZX.java +++ b/src/mightypork/gamecore/util/math/color/pal/ZX.java @@ -1,5 +1,6 @@ package mightypork.gamecore.util.math.color.pal; + import mightypork.gamecore.util.math.color.Color; diff --git a/src/mightypork/gamecore/util/math/timing/Animator.java b/src/mightypork/gamecore/util/math/timing/Animator.java index 64bcb39..670d342 100644 --- a/src/mightypork/gamecore/util/math/timing/Animator.java +++ b/src/mightypork/gamecore/util/math/timing/Animator.java @@ -54,7 +54,8 @@ public abstract class Animator extends Num implements Updateable, Pauseable { } - public void start() { + public void start() + { resume(); } @@ -78,17 +79,22 @@ public abstract class Animator extends Num implements Updateable, Pauseable { numAnim.reset(); } - public void restart() { + + public void restart() + { reset(); nextCycle(numAnim); } - public void setDuration(double secs) { + public void setDuration(double secs) + { numAnim.setDefaultDuration(secs); } - public double getDuration() { + + public double getDuration() + { return numAnim.getDefaultDuration(); } @@ -111,13 +117,17 @@ public abstract class Animator extends Num implements Updateable, Pauseable { return num.value(); } - public void setProgress(double value) { - double target = numAnim.getEnd(); + + public void setProgress(double value) + { + final double target = numAnim.getEnd(); numAnim.setTo(Calc.clamp(value, lowValue, highValue)); numAnim.animate(target, numAnim.getDefaultDuration()); } - public double getProgress() { + + public double getProgress() + { return numAnim.value(); } } diff --git a/src/mightypork/gamecore/util/math/timing/TaskRepeater.java b/src/mightypork/gamecore/util/math/timing/TaskRepeater.java index 04b4d77..584a787 100644 --- a/src/mightypork/gamecore/util/math/timing/TaskRepeater.java +++ b/src/mightypork/gamecore/util/math/timing/TaskRepeater.java @@ -9,7 +9,9 @@ public abstract class TaskRepeater extends AnimatorRewind implements Runnable, E private boolean enabled = true; - public TaskRepeater(double period) { + + public TaskRepeater(double period) + { super(period); } @@ -21,22 +23,25 @@ public abstract class TaskRepeater extends AnimatorRewind implements Runnable, E super.nextCycle(anim); } + @Override public void enable(boolean yes) { this.enabled = yes; } + @Override public boolean isEnabled() { return enabled; } + @Override public void update(double delta) { - if(!enabled) return; + if (!enabled) return; super.update(delta); } diff --git a/src/mightypork/gamecore/util/strings/StringWrapper.java b/src/mightypork/gamecore/util/strings/StringWrapper.java index c167508..8c01d68 100644 --- a/src/mightypork/gamecore/util/strings/StringWrapper.java +++ b/src/mightypork/gamecore/util/strings/StringWrapper.java @@ -1,5 +1,6 @@ package mightypork.gamecore.util.strings; + /** * String provider with constant string * @@ -22,4 +23,4 @@ public class StringWrapper implements StringProvider { return value; } -} \ No newline at end of file +} diff --git a/src/mightypork/rogue/screens/game/ScreenGame.java b/src/mightypork/rogue/screens/game/ScreenGame.java index 19b02fa..b10b742 100644 --- a/src/mightypork/rogue/screens/game/ScreenGame.java +++ b/src/mightypork/rogue/screens/game/ScreenGame.java @@ -13,9 +13,9 @@ import mightypork.rogue.world.WorldProvider; public class ScreenGame extends LayeredScreen { - private Random rand = new Random(); - - + private final Random rand = new Random(); + + public ScreenGame(AppAccess app) { super(app); @@ -28,7 +28,7 @@ public class ScreenGame extends LayeredScreen { @Override public void run() { - WorldProvider.get().createWorld(rand .nextLong()); + WorldProvider.get().createWorld(rand.nextLong()); } }); } diff --git a/src/mightypork/rogue/screens/menu/MenuButton.java b/src/mightypork/rogue/screens/menu/MenuButton.java index c3615d9..e4b5c68 100644 --- a/src/mightypork/rogue/screens/menu/MenuButton.java +++ b/src/mightypork/rogue/screens/menu/MenuButton.java @@ -17,14 +17,15 @@ class MenuButton extends ClickableComponent { private static GLFont font = Res.getFont("main_menu_button"); private final TextPainter painter; - private final VectVar offset = Vect.makeVar(); + private final VectVar offset = Vect.makeVar(); private final Vect offsetPassive = height().div(16).toVectXY(); private final Vect offsetPassive2 = height().div(24).toVectXY(); private final Color color; - public MenuButton(String text, Color color) { + public MenuButton(String text, Color color) + { this.color = color; this.painter = new TextPainter(font, AlignX.CENTER, this.color, text); diff --git a/src/mightypork/rogue/screens/menu/MenuLayer.java b/src/mightypork/rogue/screens/menu/MenuLayer.java index 0db6612..644e898 100644 --- a/src/mightypork/rogue/screens/menu/MenuLayer.java +++ b/src/mightypork/rogue/screens/menu/MenuLayer.java @@ -18,7 +18,8 @@ import mightypork.rogue.Res; class MenuLayer extends ScreenLayer { - public MenuLayer(Screen screen) { + public MenuLayer(Screen screen) + { super(screen); init(); @@ -39,7 +40,7 @@ class MenuLayer extends ScreenLayer { root.add(layout); int r = 0; - TextPainter tp = new TextPainter(Res.getFont("main_menu_title"), AlignX.CENTER, COMMODORE.PURPLE, "Rogue!"); + final TextPainter tp = new TextPainter(Res.getFont("main_menu_title"), AlignX.CENTER, COMMODORE.PURPLE, "Rogue!"); layout.put(tp, r, 0, 3, 1); r += 5; diff --git a/src/mightypork/rogue/screens/test_bouncyboxes/ScreenTestBouncy.java b/src/mightypork/rogue/screens/test_bouncyboxes/ScreenTestBouncy.java index 8e06232..e028773 100644 --- a/src/mightypork/rogue/screens/test_bouncyboxes/ScreenTestBouncy.java +++ b/src/mightypork/rogue/screens/test_bouncyboxes/ScreenTestBouncy.java @@ -7,7 +7,8 @@ import mightypork.gamecore.gui.screens.LayeredScreen; public class ScreenTestBouncy extends LayeredScreen { - public ScreenTestBouncy(AppAccess app) { + public ScreenTestBouncy(AppAccess app) + { super(app); addLayer(new LayerBouncyBoxes(this)); diff --git a/src/mightypork/rogue/world/entity/AiTimer.java b/src/mightypork/rogue/world/entity/AiTimer.java index 722c2f2..0099fb0 100644 --- a/src/mightypork/rogue/world/entity/AiTimer.java +++ b/src/mightypork/rogue/world/entity/AiTimer.java @@ -1,5 +1,6 @@ package mightypork.rogue.world.entity; + import java.io.IOException; import mightypork.gamecore.util.ion.IonBundle; @@ -9,20 +10,21 @@ import mightypork.gamecore.util.math.timing.TaskRepeater; public abstract class AiTimer extends TaskRepeater implements IonObjBundled { - public AiTimer(double duration) { + public AiTimer(double duration) + { super(duration); } @Override public abstract void run(); - - + + @Override public void load(IonBundle bundle) throws IOException { - boolean wasPaused = bundle.get("paused", isPaused()); - if(wasPaused) { + final boolean wasPaused = bundle.get("paused", isPaused()); + if (wasPaused) { pause(); } else { resume(); @@ -31,14 +33,14 @@ public abstract class AiTimer extends TaskRepeater implements IonObjBundled { setProgress(bundle.get("progress", getProgress())); setDuration(bundle.get("duration", getDuration())); } - - + + @Override public void save(IonBundle bundle) throws IOException { bundle.put("paused", isPaused()); bundle.put("progress", getProgress()); - bundle.put("duration", getDuration()); + bundle.put("duration", getDuration()); } } diff --git a/src/mightypork/rogue/world/entity/Entity.java b/src/mightypork/rogue/world/entity/Entity.java index f29944f..0384a75 100644 --- a/src/mightypork/rogue/world/entity/Entity.java +++ b/src/mightypork/rogue/world/entity/Entity.java @@ -41,7 +41,8 @@ public abstract class Entity implements IonObjBundled, Updateable { public final EntityModuleHealth health = new EntityModuleHealth(this); - public Entity(EntityModel model, int eid) { + public Entity(EntityModel model, int eid) + { this.entityId = eid; this.model = model; @@ -57,13 +58,13 @@ public abstract class Entity implements IonObjBundled, Updateable { { bundle.put("eid", entityId); - IonBundle modulesBundle = new IonBundle(); + final IonBundle modulesBundle = new IonBundle(); for (final Entry entry : modules.entrySet()) { modulesBundle.putBundled(entry.getKey(), entry.getValue()); } bundle.put("modules", modulesBundle); - IonBundle extra = new IonBundle(); + final IonBundle extra = new IonBundle(); saveExtra(extra); bundle.put("extra", extra); } @@ -81,13 +82,13 @@ public abstract class Entity implements IonObjBundled, Updateable { entityId = bundle.get("eid", -1); if (entityId < 0) throw new IllegalValueException("Bad entity id: " + entityId); - IonBundle modulesBundle = bundle.get("modules", new IonBundle()); + final IonBundle modulesBundle = bundle.get("modules", new IonBundle()); for (final Entry entry : modules.entrySet()) { modulesBundle.loadBundled(entry.getKey(), entry.getValue()); } - IonBundle extra = bundle.get("extra", new IonBundle()); + final IonBundle extra = bundle.get("extra", new IonBundle()); loadExtra(extra); } @@ -100,9 +101,7 @@ public abstract class Entity implements IonObjBundled, Updateable { protected final void addModule(String key, EntityModule module) { - if (modules.containsKey(key)) { - throw new RuntimeException("Entity module " + key + " already defined."); - } + if (modules.containsKey(key)) { throw new RuntimeException("Entity module " + key + " already defined."); } modules.put(key, module); } diff --git a/src/mightypork/rogue/world/entity/EntityModule.java b/src/mightypork/rogue/world/entity/EntityModule.java index 98d2b77..8abc83a 100644 --- a/src/mightypork/rogue/world/entity/EntityModule.java +++ b/src/mightypork/rogue/world/entity/EntityModule.java @@ -21,10 +21,12 @@ public abstract class EntityModule implements IonObjBundled, Updateable { protected final Random rand = new Random(); - public EntityModule(Entity entity) { + public EntityModule(Entity entity) + { this.entity = entity; } + public abstract boolean isModuleSaved(); diff --git a/src/mightypork/rogue/world/entity/entities/MonsterAi.java b/src/mightypork/rogue/world/entity/entities/MonsterAi.java index d1c39a4..df0de46 100644 --- a/src/mightypork/rogue/world/entity/entities/MonsterAi.java +++ b/src/mightypork/rogue/world/entity/entities/MonsterAi.java @@ -24,7 +24,7 @@ public class MonsterAi extends EntityModule implements EntityMoveListener { private boolean sleeping = true; private boolean chasing = false; - private AiTimer timerFindPrey = new AiTimer(3) { + private final AiTimer timerFindPrey = new AiTimer(3) { @Override public void run() @@ -34,7 +34,7 @@ public class MonsterAi extends EntityModule implements EntityMoveListener { } }; - private AiTimer timerSleepStart = new AiTimer(10) { + private final AiTimer timerSleepStart = new AiTimer(10) { @Override public void run() @@ -49,7 +49,8 @@ public class MonsterAi extends EntityModule implements EntityMoveListener { private int targetId = -1; - public MonsterAi(final Entity entity) { + public MonsterAi(final Entity entity) + { super(entity); pathfcNoDoor = new PathFindingContextProxy(entity.getPathfindingContext()) { @@ -57,7 +58,7 @@ public class MonsterAi extends EntityModule implements EntityMoveListener { @Override public boolean isAccessible(Coord pos) { - Tile t = entity.getLevel().getTile(pos); + final Tile t = entity.getLevel().getTile(pos); if (t.isDoor()) return false; return super.isAccessible(pos); @@ -70,15 +71,14 @@ public class MonsterAi extends EntityModule implements EntityMoveListener { private void lookForTarget() { if (rand.nextInt(3) == 0) return; // not hungry right now - - Entity prey = entity.getLevel().getClosestEntity(entity, EntityType.PLAYER, getScanRadius()); + + final Entity prey = entity.getLevel().getClosestEntity(entity, EntityType.PLAYER, getScanRadius()); if (prey != null) { // check if reachable without leaving room - List noDoorPath = PathFinder.findPath(pathfcNoDoor, entity.getCoord(), prey.getCoord()); + final List noDoorPath = PathFinder.findPath(pathfcNoDoor, entity.getCoord(), prey.getCoord()); - if (noDoorPath == null) { - return; // cant reach, give up + if (noDoorPath == null) { return; // cant reach, give up } startChasing(prey); @@ -136,7 +136,7 @@ public class MonsterAi extends EntityModule implements EntityMoveListener { public void onStepFinished() { if (chasing) { - Entity prey = entity.getLevel().getEntity(targetId); + final Entity prey = entity.getLevel().getEntity(targetId); if (prey == null || prey.isDead()) { stopChasing(); return; @@ -153,13 +153,13 @@ public class MonsterAi extends EntityModule implements EntityMoveListener { private void stepTowardsPrey(Entity prey) { // if close enough - Coord preyPos = prey.getCoord(); - if(preyPos.dist(entity.getCoord()) <= 1.5) { + final Coord preyPos = prey.getCoord(); + if (preyPos.dist(entity.getCoord()) <= 1.5) { attackPrey(prey); return; } - List preyPath = getPathToPrey(prey); + final List preyPath = getPathToPrey(prey); if (preyPath.size() > getPreyAbandonDistance()) { stopChasing(); @@ -174,13 +174,14 @@ public class MonsterAi extends EntityModule implements EntityMoveListener { { prey.receiveAttack(entity, getAttackStrength()); } - - - protected int getAttackStrength() { + + + protected int getAttackStrength() + { return 1; // For override } - - + + @Override public void onPathFinished() { diff --git a/src/mightypork/rogue/world/entity/entities/PlayerEntity.java b/src/mightypork/rogue/world/entity/entities/PlayerEntity.java index 50a7a15..9be40e8 100644 --- a/src/mightypork/rogue/world/entity/entities/PlayerEntity.java +++ b/src/mightypork/rogue/world/entity/entities/PlayerEntity.java @@ -14,7 +14,8 @@ public class PlayerEntity extends Entity { class PlayerAi extends EntityModule implements EntityMoveListener { - public PlayerAi(Entity entity) { + public PlayerAi(Entity entity) + { super(entity); } @@ -46,13 +47,14 @@ public class PlayerEntity extends Entity { } - private EntityPathfindingContext pathfc; + private EntityPathfindingContext pathfc; private EntityRenderer renderer; private final PlayerAi ai = new PlayerAi(this); - public PlayerEntity(EntityModel model, int eid) { + public PlayerEntity(EntityModel model, int eid) + { super(model, eid); pos.setStepTime(0.25); @@ -72,9 +74,7 @@ public class PlayerEntity extends Entity { public int getCost(Coord from, Coord to) { - if (!getLevel().getTile(pos.getCoord()).isExplored()) { - return 1000; - } + if (!getLevel().getTile(pos.getCoord()).isExplored()) { return 1000; } return super.getCost(from, to); @@ -104,6 +104,7 @@ public class PlayerEntity extends Entity { return renderer; } + @Override public EntityType getType() { diff --git a/src/mightypork/rogue/world/entity/entities/SimpleMonster.java b/src/mightypork/rogue/world/entity/entities/SimpleMonster.java index 015259f..6e5af97 100644 --- a/src/mightypork/rogue/world/entity/entities/SimpleMonster.java +++ b/src/mightypork/rogue/world/entity/entities/SimpleMonster.java @@ -10,15 +10,17 @@ public abstract class SimpleMonster extends Entity { /** Navigation PFC */ private EntityPathfindingContext pathfc; - private EntityModule ai = new MonsterAi(this); + private final EntityModule ai = new MonsterAi(this); - public SimpleMonster(EntityModel model, int eid) { + + public SimpleMonster(EntityModel model, int eid) + { super(model, eid); addModule("ai", ai); } - - + + @Override public PathFindingContext getPathfindingContext() { @@ -29,6 +31,7 @@ public abstract class SimpleMonster extends Entity { return pathfc; } + @Override public EntityType getType() { diff --git a/src/mightypork/rogue/world/entity/modules/EntityModuleHealth.java b/src/mightypork/rogue/world/entity/modules/EntityModuleHealth.java index 15256ab..0fae315 100644 --- a/src/mightypork/rogue/world/entity/modules/EntityModuleHealth.java +++ b/src/mightypork/rogue/world/entity/modules/EntityModuleHealth.java @@ -12,7 +12,8 @@ import mightypork.rogue.world.entity.EntityModule; public class EntityModuleHealth extends EntityModule { - public EntityModuleHealth(Entity entity) { + public EntityModuleHealth(Entity entity) + { super(entity); } diff --git a/src/mightypork/rogue/world/entity/modules/EntityModulePosition.java b/src/mightypork/rogue/world/entity/modules/EntityModulePosition.java index 80cbd4e..4b447ec 100644 --- a/src/mightypork/rogue/world/entity/modules/EntityModulePosition.java +++ b/src/mightypork/rogue/world/entity/modules/EntityModulePosition.java @@ -58,7 +58,8 @@ public class EntityModulePosition extends EntityModule { stepTime = bundle.get("step_time", stepTime); } - + + @Override public boolean isModuleSaved() { diff --git a/src/mightypork/rogue/world/entity/modules/EntityMoveListener.java b/src/mightypork/rogue/world/entity/modules/EntityMoveListener.java index 1c4c23e..c5701d4 100644 --- a/src/mightypork/rogue/world/entity/modules/EntityMoveListener.java +++ b/src/mightypork/rogue/world/entity/modules/EntityMoveListener.java @@ -1,8 +1,6 @@ package mightypork.rogue.world.entity.modules; - - public interface EntityMoveListener { /** diff --git a/src/mightypork/rogue/world/gen/MapTheme.java b/src/mightypork/rogue/world/gen/MapTheme.java index 5480a6b..dda3a80 100644 --- a/src/mightypork/rogue/world/gen/MapTheme.java +++ b/src/mightypork/rogue/world/gen/MapTheme.java @@ -19,5 +19,6 @@ public interface MapTheme { TileModel door(); + TileModel passage(); } diff --git a/src/mightypork/rogue/world/gen/rooms/DeadEndRoom.java b/src/mightypork/rogue/world/gen/rooms/DeadEndRoom.java index 3fcab11..2d8a52d 100644 --- a/src/mightypork/rogue/world/gen/rooms/DeadEndRoom.java +++ b/src/mightypork/rogue/world/gen/rooms/DeadEndRoom.java @@ -4,11 +4,10 @@ package mightypork.rogue.world.gen.rooms; import java.util.Random; import mightypork.gamecore.util.math.algo.Coord; -import mightypork.gamecore.util.math.algo.Sides; +import mightypork.rogue.world.gen.MapTheme; import mightypork.rogue.world.gen.RoomBuilder; import mightypork.rogue.world.gen.RoomDesc; import mightypork.rogue.world.gen.ScratchMap; -import mightypork.rogue.world.gen.MapTheme; public class DeadEndRoom implements RoomBuilder { @@ -16,8 +15,8 @@ public class DeadEndRoom implements RoomBuilder { @Override public RoomDesc buildToFit(ScratchMap map, MapTheme theme, Random rand, Coord center) { - Coord low = center.add(-1, -1); - Coord high = center; + final Coord low = center.add(-1, -1); + final Coord high = center; if (!map.isClear(low, high)) return null; map.set(center, theme.floor()); diff --git a/src/mightypork/rogue/world/gen/rooms/SimpleRectRoom.java b/src/mightypork/rogue/world/gen/rooms/SimpleRectRoom.java index e09cd42..1ccc9a3 100644 --- a/src/mightypork/rogue/world/gen/rooms/SimpleRectRoom.java +++ b/src/mightypork/rogue/world/gen/rooms/SimpleRectRoom.java @@ -5,10 +5,10 @@ import java.util.Random; import mightypork.gamecore.util.math.algo.Coord; import mightypork.gamecore.util.math.algo.Sides; +import mightypork.rogue.world.gen.MapTheme; import mightypork.rogue.world.gen.RoomBuilder; import mightypork.rogue.world.gen.RoomDesc; import mightypork.rogue.world.gen.ScratchMap; -import mightypork.rogue.world.gen.MapTheme; import mightypork.rogue.world.tile.TileModel; @@ -30,7 +30,7 @@ public class SimpleRectRoom implements RoomBuilder { map.border(min, max, theme.wall()); map.protect(min, max); - boolean holes = rand.nextInt(4) == 0; + final boolean holes = rand.nextInt(4) == 0; for (int i = 0; i <= 2 + rand.nextInt(6); i++) { final Coord door = min.copy(); diff --git a/src/mightypork/rogue/world/level/Level.java b/src/mightypork/rogue/world/level/Level.java index 0ac6938..68d0a53 100644 --- a/src/mightypork/rogue/world/level/Level.java +++ b/src/mightypork/rogue/world/level/Level.java @@ -2,7 +2,11 @@ package mightypork.rogue.world.level; import java.io.IOException; -import java.util.*; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; import mightypork.gamecore.logging.Log; import mightypork.gamecore.util.ion.IonBundle; @@ -21,7 +25,6 @@ import mightypork.rogue.world.entity.Entity; import mightypork.rogue.world.entity.EntityType; import mightypork.rogue.world.tile.Tile; import mightypork.rogue.world.tile.TileModel; -import mightypork.rogue.world.tile.TileType; import mightypork.rogue.world.tile.Tiles; @@ -51,11 +54,13 @@ public class Level implements MapAccess, IonObjBinary { private transient NoiseGen noiseGen; - public Level() { + public Level() + { } - public Level(int width, int height) { + public Level(int width, int height) + { size.setTo(width, height); buildArray(); } @@ -87,7 +92,7 @@ public class Level implements MapAccess, IonObjBinary { public final Tile getTile(Coord pos) { if (!pos.isInRange(0, 0, size.x - 1, size.y - 1)) return Tiles.NULL.createTile(); // out of range - + return tiles[pos.y][pos.x]; } @@ -290,17 +295,18 @@ public class Level implements MapAccess, IonObjBinary { getTile(pos).setOccupied(false); } - public void cleanCorpses() { - for(Iterator i = entitySet.iterator(); i.hasNext();) { - Entity e = i.next(); - - if(e.isDead() && e.canRemoveCorpse()) { + + public void cleanCorpses() + { + for (final Entity e : entitySet) { + if (e.isDead() && e.canRemoveCorpse()) { e.onCorpseRemoved(); removeEntity(e); } } } + public Collection getEntities() { return entitySet; @@ -387,12 +393,12 @@ public class Level implements MapAccess, IonObjBinary { Entity closest = null; double minDist = Double.MAX_VALUE; - for (Entity e : entitySet) { + for (final Entity e : entitySet) { if (e == self) continue; if (e.isDead()) continue; if (e.getType() == type) { - double dist = e.getCoord().dist(self.getCoord()); + final double dist = e.getCoord().dist(self.getCoord()); if (dist <= radius && dist < minDist) { minDist = dist; diff --git a/src/mightypork/rogue/world/tile/renderers/DoorTileRenderer.java b/src/mightypork/rogue/world/tile/renderers/DoorTileRenderer.java index 62b37dc..a009582 100644 --- a/src/mightypork/rogue/world/tile/renderers/DoorTileRenderer.java +++ b/src/mightypork/rogue/world/tile/renderers/DoorTileRenderer.java @@ -2,7 +2,6 @@ package mightypork.rogue.world.tile.renderers; import mightypork.gamecore.render.Render; -import mightypork.gamecore.resources.textures.TxQuad; import mightypork.gamecore.resources.textures.TxSheet; import mightypork.gamecore.util.math.constraints.rect.Rect; import mightypork.rogue.Res; diff --git a/src/mightypork/rogue/world/tile/tiles/WallPassageTile.java b/src/mightypork/rogue/world/tile/tiles/WallPassageTile.java index 119b707..0af638d 100644 --- a/src/mightypork/rogue/world/tile/tiles/WallPassageTile.java +++ b/src/mightypork/rogue/world/tile/tiles/WallPassageTile.java @@ -1,5 +1,6 @@ package mightypork.rogue.world.tile.tiles; + import mightypork.rogue.world.tile.TileModel; import mightypork.rogue.world.tile.TileRenderer; import mightypork.rogue.world.tile.TileType; @@ -11,17 +12,20 @@ import mightypork.rogue.world.tile.TileType; * @author MightyPork */ public class WallPassageTile extends SolidTile { - - public WallPassageTile(TileModel model, TileRenderer renderer) { + + public WallPassageTile(TileModel model, TileRenderer renderer) + { super(model, renderer); } - + + @Override public TileType getType() { return TileType.PASSAGE; } + @Override public boolean isWalkable() {