diff --git a/src/mightypork/gamecore/audio/DeferredAudio.java b/src/mightypork/gamecore/audio/DeferredAudio.java index 693b94e..fabe0d5 100644 --- a/src/mightypork/gamecore/audio/DeferredAudio.java +++ b/src/mightypork/gamecore/audio/DeferredAudio.java @@ -42,7 +42,8 @@ public class DeferredAudio extends DeferredResource { * * @param resourceName resource to load when needed */ - public DeferredAudio(String resourceName) { + public DeferredAudio(String resourceName) + { super(resourceName); } diff --git a/src/mightypork/gamecore/audio/JointVolume.java b/src/mightypork/gamecore/audio/JointVolume.java index 63dbdac..0d19709 100644 --- a/src/mightypork/gamecore/audio/JointVolume.java +++ b/src/mightypork/gamecore/audio/JointVolume.java @@ -20,7 +20,8 @@ public class JointVolume extends Volume { * @param volumes individual volumes to join */ @SafeVarargs - public JointVolume(Volume... volumes) { + public JointVolume(Volume... volumes) + { super(1D); this.volumes = volumes; } @@ -36,7 +37,7 @@ public class JointVolume extends Volume { for (final Volume v : volumes) d *= v.get(); - return Calc.clampd(d, 0, 1); + return Calc.clamp(d, 0, 1); } diff --git a/src/mightypork/gamecore/audio/NullAudio.java b/src/mightypork/gamecore/audio/NullAudio.java index c2d77ce..a73f0b3 100644 --- a/src/mightypork/gamecore/audio/NullAudio.java +++ b/src/mightypork/gamecore/audio/NullAudio.java @@ -17,7 +17,8 @@ public class NullAudio extends DeferredAudio implements NullResource { /** * new null audio */ - public NullAudio() { + public NullAudio() + { super(null); } } diff --git a/src/mightypork/gamecore/audio/SoundBank.java b/src/mightypork/gamecore/audio/SoundBank.java index d280c46..22223af 100644 --- a/src/mightypork/gamecore/audio/SoundBank.java +++ b/src/mightypork/gamecore/audio/SoundBank.java @@ -29,7 +29,8 @@ public class SoundBank extends AppAdapter { /** * @param app app access */ - public SoundBank(AppAccess app) { + public SoundBank(AppAccess app) + { super(app); if (getSoundSystem() == null) throw new NullPointerException("SoundSystem cannot be null."); } diff --git a/src/mightypork/gamecore/audio/SoundSystem.java b/src/mightypork/gamecore/audio/SoundSystem.java index 5612211..149280d 100644 --- a/src/mightypork/gamecore/audio/SoundSystem.java +++ b/src/mightypork/gamecore/audio/SoundSystem.java @@ -77,7 +77,8 @@ public class SoundSystem extends RootBusNode implements Updateable { /** * @param app app access */ - public SoundSystem(AppAccess app) { + public SoundSystem(AppAccess app) + { super(app); if (!soundSystemInited) { diff --git a/src/mightypork/gamecore/audio/Volume.java b/src/mightypork/gamecore/audio/Volume.java index ccd646c..44a541e 100644 --- a/src/mightypork/gamecore/audio/Volume.java +++ b/src/mightypork/gamecore/audio/Volume.java @@ -15,7 +15,8 @@ public class Volume extends Mutable { /** * @param d initial value */ - public Volume(Double d) { + public Volume(Double d) + { super(d); } @@ -23,7 +24,7 @@ public class Volume extends Mutable { @Override public void set(Double d) { - super.set(Calc.clampd(d, 0, 1)); + super.set(Calc.clamp(d, 0, 1)); } } diff --git a/src/mightypork/gamecore/audio/players/BaseAudioPlayer.java b/src/mightypork/gamecore/audio/players/BaseAudioPlayer.java index 79c5977..d226452 100644 --- a/src/mightypork/gamecore/audio/players/BaseAudioPlayer.java +++ b/src/mightypork/gamecore/audio/players/BaseAudioPlayer.java @@ -32,7 +32,8 @@ public abstract class BaseAudioPlayer implements Destroyable { * @param baseGain base gain (volume multiplier) * @param volume colume control */ - public BaseAudioPlayer(DeferredAudio track, double basePitch, double baseGain, Volume volume) { + public BaseAudioPlayer(DeferredAudio track, double basePitch, double baseGain, Volume volume) + { this.audio = track; this.baseGain = baseGain; diff --git a/src/mightypork/gamecore/audio/players/EffectPlayer.java b/src/mightypork/gamecore/audio/players/EffectPlayer.java index 922503b..95070bb 100644 --- a/src/mightypork/gamecore/audio/players/EffectPlayer.java +++ b/src/mightypork/gamecore/audio/players/EffectPlayer.java @@ -19,7 +19,8 @@ public class EffectPlayer extends BaseAudioPlayer { * @param baseGain base gain (volume multiplier) * @param volume volume control */ - public EffectPlayer(DeferredAudio track, double basePitch, double baseGain, Volume volume) { + public EffectPlayer(DeferredAudio track, double basePitch, double baseGain, Volume volume) + { super(track, (float) basePitch, (float) baseGain, volume); } diff --git a/src/mightypork/gamecore/audio/players/LoopPlayer.java b/src/mightypork/gamecore/audio/players/LoopPlayer.java index 6e4a041..b78a3ec 100644 --- a/src/mightypork/gamecore/audio/players/LoopPlayer.java +++ b/src/mightypork/gamecore/audio/players/LoopPlayer.java @@ -40,7 +40,8 @@ public class LoopPlayer extends BaseAudioPlayer implements Updateable, Pauseable * @param baseGain base gain (volume multiplier) * @param volume volume control */ - public LoopPlayer(DeferredAudio track, double basePitch, double baseGain, Volume volume) { + public LoopPlayer(DeferredAudio track, double basePitch, double baseGain, Volume volume) + { super(track, (float) basePitch, (float) baseGain, volume); paused = true; diff --git a/src/mightypork/gamecore/control/AppAdapter.java b/src/mightypork/gamecore/control/AppAdapter.java index e5c708e..2b7f288 100644 --- a/src/mightypork/gamecore/control/AppAdapter.java +++ b/src/mightypork/gamecore/control/AppAdapter.java @@ -20,7 +20,8 @@ public class AppAdapter implements AppAccess { /** * @param app app access */ - public AppAdapter(AppAccess app) { + public AppAdapter(AppAccess app) + { if (app == null) throw new NullPointerException("AppAccess instance cannot be null."); this.app = app; diff --git a/src/mightypork/gamecore/control/AppModule.java b/src/mightypork/gamecore/control/AppModule.java index 55dc591..002e64a 100644 --- a/src/mightypork/gamecore/control/AppModule.java +++ b/src/mightypork/gamecore/control/AppModule.java @@ -23,7 +23,8 @@ public abstract class AppModule extends RootBusNode implements AppAccess { * * @param app access to app systems */ - public AppModule(AppAccess app) { + public AppModule(AppAccess app) + { super(app); this.app = app; diff --git a/src/mightypork/gamecore/control/AppSubModule.java b/src/mightypork/gamecore/control/AppSubModule.java index 0431743..634813a 100644 --- a/src/mightypork/gamecore/control/AppSubModule.java +++ b/src/mightypork/gamecore/control/AppSubModule.java @@ -25,7 +25,8 @@ public class AppSubModule extends BusNode implements AppAccess { * * @param app access to app systems */ - public AppSubModule(AppAccess app) { + public AppSubModule(AppAccess app) + { super(app); this.app = app; diff --git a/src/mightypork/gamecore/control/GameLoop.java b/src/mightypork/gamecore/control/GameLoop.java index b4ca9d5..e4ceb35 100644 --- a/src/mightypork/gamecore/control/GameLoop.java +++ b/src/mightypork/gamecore/control/GameLoop.java @@ -28,7 +28,8 @@ public abstract class GameLoop extends AppModule implements MainLoopTaskRequest. /** * @param app {@link AppAccess} instance */ - public GameLoop(AppAccess app) { + public GameLoop(AppAccess app) + { super(app); } diff --git a/src/mightypork/gamecore/control/SlickLogRedirector.java b/src/mightypork/gamecore/control/SlickLogRedirector.java index 614a7a4..a135aac 100644 --- a/src/mightypork/gamecore/control/SlickLogRedirector.java +++ b/src/mightypork/gamecore/control/SlickLogRedirector.java @@ -21,7 +21,8 @@ public class SlickLogRedirector implements LogSystem { /** * @param log log to redirect into */ - public SlickLogRedirector(LogWriter log) { + public SlickLogRedirector(LogWriter log) + { this.l = log; } diff --git a/src/mightypork/gamecore/control/events/KeyEvent.java b/src/mightypork/gamecore/control/events/KeyEvent.java index 1aaadf2..ea03321 100644 --- a/src/mightypork/gamecore/control/events/KeyEvent.java +++ b/src/mightypork/gamecore/control/events/KeyEvent.java @@ -23,7 +23,8 @@ public class KeyEvent implements Event { * @param c typed char (can be zero char) * @param down true = pressed, false = released. */ - public KeyEvent(int key, char c, boolean down) { + public KeyEvent(int key, char c, boolean down) + { this.key = key; this.c = c; this.down = down; diff --git a/src/mightypork/gamecore/control/events/LayoutChangeEvent.java b/src/mightypork/gamecore/control/events/LayoutChangeEvent.java index b22741f..f5c0e17 100644 --- a/src/mightypork/gamecore/control/events/LayoutChangeEvent.java +++ b/src/mightypork/gamecore/control/events/LayoutChangeEvent.java @@ -14,7 +14,8 @@ import mightypork.util.control.eventbus.events.flags.ImmediateEvent; @ImmediateEvent public class LayoutChangeEvent implements Event { - public LayoutChangeEvent() { + public LayoutChangeEvent() + { } diff --git a/src/mightypork/gamecore/control/events/MainLoopTaskRequest.java b/src/mightypork/gamecore/control/events/MainLoopTaskRequest.java index e4f254e..60b860e 100644 --- a/src/mightypork/gamecore/control/events/MainLoopTaskRequest.java +++ b/src/mightypork/gamecore/control/events/MainLoopTaskRequest.java @@ -19,7 +19,8 @@ public class MainLoopTaskRequest implements Event /** * @param task task to run on main thread in rendering context */ - public MainLoopTaskRequest(Runnable task) { + public MainLoopTaskRequest(Runnable task) + { this.task = task; } diff --git a/src/mightypork/gamecore/control/events/MouseButtonEvent.java b/src/mightypork/gamecore/control/events/MouseButtonEvent.java index c520055..11d66af 100644 --- a/src/mightypork/gamecore/control/events/MouseButtonEvent.java +++ b/src/mightypork/gamecore/control/events/MouseButtonEvent.java @@ -31,7 +31,8 @@ public class MouseButtonEvent implements Event { * @param down button pressed * @param wheeld wheel change */ - public MouseButtonEvent(Vect pos, int button, boolean down, int wheeld) { + public MouseButtonEvent(Vect pos, int button, boolean down, int wheeld) + { this.button = button; this.down = down; this.pos = pos; diff --git a/src/mightypork/gamecore/control/events/MouseMotionEvent.java b/src/mightypork/gamecore/control/events/MouseMotionEvent.java index 45c700c..a05cf14 100644 --- a/src/mightypork/gamecore/control/events/MouseMotionEvent.java +++ b/src/mightypork/gamecore/control/events/MouseMotionEvent.java @@ -23,7 +23,8 @@ public class MouseMotionEvent implements Event { * @param pos end pos * @param move move vector */ - public MouseMotionEvent(Vect pos, Vect move) { + public MouseMotionEvent(Vect pos, Vect move) + { this.move = move.freeze(); this.pos = pos.freeze(); } diff --git a/src/mightypork/gamecore/control/events/ResourceLoadRequest.java b/src/mightypork/gamecore/control/events/ResourceLoadRequest.java index 506806d..d3045d1 100644 --- a/src/mightypork/gamecore/control/events/ResourceLoadRequest.java +++ b/src/mightypork/gamecore/control/events/ResourceLoadRequest.java @@ -20,7 +20,8 @@ public class ResourceLoadRequest implements Event /** * @param resource resource to load */ - public ResourceLoadRequest(Deferred resource) { + public ResourceLoadRequest(Deferred resource) + { this.resource = resource; } diff --git a/src/mightypork/gamecore/control/events/ScreenRequestEvent.java b/src/mightypork/gamecore/control/events/ScreenRequestEvent.java index c9ccbfd..62f0376 100644 --- a/src/mightypork/gamecore/control/events/ScreenRequestEvent.java +++ b/src/mightypork/gamecore/control/events/ScreenRequestEvent.java @@ -19,7 +19,8 @@ public class ScreenRequestEvent implements Event { /** * @param screenKey screen name */ - public ScreenRequestEvent(String screenKey) { + public ScreenRequestEvent(String screenKey) + { scrName = screenKey; } diff --git a/src/mightypork/gamecore/control/events/UpdateEvent.java b/src/mightypork/gamecore/control/events/UpdateEvent.java index f86e482..0f9dd0a 100644 --- a/src/mightypork/gamecore/control/events/UpdateEvent.java +++ b/src/mightypork/gamecore/control/events/UpdateEvent.java @@ -22,7 +22,8 @@ public class UpdateEvent implements Event { /** * @param deltaTime time since last update (sec) */ - public UpdateEvent(double deltaTime) { + public UpdateEvent(double deltaTime) + { this.deltaTime = deltaTime; } diff --git a/src/mightypork/gamecore/control/events/ViewportChangeEvent.java b/src/mightypork/gamecore/control/events/ViewportChangeEvent.java index 04ed3d1..25123ef 100644 --- a/src/mightypork/gamecore/control/events/ViewportChangeEvent.java +++ b/src/mightypork/gamecore/control/events/ViewportChangeEvent.java @@ -22,7 +22,8 @@ public class ViewportChangeEvent implements Event * @param fullscreen is now fullscreen * @param size new screen size */ - public ViewportChangeEvent(boolean fsChanged, boolean fullscreen, Vect size) { + public ViewportChangeEvent(boolean fsChanged, boolean fullscreen, Vect size) + { this.fullscreen = fullscreen; this.screenSize = size; this.fsChanged = fsChanged; diff --git a/src/mightypork/gamecore/gui/components/LayoutComponent.java b/src/mightypork/gamecore/gui/components/LayoutComponent.java index bd32e3e..31e687e 100644 --- a/src/mightypork/gamecore/gui/components/LayoutComponent.java +++ b/src/mightypork/gamecore/gui/components/LayoutComponent.java @@ -23,14 +23,16 @@ public abstract class LayoutComponent extends VisualComponent implements Enablea final LinkedList components = new LinkedList<>(); - public LayoutComponent(AppAccess app, RectBound context) { + public LayoutComponent(AppAccess app, RectBound context) + { this.subModule = new AppSubModule(app); setRect(context); enableCaching(true); // layout is typically updated only when screen resizes. } - public LayoutComponent(AppAccess app) { + public LayoutComponent(AppAccess app) + { this(app, null); } diff --git a/src/mightypork/gamecore/gui/components/VisualComponent.java b/src/mightypork/gamecore/gui/components/VisualComponent.java index ea10462..2956012 100644 --- a/src/mightypork/gamecore/gui/components/VisualComponent.java +++ b/src/mightypork/gamecore/gui/components/VisualComponent.java @@ -23,7 +23,8 @@ public abstract class VisualComponent extends AbstractRectCache implements Compo private boolean visible = true; - public VisualComponent() { + public VisualComponent() + { super(); enableCaching(false); } diff --git a/src/mightypork/gamecore/gui/components/layout/ColumnHolder.java b/src/mightypork/gamecore/gui/components/layout/ColumnHolder.java index b36cef5..e4a8f0c 100644 --- a/src/mightypork/gamecore/gui/components/layout/ColumnHolder.java +++ b/src/mightypork/gamecore/gui/components/layout/ColumnHolder.java @@ -24,7 +24,8 @@ public class ColumnHolder extends LayoutComponent { * @param context context * @param cols number of columns */ - public ColumnHolder(AppAccess app, RectBound context, int cols) { + public ColumnHolder(AppAccess app, RectBound context, int cols) + { super(app, context); this.tiler = columns(cols); } @@ -37,7 +38,8 @@ public class ColumnHolder extends LayoutComponent { * @param app app access * @param cols number of columns */ - public ColumnHolder(AppAccess app, int cols) { + public ColumnHolder(AppAccess app, int cols) + { this(app, null, cols); } diff --git a/src/mightypork/gamecore/gui/components/layout/ConstraintLayout.java b/src/mightypork/gamecore/gui/components/layout/ConstraintLayout.java index 12aa24e..da4744f 100644 --- a/src/mightypork/gamecore/gui/components/layout/ConstraintLayout.java +++ b/src/mightypork/gamecore/gui/components/layout/ConstraintLayout.java @@ -14,12 +14,14 @@ import mightypork.util.constraints.rect.proxy.RectBound; */ public class ConstraintLayout extends LayoutComponent { - public ConstraintLayout(AppAccess app) { + public ConstraintLayout(AppAccess app) + { super(app); } - public ConstraintLayout(AppAccess app, RectBound context) { + public ConstraintLayout(AppAccess app, RectBound context) + { super(app, context); } diff --git a/src/mightypork/gamecore/gui/components/layout/GridLayout.java b/src/mightypork/gamecore/gui/components/layout/GridLayout.java index e954df4..517d004 100644 --- a/src/mightypork/gamecore/gui/components/layout/GridLayout.java +++ b/src/mightypork/gamecore/gui/components/layout/GridLayout.java @@ -24,7 +24,8 @@ public class GridLayout extends LayoutComponent { * @param rows number of rows * @param cols number of columns */ - public GridLayout(AppAccess app, RectBound context, int rows, int cols) { + public GridLayout(AppAccess app, RectBound context, int rows, int cols) + { super(app, context); this.tiler = tiles(cols, rows); } @@ -38,7 +39,8 @@ public class GridLayout extends LayoutComponent { * @param rows number of rows * @param cols number of columns */ - public GridLayout(AppAccess app, int rows, int cols) { + public GridLayout(AppAccess app, int rows, int cols) + { this(app, null, rows, cols); } diff --git a/src/mightypork/gamecore/gui/components/layout/HorizontalFixedFlowLayout.java b/src/mightypork/gamecore/gui/components/layout/HorizontalFixedFlowLayout.java index d6ff371..1e5513d 100644 --- a/src/mightypork/gamecore/gui/components/layout/HorizontalFixedFlowLayout.java +++ b/src/mightypork/gamecore/gui/components/layout/HorizontalFixedFlowLayout.java @@ -28,7 +28,8 @@ public class HorizontalFixedFlowLayout extends LayoutComponent { * @param elementWidth width of all elements * @param align component align. Legal values are LEFT and RIGHT. */ - public HorizontalFixedFlowLayout(AppAccess app, RectBound context, Num elementWidth, AlignX align) { + public HorizontalFixedFlowLayout(AppAccess app, RectBound context, Num elementWidth, AlignX align) + { super(app, context); this.colWidth = elementWidth; this.align = align; @@ -47,7 +48,8 @@ public class HorizontalFixedFlowLayout extends LayoutComponent { * @param elementWidth width of all elements * @param align component align. Legal values are LEFT and RIGHT. */ - public HorizontalFixedFlowLayout(AppAccess app, Num elementWidth, AlignX align) { + public HorizontalFixedFlowLayout(AppAccess app, Num elementWidth, AlignX align) + { this(app, null, elementWidth, align); } diff --git a/src/mightypork/gamecore/gui/components/layout/RowHolder.java b/src/mightypork/gamecore/gui/components/layout/RowHolder.java index 73e3c53..d2289a1 100644 --- a/src/mightypork/gamecore/gui/components/layout/RowHolder.java +++ b/src/mightypork/gamecore/gui/components/layout/RowHolder.java @@ -26,7 +26,8 @@ public class RowHolder extends LayoutComponent { * @param app app access * @param rows number of rows */ - public RowHolder(AppAccess app, int rows) { + public RowHolder(AppAccess app, int rows) + { this(app, null, rows); } @@ -36,7 +37,8 @@ public class RowHolder extends LayoutComponent { * @param context bounding context * @param rows number of rows */ - public RowHolder(AppAccess app, RectBound context, int rows) { + public RowHolder(AppAccess app, RectBound context, int rows) + { super(app, context); this.tiler = rows(rows); } diff --git a/src/mightypork/gamecore/gui/components/layout/VerticalFixedFlowLayout.java b/src/mightypork/gamecore/gui/components/layout/VerticalFixedFlowLayout.java index 5a3931c..57f3522 100644 --- a/src/mightypork/gamecore/gui/components/layout/VerticalFixedFlowLayout.java +++ b/src/mightypork/gamecore/gui/components/layout/VerticalFixedFlowLayout.java @@ -28,7 +28,8 @@ public class VerticalFixedFlowLayout extends LayoutComponent { * @param elementHeight height of all elements * @param align component align. Legal values are TOP and BOTTOM. */ - public VerticalFixedFlowLayout(AppAccess app, RectBound context, Num elementHeight, AlignY align) { + public VerticalFixedFlowLayout(AppAccess app, RectBound context, Num elementHeight, AlignY align) + { super(app, context); this.rowHeight = elementHeight; this.align = align; @@ -47,7 +48,8 @@ public class VerticalFixedFlowLayout extends LayoutComponent { * @param elementHeight height of all elements * @param align component align. Legal values are TOP and BOTTOM. */ - public VerticalFixedFlowLayout(AppAccess app, Num elementHeight, AlignY align) { + public VerticalFixedFlowLayout(AppAccess app, Num elementHeight, AlignY align) + { this(app, null, elementHeight, align); } diff --git a/src/mightypork/gamecore/gui/components/painters/ImagePainter.java b/src/mightypork/gamecore/gui/components/painters/ImagePainter.java index 704765b..9de3150 100644 --- a/src/mightypork/gamecore/gui/components/painters/ImagePainter.java +++ b/src/mightypork/gamecore/gui/components/painters/ImagePainter.java @@ -19,7 +19,8 @@ public class ImagePainter extends VisualComponent { /** * @param texture drawn image */ - public ImagePainter(TxQuad texture) { + public ImagePainter(TxQuad texture) + { this.texture = texture; } diff --git a/src/mightypork/gamecore/gui/components/painters/QuadPainter.java b/src/mightypork/gamecore/gui/components/painters/QuadPainter.java index ff8d67d..94d78e9 100644 --- a/src/mightypork/gamecore/gui/components/painters/QuadPainter.java +++ b/src/mightypork/gamecore/gui/components/painters/QuadPainter.java @@ -38,7 +38,8 @@ public class QuadPainter extends VisualComponent { * * @param color */ - public QuadPainter(Color color) { + public QuadPainter(Color color) + { this.colorHMinVMin = color; this.colorHMaxVMin = color; this.colorHMaxVMax = color; @@ -54,7 +55,8 @@ public class QuadPainter extends VisualComponent { * @param colorHMaxVMax * @param colorHMinVMax */ - public QuadPainter(Color colorHMinVMin, Color colorHMaxVMin, Color colorHMaxVMax, Color colorHMinVMax) { + public QuadPainter(Color colorHMinVMin, Color colorHMaxVMin, Color colorHMaxVMax, Color colorHMinVMax) + { this.colorHMinVMin = colorHMinVMin; this.colorHMaxVMin = colorHMaxVMin; this.colorHMaxVMax = colorHMaxVMax; diff --git a/src/mightypork/gamecore/gui/components/painters/TextPainter.java b/src/mightypork/gamecore/gui/components/painters/TextPainter.java index d9ee7d0..7d0ba6f 100644 --- a/src/mightypork/gamecore/gui/components/painters/TextPainter.java +++ b/src/mightypork/gamecore/gui/components/painters/TextPainter.java @@ -34,7 +34,8 @@ public class TextPainter extends VisualComponent { /** * @param font font to use */ - public TextPainter(GLFont font) { + public TextPainter(GLFont font) + { this(font, AlignX.LEFT, Color.WHITE); } @@ -47,7 +48,8 @@ public class TextPainter extends VisualComponent { * @param color default color * @param text drawn text */ - public TextPainter(GLFont font, AlignX align, Color color, String text) { + public TextPainter(GLFont font, AlignX align, Color color, String text) + { this(font, align, color, new StringWrapper(text)); } @@ -60,7 +62,8 @@ public class TextPainter extends VisualComponent { * @param color default color * @param text text provider */ - public TextPainter(GLFont font, AlignX align, Color color, StringProvider text) { + public TextPainter(GLFont font, AlignX align, Color color, StringProvider text) + { this.font = new FontRenderer(font); this.color = color; this.align = align; @@ -73,7 +76,8 @@ public class TextPainter extends VisualComponent { * @param align text align * @param color default color */ - public TextPainter(GLFont font, AlignX align, Color color) { + public TextPainter(GLFont font, AlignX align, Color color) + { this(font, align, color, (StringProvider) null); } diff --git a/src/mightypork/gamecore/gui/screens/BaseScreen.java b/src/mightypork/gamecore/gui/screens/BaseScreen.java index 92d8dfc..55433f7 100644 --- a/src/mightypork/gamecore/gui/screens/BaseScreen.java +++ b/src/mightypork/gamecore/gui/screens/BaseScreen.java @@ -28,7 +28,8 @@ public abstract class BaseScreen extends AppSubModule implements Screen, KeyBind /** * @param app app access */ - public BaseScreen(AppAccess app) { + public BaseScreen(AppAccess app) + { super(app); // disable events initially diff --git a/src/mightypork/gamecore/gui/screens/LayeredScreen.java b/src/mightypork/gamecore/gui/screens/LayeredScreen.java index 6be4b97..45d510c 100644 --- a/src/mightypork/gamecore/gui/screens/LayeredScreen.java +++ b/src/mightypork/gamecore/gui/screens/LayeredScreen.java @@ -20,7 +20,8 @@ public abstract class LayeredScreen extends BaseScreen { /** * @param app app access */ - public LayeredScreen(AppAccess app) { + public LayeredScreen(AppAccess app) + { super(app); } diff --git a/src/mightypork/gamecore/gui/screens/Overlay.java b/src/mightypork/gamecore/gui/screens/Overlay.java index 7654bbb..6ec6e19 100644 --- a/src/mightypork/gamecore/gui/screens/Overlay.java +++ b/src/mightypork/gamecore/gui/screens/Overlay.java @@ -42,7 +42,8 @@ public abstract class Overlay extends AppSubModule implements Updateable, Compar protected final Collection updated = new LinkedHashSet<>(); - public Overlay(AppAccess app) { + public Overlay(AppAccess app) + { super(app); this.mouse = getInput().getMousePos(); diff --git a/src/mightypork/gamecore/gui/screens/ScreenLayer.java b/src/mightypork/gamecore/gui/screens/ScreenLayer.java index 50dead1..d3781b2 100644 --- a/src/mightypork/gamecore/gui/screens/ScreenLayer.java +++ b/src/mightypork/gamecore/gui/screens/ScreenLayer.java @@ -17,7 +17,8 @@ public abstract class ScreenLayer extends Overlay { /** * @param screen parent screen */ - public ScreenLayer(Screen screen) { + public ScreenLayer(Screen screen) + { super(screen); // screen as AppAccess this.screen = screen; diff --git a/src/mightypork/gamecore/gui/screens/ScreenRegistry.java b/src/mightypork/gamecore/gui/screens/ScreenRegistry.java index 9652a31..0bbcea4 100644 --- a/src/mightypork/gamecore/gui/screens/ScreenRegistry.java +++ b/src/mightypork/gamecore/gui/screens/ScreenRegistry.java @@ -31,7 +31,8 @@ public class ScreenRegistry extends AppModule implements ScreenRequestEvent.List /** * @param app app access */ - public ScreenRegistry(AppAccess app) { + public ScreenRegistry(AppAccess app) + { super(app); } diff --git a/src/mightypork/gamecore/input/InputSystem.java b/src/mightypork/gamecore/input/InputSystem.java index 220513e..8791e2a 100644 --- a/src/mightypork/gamecore/input/InputSystem.java +++ b/src/mightypork/gamecore/input/InputSystem.java @@ -55,7 +55,8 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder { /** * @param app app access */ - public InputSystem(AppAccess app) { + public InputSystem(AppAccess app) + { super(app); initDevices(); diff --git a/src/mightypork/gamecore/input/KeyBinding.java b/src/mightypork/gamecore/input/KeyBinding.java index 4897f4b..50e8984 100644 --- a/src/mightypork/gamecore/input/KeyBinding.java +++ b/src/mightypork/gamecore/input/KeyBinding.java @@ -20,7 +20,8 @@ public class KeyBinding implements KeyEvent.Listener { * @param stroke trigger keystroke * @param handler action */ - public KeyBinding(KeyStroke stroke, Runnable handler) { + public KeyBinding(KeyStroke stroke, Runnable handler) + { this.keystroke = stroke; this.handler = handler; diff --git a/src/mightypork/gamecore/input/KeyStroke.java b/src/mightypork/gamecore/input/KeyStroke.java index 10cf933..75b6644 100644 --- a/src/mightypork/gamecore/input/KeyStroke.java +++ b/src/mightypork/gamecore/input/KeyStroke.java @@ -25,7 +25,8 @@ public class KeyStroke { * @param fallingEdge true for falling edge, up for rising edge * @param keys keys that must be pressed */ - public KeyStroke(boolean fallingEdge, int... keys) { + public KeyStroke(boolean fallingEdge, int... keys) + { this.fallingEdge = fallingEdge; for (final int k : keys) { this.keys.add(k); @@ -38,7 +39,8 @@ public class KeyStroke { * * @param keys */ - public KeyStroke(int... keys) { + public KeyStroke(int... keys) + { fallingEdge = false; for (final int k : keys) { this.keys.add(k); diff --git a/src/mightypork/gamecore/loading/AsyncResourceLoader.java b/src/mightypork/gamecore/loading/AsyncResourceLoader.java index 540f363..66cf9e3 100644 --- a/src/mightypork/gamecore/loading/AsyncResourceLoader.java +++ b/src/mightypork/gamecore/loading/AsyncResourceLoader.java @@ -52,7 +52,8 @@ public class AsyncResourceLoader extends Thread implements ResourceLoadRequest.L /** * @param app app acceess */ - public AsyncResourceLoader(BusAccess app) { + public AsyncResourceLoader(BusAccess app) + { super("Deferred loader"); this.app = app; app.getEventBus().subscribe(this); diff --git a/src/mightypork/gamecore/loading/DeferredResource.java b/src/mightypork/gamecore/loading/DeferredResource.java index d5d871d..160b2e3 100644 --- a/src/mightypork/gamecore/loading/DeferredResource.java +++ b/src/mightypork/gamecore/loading/DeferredResource.java @@ -25,7 +25,8 @@ public abstract class DeferredResource implements Deferred, Destroyable { * @param resource resource path / name; this string is later used in * loadResource() */ - public DeferredResource(String resource) { + public DeferredResource(String resource) + { this.resource = resource; } diff --git a/src/mightypork/gamecore/render/DisplaySystem.java b/src/mightypork/gamecore/render/DisplaySystem.java index dfe3475..39e3ec5 100644 --- a/src/mightypork/gamecore/render/DisplaySystem.java +++ b/src/mightypork/gamecore/render/DisplaySystem.java @@ -54,7 +54,8 @@ public class DisplaySystem extends AppModule implements RectBound { /** * @param app app access */ - public DisplaySystem(AppAccess app) { + public DisplaySystem(AppAccess app) + { super(app); } diff --git a/src/mightypork/gamecore/render/Screenshot.java b/src/mightypork/gamecore/render/Screenshot.java index 5604aec..eb9bf2a 100644 --- a/src/mightypork/gamecore/render/Screenshot.java +++ b/src/mightypork/gamecore/render/Screenshot.java @@ -30,7 +30,8 @@ public class Screenshot { * @param bpp bits per pixel (typically 4) * @param buffer */ - public Screenshot(int width, int height, int bpp, ByteBuffer buffer) { + public Screenshot(int width, int height, int bpp, ByteBuffer buffer) + { this.width = width; this.height = height; this.bpp = bpp; diff --git a/src/mightypork/gamecore/render/fonts/FontBank.java b/src/mightypork/gamecore/render/fonts/FontBank.java index 10a5554..8fafccc 100644 --- a/src/mightypork/gamecore/render/fonts/FontBank.java +++ b/src/mightypork/gamecore/render/fonts/FontBank.java @@ -21,7 +21,8 @@ public class FontBank extends AppAdapter { /** * @param app app access */ - public FontBank(AppAccess app) { + public FontBank(AppAccess app) + { super(app); } diff --git a/src/mightypork/gamecore/render/fonts/FontRenderer.java b/src/mightypork/gamecore/render/fonts/FontRenderer.java index 2ea3e95..c58421a 100644 --- a/src/mightypork/gamecore/render/fonts/FontRenderer.java +++ b/src/mightypork/gamecore/render/fonts/FontRenderer.java @@ -23,7 +23,8 @@ public class FontRenderer { /** * @param font used font */ - public FontRenderer(GLFont font) { + public FontRenderer(GLFont font) + { this(font, Color.WHITE); } @@ -32,7 +33,8 @@ public class FontRenderer { * @param font used font * @param color drawing color */ - public FontRenderer(GLFont font, Color color) { + public FontRenderer(GLFont font, Color color) + { this.font = font; this.color = color; } diff --git a/src/mightypork/gamecore/render/fonts/impl/CachedFont.java b/src/mightypork/gamecore/render/fonts/impl/CachedFont.java index 682c13c..e70cbdc 100644 --- a/src/mightypork/gamecore/render/fonts/impl/CachedFont.java +++ b/src/mightypork/gamecore/render/fonts/impl/CachedFont.java @@ -85,7 +85,8 @@ public class CachedFont implements GLFont { * @param filter used Gl filter * @param chars chars to load */ - public CachedFont(java.awt.Font font, boolean antialias, FilterMode filter, String chars) { + public CachedFont(java.awt.Font font, boolean antialias, FilterMode filter, String chars) + { this(font, antialias, filter, chars.toCharArray()); } @@ -98,7 +99,8 @@ public class CachedFont implements GLFont { * @param filter used Gl filter * @param chars chars to load */ - public CachedFont(java.awt.Font font, boolean antialias, FilterMode filter, char[] chars) { + public CachedFont(java.awt.Font font, boolean antialias, FilterMode filter, char[] chars) + { GLUtils.checkGLContext(); this.font = font; @@ -158,7 +160,8 @@ public class CachedFont implements GLFont { public int height; - public LoadedGlyph(char c, BufferedImage image) { + public LoadedGlyph(char c, BufferedImage image) + { this.image = image; this.c = c; this.width = image.getWidth(); diff --git a/src/mightypork/gamecore/render/fonts/impl/DeferredFont.java b/src/mightypork/gamecore/render/fonts/impl/DeferredFont.java index 9abb5ec..ec8f5b1 100644 --- a/src/mightypork/gamecore/render/fonts/impl/DeferredFont.java +++ b/src/mightypork/gamecore/render/fonts/impl/DeferredFont.java @@ -32,7 +32,8 @@ public class DeferredFont extends DeferredResource implements GLFont { int numval; - private FontStyle(int style) { + private FontStyle(int style) + { this.numval = style; } } @@ -53,7 +54,8 @@ public class DeferredFont extends DeferredResource implements GLFont { * @param chars chars to load; null to load basic chars only * @param size size (px) */ - public DeferredFont(String resourcePath, String chars, double size) { + public DeferredFont(String resourcePath, String chars, double size) + { this(resourcePath, chars, size, FontStyle.PLAIN, false, FilterMode.NEAREST); } @@ -68,7 +70,8 @@ public class DeferredFont extends DeferredResource implements GLFont { * @param antialias use antialiasing for caching texture * @param filter gl filtering mode */ - public DeferredFont(String resourcePath, String chars, double size, FontStyle style, boolean antialias, FilterMode filter) { + public DeferredFont(String resourcePath, String chars, double size, FontStyle style, boolean antialias, FilterMode filter) + { super(resourcePath); this.size = size; this.style = style; diff --git a/src/mightypork/gamecore/render/fonts/impl/DeferredFontNative.java b/src/mightypork/gamecore/render/fonts/impl/DeferredFontNative.java index c7b4ba6..ba7b101 100644 --- a/src/mightypork/gamecore/render/fonts/impl/DeferredFontNative.java +++ b/src/mightypork/gamecore/render/fonts/impl/DeferredFontNative.java @@ -27,7 +27,8 @@ public class DeferredFontNative extends DeferredFont { * @param antialias use antialiasing when drawn on the cache texture * @param filter GL filtering mode */ - public DeferredFontNative(String fontName, String extraChars, double size, FontStyle style, boolean antialias, FilterMode filter) { + public DeferredFontNative(String fontName, String extraChars, double size, FontStyle style, boolean antialias, FilterMode filter) + { super(fontName, extraChars, size, style, antialias, filter); } diff --git a/src/mightypork/gamecore/render/textures/DeferredTexture.java b/src/mightypork/gamecore/render/textures/DeferredTexture.java index 035a95e..65475a6 100644 --- a/src/mightypork/gamecore/render/textures/DeferredTexture.java +++ b/src/mightypork/gamecore/render/textures/DeferredTexture.java @@ -27,7 +27,8 @@ public class DeferredTexture extends DeferredResource implements GLTexture { /** * @param resourcePath resource path */ - public DeferredTexture(String resourcePath) { + public DeferredTexture(String resourcePath) + { super(resourcePath); } @@ -212,6 +213,7 @@ public class DeferredTexture extends DeferredResource implements GLTexture { this.wrap = wrapping; } + @Override public QuadGrid grid(int x, int y) { diff --git a/src/mightypork/gamecore/render/textures/FilterMode.java b/src/mightypork/gamecore/render/textures/FilterMode.java index 5e8a893..c7ab0c8 100644 --- a/src/mightypork/gamecore/render/textures/FilterMode.java +++ b/src/mightypork/gamecore/render/textures/FilterMode.java @@ -16,7 +16,8 @@ public enum FilterMode public final int num; - private FilterMode(int gl) { + private FilterMode(int gl) + { this.num = gl; } } diff --git a/src/mightypork/gamecore/render/textures/GLTexture.java b/src/mightypork/gamecore/render/textures/GLTexture.java index b0de888..1adf29e 100644 --- a/src/mightypork/gamecore/render/textures/GLTexture.java +++ b/src/mightypork/gamecore/render/textures/GLTexture.java @@ -1,10 +1,10 @@ package mightypork.gamecore.render.textures; -import org.newdawn.slick.opengl.Texture; - import mightypork.util.constraints.rect.Rect; +import org.newdawn.slick.opengl.Texture; + /** * Texture with filter and wrap mode diff --git a/src/mightypork/gamecore/render/textures/QuadGrid.java b/src/mightypork/gamecore/render/textures/QuadGrid.java index a2493a4..65f58a6 100644 --- a/src/mightypork/gamecore/render/textures/QuadGrid.java +++ b/src/mightypork/gamecore/render/textures/QuadGrid.java @@ -12,12 +12,14 @@ import mightypork.util.constraints.rect.Rect; public class QuadGrid { private final GLTexture tx; - private int txHeight; - private int txWidth; - private double tileW; - private double tileH; + private final int txHeight; + private final int txWidth; + private final double tileW; + private final double tileH; - public QuadGrid(GLTexture tx, int tilesX, int tilesY) { + + public QuadGrid(GLTexture tx, int tilesX, int tilesY) + { this.tx = tx; this.txWidth = tilesX; this.txHeight = tilesY; diff --git a/src/mightypork/gamecore/render/textures/TextureBank.java b/src/mightypork/gamecore/render/textures/TextureBank.java index 6723ad9..11dcc67 100644 --- a/src/mightypork/gamecore/render/textures/TextureBank.java +++ b/src/mightypork/gamecore/render/textures/TextureBank.java @@ -18,14 +18,16 @@ import mightypork.util.error.KeyAlreadyExistsException; */ public class TextureBank extends AppAdapter { - private final Map textures = new HashMap<>(); - private final Map quads = new HashMap<>(); + private final Map textures = new HashMap<>(); + private final Map quads = new HashMap<>(); private final Map sheets = new HashMap<>(); + /** * @param app app access */ - public TextureBank(AppAccess app) { + public TextureBank(AppAccess app) + { super(app); } diff --git a/src/mightypork/gamecore/render/textures/TxQuad.java b/src/mightypork/gamecore/render/textures/TxQuad.java index a00250d..d588505 100644 --- a/src/mightypork/gamecore/render/textures/TxQuad.java +++ b/src/mightypork/gamecore/render/textures/TxQuad.java @@ -62,7 +62,8 @@ public class TxQuad { * @param x2 right bottom X (0-1) * @param y2 right bottom Y (0-1) */ - public TxQuad(GLTexture tx, double x1, double y1, double x2, double y2) { + public TxQuad(GLTexture tx, double x1, double y1, double x2, double y2) + { this(tx, Rect.make(x1, y1, x2, y2)); } @@ -71,7 +72,8 @@ public class TxQuad { * @param tx Texture * @param uvs Rect of texture UVs (0-1); will be frozen. */ - public TxQuad(GLTexture tx, Rect uvs) { + public TxQuad(GLTexture tx, Rect uvs) + { this.tx = tx; this.uvs = uvs.freeze(); } @@ -82,7 +84,8 @@ public class TxQuad { * * @param txQuad a copied quad */ - public TxQuad(TxQuad txQuad) { + public TxQuad(TxQuad txQuad) + { this.tx = txQuad.tx; this.uvs = txQuad.uvs; } diff --git a/src/mightypork/gamecore/render/textures/TxSheet.java b/src/mightypork/gamecore/render/textures/TxSheet.java index 68a0f32..28485b2 100644 --- a/src/mightypork/gamecore/render/textures/TxSheet.java +++ b/src/mightypork/gamecore/render/textures/TxSheet.java @@ -17,10 +17,11 @@ public class TxSheet { private final Random rand = new Random(); private final Random randForSeed = new Random(); - private int count; + private final int count; - public TxSheet(TxQuad tx, int width, int height) { + public TxSheet(TxQuad tx, int width, int height) + { this.original = tx; this.width = width; this.count = width * height; diff --git a/src/mightypork/gamecore/render/textures/WrapMode.java b/src/mightypork/gamecore/render/textures/WrapMode.java index aafb62b..921aa26 100644 --- a/src/mightypork/gamecore/render/textures/WrapMode.java +++ b/src/mightypork/gamecore/render/textures/WrapMode.java @@ -16,7 +16,8 @@ public enum WrapMode public final int num; - private WrapMode(int gl) { + private WrapMode(int gl) + { this.num = gl; } } diff --git a/src/mightypork/rogue/App.java b/src/mightypork/rogue/App.java index 306aa74..7d992ff 100644 --- a/src/mightypork/rogue/App.java +++ b/src/mightypork/rogue/App.java @@ -24,9 +24,8 @@ import mightypork.rogue.screens.test_cat_sound.ScreenTestCat; import mightypork.rogue.screens.test_render.ScreenTestRender; import mightypork.rogue.world.WorldMap; import mightypork.rogue.world.item.Item; -import mightypork.rogue.world.item.ItemData; import mightypork.rogue.world.tile.Tile; -import mightypork.rogue.world.tile.TileData; +import mightypork.rogue.world.tile.TileItems; import mightypork.util.control.eventbus.EventBus; import mightypork.util.control.eventbus.events.Event; import mightypork.util.files.ion.Ion; @@ -108,11 +107,10 @@ public final class App extends BaseApp { @Override protected void preInit() { - Ion.registerIonizable(Tile.ION_MARK, Tile.class); // 700 - Ion.registerIonizable(Item.ION_MARK, Item.class); // 701 - Ion.registerIonizable(WorldMap.ION_MARK, WorldMap.class); // 702 - Ion.registerIonizable(TileData.ION_MARK, TileData.class); // 703 - Ion.registerIonizable(ItemData.ION_MARK, ItemData.class); // 704 + Ion.registerIonizable(Tile.ION_MARK, Tile.class); + Ion.registerIonizable(Item.ION_MARK, Item.class); + Ion.registerIonizable(WorldMap.ION_MARK, WorldMap.class); + Ion.registerIonizable(TileItems.ION_MARK, TileItems.class); // used by tile to store contained items } diff --git a/src/mightypork/rogue/MainLoop.java b/src/mightypork/rogue/MainLoop.java index 7132439..205f75c 100644 --- a/src/mightypork/rogue/MainLoop.java +++ b/src/mightypork/rogue/MainLoop.java @@ -19,7 +19,8 @@ import mightypork.util.logging.Log; public final class MainLoop extends GameLoop implements ActionRequest.Listener { - public MainLoop(BaseApp app) { + public MainLoop(BaseApp app) + { super(app); } @@ -83,7 +84,8 @@ public final class MainLoop extends GameLoop implements ActionRequest.Listener { private final Screenshot scr; - public TaskTakeScreenshot() { + public TaskTakeScreenshot() + { scr = getDisplay().takeScreenshot(); } diff --git a/src/mightypork/rogue/Res.java b/src/mightypork/rogue/Res.java index 319ae4c..ad42951 100644 --- a/src/mightypork/rogue/Res.java +++ b/src/mightypork/rogue/Res.java @@ -67,7 +67,7 @@ public final class Res { texture = textures.loadTexture("test.kitten", "/res/img/kitten.png", FilterMode.LINEAR, WrapMode.CLAMP); texture = textures.loadTexture("gui1", "/res/img/gui1.png", FilterMode.NEAREST, WrapMode.CLAMP); - QuadGrid gui = texture.grid(4, 4); + final QuadGrid gui = texture.grid(4, 4); textures.addQuad("item_frame", gui.makeQuad(0, 0)); textures.addQuad("sword", gui.makeQuad(1, 0)); textures.addQuad("meat", gui.makeQuad(2, 0)); @@ -78,7 +78,7 @@ public final class Res { textures.addQuad("panel", gui.makeQuad(0, 3.75, 4, .25)); texture = textures.loadTexture("tiles", "/res/img/map_tiles.png", FilterMode.NEAREST, WrapMode.CLAMP); - QuadGrid tiles = texture.grid(32, 32); + final QuadGrid tiles = texture.grid(32, 32); textures.addSheet("tile.mossy_bricks.wall", tiles.makeSheet(4, 0, 7, 1)); textures.addSheet("tile.mossy_bricks.floor", tiles.makeSheet(16, 5, 7, 1)); diff --git a/src/mightypork/rogue/events/ActionRequest.java b/src/mightypork/rogue/events/ActionRequest.java index bf7cd0a..3390d90 100644 --- a/src/mightypork/rogue/events/ActionRequest.java +++ b/src/mightypork/rogue/events/ActionRequest.java @@ -16,7 +16,8 @@ public class ActionRequest implements Event { private final RequestType type; - public ActionRequest(RequestType request) { + public ActionRequest(RequestType request) + { type = request; } diff --git a/src/mightypork/rogue/screens/CrossfadeOverlay.java b/src/mightypork/rogue/screens/CrossfadeOverlay.java index c7554a0..779c7a2 100644 --- a/src/mightypork/rogue/screens/CrossfadeOverlay.java +++ b/src/mightypork/rogue/screens/CrossfadeOverlay.java @@ -47,7 +47,8 @@ public class CrossfadeOverlay extends Overlay implements CrossfadeRequest.Listen }; - public CrossfadeOverlay(AppAccess app) { + public CrossfadeOverlay(AppAccess app) + { super(app); final QuadPainter qp = new QuadPainter(color); diff --git a/src/mightypork/rogue/screens/CrossfadeRequest.java b/src/mightypork/rogue/screens/CrossfadeRequest.java index c4742d1..8863ed4 100644 --- a/src/mightypork/rogue/screens/CrossfadeRequest.java +++ b/src/mightypork/rogue/screens/CrossfadeRequest.java @@ -15,7 +15,8 @@ public class CrossfadeRequest implements Event { /** * @param screen screen key to show. Null = exit the app. */ - public CrossfadeRequest(String screen) { + public CrossfadeRequest(String screen) + { super(); this.screen = screen; } diff --git a/src/mightypork/rogue/screens/FpsOverlay.java b/src/mightypork/rogue/screens/FpsOverlay.java index b07f4d5..ac91df0 100644 --- a/src/mightypork/rogue/screens/FpsOverlay.java +++ b/src/mightypork/rogue/screens/FpsOverlay.java @@ -22,7 +22,8 @@ public class FpsOverlay extends Overlay { TextPainter tp; - public FpsOverlay(AppAccess screen) { + public FpsOverlay(AppAccess screen) + { super(screen); /* diff --git a/src/mightypork/rogue/screens/ingame/GameGui.java b/src/mightypork/rogue/screens/ingame/GameGui.java index 77681b3..54e2074 100644 --- a/src/mightypork/rogue/screens/ingame/GameGui.java +++ b/src/mightypork/rogue/screens/ingame/GameGui.java @@ -16,7 +16,8 @@ import mightypork.util.math.color.PAL16; public class GameGui extends ScreenLayer { - public GameGui(Screen screen) { + public GameGui(Screen screen) + { super(screen); final Num h = root.height(); diff --git a/src/mightypork/rogue/screens/ingame/HeartBar.java b/src/mightypork/rogue/screens/ingame/HeartBar.java index f37da5d..3773517 100644 --- a/src/mightypork/rogue/screens/ingame/HeartBar.java +++ b/src/mightypork/rogue/screens/ingame/HeartBar.java @@ -28,7 +28,8 @@ public class HeartBar extends VisualComponent { * @param img_off * @param align */ - public HeartBar(int total, int active, TxQuad img_on, TxQuad img_off, AlignX align) { + public HeartBar(int total, int active, TxQuad img_on, TxQuad img_off, AlignX align) + { super(); this.total = total; this.active = active; diff --git a/src/mightypork/rogue/screens/ingame/NavItemSlot.java b/src/mightypork/rogue/screens/ingame/NavItemSlot.java index bf34d48..1b30faa 100644 --- a/src/mightypork/rogue/screens/ingame/NavItemSlot.java +++ b/src/mightypork/rogue/screens/ingame/NavItemSlot.java @@ -24,7 +24,8 @@ public class NavItemSlot extends ClickableComponent implements MouseMotionEvent. private boolean wasInside = false; - public NavItemSlot(TxQuad image) { + public NavItemSlot(TxQuad image) + { this.image = image; this.frame = Res.getTxQuad("item_frame"); diff --git a/src/mightypork/rogue/screens/ingame/ScreenGame.java b/src/mightypork/rogue/screens/ingame/ScreenGame.java index d995bc4..372d495 100644 --- a/src/mightypork/rogue/screens/ingame/ScreenGame.java +++ b/src/mightypork/rogue/screens/ingame/ScreenGame.java @@ -7,7 +7,8 @@ import mightypork.gamecore.gui.screens.LayeredScreen; public class ScreenGame extends LayeredScreen { - public ScreenGame(AppAccess app) { + public ScreenGame(AppAccess app) + { super(app); addLayer(new GameGui(this)); diff --git a/src/mightypork/rogue/screens/main_menu/MenuButton.java b/src/mightypork/rogue/screens/main_menu/MenuButton.java index 419dd7b..a823582 100644 --- a/src/mightypork/rogue/screens/main_menu/MenuButton.java +++ b/src/mightypork/rogue/screens/main_menu/MenuButton.java @@ -31,7 +31,8 @@ class MenuButton extends ClickableComponent { private final NumVar alphaMulSh = Num.makeVar(SH_ALPHA_OFF); - public MenuButton(String text, Color color) { + public MenuButton(String text, Color color) + { this.color = color.withAlpha(alphaMul); this.painter = new TextPainter(font, AlignX.CENTER, this.color, text); diff --git a/src/mightypork/rogue/screens/main_menu/MenuLayer.java b/src/mightypork/rogue/screens/main_menu/MenuLayer.java index c69d4c0..a99504e 100644 --- a/src/mightypork/rogue/screens/main_menu/MenuLayer.java +++ b/src/mightypork/rogue/screens/main_menu/MenuLayer.java @@ -17,7 +17,8 @@ import mightypork.util.math.color.PAL16; class MenuLayer extends ScreenLayer { - public MenuLayer(BaseScreen screen) { + public MenuLayer(BaseScreen screen) + { super(screen); init(); diff --git a/src/mightypork/rogue/screens/main_menu/ScreenMainMenu.java b/src/mightypork/rogue/screens/main_menu/ScreenMainMenu.java index a185908..f558f89 100644 --- a/src/mightypork/rogue/screens/main_menu/ScreenMainMenu.java +++ b/src/mightypork/rogue/screens/main_menu/ScreenMainMenu.java @@ -7,7 +7,8 @@ import mightypork.gamecore.gui.screens.LayeredScreen; public class ScreenMainMenu extends LayeredScreen { - public ScreenMainMenu(AppAccess app) { + public ScreenMainMenu(AppAccess app) + { super(app); addLayer(new MenuLayer(this)); diff --git a/src/mightypork/rogue/screens/test_bouncyboxes/BouncyBox.java b/src/mightypork/rogue/screens/test_bouncyboxes/BouncyBox.java index 35c72c9..b265d68 100644 --- a/src/mightypork/rogue/screens/test_bouncyboxes/BouncyBox.java +++ b/src/mightypork/rogue/screens/test_bouncyboxes/BouncyBox.java @@ -23,7 +23,8 @@ public class BouncyBox extends VisualComponent implements Updateable { private final NumAnimated pos = new NumAnimated(0, Easing.BOUNCE_OUT); - public BouncyBox() { + public BouncyBox() + { super(); enableCaching(true); diff --git a/src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java b/src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java index 1337f4d..99ccd34 100644 --- a/src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java +++ b/src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java @@ -23,7 +23,8 @@ public class LayerBouncyBoxes extends ScreenLayer { private RowHolder layout; - public LayerBouncyBoxes(BaseScreen screen) { + public LayerBouncyBoxes(BaseScreen screen) + { super(screen); bindKey(new KeyStroke(true, Keys.RIGHT), new Runnable() { diff --git a/src/mightypork/rogue/screens/test_bouncyboxes/ScreenTestBouncy.java b/src/mightypork/rogue/screens/test_bouncyboxes/ScreenTestBouncy.java index 70f01ac..3223c46 100644 --- a/src/mightypork/rogue/screens/test_bouncyboxes/ScreenTestBouncy.java +++ b/src/mightypork/rogue/screens/test_bouncyboxes/ScreenTestBouncy.java @@ -10,7 +10,8 @@ public class ScreenTestBouncy extends LayeredScreen { private final LayerBouncyBoxes layer; - public ScreenTestBouncy(AppAccess app) { + public ScreenTestBouncy(AppAccess app) + { super(app); layer = new LayerBouncyBoxes(this); diff --git a/src/mightypork/rogue/screens/test_cat_sound/LayerColor.java b/src/mightypork/rogue/screens/test_cat_sound/LayerColor.java index fc78ef2..e2cd1a7 100644 --- a/src/mightypork/rogue/screens/test_cat_sound/LayerColor.java +++ b/src/mightypork/rogue/screens/test_cat_sound/LayerColor.java @@ -9,7 +9,8 @@ import mightypork.util.math.color.Color; public class LayerColor extends ScreenLayer { - public LayerColor(BaseScreen screen, Color color) { + public LayerColor(BaseScreen screen, Color color) + { super(screen); root.add(new QuadPainter(color)); diff --git a/src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java b/src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java index dd1bd7b..3cff7d5 100644 --- a/src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java +++ b/src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java @@ -29,7 +29,8 @@ public class LayerFlyingCat extends ScreenLayer implements MouseButtonEvent.List private final Random rand = new Random(); - public LayerFlyingCat(BaseScreen screen) { + public LayerFlyingCat(BaseScreen screen) + { super(screen); // timing diff --git a/src/mightypork/rogue/screens/test_cat_sound/ScreenTestCat.java b/src/mightypork/rogue/screens/test_cat_sound/ScreenTestCat.java index aacaa87..dc196cb 100644 --- a/src/mightypork/rogue/screens/test_cat_sound/ScreenTestCat.java +++ b/src/mightypork/rogue/screens/test_cat_sound/ScreenTestCat.java @@ -12,7 +12,8 @@ import mightypork.rogue.events.ActionRequest.RequestType; public class ScreenTestCat extends LayeredScreen { - public ScreenTestCat(AppAccess app) { + public ScreenTestCat(AppAccess app) + { super(app); addLayer(new LayerFlyingCat(this)); diff --git a/src/mightypork/rogue/screens/test_render/LayerTestGradient.java b/src/mightypork/rogue/screens/test_render/LayerTestGradient.java index 50a4ef1..a5d1afa 100644 --- a/src/mightypork/rogue/screens/test_render/LayerTestGradient.java +++ b/src/mightypork/rogue/screens/test_render/LayerTestGradient.java @@ -14,7 +14,8 @@ public class LayerTestGradient extends ScreenLayer { private final RectBound pos2; - public LayerTestGradient(BaseScreen screen) { + public LayerTestGradient(BaseScreen screen) + { super(screen); pos1 = root.topEdge().growDown(64); diff --git a/src/mightypork/rogue/screens/test_render/ScreenTestRender.java b/src/mightypork/rogue/screens/test_render/ScreenTestRender.java index 4a6fd9d..9839ea6 100644 --- a/src/mightypork/rogue/screens/test_render/ScreenTestRender.java +++ b/src/mightypork/rogue/screens/test_render/ScreenTestRender.java @@ -7,7 +7,8 @@ import mightypork.gamecore.gui.screens.LayeredScreen; public class ScreenTestRender extends LayeredScreen { - public ScreenTestRender(AppAccess app) { + public ScreenTestRender(AppAccess app) + { super(app); addLayer(new LayerTestGradient(this)); diff --git a/src/mightypork/rogue/world/Entity.java b/src/mightypork/rogue/world/Entity.java deleted file mode 100644 index 3d8bdf5..0000000 --- a/src/mightypork/rogue/world/Entity.java +++ /dev/null @@ -1,130 +0,0 @@ -package mightypork.rogue.world; - - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import mightypork.util.constraints.rect.proxy.RectBound; -import mightypork.util.control.timing.Updateable; -import mightypork.util.files.ion.Ion; -import mightypork.util.files.ion.Ionizable; - - -/** - * Abstract entity - * - * @author MightyPork - * @param Data object class - * @param Model class - * @param Render context class - */ -public abstract class Entity, R extends RectBound> implements Ionizable, Updateable { - - protected M model; - protected D data; - - - /** - * Used by Ion for loading. - */ - public Entity() { - } - - - /** - * Create from model - * - * @param model model - */ - public Entity(M model) { - setModel(model); - } - - - @Override - public final void loadFrom(InputStream in) throws IOException - { - final int id = Ion.readInt(in); - setModel(id); - model.load(data, in); // load saved data - } - - - private void initData() - { - data = model.createData(); - } - - - /** - * @return data - */ - public final D getData() - { - return data; - } - - - /** - * @return entity model - */ - public final M getModel() - { - return model; - } - - - /** - * Assign a model. - * - * @param id model id - */ - public final void setModel(int id) - { - setModel(getModelForId(id)); - } - - - /** - * Assign a model. - * - * @param model model - */ - public final void setModel(M model) - { - this.model = model; - initData(); - } - - - @Override - public final void saveTo(OutputStream out) throws IOException - { - Ion.writeInt(out, model.getId()); - model.save(data, out); - } - - - public void render(R context) - { - model.render(data, context); - } - - - @Override - public void update(double delta) - { - model.update(data, delta); - } - - - /** - * Get model for ID - * - * @param id id - * @return model for the ID - */ - protected abstract M getModelForId(int id); - -} diff --git a/src/mightypork/rogue/world/EntityModel.java b/src/mightypork/rogue/world/EntityModel.java deleted file mode 100644 index 034f872..0000000 --- a/src/mightypork/rogue/world/EntityModel.java +++ /dev/null @@ -1,75 +0,0 @@ -package mightypork.rogue.world; - - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import mightypork.util.annotations.DefaultImpl; -import mightypork.util.constraints.rect.proxy.RectBound; - - -/** - * Entity model. Provides concrete implementation to an entity, working with - * it's data object. - * - * @author MightyPork - * @param Data object class - * @param Render context class - */ -public abstract class EntityModel { - - /** Model id */ - private final int id; - - - /** - * Create a model. The caller must then register this instance in a Model - * registry for the particular entity type. - * - * @param id model id - */ - public EntityModel(int id) { - this.id = id; - } - - - /** - * Get the model id. - * - * @return id - */ - public final int getId() - { - return id; - } - - - /** - * Create a data object and populate it with default values.
- * It's allowed to return null for no data. - * - * @return data object - */ - public abstract D createData(); - - - /** - * Render the item according to given context. - * - * @param data rendered item - * @param context rendering context - */ - public abstract void render(D data, R context); - - - /** - * Update the item (animation, decay etc) - * - * @param item item to update - * @param delta delta time - */ - @DefaultImpl - public abstract void update(D item, double delta); - -} diff --git a/src/mightypork/rogue/world/WorldMap.java b/src/mightypork/rogue/world/WorldMap.java index dc11685..99468c4 100644 --- a/src/mightypork/rogue/world/WorldMap.java +++ b/src/mightypork/rogue/world/WorldMap.java @@ -7,7 +7,9 @@ import java.io.OutputStream; import mightypork.rogue.world.tile.Tile; import mightypork.rogue.world.tile.TileGrid; +import mightypork.rogue.world.tile.Tiles; import mightypork.util.files.ion.Ion; +import mightypork.util.files.ion.IonConstructor; import mightypork.util.files.ion.Ionizable; @@ -21,12 +23,14 @@ public class WorldMap implements TileGrid, Ionizable { private Tile[][] tiles; - public WorldMap() { - // constructor for ION + @IonConstructor + public WorldMap() + { } - public WorldMap(int width, int height) { + public WorldMap(int width, int height) + { this.width = width; this.height = height; buildArray(); @@ -36,6 +40,12 @@ public class WorldMap implements TileGrid, Ionizable { private void buildArray() { this.tiles = new Tile[height][width]; + + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + tiles[y][x] = Tiles.NONE.create(); + } + } } @@ -73,35 +83,27 @@ public class WorldMap implements TileGrid, Ionizable { @Override - public void loadFrom(InputStream in) throws IOException + public void load(InputStream in) throws IOException { width = Ion.readInt(in); height = Ion.readInt(in); buildArray(); - while (true) { - final short mark = Ion.readMark(in); - if (mark == Ion.END) { - break; - } else if (mark == Ion.ENTRY) { - - final int x = Ion.readInt(in); - final int y = Ion.readInt(in); - - final Tile tile = (Tile) Ion.readObject(in); - - setTile(tile, x, y); - - } else { - throw new IOException("Invalid mark encountered while reading tile map."); - } + while (Ion.hasNextEntry(in)) { + + final int x = Ion.readInt(in); + final int y = Ion.readInt(in); + + final Tile tile = (Tile) Ion.readObject(in); + + setTile(tile, x, y); } } @Override - public void saveTo(OutputStream out) throws IOException + public void save(OutputStream out) throws IOException { Ion.writeInt(out, width); Ion.writeInt(out, height); @@ -109,7 +111,8 @@ public class WorldMap implements TileGrid, Ionizable { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { final Tile t = getTile(x, y); - if (t != null) { + // skip null tiles + if (!t.getModel().isNullTile()) { Ion.writeMark(out, Ion.ENTRY); Ion.writeInt(out, x); Ion.writeInt(out, y); @@ -118,6 +121,7 @@ public class WorldMap implements TileGrid, Ionizable { } } + // end of sequence Ion.writeMark(out, Ion.END); } diff --git a/src/mightypork/rogue/world/item/Item.java b/src/mightypork/rogue/world/item/Item.java index 8c9a2f7..c7abb17 100644 --- a/src/mightypork/rogue/world/item/Item.java +++ b/src/mightypork/rogue/world/item/Item.java @@ -1,34 +1,87 @@ package mightypork.rogue.world.item; -import mightypork.rogue.world.Entity; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import mightypork.rogue.world.tile.TileRenderContext; import mightypork.util.constraints.rect.proxy.RectBound; +import mightypork.util.control.timing.Animator; +import mightypork.util.control.timing.AnimatorBounce; +import mightypork.util.control.timing.Updateable; +import mightypork.util.files.ion.Ion; +import mightypork.util.files.ion.IonBundle; +import mightypork.util.files.ion.IonConstructor; +import mightypork.util.files.ion.Ionizable; +import mightypork.util.math.Easing; -public final class Item extends Entity { +public class Item implements Updateable, Ionizable { public static final short ION_MARK = 701; + private transient ItemModel model; + public transient Object modelData; + public transient Animator anim; + + public int id; + + public boolean[] flags; + public int[] numbers; + - public Item() { - super(); + public Item(int id) + { + this(Items.get(id)); } - public Item(ItemModel model) { - super(model); + @IonConstructor + public Item() + { } - public Item(int id) { - super(Items.get(id)); + public Item(ItemModel model) + { + this.model = model; + this.id = model.id; + this.anim = new AnimatorBounce(2, Easing.SINE_BOTH); + } + + + public void render(RectBound context) + { + model.render(this, context); } @Override - protected ItemModel getModelForId(int id) + public void save(OutputStream out) throws IOException { - return Items.get(id); + final IonBundle ib = new IonBundle(); + + ib.put("id", id); + ib.put("flags", flags); + ib.put("numbers", numbers); + + Ion.writeObject(out, ib); + } + + + @Override + public void load(InputStream in) throws IOException + { + final IonBundle ib = (IonBundle) Ion.readObject(in); + + id = ib.get("id", id); + flags = ib.get("flags", flags); + numbers = ib.get("numbers", numbers); + + if (id != model.id) { + model = Items.get(id); + } } @@ -38,4 +91,20 @@ public final class Item extends Entity { return ION_MARK; } + + @Override + public void update(double delta) + { + if (anim != null) { + anim.update(delta); + + } + } + + + public void renderOnTile(TileRenderContext context) + { + model.renderOnTile(this, context); + } + } diff --git a/src/mightypork/rogue/world/item/ItemData.java b/src/mightypork/rogue/world/item/ItemData.java deleted file mode 100644 index dca443d..0000000 --- a/src/mightypork/rogue/world/item/ItemData.java +++ /dev/null @@ -1,13 +0,0 @@ -package mightypork.rogue.world.item; - - -/** - * Item data object. - * - * @author MightyPork - */ -public final class ItemData { - - public static final int ION_MARK = 704; - -} diff --git a/src/mightypork/rogue/world/item/ItemModel.java b/src/mightypork/rogue/world/item/ItemModel.java index 98eaf96..c7acac7 100644 --- a/src/mightypork/rogue/world/item/ItemModel.java +++ b/src/mightypork/rogue/world/item/ItemModel.java @@ -1,19 +1,50 @@ package mightypork.rogue.world.item; -import mightypork.rogue.world.EntityModel; +import mightypork.rogue.world.tile.TileRenderContext; +import mightypork.util.annotations.DefaultImpl; +import mightypork.util.constraints.num.proxy.NumBoundAdapter; +import mightypork.util.constraints.rect.Rect; import mightypork.util.constraints.rect.proxy.RectBound; +import mightypork.util.constraints.rect.proxy.RectBoundAdapter; -/** - * An item model - * - * @author MightyPork - */ -public abstract class ItemModel extends EntityModel { - - public ItemModel(int id) { - super(id); +public abstract class ItemModel { + + public final int id; + + private final RectBoundAdapter tileRect = new RectBoundAdapter(); + private final NumBoundAdapter yOffset = new NumBoundAdapter(); + + private final Rect itemRect = tileRect.shrink(tileRect.height().perc(10)).moveY(yOffset.neg()); + + + public ItemModel(int id) + { Items.register(id, this); + this.id = id; + } + + + /** + * @return new tile with this model + */ + @DefaultImpl + public Item create() + { + return new Item(this); } + + + public abstract void render(Item item, RectBound context); + + + public void renderOnTile(Item item, TileRenderContext context) + { + tileRect.setRect(context.getRect()); + yOffset.setNum(item.anim); + + render(item, itemRect); + } + } diff --git a/src/mightypork/rogue/world/item/Items.java b/src/mightypork/rogue/world/item/Items.java index 23960ba..cb18aaf 100644 --- a/src/mightypork/rogue/world/item/Items.java +++ b/src/mightypork/rogue/world/item/Items.java @@ -1,25 +1,27 @@ package mightypork.rogue.world.item; -import java.util.HashMap; -import java.util.Map; - - +/** + * Item registry + * + * @author MightyPork + */ public final class Items { - private static final Map registered = new HashMap<>(); + private static final ItemModel[] items = new ItemModel[256]; static void register(int id, ItemModel model) { - if (registered.containsKey(id)) throw new IllegalArgumentException("Item ID " + id + " already in use."); - registered.put(id, model); + if (id < 0 || id >= items.length) if (items[id] != null) throw new IllegalArgumentException("Item ID " + id + " already in use."); + + items[id] = model; } public static ItemModel get(int id) { - final ItemModel m = registered.get(id); + final ItemModel m = items[id]; if (m == null) throw new IllegalArgumentException("No item with ID " + id + "."); return m; } diff --git a/src/mightypork/rogue/world/tile/Tile.java b/src/mightypork/rogue/world/tile/Tile.java index 031ba63..8757e63 100644 --- a/src/mightypork/rogue/world/tile/Tile.java +++ b/src/mightypork/rogue/world/tile/Tile.java @@ -1,118 +1,116 @@ package mightypork.rogue.world.tile; -import mightypork.rogue.world.Entity; -import mightypork.rogue.world.item.Item; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import mightypork.util.control.timing.Animator; +import mightypork.util.control.timing.Updateable; +import mightypork.util.files.ion.Ion; +import mightypork.util.files.ion.IonBundle; +import mightypork.util.files.ion.IonConstructor; +import mightypork.util.files.ion.Ionizable; -/** - * Concrete tile in the world. - * - * @author MightyPork - */ -public final class Tile extends Entity { + +public final class Tile implements Ionizable, Updateable { public static final short ION_MARK = 700; - /** Whether the tile is occupied by an entity */ - private transient boolean occupied; - + private transient TileModel model; + public transient Object modelData; + public transient Animator anim; - public Tile() { - super(); - } + public int id; + public TileItems items; - public Tile(TileModel model) { - super(model); - } + public boolean[] flags; + public int[] numbers; - public Tile(int id) { - super(Tiles.get(id)); + public Tile(int id) + { + this(Tiles.get(id)); } - @Override - protected TileModel getModelForId(int id) + @IonConstructor + public Tile() { - return Tiles.get(id); } - @Override - public short getIonMark() + public Tile(TileModel model) { - return ION_MARK; + this.model = model; + this.id = model.id; + this.items = new TileItems(); } - @Override public void render(TileRenderContext context) { - super.render(context); + model.render(this, context); - // render laying-on-top item - if (!data.items.isEmpty()) { - final Item item = data.items.peek(); - - item.render(context.getRect()); + if (!items.isEmpty()) { + items.peek().renderOnTile(context); } } @Override - public void update(double delta) + public void save(OutputStream out) throws IOException { - super.update(delta); + if (model.isNullTile()) throw new RuntimeException("Cannot save null tile."); - // update laying-on-top item - if (!data.items.isEmpty()) { - final Item item = data.items.peek(); - item.update(delta); - } - } - - - /** - * Try to reveal secrets of this tile - */ - public void search() - { - model.search(data); + final IonBundle ib = new IonBundle(); + + ib.put("id", id); + ib.put("flags", flags); + ib.put("numbers", numbers); + ib.put("items", items); + + Ion.writeObject(out, ib); } - /** - * @return true if a mob can walk through - */ - public boolean isWalkable() + @Override + public void load(InputStream in) throws IOException { - return model.isWalkable(data); + final IonBundle ib = (IonBundle) Ion.readObject(in); + + id = ib.get("id", id); + flags = ib.get("flags", flags); + numbers = ib.get("numbers", numbers); + items = ib.get("items", items); + + // renew model + if (model == null || id != model.id) { + model = Tiles.get(id); + } } - public boolean hasItem() + @Override + public short getIonMark() { - return !data.items.isEmpty(); + return ION_MARK; } - public Item removeItem() + @Override + public void update(double delta) { - if(!hasItem()) return null; - return data.items.pop(); + if (!items.isEmpty()) { + items.peek().update(delta); + } } - public boolean isOccupied() + public TileModel getModel() { - return occupied; + return model; } - - public void setOccupied(boolean occupied) - { - this.occupied = occupied; - } } diff --git a/src/mightypork/rogue/world/tile/TileData.java b/src/mightypork/rogue/world/tile/TileData.java deleted file mode 100644 index bf0be49..0000000 --- a/src/mightypork/rogue/world/tile/TileData.java +++ /dev/null @@ -1,54 +0,0 @@ -package mightypork.rogue.world.tile; - - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Stack; - -import mightypork.rogue.world.item.Item; -import mightypork.util.files.ion.IonList; -import mightypork.util.files.ion.Ionizable; - - -/** - * Tile data object. - * - * @author MightyPork - */ -public final class TileData implements Ionizable { - - public static final short ION_MARK = 703; - - /** Items dropped onto this tile */ - public final Stack items = new Stack<>(); - - public int id; - - public boolean[] flags; - public int[] numbers; - - - @Override - public void loadFrom(InputStream in) throws IOException - { - - } - - @Override - public void saveTo(OutputStream out) throws IOException - { - } - - @Override - public short getIonMark() - { - return 0; - } - - public Tile toTile() { - Tile t = new Tile(Tiles.get(id)); - t.s - } - -} diff --git a/src/mightypork/rogue/world/tile/TileItems.java b/src/mightypork/rogue/world/tile/TileItems.java new file mode 100644 index 0000000..fd61f86 --- /dev/null +++ b/src/mightypork/rogue/world/tile/TileItems.java @@ -0,0 +1,39 @@ +package mightypork.rogue.world.tile; + + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Stack; + +import mightypork.rogue.world.item.Item; +import mightypork.util.files.ion.Ion; +import mightypork.util.files.ion.Ionizable; + + +public class TileItems extends Stack implements Ionizable { + + public static final short ION_MARK = 703; + + + @Override + public void load(InputStream in) throws IOException + { + Ion.readSequence(in, this); + } + + + @Override + public void save(OutputStream out) throws IOException + { + Ion.writeSequence(out, this); + } + + + @Override + public short getIonMark() + { + return ION_MARK; + } + +} diff --git a/src/mightypork/rogue/world/tile/TileModel.java b/src/mightypork/rogue/world/tile/TileModel.java index e3b6584..5ecfbf4 100644 --- a/src/mightypork/rogue/world/tile/TileModel.java +++ b/src/mightypork/rogue/world/tile/TileModel.java @@ -1,51 +1,62 @@ package mightypork.rogue.world.tile; -import mightypork.rogue.world.EntityModel; import mightypork.util.annotations.DefaultImpl; -public abstract class TileModel extends EntityModel { +/** + * Singleton-like tile implementation + * + * @author MightyPork + */ +public abstract class TileModel { - public TileModel(int id) { - super(id); + /** Model ID */ + public final int id; + + + public TileModel(int id) + { Tiles.register(id, this); + this.id = id; } - @Override - public TileData createData() + + /** + * @return new tile with this model + */ + @DefaultImpl + public Tile create() { - return null; + return new Tile(this); } /** - * Test if this tile type is potentially walkable. Used during world - * generation. + * Render the tile. * - * @return can be walked through (if discovered / open) + * @param tile + * @param context */ - public abstract boolean isWalkable(); + public abstract void render(Tile tile, TileRenderContext context); /** - * Try to reveal a secret. - * - * @param data tile data + * @param tile + * @return is walkable at the current conditions */ - @DefaultImpl - public void search(TileData data) - { - // do nothing. - } + public abstract boolean isWalkable(Tile tile); /** - * Check if a mob can walk through. - * - * @param data tile data - * @return is walkable + * @return true if the tile can be walkable at some conditions */ - public abstract boolean isWalkable(TileData data); + public abstract boolean isPotentiallyWalkable(); + + + public boolean isNullTile() + { + return false; + } } diff --git a/src/mightypork/rogue/world/tile/TileRenderContext.java b/src/mightypork/rogue/world/tile/TileRenderContext.java index f6aa249..6eb6eee 100644 --- a/src/mightypork/rogue/world/tile/TileRenderContext.java +++ b/src/mightypork/rogue/world/tile/TileRenderContext.java @@ -16,7 +16,8 @@ public final class TileRenderContext implements RectBound { public int x, y; - public TileRenderContext(TileGrid map, Rect drawArea, long renderNoiseSeed) { + public TileRenderContext(TileGrid map, Rect drawArea, long renderNoiseSeed) + { this.map = map; this.tiler = drawArea.tiles(map.getWidth(), map.getHeight()); this.noise = new NoiseGen(0.2, 0, 0.5, 1, renderNoiseSeed); @@ -45,7 +46,7 @@ public final class TileRenderContext implements RectBound { /** * @return per-coord noise value 0..1 */ - public double getNoise() + public double getTileNoise() { return noise.valueAt(x, y); } @@ -56,4 +57,10 @@ public final class TileRenderContext implements RectBound { this.x = x; this.y = y; } + + + public void renderTile(Tile t) + { + t.render(this); + } } diff --git a/src/mightypork/rogue/world/tile/Tiles.java b/src/mightypork/rogue/world/tile/Tiles.java index 2888e4a..0a8ecc7 100644 --- a/src/mightypork/rogue/world/tile/Tiles.java +++ b/src/mightypork/rogue/world/tile/Tiles.java @@ -1,26 +1,42 @@ package mightypork.rogue.world.tile; -import java.util.HashMap; -import java.util.Map; +import mightypork.rogue.world.tile.models.Floor; +import mightypork.rogue.world.tile.models.NullTile; +/** + * Tile registry + * + * @author MightyPork + */ public final class Tiles { - private static final Map registered = new HashMap<>(); + private static final TileModel[] tiles = new TileModel[256]; + + public static final TileModel NONE = new NullTile(0); + public static final TileModel FLOOR_MOSSY = new Floor(1, "tile.mossy_bricks.floor"); + public static final TileModel WALL_MOSSY = new Floor(2, "tile.mossy_bricks.wall"); static void register(int id, TileModel model) { - if (registered.containsKey(id)) throw new IllegalArgumentException("Tile ID " + id + " already in use."); - registered.put(id, model); + if (id < 0 || id >= tiles.length) if (tiles[id] != null) { + throw new IllegalArgumentException("Tile ID " + id + " already in use."); + } + + tiles[id] = model; } public static TileModel get(int id) { - final TileModel m = registered.get(id); - if (m == null) throw new IllegalArgumentException("No tile with ID " + id + "."); + final TileModel m = tiles[id]; + + if (m == null) { + throw new IllegalArgumentException("No tile with ID " + id + "."); + } + return m; } } diff --git a/src/mightypork/rogue/world/tile/impl/SimpleFloor.java b/src/mightypork/rogue/world/tile/impl/SimpleFloor.java deleted file mode 100644 index 4edc21e..0000000 --- a/src/mightypork/rogue/world/tile/impl/SimpleFloor.java +++ /dev/null @@ -1,15 +0,0 @@ -package mightypork.rogue.world.tile.impl; - -public class SimpleFloor extends SimpleTile { - - public SimpleFloor(int id, String sheetKey) { - super(id, sheetKey); - } - - @Override - public boolean isWalkable() - { - return true; - } - -} diff --git a/src/mightypork/rogue/world/tile/impl/SimpleTile.java b/src/mightypork/rogue/world/tile/impl/SimpleTile.java deleted file mode 100644 index dfa8b58..0000000 --- a/src/mightypork/rogue/world/tile/impl/SimpleTile.java +++ /dev/null @@ -1,71 +0,0 @@ -package mightypork.rogue.world.tile.impl; - - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import mightypork.gamecore.render.DisplaySystem; -import mightypork.gamecore.render.Render; -import mightypork.gamecore.render.textures.TxSheet; -import mightypork.rogue.Res; -import mightypork.rogue.world.tile.TileData; -import mightypork.rogue.world.tile.TileModel; -import mightypork.rogue.world.tile.TileRenderContext; -import mightypork.util.annotations.DefaultImpl; - - -public abstract class SimpleTile extends TileModel { - - private TxSheet sheet; - - - public SimpleTile(int id, String sheetKey) { - super(id); - this.sheet = Res.getTxSheet(sheetKey); - } - - - @Override - @DefaultImpl - public void load(TileData data, InputStream in) throws IOException - { - // do nothing - } - - - @Override - @DefaultImpl - public void save(TileData data, OutputStream out) throws IOException - { - // do nothing - } - - - @Override - public void render(TileData data, TileRenderContext context) - { - // TODO worldmap should take care of this and break the row drawing when it encounters end of screen etc - - // not in screen -> no draw - if (!context.getRect().intersectsWith(DisplaySystem.getBounds())) return; - - Render.quadTextured(context.getRect(), sheet.getRandomQuad(context.getNoise())); - } - - - @Override - @DefaultImpl - public void update(TileData item, double delta) - { - // do nothing - } - - @Override - @DefaultImpl - public boolean isWalkable(TileData data) - { - return isWalkable(); - } - -} diff --git a/src/mightypork/rogue/world/tile/impl/SimpleWall.java b/src/mightypork/rogue/world/tile/impl/SimpleWall.java deleted file mode 100644 index 277e146..0000000 --- a/src/mightypork/rogue/world/tile/impl/SimpleWall.java +++ /dev/null @@ -1,16 +0,0 @@ -package mightypork.rogue.world.tile.impl; - - -public class SimpleWall extends SimpleTile { - - public SimpleWall(int id, String sheetKey) { - super(id, sheetKey); - } - - @Override - public boolean isWalkable() - { - return false; - } - -} diff --git a/src/mightypork/rogue/world/tile/models/Floor.java b/src/mightypork/rogue/world/tile/models/Floor.java new file mode 100644 index 0000000..c975969 --- /dev/null +++ b/src/mightypork/rogue/world/tile/models/Floor.java @@ -0,0 +1,18 @@ +package mightypork.rogue.world.tile.models; + + +public class Floor extends SimpleTile { + + public Floor(int id, String sheetKey) + { + super(id, sheetKey); + } + + + @Override + public boolean isPotentiallyWalkable() + { + return true; + } + +} diff --git a/src/mightypork/rogue/world/tile/models/NullTile.java b/src/mightypork/rogue/world/tile/models/NullTile.java new file mode 100644 index 0000000..dd27f2b --- /dev/null +++ b/src/mightypork/rogue/world/tile/models/NullTile.java @@ -0,0 +1,57 @@ +package mightypork.rogue.world.tile.models; + + +import mightypork.rogue.world.tile.Tile; +import mightypork.rogue.world.tile.TileModel; +import mightypork.rogue.world.tile.TileRenderContext; + + +public class NullTile extends TileModel { + + private Tile inst; + + + public NullTile(int id) + { + super(id); + } + + + @Override + public void render(Tile tile, TileRenderContext context) + { + } + + + @Override + public boolean isWalkable(Tile tile) + { + return false; + } + + + @Override + public boolean isPotentiallyWalkable() + { + return true; + } + + + @Override + public boolean isNullTile() + { + return true; + } + + + @Override + public Tile create() + { + if (inst == null) { + inst = new Tile(this); + } + + return inst; + } + +} diff --git a/src/mightypork/rogue/world/tile/models/SimpleTile.java b/src/mightypork/rogue/world/tile/models/SimpleTile.java new file mode 100644 index 0000000..1a47aa2 --- /dev/null +++ b/src/mightypork/rogue/world/tile/models/SimpleTile.java @@ -0,0 +1,43 @@ +package mightypork.rogue.world.tile.models; + + +import mightypork.gamecore.render.Render; +import mightypork.gamecore.render.textures.TxSheet; +import mightypork.rogue.Res; +import mightypork.rogue.world.tile.Tile; +import mightypork.rogue.world.tile.TileModel; +import mightypork.rogue.world.tile.TileRenderContext; +import mightypork.util.annotations.DefaultImpl; + + +public abstract class SimpleTile extends TileModel { + + protected final TxSheet sheet; + + + public SimpleTile(int id, String sheetKey) + { + super(id); + this.sheet = Res.getTxSheet(sheetKey); + } + + + @Override + public void render(Tile tile, TileRenderContext context) + { + Render.quadTextured(context.getRect(), sheet.getRandomQuad(context.getTileNoise())); + } + + + @Override + @DefaultImpl + public boolean isWalkable(Tile tile) + { + return isPotentiallyWalkable(); + } + + + @Override + public abstract boolean isPotentiallyWalkable(); + +} diff --git a/src/mightypork/rogue/world/tile/models/Wall.java b/src/mightypork/rogue/world/tile/models/Wall.java new file mode 100644 index 0000000..3efd6d4 --- /dev/null +++ b/src/mightypork/rogue/world/tile/models/Wall.java @@ -0,0 +1,18 @@ +package mightypork.rogue.world.tile.models; + + +public class Wall extends SimpleTile { + + public Wall(int id, String sheetKey) + { + super(id, sheetKey); + } + + + @Override + public boolean isPotentiallyWalkable() + { + return false; + } + +} diff --git a/src/mightypork/test/FakeTile.java b/src/mightypork/test/FakeTile.java deleted file mode 100644 index 19ab7cd..0000000 --- a/src/mightypork/test/FakeTile.java +++ /dev/null @@ -1,84 +0,0 @@ -package mightypork.test; - - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import mightypork.rogue.world.tile.TileData; -import mightypork.rogue.world.tile.TileModel; -import mightypork.rogue.world.tile.TileRenderContext; -import mightypork.util.files.ion.Ion; - - -class FakeTileData extends TileData { - - int number; - String name; -} - - -public class FakeTile extends TileModel { - - public FakeTile(int id) { - super(id); - } - - - @Override - public boolean isWalkable() - { - return true; - } - - - @Override - public boolean isWalkable(TileData data) - { - return true; - } - - - @Override - public TileData createData() - { - return new FakeTileData() { - - { - number = 255; - name = "ABC"; - } - }; - } - - - @Override - public void load(TileData data, InputStream in) throws IOException - { - ((FakeTileData) data).name = Ion.readString(in); - ((FakeTileData) data).number = Ion.readInt(in); - } - - - @Override - public void save(TileData data, OutputStream out) throws IOException - { - Ion.writeString(out, ((FakeTileData) data).name); - Ion.writeInt(out, ((FakeTileData) data).number); - } - - - @Override - public void render(TileData data, TileRenderContext context) - { - // - } - - - @Override - public void update(TileData item, double delta) - { - // - } - -} diff --git a/src/mightypork/test/TestRandomSeed.java b/src/mightypork/test/TestRandomSeed.java index bbf762a..ff19311 100644 --- a/src/mightypork/test/TestRandomSeed.java +++ b/src/mightypork/test/TestRandomSeed.java @@ -10,8 +10,8 @@ public class TestRandomSeed { { { - Random rand = new Random(); - long begin = System.currentTimeMillis(); + final Random rand = new Random(); + final long begin = System.currentTimeMillis(); for (int i = 0; i < 1000000; i++) { rand.setSeed(1000); @@ -21,10 +21,10 @@ public class TestRandomSeed { } { - long begin = System.currentTimeMillis(); + final long begin = System.currentTimeMillis(); for (int i = 0; i < 1000000; i++) { - Random rand = new Random(); + final Random rand = new Random(); rand.setSeed(1000); } diff --git a/src/mightypork/test/TestTileMap.java b/src/mightypork/test/TestTileMap.java deleted file mode 100644 index 3caf54a..0000000 --- a/src/mightypork/test/TestTileMap.java +++ /dev/null @@ -1,46 +0,0 @@ -package mightypork.test; - - -import java.io.IOException; - -import mightypork.rogue.world.WorldMap; -import mightypork.rogue.world.item.Item; -import mightypork.rogue.world.tile.Tile; -import mightypork.rogue.world.tile.TileModel; -import mightypork.util.files.ion.Ion; - - -public class TestTileMap { - - public static void main(String[] args) throws IOException - { - - Ion.registerIonizable(WorldMap.ION_MARK, WorldMap.class); - Ion.registerIonizable(Tile.ION_MARK, Tile.class); - Ion.registerIonizable(Item.ION_MARK, Item.class); - - // register tile - final TileModel tm = new FakeTile(1); - -// -// WorldMap map = new WorldMap(10, 10); -// -// Random r = new Random(); -// -// for(int i=0; i<10; i++) { -// map.setTile(1, r.nextInt(10),r.nextInt(10)); -// } -// -// Ion.toFile("maptest.ion", map); - - final WorldMap map = (WorldMap) Ion.fromFile("maptest.ion"); - for (int y = 0; y < map.getHeight(); y++) { - for (int x = 0; x < map.getWidth(); x++) { - final Tile t = map.getTile(x, y); - System.out.print(" " + (t == null ? " " : ((FakeTileData) t.getData()).number)); - } - - System.out.println(); - } - } -} diff --git a/src/mightypork/util/annotations/DefaultImpl.java b/src/mightypork/util/annotations/DefaultImpl.java index 7d5ef30..a74072c 100644 --- a/src/mightypork/util/annotations/DefaultImpl.java +++ b/src/mightypork/util/annotations/DefaultImpl.java @@ -10,7 +10,8 @@ import java.lang.annotation.Target; /** * Marked method can be safely overriden; it's left blank (or with default - * implementation) as a convenience. + * implementation) as a convenience.
+ * This is a description annotation and has no other function. * * @author MightyPork */ diff --git a/src/mightypork/util/annotations/FactoryMethod.java b/src/mightypork/util/annotations/FactoryMethod.java index 250b7d0..604b27c 100644 --- a/src/mightypork/util/annotations/FactoryMethod.java +++ b/src/mightypork/util/annotations/FactoryMethod.java @@ -9,7 +9,8 @@ import java.lang.annotation.Target; /** - * Marks a static factory method + * Marks a static factory method. This is a description annotation and has no + * other function. * * @author MightyPork */ diff --git a/src/mightypork/util/config/PropertyManager.java b/src/mightypork/util/config/PropertyManager.java index fbf2f40..d84c6e1 100644 --- a/src/mightypork/util/config/PropertyManager.java +++ b/src/mightypork/util/config/PropertyManager.java @@ -33,7 +33,8 @@ public class PropertyManager { public T defaultValue; - public Property(String key, T defaultValue, String comment) { + public Property(String key, T defaultValue, String comment) + { super(); this.comment = comment; this.key = key; @@ -54,7 +55,8 @@ public class PropertyManager { private class BooleanProperty extends Property { - public BooleanProperty(String key, Boolean defaultValue, String comment) { + public BooleanProperty(String key, Boolean defaultValue, String comment) + { super(key, defaultValue, comment); } @@ -68,7 +70,8 @@ public class PropertyManager { private class IntegerProperty extends Property { - public IntegerProperty(String key, Integer defaultValue, String comment) { + public IntegerProperty(String key, Integer defaultValue, String comment) + { super(key, defaultValue, comment); } @@ -82,7 +85,8 @@ public class PropertyManager { private class DoubleProperty extends Property { - public DoubleProperty(String key, Double defaultValue, String comment) { + public DoubleProperty(String key, Double defaultValue, String comment) + { super(key, defaultValue, comment); } @@ -96,7 +100,8 @@ public class PropertyManager { private class StringProperty extends Property { - public StringProperty(String key, String defaultValue, String comment) { + public StringProperty(String key, String defaultValue, String comment) + { super(key, defaultValue, comment); } @@ -110,7 +115,8 @@ public class PropertyManager { private class RangeProperty extends Property { - public RangeProperty(String key, Range defaultValue, String comment) { + public RangeProperty(String key, Range defaultValue, String comment) + { super(key, defaultValue, comment); } @@ -124,7 +130,8 @@ public class PropertyManager { private class CoordProperty extends Property { - public CoordProperty(String key, Vect defaultValue, String comment) { + public CoordProperty(String key, Vect defaultValue, String comment) + { super(key, defaultValue, comment); } @@ -158,7 +165,8 @@ public class PropertyManager { * @param file file with the props * @param comment the initial comment. Use \n in it if you want. */ - public PropertyManager(File file, String comment) { + public PropertyManager(File file, String comment) + { this.file = file; this.entries = new TreeMap<>(); this.overrideValues = new TreeMap<>(); diff --git a/src/mightypork/util/constraints/num/NumConst.java b/src/mightypork/util/constraints/num/NumConst.java index 4209137..484fac3 100644 --- a/src/mightypork/util/constraints/num/NumConst.java +++ b/src/mightypork/util/constraints/num/NumConst.java @@ -17,12 +17,14 @@ public class NumConst extends Num { private NumDigest digest; - NumConst(Num copied) { + NumConst(Num copied) + { this.value = copied.value(); } - NumConst(double value) { + NumConst(double value) + { this.value = value; } diff --git a/src/mightypork/util/constraints/num/caching/AbstractNumCache.java b/src/mightypork/util/constraints/num/caching/AbstractNumCache.java index 0958bda..56494fd 100644 --- a/src/mightypork/util/constraints/num/caching/AbstractNumCache.java +++ b/src/mightypork/util/constraints/num/caching/AbstractNumCache.java @@ -25,7 +25,8 @@ public abstract class AbstractNumCache extends NumAdapter implements ConstraintC private boolean cachingEnabled = true; - public AbstractNumCache() { + public AbstractNumCache() + { enableDigestCaching(true); // it changes only on poll } diff --git a/src/mightypork/util/constraints/num/caching/NumCache.java b/src/mightypork/util/constraints/num/caching/NumCache.java index 0f1ea27..1ef6cde 100644 --- a/src/mightypork/util/constraints/num/caching/NumCache.java +++ b/src/mightypork/util/constraints/num/caching/NumCache.java @@ -15,7 +15,8 @@ public class NumCache extends AbstractNumCache { private final Num source; - public NumCache(Num source) { + public NumCache(Num source) + { this.source = source; } diff --git a/src/mightypork/util/constraints/num/caching/NumDigest.java b/src/mightypork/util/constraints/num/caching/NumDigest.java index 1b16ccd..cf513e3 100644 --- a/src/mightypork/util/constraints/num/caching/NumDigest.java +++ b/src/mightypork/util/constraints/num/caching/NumDigest.java @@ -9,7 +9,8 @@ public class NumDigest { public final double value; - public NumDigest(Num num) { + public NumDigest(Num num) + { this.value = num.value(); } diff --git a/src/mightypork/util/constraints/num/mutable/NumAnimated.java b/src/mightypork/util/constraints/num/mutable/NumAnimated.java index 47e3e03..a05688a 100644 --- a/src/mightypork/util/constraints/num/mutable/NumAnimated.java +++ b/src/mightypork/util/constraints/num/mutable/NumAnimated.java @@ -45,7 +45,8 @@ public class NumAnimated extends NumMutable implements Updateable, Pauseable { * * @param value initial value */ - public NumAnimated(double value) { + public NumAnimated(double value) + { setTo(value); } @@ -56,7 +57,8 @@ public class NumAnimated extends NumMutable implements Updateable, Pauseable { * @param value initial value * @param easing easing function */ - public NumAnimated(double value, Easing easing) { + public NumAnimated(double value, Easing easing) + { this(value); setEasing(easing); } @@ -69,7 +71,8 @@ public class NumAnimated extends NumMutable implements Updateable, Pauseable { * @param easingIn easing function (fade in) * @param easingOut easing function (fade out) */ - public NumAnimated(double value, Easing easingIn, Easing easingOut) { + public NumAnimated(double value, Easing easingIn, Easing easingOut) + { this(value); setEasing(easingIn, easingOut); } @@ -80,7 +83,8 @@ public class NumAnimated extends NumMutable implements Updateable, Pauseable { * * @param other other animator */ - public NumAnimated(NumAnimated other) { + public NumAnimated(NumAnimated other) + { setTo(other); } @@ -194,7 +198,7 @@ public class NumAnimated extends NumMutable implements Updateable, Pauseable { { if (paused || isFinished()) return; - elapsedTime = Calc.clampd(elapsedTime + delta, 0, duration); + elapsedTime = Calc.clamp(elapsedTime + delta, 0, duration); if (isFinished()) { duration = 0; elapsedTime = 0; diff --git a/src/mightypork/util/constraints/num/mutable/NumAnimatedDeg.java b/src/mightypork/util/constraints/num/mutable/NumAnimatedDeg.java index 8e144d3..7d0c9d4 100644 --- a/src/mightypork/util/constraints/num/mutable/NumAnimatedDeg.java +++ b/src/mightypork/util/constraints/num/mutable/NumAnimatedDeg.java @@ -13,17 +13,20 @@ import mightypork.util.math.Easing; */ public class NumAnimatedDeg extends NumAnimated { - public NumAnimatedDeg(NumAnimated other) { + public NumAnimatedDeg(NumAnimated other) + { super(other); } - public NumAnimatedDeg(double value) { + public NumAnimatedDeg(double value) + { super(value); } - public NumAnimatedDeg(double value, Easing easing) { + public NumAnimatedDeg(double value, Easing easing) + { super(value, easing); } diff --git a/src/mightypork/util/constraints/num/mutable/NumAnimatedRad.java b/src/mightypork/util/constraints/num/mutable/NumAnimatedRad.java index 02b19e5..e0079ff 100644 --- a/src/mightypork/util/constraints/num/mutable/NumAnimatedRad.java +++ b/src/mightypork/util/constraints/num/mutable/NumAnimatedRad.java @@ -13,17 +13,20 @@ import mightypork.util.math.Easing; */ public class NumAnimatedRad extends NumAnimated { - public NumAnimatedRad(NumAnimated other) { + public NumAnimatedRad(NumAnimated other) + { super(other); } - public NumAnimatedRad(double value) { + public NumAnimatedRad(double value) + { super(value); } - public NumAnimatedRad(double value, Easing easing) { + public NumAnimatedRad(double value, Easing easing) + { super(value, easing); } diff --git a/src/mightypork/util/constraints/num/mutable/NumVar.java b/src/mightypork/util/constraints/num/mutable/NumVar.java index 0d551b2..e239b28 100644 --- a/src/mightypork/util/constraints/num/mutable/NumVar.java +++ b/src/mightypork/util/constraints/num/mutable/NumVar.java @@ -14,12 +14,14 @@ public class NumVar extends NumMutable { private double value; - public NumVar(Num value) { + public NumVar(Num value) + { this(value.value()); } - public NumVar(double value) { + public NumVar(double value) + { this.value = value; } diff --git a/src/mightypork/util/constraints/num/proxy/NumBoundAdapter.java b/src/mightypork/util/constraints/num/proxy/NumBoundAdapter.java index 29158dc..07bb34e 100644 --- a/src/mightypork/util/constraints/num/proxy/NumBoundAdapter.java +++ b/src/mightypork/util/constraints/num/proxy/NumBoundAdapter.java @@ -9,11 +9,13 @@ public class NumBoundAdapter extends NumAdapter implements PluggableNumBound { private NumBound backing = null; - public NumBoundAdapter() { + public NumBoundAdapter() + { } - public NumBoundAdapter(NumBound bound) { + public NumBoundAdapter(NumBound bound) + { backing = bound; } diff --git a/src/mightypork/util/constraints/num/proxy/NumProxy.java b/src/mightypork/util/constraints/num/proxy/NumProxy.java index 7624d5a..f44d637 100644 --- a/src/mightypork/util/constraints/num/proxy/NumProxy.java +++ b/src/mightypork/util/constraints/num/proxy/NumProxy.java @@ -9,7 +9,8 @@ public class NumProxy extends NumAdapter { private final Num source; - public NumProxy(Num source) { + public NumProxy(Num source) + { this.source = source; } diff --git a/src/mightypork/util/constraints/rect/Rect.java b/src/mightypork/util/constraints/rect/Rect.java index 1b81f5a..42a4214 100644 --- a/src/mightypork/util/constraints/rect/Rect.java +++ b/src/mightypork/util/constraints/rect/Rect.java @@ -1,5 +1,6 @@ package mightypork.util.constraints.rect; + import mightypork.util.annotations.FactoryMethod; import mightypork.util.constraints.DigestCache; import mightypork.util.constraints.Digestable; @@ -952,7 +953,7 @@ public abstract class Rect implements RectBound, Digestable { return new TiledRect(this, 1, rows); } - + /** * Check for intersection * @@ -971,10 +972,10 @@ public abstract class Rect implements RectBound, Digestable { return false; } - double tx = this.origin().x(); - double ty = this.origin().y(); - double rx = other.origin().x(); - double ry = other.origin().y(); + final double tx = this.origin().x(); + final double ty = this.origin().y(); + final double rx = other.origin().x(); + final double ry = other.origin().y(); rw += rx; rh += ry; diff --git a/src/mightypork/util/constraints/rect/RectConst.java b/src/mightypork/util/constraints/rect/RectConst.java index b456cff..655ec84 100644 --- a/src/mightypork/util/constraints/rect/RectConst.java +++ b/src/mightypork/util/constraints/rect/RectConst.java @@ -46,7 +46,8 @@ public class RectConst extends Rect { * @param width * @param height */ - RectConst(double x, double y, double width, double height) { + RectConst(double x, double y, double width, double height) + { this.pos = Vect.make(x, y); this.size = Vect.make(width, height); } @@ -58,7 +59,8 @@ public class RectConst extends Rect { * @param origin * @param size */ - RectConst(Vect origin, Vect size) { + RectConst(Vect origin, Vect size) + { this.pos = origin.freeze(); this.size = size.freeze(); } @@ -69,7 +71,8 @@ public class RectConst extends Rect { * * @param another other coord */ - RectConst(Rect another) { + RectConst(Rect another) + { this.pos = another.origin().freeze(); this.size = another.size().freeze(); } diff --git a/src/mightypork/util/constraints/rect/builders/TiledRect.java b/src/mightypork/util/constraints/rect/builders/TiledRect.java index 0bebaab..e2523cd 100644 --- a/src/mightypork/util/constraints/rect/builders/TiledRect.java +++ b/src/mightypork/util/constraints/rect/builders/TiledRect.java @@ -20,7 +20,8 @@ public class TiledRect extends RectProxy { final private Num perCol; - public TiledRect(Rect source, int horizontal, int vertical) { + public TiledRect(Rect source, int horizontal, int vertical) + { super(source); this.tilesX = horizontal; this.tilesY = vertical; diff --git a/src/mightypork/util/constraints/rect/caching/AbstractRectCache.java b/src/mightypork/util/constraints/rect/caching/AbstractRectCache.java index 258f62f..6e88f05 100644 --- a/src/mightypork/util/constraints/rect/caching/AbstractRectCache.java +++ b/src/mightypork/util/constraints/rect/caching/AbstractRectCache.java @@ -25,7 +25,8 @@ public abstract class AbstractRectCache extends RectAdapter implements Constrain private boolean cachingEnabled = true; - public AbstractRectCache() { + public AbstractRectCache() + { enableDigestCaching(true); // it changes only on poll } diff --git a/src/mightypork/util/constraints/rect/caching/RectCache.java b/src/mightypork/util/constraints/rect/caching/RectCache.java index ccc015a..32f6c96 100644 --- a/src/mightypork/util/constraints/rect/caching/RectCache.java +++ b/src/mightypork/util/constraints/rect/caching/RectCache.java @@ -15,7 +15,8 @@ public class RectCache extends AbstractRectCache { private final Rect source; - public RectCache(Rect source) { + public RectCache(Rect source) + { this.source = source; } diff --git a/src/mightypork/util/constraints/rect/caching/RectDigest.java b/src/mightypork/util/constraints/rect/caching/RectDigest.java index 4ab1a79..fe372bb 100644 --- a/src/mightypork/util/constraints/rect/caching/RectDigest.java +++ b/src/mightypork/util/constraints/rect/caching/RectDigest.java @@ -18,7 +18,8 @@ public class RectDigest { public final double bottom; - public RectDigest(Rect rect) { + public RectDigest(Rect rect) + { final RectConst frozen = rect.freeze(); diff --git a/src/mightypork/util/constraints/rect/mutable/RectVar.java b/src/mightypork/util/constraints/rect/mutable/RectVar.java index 407147d..9233b07 100644 --- a/src/mightypork/util/constraints/rect/mutable/RectVar.java +++ b/src/mightypork/util/constraints/rect/mutable/RectVar.java @@ -19,7 +19,8 @@ public class RectVar extends RectMutable { * @param width * @param height */ - public RectVar(double x, double y, double width, double height) { + public RectVar(double x, double y, double width, double height) + { this.pos.setTo(x, y); this.size.setTo(width, height); } diff --git a/src/mightypork/util/constraints/rect/proxy/RectBoundAdapter.java b/src/mightypork/util/constraints/rect/proxy/RectBoundAdapter.java index 716bf4e..20e0429 100644 --- a/src/mightypork/util/constraints/rect/proxy/RectBoundAdapter.java +++ b/src/mightypork/util/constraints/rect/proxy/RectBoundAdapter.java @@ -14,11 +14,13 @@ public class RectBoundAdapter extends RectAdapter implements PluggableRectBound private RectBound backing = null; - public RectBoundAdapter() { + public RectBoundAdapter() + { } - public RectBoundAdapter(RectBound bound) { + public RectBoundAdapter(RectBound bound) + { backing = bound; } diff --git a/src/mightypork/util/constraints/rect/proxy/RectProxy.java b/src/mightypork/util/constraints/rect/proxy/RectProxy.java index fdd92dd..88c4e6b 100644 --- a/src/mightypork/util/constraints/rect/proxy/RectProxy.java +++ b/src/mightypork/util/constraints/rect/proxy/RectProxy.java @@ -9,7 +9,8 @@ public class RectProxy extends RectAdapter { private final Rect source; - public RectProxy(Rect source) { + public RectProxy(Rect source) + { this.source = source; } diff --git a/src/mightypork/util/constraints/rect/proxy/RectVectAdapter.java b/src/mightypork/util/constraints/rect/proxy/RectVectAdapter.java index 5ad183e..d835106 100644 --- a/src/mightypork/util/constraints/rect/proxy/RectVectAdapter.java +++ b/src/mightypork/util/constraints/rect/proxy/RectVectAdapter.java @@ -16,7 +16,8 @@ public class RectVectAdapter extends Rect { private final Vect size; - public RectVectAdapter(Vect origin, Vect size) { + public RectVectAdapter(Vect origin, Vect size) + { this.origin = origin; this.size = size; } diff --git a/src/mightypork/util/constraints/vect/VectConst.java b/src/mightypork/util/constraints/vect/VectConst.java index 58927dc..f041dba 100644 --- a/src/mightypork/util/constraints/vect/VectConst.java +++ b/src/mightypork/util/constraints/vect/VectConst.java @@ -32,12 +32,14 @@ public final class VectConst extends Vect { private VectDigest digest; - VectConst(Vect other) { + VectConst(Vect other) + { this(other.x(), other.y(), other.z()); } - VectConst(double x, double y, double z) { + VectConst(double x, double y, double z) + { this.x = x; this.y = y; this.z = z; diff --git a/src/mightypork/util/constraints/vect/VectProxy.java b/src/mightypork/util/constraints/vect/VectProxy.java index 4b3a529..0211d36 100644 --- a/src/mightypork/util/constraints/vect/VectProxy.java +++ b/src/mightypork/util/constraints/vect/VectProxy.java @@ -9,7 +9,8 @@ public class VectProxy extends VectAdapter { private final Vect source; - public VectProxy(Vect source) { + public VectProxy(Vect source) + { this.source = source; } diff --git a/src/mightypork/util/constraints/vect/caching/AbstractVectCache.java b/src/mightypork/util/constraints/vect/caching/AbstractVectCache.java index 6e93d3f..ceba706 100644 --- a/src/mightypork/util/constraints/vect/caching/AbstractVectCache.java +++ b/src/mightypork/util/constraints/vect/caching/AbstractVectCache.java @@ -25,7 +25,8 @@ public abstract class AbstractVectCache extends VectAdapter implements Constrain private boolean cachingEnabled = true; - public AbstractVectCache() { + public AbstractVectCache() + { enableDigestCaching(true); // it changes only on poll } diff --git a/src/mightypork/util/constraints/vect/caching/VectCache.java b/src/mightypork/util/constraints/vect/caching/VectCache.java index 5fb3977..482c98c 100644 --- a/src/mightypork/util/constraints/vect/caching/VectCache.java +++ b/src/mightypork/util/constraints/vect/caching/VectCache.java @@ -15,7 +15,8 @@ public class VectCache extends AbstractVectCache { private final Vect source; - public VectCache(Vect source) { + public VectCache(Vect source) + { this.source = source; enableDigestCaching(true); } diff --git a/src/mightypork/util/constraints/vect/caching/VectDigest.java b/src/mightypork/util/constraints/vect/caching/VectDigest.java index e56af0d..2350112 100644 --- a/src/mightypork/util/constraints/vect/caching/VectDigest.java +++ b/src/mightypork/util/constraints/vect/caching/VectDigest.java @@ -11,7 +11,8 @@ public class VectDigest { public final double z; - public VectDigest(Vect vect) { + public VectDigest(Vect vect) + { this.x = vect.x(); this.y = vect.y(); this.z = vect.z(); diff --git a/src/mightypork/util/constraints/vect/mutable/VectAnimated.java b/src/mightypork/util/constraints/vect/mutable/VectAnimated.java index f05e7e1..0fa6166 100644 --- a/src/mightypork/util/constraints/vect/mutable/VectAnimated.java +++ b/src/mightypork/util/constraints/vect/mutable/VectAnimated.java @@ -28,7 +28,8 @@ public class VectAnimated extends VectMutable implements Pauseable, Updateable { * @param y y animator * @param z z animator */ - public VectAnimated(NumAnimated x, NumAnimated y, NumAnimated z) { + public VectAnimated(NumAnimated x, NumAnimated y, NumAnimated z) + { this.x = x; this.y = y; this.z = z; @@ -41,7 +42,8 @@ public class VectAnimated extends VectMutable implements Pauseable, Updateable { * @param start initial positioon * @param easing animation easing */ - public VectAnimated(Vect start, Easing easing) { + public VectAnimated(Vect start, Easing easing) + { x = new NumAnimated(start.x(), easing); y = new NumAnimated(start.y(), easing); z = new NumAnimated(start.z(), easing); diff --git a/src/mightypork/util/constraints/vect/mutable/VectVar.java b/src/mightypork/util/constraints/vect/mutable/VectVar.java index ded546c..42ed563 100644 --- a/src/mightypork/util/constraints/vect/mutable/VectVar.java +++ b/src/mightypork/util/constraints/vect/mutable/VectVar.java @@ -17,7 +17,8 @@ public class VectVar extends VectMutable { * @param y Y coordinate * @param z Z coordinate */ - public VectVar(double x, double y, double z) { + public VectVar(double x, double y, double z) + { super(); this.x = x; this.y = y; diff --git a/src/mightypork/util/constraints/vect/proxy/VectBoundAdapter.java b/src/mightypork/util/constraints/vect/proxy/VectBoundAdapter.java index 9cf8d4e..2a4d39d 100644 --- a/src/mightypork/util/constraints/vect/proxy/VectBoundAdapter.java +++ b/src/mightypork/util/constraints/vect/proxy/VectBoundAdapter.java @@ -9,11 +9,13 @@ public class VectBoundAdapter extends VectAdapter implements PluggableVectBound private VectBound backing = null; - public VectBoundAdapter() { + public VectBoundAdapter() + { } - public VectBoundAdapter(VectBound bound) { + public VectBoundAdapter(VectBound bound) + { backing = bound; } diff --git a/src/mightypork/util/constraints/vect/proxy/VectNumAdapter.java b/src/mightypork/util/constraints/vect/proxy/VectNumAdapter.java index 35b9269..036574e 100644 --- a/src/mightypork/util/constraints/vect/proxy/VectNumAdapter.java +++ b/src/mightypork/util/constraints/vect/proxy/VectNumAdapter.java @@ -18,14 +18,16 @@ public class VectNumAdapter extends Vect { private final Num constrZ; - public VectNumAdapter(Num x, Num y, Num z) { + public VectNumAdapter(Num x, Num y, Num z) + { this.constrX = x; this.constrY = y; this.constrZ = z; } - public VectNumAdapter(Num x, Num y) { + public VectNumAdapter(Num x, Num y) + { this.constrX = x; this.constrY = y; this.constrZ = Num.ZERO; diff --git a/src/mightypork/util/control/eventbus/BufferedHashSet.java b/src/mightypork/util/control/eventbus/BufferedHashSet.java index cfc4f88..ef0d167 100644 --- a/src/mightypork/util/control/eventbus/BufferedHashSet.java +++ b/src/mightypork/util/control/eventbus/BufferedHashSet.java @@ -24,7 +24,8 @@ public class BufferedHashSet extends HashSet { /** * make empty */ - public BufferedHashSet() { + public BufferedHashSet() + { super(); } @@ -34,7 +35,8 @@ public class BufferedHashSet extends HashSet { * * @param c */ - public BufferedHashSet(Collection c) { + public BufferedHashSet(Collection c) + { super(c); } @@ -45,7 +47,8 @@ public class BufferedHashSet extends HashSet { * @param initialCapacity * @param loadFactor */ - public BufferedHashSet(int initialCapacity, float loadFactor) { + public BufferedHashSet(int initialCapacity, float loadFactor) + { super(initialCapacity, loadFactor); } @@ -55,7 +58,8 @@ public class BufferedHashSet extends HashSet { * * @param initialCapacity */ - public BufferedHashSet(int initialCapacity) { + public BufferedHashSet(int initialCapacity) + { super(initialCapacity); } diff --git a/src/mightypork/util/control/eventbus/EventBus.java b/src/mightypork/util/control/eventbus/EventBus.java index fbb97af..aee4b79 100644 --- a/src/mightypork/util/control/eventbus/EventBus.java +++ b/src/mightypork/util/control/eventbus/EventBus.java @@ -35,7 +35,8 @@ final public class EventBus implements Destroyable { private final Event evt; - public DelayQueueEntry(double seconds, Event event) { + public DelayQueueEntry(double seconds, Event event) + { super(); this.due = System.currentTimeMillis() + (long) (seconds * 1000); this.evt = event; @@ -71,7 +72,8 @@ final public class EventBus implements Destroyable { public volatile boolean stopped = false; - public QueuePollingThread() { + public QueuePollingThread() + { super("Queue Polling Thread"); } @@ -141,7 +143,8 @@ final public class EventBus implements Destroyable { /** * Make a new bus and start it's queue thread. */ - public EventBus() { + public EventBus() + { busThread = new QueuePollingThread(); busThread.setDaemon(true); busThread.start(); diff --git a/src/mightypork/util/control/eventbus/EventChannel.java b/src/mightypork/util/control/eventbus/EventChannel.java index a7c29aa..481d105 100644 --- a/src/mightypork/util/control/eventbus/EventChannel.java +++ b/src/mightypork/util/control/eventbus/EventChannel.java @@ -30,7 +30,8 @@ class EventChannel, CLIENT> { * @param eventClass event class * @param clientClass client class */ - public EventChannel(Class eventClass, Class clientClass) { + public EventChannel(Class eventClass, Class clientClass) + { if (eventClass == null || clientClass == null) { throw new NullPointerException("Null Event or Client class."); diff --git a/src/mightypork/util/control/eventbus/clients/BusNode.java b/src/mightypork/util/control/eventbus/clients/BusNode.java index 52d79f5..fa90ba8 100644 --- a/src/mightypork/util/control/eventbus/clients/BusNode.java +++ b/src/mightypork/util/control/eventbus/clients/BusNode.java @@ -27,7 +27,8 @@ public abstract class BusNode implements BusAccess, ClientHub { /** * @param busAccess access to bus */ - public BusNode(BusAccess busAccess) { + public BusNode(BusAccess busAccess) + { this.busAccess = busAccess; } diff --git a/src/mightypork/util/control/eventbus/clients/RootBusNode.java b/src/mightypork/util/control/eventbus/clients/RootBusNode.java index a02d4b6..67ab46f 100644 --- a/src/mightypork/util/control/eventbus/clients/RootBusNode.java +++ b/src/mightypork/util/control/eventbus/clients/RootBusNode.java @@ -15,7 +15,8 @@ public abstract class RootBusNode extends BusNode implements Destroyable { /** * @param busAccess access to bus */ - public RootBusNode(BusAccess busAccess) { + public RootBusNode(BusAccess busAccess) + { super(busAccess); getEventBus().subscribe(this); diff --git a/src/mightypork/util/control/timing/Animator.java b/src/mightypork/util/control/timing/Animator.java new file mode 100644 index 0000000..765304f --- /dev/null +++ b/src/mightypork/util/control/timing/Animator.java @@ -0,0 +1,94 @@ +package mightypork.util.control.timing; + + +import mightypork.util.annotations.DefaultImpl; +import mightypork.util.constraints.num.Num; +import mightypork.util.constraints.num.mutable.NumAnimated; +import mightypork.util.constraints.num.proxy.NumBound; +import mightypork.util.math.Easing; + + +public abstract class Animator implements Updateable, Pauseable, NumBound { + + private final NumAnimated animator; + private final Num num; + + + public Animator(double period) + { + this(0, 1, period, Easing.LINEAR); + } + + + public Animator(double start, double end, double period) + { + this(start, end, period, Easing.LINEAR); + } + + + public Animator(double period, Easing easing) + { + this(0, 1, period, easing); + } + + + public Animator(double start, double end, double period, Easing easing) + { + animator = new NumAnimated(0, easing); + animator.setDefaultDuration(period); + + this.num = animator.mul(end - start).add(start); + } + + + @Override + public final void pause() + { + animator.pause(); + } + + + @Override + public final void resume() + { + animator.resume(); + } + + + @Override + public final boolean isPaused() + { + return animator.isPaused(); + } + + + public final void reset() + { + animator.reset(); + } + + + @Override + public final void update(double delta) + { + animator.update(delta); + if (animator.isFinished()) nextCycle(animator); + } + + + @DefaultImpl + protected abstract void nextCycle(NumAnimated anim); + + + @Override + public final Num getNum() + { + return num; + } + + + public final double value() + { + return num.value(); + } +} diff --git a/src/mightypork/util/control/timing/AnimatorBounce.java b/src/mightypork/util/control/timing/AnimatorBounce.java new file mode 100644 index 0000000..ed6eb7a --- /dev/null +++ b/src/mightypork/util/control/timing/AnimatorBounce.java @@ -0,0 +1,52 @@ +package mightypork.util.control.timing; + + +import mightypork.util.constraints.num.mutable.NumAnimated; +import mightypork.util.math.Easing; + + +/** + * Animator that upon reaching max, animates back down and then up again + * + * @author MightyPork + */ +public class AnimatorBounce extends Animator { + + private final boolean wasUp = false; + + + public AnimatorBounce(double start, double end, double period, Easing easing) + { + super(start, end, period, easing); + } + + + public AnimatorBounce(double start, double end, double period) + { + super(start, end, period); + } + + + public AnimatorBounce(double period, Easing easing) + { + super(period, easing); + } + + + public AnimatorBounce(double period) + { + super(period); + } + + + @Override + protected void nextCycle(NumAnimated anim) + { + if (wasUp) { + anim.fadeOut(); + } else { + anim.fadeIn(); + } + } + +} diff --git a/src/mightypork/util/control/timing/AnimatorRewind.java b/src/mightypork/util/control/timing/AnimatorRewind.java new file mode 100644 index 0000000..fa5a6b3 --- /dev/null +++ b/src/mightypork/util/control/timing/AnimatorRewind.java @@ -0,0 +1,47 @@ +package mightypork.util.control.timing; + + +import mightypork.util.constraints.num.mutable.NumAnimated; +import mightypork.util.math.Easing; + + +/** + * Animator that upon reaching top, jumps straight to zero and continues another + * cycle. + * + * @author MightyPork + */ +public class AnimatorRewind extends Animator { + + public AnimatorRewind(double start, double end, double period, Easing easing) + { + super(start, end, period, easing); + } + + + public AnimatorRewind(double start, double end, double period) + { + super(start, end, period); + } + + + public AnimatorRewind(double period, Easing easing) + { + super(period, easing); + } + + + public AnimatorRewind(double period) + { + super(period); + } + + + @Override + protected void nextCycle(NumAnimated anim) + { + anim.reset(); + anim.fadeIn(); + } + +} diff --git a/src/mightypork/util/control/timing/TimerDelta.java b/src/mightypork/util/control/timing/TimerDelta.java index acc96e7..f7f3225 100644 --- a/src/mightypork/util/control/timing/TimerDelta.java +++ b/src/mightypork/util/control/timing/TimerDelta.java @@ -16,7 +16,8 @@ public class TimerDelta { /** * New delta timer */ - public TimerDelta() { + public TimerDelta() + { lastFrame = System.nanoTime(); } diff --git a/src/mightypork/util/control/timing/TimerFps.java b/src/mightypork/util/control/timing/TimerFps.java index a699585..5e30d42 100644 --- a/src/mightypork/util/control/timing/TimerFps.java +++ b/src/mightypork/util/control/timing/TimerFps.java @@ -22,7 +22,8 @@ public class TimerFps { * * @param fps target FPS */ - public TimerFps(long fps) { + public TimerFps(long fps) + { FRAME = Math.round(SECOND / (double) fps); lastFrame = System.nanoTime(); diff --git a/src/mightypork/util/error/KeyAlreadyExistsException.java b/src/mightypork/util/error/KeyAlreadyExistsException.java index dc432c4..43536cd 100644 --- a/src/mightypork/util/error/KeyAlreadyExistsException.java +++ b/src/mightypork/util/error/KeyAlreadyExistsException.java @@ -2,20 +2,27 @@ package mightypork.util.error; public class KeyAlreadyExistsException extends RuntimeException { - - public KeyAlreadyExistsException() { + + public KeyAlreadyExistsException() + { super(); } - - public KeyAlreadyExistsException(String message, Throwable cause) { + + + public KeyAlreadyExistsException(String message, Throwable cause) + { super(message, cause); } - - public KeyAlreadyExistsException(String message) { + + + public KeyAlreadyExistsException(String message) + { super(message); } - - public KeyAlreadyExistsException(Throwable cause) { + + + public KeyAlreadyExistsException(Throwable cause) + { super(cause); } diff --git a/src/mightypork/util/files/FileTreeDiff.java b/src/mightypork/util/files/FileTreeDiff.java index 44cec84..d65682e 100644 --- a/src/mightypork/util/files/FileTreeDiff.java +++ b/src/mightypork/util/files/FileTreeDiff.java @@ -130,7 +130,8 @@ public class FileTreeDiff { private class NotEqualException extends Exception { - public NotEqualException(String msg) { + public NotEqualException(String msg) + { super(msg); } @@ -142,7 +143,8 @@ public class FileTreeDiff { public T b; - public Tuple(T a, T b) { + public Tuple(T a, T b) + { this.a = a; this.b = b; } diff --git a/src/mightypork/util/files/ion/Ion.java b/src/mightypork/util/files/ion/Ion.java index 4cd9a58..b667b93 100644 --- a/src/mightypork/util/files/ion/Ion.java +++ b/src/mightypork/util/files/ion/Ion.java @@ -3,8 +3,8 @@ package mightypork.util.files.ion; import java.io.*; import java.nio.ByteBuffer; -import java.util.HashMap; -import java.util.Map; +import java.util.*; +import java.util.Map.Entry; import mightypork.util.logging.Log; @@ -108,8 +108,7 @@ public class Ion { static { markRangeChecking = false; - registerIonizable(DATA_BUNDLE, IonDataBundle.class); - registerIonizable(DATA_LIST, IonDataList.class); + registerIonizable(DATA_BUNDLE, IonBundle.class); markRangeChecking = true; } @@ -248,131 +247,130 @@ public class Ion { */ public static Object readObject(InputStream in) throws IOException { - try { - final short mark = readMark(in); - if (customIonizables.containsKey(mark)) { - Ionizable ionObj; + final short mark = readMark(in); + if (customIonizables.containsKey(mark)) { + Ionizable loaded; + + try { - try { - ionObj = ((Ionizable) customIonizables.get(mark).newInstance()); - } catch (InstantiationException | IllegalAccessException e) { - throw new IOException("Cound not instantiate: " + Log.str(customIonizables.get(mark)), e); - } + final Class clz = customIonizables.get(mark); + loaded = ((Ionizable) clz.newInstance()); - ionObj.loadFrom(in); - return ionObj; + } catch (InstantiationException | IllegalAccessException e) { + throw new IOException("Cound not instantiate: " + Log.str(customIonizables.get(mark)), e); } - int length; - - switch (mark) { - case NULL: - return null; - - case BOOLEAN: - return readBoolean(in); - - case BYTE: - return readByte(in); - - case CHAR: - return readChar(in); - - case SHORT: - return readShort(in); - - case INT: - return readInt(in); - - case LONG: - return readLong(in); - - case FLOAT: - return readFloat(in); - - case DOUBLE: - return readDouble(in); - - case STRING: - return readString(in); - - case BOOLEAN_ARRAY: - length = readInt(in); - final boolean[] bools = new boolean[length]; - for (int i = 0; i < length; i++) { - bools[i] = readBoolean(in); - } - return bools; - - case BYTE_ARRAY: - length = readInt(in); - final byte[] bytes = new byte[length]; - for (int i = 0; i < length; i++) { - bytes[i] = readByte(in); - } - return bytes; - - case CHAR_ARRAY: - length = readInt(in); - final char[] chars = new char[length]; - for (int i = 0; i < length; i++) { - chars[i] = readChar(in); - } - return chars; - - case SHORT_ARRAY: - length = readInt(in); - final short[] shorts = new short[length]; - for (int i = 0; i < length; i++) { - shorts[i] = readShort(in); - } - return shorts; - - case INT_ARRAY: - length = readInt(in); - final int[] ints = new int[length]; - for (int i = 0; i < length; i++) { - ints[i] = readInt(in); - } - return ints; - - case LONG_ARRAY: - length = readInt(in); - final long[] longs = new long[length]; - for (int i = 0; i < length; i++) { - longs[i] = readLong(in); - } - return longs; - - case FLOAT_ARRAY: - length = readInt(in); - final float[] floats = new float[length]; - for (int i = 0; i < length; i++) { - floats[i] = readFloat(in); - } - return floats; - - case DOUBLE_ARRAY: - length = readInt(in); - final double[] doubles = new double[length]; - for (int i = 0; i < length; i++) { - doubles[i] = readDouble(in); - } - return doubles; - - case STRING_ARRAY: - length = readInt(in); - final String[] Strings = new String[length]; - for (int i = 0; i < length; i++) { - Strings[i] = readString(in); - } - return Strings; - - default: - throw new IOException("Invalid Ion mark: " + mark); - } - } catch (final IOException e) { - throw new IOException("Error loading ION file: ", e); + loaded.load(in); + return loaded; + } + + int length; + + switch (mark) { + case NULL: + return null; + + case BOOLEAN: + return readBoolean(in); + + case BYTE: + return readByte(in); + + case CHAR: + return readChar(in); + + case SHORT: + return readShort(in); + + case INT: + return readInt(in); + + case LONG: + return readLong(in); + + case FLOAT: + return readFloat(in); + + case DOUBLE: + return readDouble(in); + + case STRING: + return readString(in); + + case BOOLEAN_ARRAY: + length = readInt(in); + final boolean[] bools = new boolean[length]; + for (int i = 0; i < length; i++) { + bools[i] = readBoolean(in); + } + return bools; + + case BYTE_ARRAY: + length = readInt(in); + final byte[] bytes = new byte[length]; + for (int i = 0; i < length; i++) { + bytes[i] = readByte(in); + } + return bytes; + + case CHAR_ARRAY: + length = readInt(in); + final char[] chars = new char[length]; + for (int i = 0; i < length; i++) { + chars[i] = readChar(in); + } + return chars; + + case SHORT_ARRAY: + length = readInt(in); + final short[] shorts = new short[length]; + for (int i = 0; i < length; i++) { + shorts[i] = readShort(in); + } + return shorts; + + case INT_ARRAY: + length = readInt(in); + final int[] ints = new int[length]; + for (int i = 0; i < length; i++) { + ints[i] = readInt(in); + } + return ints; + + case LONG_ARRAY: + length = readInt(in); + final long[] longs = new long[length]; + for (int i = 0; i < length; i++) { + longs[i] = readLong(in); + } + return longs; + + case FLOAT_ARRAY: + length = readInt(in); + final float[] floats = new float[length]; + for (int i = 0; i < length; i++) { + floats[i] = readFloat(in); + } + return floats; + + case DOUBLE_ARRAY: + length = readInt(in); + final double[] doubles = new double[length]; + for (int i = 0; i < length; i++) { + doubles[i] = readDouble(in); + } + return doubles; + + case STRING_ARRAY: + length = readInt(in); + final String[] Strings = new String[length]; + for (int i = 0; i < length; i++) { + Strings[i] = readString(in); + } + return Strings; + + default: + throw new IOException("Invalid Ion mark: " + mark); } } @@ -404,126 +402,121 @@ public class Ion { */ public static void writeObject(OutputStream out, Object obj) throws IOException { - try { - if (obj instanceof Ionizable) { - writeMark(out, ((Ionizable) obj).getIonMark()); - ((Ionizable) obj).saveTo(out); - return; - } - - if (obj instanceof Boolean) { - writeMark(out, BOOLEAN); - writeBoolean(out, (Boolean) obj); - return; - } - - if (obj instanceof Byte) { - writeMark(out, BYTE); - writeByte(out, (Byte) obj); - return; - } - - if (obj instanceof Character) { - writeMark(out, CHAR); - writeChar(out, (Character) obj); - return; - } - - if (obj instanceof Short) { - writeMark(out, SHORT); - writeShort(out, (Short) obj); - return; - } - - if (obj instanceof Integer) { - writeMark(out, INT); - writeInt(out, (Integer) obj); - return; - } - - if (obj instanceof Long) { - writeMark(out, LONG); - writeLong(out, (Long) obj); - return; - } - - if (obj instanceof Float) { - writeMark(out, FLOAT); - writeFloat(out, (Float) obj); - return; - } - - if (obj instanceof Double) { - writeMark(out, DOUBLE); - writeDouble(out, (Double) obj); - return; - } - - if (obj instanceof String) { - writeMark(out, STRING); - writeString(out, (String) obj); - return; - } - - if (obj instanceof boolean[]) { - writeMark(out, BOOLEAN_ARRAY); - writeBooleanArray(out, (boolean[]) obj); - return; - } - - if (obj instanceof byte[]) { - writeMark(out, BYTE_ARRAY); - writeByteArray(out, (byte[]) obj); - return; - } - - if (obj instanceof char[]) { - writeMark(out, CHAR_ARRAY); - writeCharArray(out, (char[]) obj); - return; - } - - if (obj instanceof short[]) { - writeMark(out, SHORT_ARRAY); - writeShortArray(out, (short[]) obj); - return; - } - - if (obj instanceof int[]) { - writeMark(out, INT_ARRAY); - writeIntArray(out, (int[]) obj); - return; - } - - if (obj instanceof long[]) { - writeMark(out, LONG_ARRAY); - writeLongArray(out, (long[]) obj); - return; - } - - if (obj instanceof float[]) { - writeMark(out, FLOAT_ARRAY); - writeFloatArray(out, (float[]) obj); - return; - } - - if (obj instanceof double[]) { - writeMark(out, DOUBLE_ARRAY); - writeDoubleArray(out, (double[]) obj); - return; - } - - if (obj instanceof String[]) { - writeMark(out, STRING_ARRAY); - writeStringArray(out, (String[]) obj); - return; - } - - throw new IOException("Object " + Log.str(obj) + " could not be be ionized."); - - } catch (final IOException e) { - throw new IOException("Could not store: " + obj, e); + if (obj instanceof Ionizable) { + writeMark(out, ((Ionizable) obj).getIonMark()); + ((Ionizable) obj).save(out); + return; + } + + if (obj instanceof Boolean) { + writeMark(out, BOOLEAN); + writeBoolean(out, (Boolean) obj); + return; + } + + if (obj instanceof Byte) { + writeMark(out, BYTE); + writeByte(out, (Byte) obj); + return; + } + + if (obj instanceof Character) { + writeMark(out, CHAR); + writeChar(out, (Character) obj); + return; + } + + if (obj instanceof Short) { + writeMark(out, SHORT); + writeShort(out, (Short) obj); + return; + } + + if (obj instanceof Integer) { + writeMark(out, INT); + writeInt(out, (Integer) obj); + return; + } + + if (obj instanceof Long) { + writeMark(out, LONG); + writeLong(out, (Long) obj); + return; + } + + if (obj instanceof Float) { + writeMark(out, FLOAT); + writeFloat(out, (Float) obj); + return; + } + + if (obj instanceof Double) { + writeMark(out, DOUBLE); + writeDouble(out, (Double) obj); + return; } + + if (obj instanceof String) { + writeMark(out, STRING); + writeString(out, (String) obj); + return; + } + + if (obj instanceof boolean[]) { + writeMark(out, BOOLEAN_ARRAY); + writeBooleanArray(out, (boolean[]) obj); + return; + } + + if (obj instanceof byte[]) { + writeMark(out, BYTE_ARRAY); + writeByteArray(out, (byte[]) obj); + return; + } + + if (obj instanceof char[]) { + writeMark(out, CHAR_ARRAY); + writeCharArray(out, (char[]) obj); + return; + } + + if (obj instanceof short[]) { + writeMark(out, SHORT_ARRAY); + writeShortArray(out, (short[]) obj); + return; + } + + if (obj instanceof int[]) { + writeMark(out, INT_ARRAY); + writeIntArray(out, (int[]) obj); + return; + } + + if (obj instanceof long[]) { + writeMark(out, LONG_ARRAY); + writeLongArray(out, (long[]) obj); + return; + } + + if (obj instanceof float[]) { + writeMark(out, FLOAT_ARRAY); + writeFloatArray(out, (float[]) obj); + return; + } + + if (obj instanceof double[]) { + writeMark(out, DOUBLE_ARRAY); + writeDoubleArray(out, (double[]) obj); + return; + } + + if (obj instanceof String[]) { + writeMark(out, STRING_ARRAY); + writeStringArray(out, (String[]) obj); + return; + } + + throw new IOException("Object " + Log.str(obj) + " could not be be ionized."); } @@ -1164,4 +1157,130 @@ public class Ion { return Strings; } + + /** + * Reads mark and returns true if the mark is ENTRY, false if the mark is + * END. Throws an exception otherwise. + * + * @param in input stream + * @return mark was ENTRY + * @throws IOException when the mark is neither ENTRY or END. + */ + public static boolean hasNextEntry(InputStream in) throws IOException + { + final short mark = readMark(in); + if (mark == ENTRY) return true; + if (mark == END) return false; + + throw new IOException("Unexpected mark encountered while reading sequence."); + } + + + /** + * Read a sequence of elements + * + * @param in input stream + * @return the collection + * @throws IOException + */ + public static Collection readSequence(InputStream in) throws IOException + { + return readSequence(in, new LinkedList()); + } + + + /** + * Load entries into a collection + * + * @param in input stream + * @param filled collection to populate + * @return the collection + * @throws IOException + */ + @SuppressWarnings("unchecked") + public static Collection readSequence(InputStream in, Collection filled) throws IOException + { + try { + while (hasNextEntry(in)) { + filled.add((T) readObject(in)); + } + return filled; + } catch (final ClassCastException e) { + throw new IOException("Unexpected element type."); + } + } + + + /** + * Write collection entries to a stream + * + * @param out output stream + * @param sequence written collection + * @throws IOException + */ + public static void writeSequence(OutputStream out, Collection sequence) throws IOException + { + for (final T element : sequence) { + writeMark(out, ENTRY); + writeObject(out, element); + } + writeMark(out, END); + } + + + /** + * Read a map of elements + * + * @param in input stream + * @return the map + * @throws IOException + */ + public static Map readMap(InputStream in) throws IOException + { + return readMap(in, new LinkedHashMap()); + } + + + /** + * Load data into a map + * + * @param in input stream + * @param filled filled map + * @return the map + * @throws IOException + */ + @SuppressWarnings("unchecked") + public static Map readMap(InputStream in, Map filled) throws IOException + { + try { + while (hasNextEntry(in)) { + final K key = (K) readObject(in); + final V value = (V) readObject(in); + + filled.put(key, value); + } + return filled; + } catch (final ClassCastException e) { + throw new IOException("Unexpected element type."); + } + } + + + /** + * Write a map + * + * @param out output stream + * @param map map to write + * @throws IOException + */ + public static void writeMap(OutputStream out, Map map) throws IOException + { + for (final Entry e : map.entrySet()) { + writeMark(out, ENTRY); + writeObject(out, e.getKey()); + writeObject(out, e.getValue()); + } + writeMark(out, END); + } + } diff --git a/src/mightypork/util/files/ion/IonBundle.java b/src/mightypork/util/files/ion/IonBundle.java new file mode 100644 index 0000000..95c3ff0 --- /dev/null +++ b/src/mightypork/util/files/ion/IonBundle.java @@ -0,0 +1,69 @@ +package mightypork.util.files.ion; + + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.LinkedHashMap; + + +/** + * Data bundle. + * + * @author MightyPork + */ +public class IonBundle extends LinkedHashMap implements Ionizable { + + /** + * Get an object. If not found, fallback is returned. + * + * @param key key + * @param fallback fallback + * @return element + */ + public T get(String key, T fallback) + { + try { + final T itm = (T) super.get(key); + if (itm == null) return fallback; + return itm; + } catch (final ClassCastException e) { + return fallback; + } + } + + + /** + * Store an element. It's allowed to store any object, but only primitive + * types, String, their arrays, and Ionizable objects can be successfully + * stored to stream.. + */ + @Override + public Object put(String key, Object value) + { + return super.put(key, value); + } + + + @Override + public short getIonMark() + { + return Ion.DATA_BUNDLE; + } + + + @Override + public void load(InputStream in) throws IOException + { + clear(); + Ion.readMap(in, this); + } + + + @Override + public void save(OutputStream out) throws IOException + { + Ion.writeMap(out, this); + } + +} diff --git a/src/mightypork/util/files/ion/IonConstructor.java b/src/mightypork/util/files/ion/IonConstructor.java new file mode 100644 index 0000000..39a7a73 --- /dev/null +++ b/src/mightypork/util/files/ion/IonConstructor.java @@ -0,0 +1,22 @@ +package mightypork.util.files.ion; + + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + + +/** + * Implicit constructor marked like this is intended to be solely used for ION + * de-serialization. This is a description annotation and has no other function. + * + * @author MightyPork + */ +@Retention(RetentionPolicy.SOURCE) +@Target(ElementType.CONSTRUCTOR) +@Documented +public @interface IonConstructor { + +} diff --git a/src/mightypork/util/files/ion/IonDataBundle.java b/src/mightypork/util/files/ion/IonDataBundle.java deleted file mode 100644 index 53f43c9..0000000 --- a/src/mightypork/util/files/ion/IonDataBundle.java +++ /dev/null @@ -1,136 +0,0 @@ -package mightypork.util.files.ion; - - -/** - * Ionizable HashMap with getters and setters for individual - * supported types. - * - * @author MightyPork - */ -public class IonDataBundle extends IonMap { - - public boolean getBoolean(String key) - { - return (Boolean) getOfType(key, Boolean.class); - } - - - public byte getByte(String key) - { - return (Byte) getOfType(key, Byte.class); - } - - - public char getChar(String key) - { - return (Character) getOfType(key, Character.class); - } - - - public short getShort(String key) - { - return (Short) getOfType(key, Short.class); - } - - - public int getInt(String key) - { - return (Integer) getOfType(key, Integer.class); - } - - - public long getLong(String key) - { - return (Long) getOfType(key, Long.class); - } - - - public float getFloat(String key) - { - return (Float) getOfType(key, Float.class); - } - - - public double getDouble(String key) - { - return (Double) getOfType(key, Double.class); - } - - - public String getString(String key) - { - return (String) getOfType(key, String.class); - } - - - public void putBoolean(String key, boolean num) - { - super.put(key, num); - } - - - public void putByte(String key, int num) - { - super.put(key, (byte) num); - } - - - public void putChar(String key, char num) - { - super.put(key, num); - } - - - public void putShort(String key, int num) - { - super.put(key, num); - } - - - public void putInt(String key, int num) - { - super.put(key, num); - } - - - public void putLong(String key, long num) - { - super.put(key, num); - } - - - public void putFloat(String key, double num) - { - super.put(key, (float) num); - } - - - public void putDouble(String key, double num) - { - super.put(key, num); - } - - - public void putString(String key, String num) - { - super.put(key, num); - } - - - public Object getOfType(String key, Class type) - { - final Object o = super.get(key); - if (o == null || !o.getClass().isAssignableFrom(type)) { - throw new RuntimeException("Incorrect object type"); - } - return o; - } - - - @Override - public short getIonMark() - { - return Ion.DATA_BUNDLE; - } - -} diff --git a/src/mightypork/util/files/ion/IonDataList.java b/src/mightypork/util/files/ion/IonDataList.java deleted file mode 100644 index 28a1b80..0000000 --- a/src/mightypork/util/files/ion/IonDataList.java +++ /dev/null @@ -1,147 +0,0 @@ -package mightypork.util.files.ion; - - -/** - * Ionizable Arraylist - * - * @author MightyPork - */ -public class IonDataList extends IonList { - - public Ionizable getIonizable(int index) - { - return (Ionizable) getOfType(index, Ionizable.class); - } - - - public boolean getBoolean(int index) - { - return (Boolean) getOfType(index, Boolean.class); - } - - - public byte getByte(int index) - { - return (Byte) getOfType(index, Byte.class); - } - - - public char getChar(int index) - { - return (Character) getOfType(index, Character.class); - } - - - public short getShort(int index) - { - return (Short) getOfType(index, Short.class); - } - - - public int getInt(int index) - { - return (Integer) getOfType(index, Integer.class); - } - - - public long getLong(int index) - { - return (Long) getOfType(index, Long.class); - } - - - public float getFloat(int index) - { - return (Float) getOfType(index, Float.class); - } - - - public double getDouble(int index) - { - return (Double) getOfType(index, Double.class); - } - - - public String getString(int index) - { - return (String) getOfType(index, String.class); - } - - - public void addIonizable(Ionizable o) - { - super.add(o); - } - - - public void addBoolean(boolean o) - { - super.add(o); - } - - - public void addByte(byte o) - { - super.add(o); - } - - - public void addChar(char o) - { - super.add(o); - } - - - public void addShort(short o) - { - super.add(o); - } - - - public void addInt(int o) - { - super.add(o); - } - - - public void addLong(long o) - { - super.add(o); - } - - - public void addFloat(float o) - { - super.add(o); - } - - - public void addDouble(double o) - { - super.add(o); - } - - - public void addString(String o) - { - super.add(o); - } - - - public Object getOfType(int index, Class type) - { - final Object o = super.get(index); - if (o == null || !o.getClass().isAssignableFrom(type)) { - throw new RuntimeException("Incorrect object type"); - } - return o; - } - - - @Override - public short getIonMark() - { - return Ion.DATA_LIST; - } - -} diff --git a/src/mightypork/util/files/ion/IonList.java b/src/mightypork/util/files/ion/IonList.java deleted file mode 100644 index e8dca66..0000000 --- a/src/mightypork/util/files/ion/IonList.java +++ /dev/null @@ -1,80 +0,0 @@ -package mightypork.util.files.ion; - - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; - - -/** - * Ionizable Arraylist - * - * @author MightyPork - * @param - */ -public abstract class IonList extends ArrayList implements Ionizable { - - @Override - public void loadFrom(InputStream in) throws IOException - { - try { - while (true) { - final short mark = Ion.readMark(in); - - if (mark == Ion.ENTRY) { - final T value = (T) Ion.readObject(in); - add(value); - } else if (mark == Ion.END) { - break; - } else { - throw new IOException("Unexpected mark in IonList: " + mark); - } - } - readCustomData(in); - } catch (final IOException e) { - throw new IOException("Error reading ion list", e); - } - } - - - @Override - public void saveTo(OutputStream out) throws IOException - { - try { - for (final T entry : this) { - Ion.writeMark(out, Ion.ENTRY); - Ion.writeObject(out, entry); - } - Ion.writeMark(out, Ion.END); - writeCustomData(out); - } catch (final IOException e) { - throw new IOException("Error reading ion map", e); - } - } - - - /** - * Read custom data of this AbstractIonList implementation - * - * @param in input stream - */ - public void readCustomData(InputStream in) - { - } - - - /** - * Write custom data of this AbstractIonList implementation - * - * @param out output stream - */ - public void writeCustomData(OutputStream out) - { - } - - - @Override - public abstract short getIonMark(); - -} diff --git a/src/mightypork/util/files/ion/IonMap.java b/src/mightypork/util/files/ion/IonMap.java deleted file mode 100644 index 9a33c46..0000000 --- a/src/mightypork/util/files/ion/IonMap.java +++ /dev/null @@ -1,104 +0,0 @@ -package mightypork.util.files.ion; - - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.LinkedHashMap; - -import mightypork.util.annotations.DefaultImpl; - - -/** - * Ionizable HashMap - * - * @author MightyPork - * @param key - * @param value - */ -public abstract class IonMap extends LinkedHashMap implements Ionizable { - - @Override - public V get(Object key) - { - return super.get(key); - } - - - @Override - public V put(K key, V value) - { - return super.put(key, value); - } - - - @Override - public void loadFrom(InputStream in) throws IOException - { - try { - while (true) { - final short mark = Ion.readMark(in); - if (mark == Ion.ENTRY) { - final K key = (K) Ion.readObject(in); - final V value = (V) Ion.readObject(in); - put(key, value); - - } else if (mark == Ion.END) { - break; - } else { - throw new RuntimeException("Unexpected mark in IonMap: " + mark); - } - } - readCustomData(in); - } catch (final IOException | ClassCastException e) { - throw new IOException("Error reading ion map", e); - } - } - - - @Override - public void saveTo(OutputStream out) throws IOException - { - try { - for (final java.util.Map.Entry entry : entrySet()) { - Ion.writeMark(out, Ion.ENTRY); - Ion.writeObject(out, entry.getKey()); - Ion.writeObject(out, entry.getValue()); - } - Ion.writeMark(out, Ion.END); - writeCustomData(out); - } catch (final IOException e) { - throw new IOException("Error writing ion map", e); - } - } - - - /** - * Read custom data of this AbstractIonMap implementation - * - * @param in input stream - */ - @DefaultImpl - public void readCustomData(InputStream in) - { - } - - - /** - * Write custom data of this AbstractIonMap implementation - * - * @param out output stream - */ - @DefaultImpl - public void writeCustomData(OutputStream out) - { - } - - - @Override - public short getIonMark() - { - return Ion.DATA_BUNDLE; - } - -} diff --git a/src/mightypork/util/files/ion/Ionizable.java b/src/mightypork/util/files/ion/Ionizable.java index e7bee44..d299012 100644 --- a/src/mightypork/util/files/ion/Ionizable.java +++ b/src/mightypork/util/files/ion/Ionizable.java @@ -22,7 +22,7 @@ public interface Ionizable { * @param in input stream * @throws IOException */ - void loadFrom(InputStream in) throws IOException; + void load(InputStream in) throws IOException; /** @@ -32,7 +32,7 @@ public interface Ionizable { * @param out Output stream * @throws IOException */ - void saveTo(OutputStream out) throws IOException; + void save(OutputStream out) throws IOException; /** diff --git a/src/mightypork/util/files/zip/ZipBuilder.java b/src/mightypork/util/files/zip/ZipBuilder.java index 85dcd27..a6cbdef 100644 --- a/src/mightypork/util/files/zip/ZipBuilder.java +++ b/src/mightypork/util/files/zip/ZipBuilder.java @@ -29,7 +29,8 @@ public class ZipBuilder { * @param target target zip file * @throws IOException if the file is directory or cannot be created */ - public ZipBuilder(File target) throws IOException { + public ZipBuilder(File target) throws IOException + { if (!target.getParentFile().mkdirs()) throw new IOException("Could not create output directory."); diff --git a/src/mightypork/util/logging/writers/ArchivingLog.java b/src/mightypork/util/logging/writers/ArchivingLog.java index 116b2ef..baf30ad 100644 --- a/src/mightypork/util/logging/writers/ArchivingLog.java +++ b/src/mightypork/util/logging/writers/ArchivingLog.java @@ -31,7 +31,8 @@ public class ArchivingLog extends SimpleLog { * @param file log file (in log directory) * @param oldLogCount number of old log files to keep: -1 all, 0 none. */ - public ArchivingLog(String name, File file, int oldLogCount) { + public ArchivingLog(String name, File file, int oldLogCount) + { super(name, file); this.logs_to_keep = oldLogCount; } @@ -43,7 +44,8 @@ public class ArchivingLog extends SimpleLog { * @param name log name * @param file log file (in log directory) */ - public ArchivingLog(String name, File file) { + public ArchivingLog(String name, File file) + { super(name, file); this.logs_to_keep = 5; } diff --git a/src/mightypork/util/logging/writers/SimpleLog.java b/src/mightypork/util/logging/writers/SimpleLog.java index 604ddea..bdc2249 100644 --- a/src/mightypork/util/logging/writers/SimpleLog.java +++ b/src/mightypork/util/logging/writers/SimpleLog.java @@ -48,7 +48,8 @@ public class SimpleLog implements LogWriter { private final long started_ms; - public SimpleLog(String name, File file) { + public SimpleLog(String name, File file) + { this.name = name; this.file = file; this.started_ms = System.currentTimeMillis(); diff --git a/src/mightypork/util/math/Calc.java b/src/mightypork/util/math/Calc.java index a36fbb3..516c657 100644 --- a/src/mightypork/util/math/Calc.java +++ b/src/mightypork/util/math/Calc.java @@ -49,7 +49,6 @@ public class Calc { return Math.abs(a * x + b * y + c) / Math.sqrt(a * a + b * b); } - private static class Angles { public static double delta(double alpha, double beta, double a360) @@ -384,7 +383,8 @@ public class Calc { } private static Random rand = new Random(); - + + public static double sphereSurface(double radius) { return 4D * Math.PI * square(radius); diff --git a/src/mightypork/util/math/Easing.java b/src/mightypork/util/math/Easing.java index 4f34a09..4cf0593 100644 --- a/src/mightypork/util/math/Easing.java +++ b/src/mightypork/util/math/Easing.java @@ -72,7 +72,8 @@ public abstract class Easing { /** * @param in Easing to reverse */ - public Reverse(Easing in) { + public Reverse(Easing in) + { this.ea = in; } @@ -101,7 +102,8 @@ public abstract class Easing { * @param in initial EasingFunction * @param out terminal EasingFunction */ - public Composite(Easing in, Easing out) { + public Composite(Easing in, Easing out) + { this.in = in; this.out = out; } diff --git a/src/mightypork/util/math/Polar.java b/src/mightypork/util/math/Polar.java index 6913caa..4be6afd 100644 --- a/src/mightypork/util/math/Polar.java +++ b/src/mightypork/util/math/Polar.java @@ -26,7 +26,8 @@ public class Polar { * @param angle angle in RAD * @param distance distance from origin */ - public Polar(double angle, double distance) { + public Polar(double angle, double distance) + { this(angle, false, distance); } @@ -38,7 +39,8 @@ public class Polar { * @param deg angle is in DEG * @param distance radius */ - public Polar(double angle, boolean deg, double distance) { + public Polar(double angle, boolean deg, double distance) + { this.radius = distance; this.angle = deg ? Math.toRadians(angle) : angle; } diff --git a/src/mightypork/util/math/Range.java b/src/mightypork/util/math/Range.java index 7596d24..5900a8b 100644 --- a/src/mightypork/util/math/Range.java +++ b/src/mightypork/util/math/Range.java @@ -25,7 +25,8 @@ public class Range { /** * Implicit range constructor 0-1 */ - public Range() { + public Range() + { } @@ -35,7 +36,8 @@ public class Range { * @param min min number * @param max max number */ - public Range(double min, double max) { + public Range(double min, double max) + { this.min = min; this.max = max; norm(); @@ -47,7 +49,8 @@ public class Range { * * @param minmax min = max number */ - public Range(double minmax) { + public Range(double minmax) + { this.min = minmax; this.max = minmax; } @@ -178,5 +181,4 @@ public class Range { this.max = max; norm(); } - } diff --git a/src/mightypork/util/math/color/Color.java b/src/mightypork/util/math/color/Color.java index 2559194..73d2996 100644 --- a/src/mightypork/util/math/color/Color.java +++ b/src/mightypork/util/math/color/Color.java @@ -137,13 +137,13 @@ public abstract class Color { protected static final double clamp(Num n) { - return Calc.clampd(n.value(), 0, 1); + return Calc.clamp(n.value(), 0, 1); } protected static final double clamp(double n) { - return Calc.clampd(n, 0, 1); + return Calc.clamp(n, 0, 1); } diff --git a/src/mightypork/util/math/color/ColorAlphaAdjuster.java b/src/mightypork/util/math/color/ColorAlphaAdjuster.java index 3868789..4e04371 100644 --- a/src/mightypork/util/math/color/ColorAlphaAdjuster.java +++ b/src/mightypork/util/math/color/ColorAlphaAdjuster.java @@ -10,7 +10,8 @@ public class ColorAlphaAdjuster extends Color { private final Num alphaAdjust; - public ColorAlphaAdjuster(Color source, Num alphaMul) { + public ColorAlphaAdjuster(Color source, Num alphaMul) + { this.source = source; this.alphaAdjust = alphaMul; } diff --git a/src/mightypork/util/math/color/ColorHsb.java b/src/mightypork/util/math/color/ColorHsb.java index 5130642..0f038f2 100644 --- a/src/mightypork/util/math/color/ColorHsb.java +++ b/src/mightypork/util/math/color/ColorHsb.java @@ -12,7 +12,8 @@ public class ColorHsb extends Color { private final Num a; - public ColorHsb(Num h, Num s, Num b, Num a) { + public ColorHsb(Num h, Num s, Num b, Num a) + { this.h = h; this.s = s; this.b = b; diff --git a/src/mightypork/util/math/color/ColorRgb.java b/src/mightypork/util/math/color/ColorRgb.java index 5586620..3cd28ba 100644 --- a/src/mightypork/util/math/color/ColorRgb.java +++ b/src/mightypork/util/math/color/ColorRgb.java @@ -12,7 +12,8 @@ public class ColorRgb extends Color { private final Num a; - public ColorRgb(Num r, Num g, Num b, Num a) { + public ColorRgb(Num r, Num g, Num b, Num a) + { this.r = r; this.g = g; this.b = b; diff --git a/src/mightypork/util/math/noise/NoiseGen.java b/src/mightypork/util/math/noise/NoiseGen.java index 32081de..25dd1c0 100644 --- a/src/mightypork/util/math/noise/NoiseGen.java +++ b/src/mightypork/util/math/noise/NoiseGen.java @@ -27,7 +27,8 @@ public class NoiseGen { * @param middle middle bound ("surface") * @param high high bound ("hill") */ - public NoiseGen(double density, double low, double middle, double high) { + public NoiseGen(double density, double low, double middle, double high) + { this(density, low, middle, high, Double.doubleToLongBits(Math.random())); } @@ -41,7 +42,8 @@ public class NoiseGen { * @param high high bound ("hill") * @param seed random seed to use */ - public NoiseGen(double density, double low, double middle, double high, long seed) { + public NoiseGen(double density, double low, double middle, double high, long seed) + { if (low > middle || middle > high) throw new IllegalArgumentException("Invalid value range."); this.density = density; diff --git a/src/mightypork/util/math/noise/PerlinNoiseGenerator.java b/src/mightypork/util/math/noise/PerlinNoiseGenerator.java index da95165..ce54139 100644 --- a/src/mightypork/util/math/noise/PerlinNoiseGenerator.java +++ b/src/mightypork/util/math/noise/PerlinNoiseGenerator.java @@ -60,7 +60,8 @@ public class PerlinNoiseGenerator { /** * Create a new noise creator with the default seed value */ - public PerlinNoiseGenerator() { + public PerlinNoiseGenerator() + { this(DEFAULT_SEED); } @@ -70,7 +71,8 @@ public class PerlinNoiseGenerator { * * @param seed The seed value to use */ - public PerlinNoiseGenerator(long seed) { + public PerlinNoiseGenerator(long seed) + { p_imp = new int[DEFAULT_SAMPLE_SIZE << 1]; int i, j, k; diff --git a/src/mightypork/util/objects/Mutable.java b/src/mightypork/util/objects/Mutable.java index d9a27c3..69723c2 100644 --- a/src/mightypork/util/objects/Mutable.java +++ b/src/mightypork/util/objects/Mutable.java @@ -18,7 +18,8 @@ public class Mutable { * * @param o value */ - public Mutable(T o) { + public Mutable(T o) + { this.o = o; } diff --git a/src/mightypork/util/objects/Pair.java b/src/mightypork/util/objects/Pair.java index d87079e..87bda0c 100644 --- a/src/mightypork/util/objects/Pair.java +++ b/src/mightypork/util/objects/Pair.java @@ -31,7 +31,8 @@ public class Pair { * @param first 1st object * @param second 2nd object */ - public Pair(T1 first, T2 second) { + public Pair(T1 first, T2 second) + { this.first = first; this.second = second; } @@ -68,7 +69,7 @@ public class Pair { final Pair t = (Pair) obj; - return Calc.areObjectsEqual(first, t.first) && Calc.areObjectsEqual(second, t.second); + return Calc.areEqual(first, t.first) && Calc.areEqual(second, t.second); } diff --git a/src/mightypork/util/objects/Triad.java b/src/mightypork/util/objects/Triad.java index 4f81eaf..4dcd9fd 100644 --- a/src/mightypork/util/objects/Triad.java +++ b/src/mightypork/util/objects/Triad.java @@ -28,7 +28,8 @@ public class Triad extends Pair { * @param objB 2nd object * @param objC 3rd object */ - public Triad(T1 objA, T2 objB, T3 objC) { + public Triad(T1 objA, T2 objB, T3 objC) + { super(objA, objB); third = objC; } @@ -59,7 +60,7 @@ public class Triad extends Pair { { if (!super.equals(obj)) return false; - return Calc.areObjectsEqual(third, ((Triad) obj).third); + return Calc.areEqual(third, ((Triad) obj).third); } diff --git a/src/mightypork/util/string/StringProvider.java b/src/mightypork/util/string/StringProvider.java index 04b25c8..4f21e9b 100644 --- a/src/mightypork/util/string/StringProvider.java +++ b/src/mightypork/util/string/StringProvider.java @@ -20,7 +20,8 @@ public interface StringProvider { private final String value; - public StringWrapper(String value) { + public StringWrapper(String value) + { this.value = value; } diff --git a/src/mightypork/util/string/filtering/FileSuffixFilter.java b/src/mightypork/util/string/filtering/FileSuffixFilter.java index 9f65792..359b883 100644 --- a/src/mightypork/util/string/filtering/FileSuffixFilter.java +++ b/src/mightypork/util/string/filtering/FileSuffixFilter.java @@ -21,7 +21,8 @@ public class FileSuffixFilter implements FileFilter { * * @param suffixes var-args allowed suffixes, case insensitive */ - public FileSuffixFilter(String... suffixes) { + public FileSuffixFilter(String... suffixes) + { this.suffixes = suffixes; } diff --git a/src/mightypork/util/string/filtering/RegexCharFilter.java b/src/mightypork/util/string/filtering/RegexCharFilter.java index 95d8e9a..ee646fb 100644 --- a/src/mightypork/util/string/filtering/RegexCharFilter.java +++ b/src/mightypork/util/string/filtering/RegexCharFilter.java @@ -6,7 +6,8 @@ public class RegexCharFilter implements CharFilter { private final String formula; - public RegexCharFilter(String regex) { + public RegexCharFilter(String regex) + { this.formula = regex; } diff --git a/src/mightypork/util/string/filtering/WhitelistCharFilter.java b/src/mightypork/util/string/filtering/WhitelistCharFilter.java index 64180be..8534463 100644 --- a/src/mightypork/util/string/filtering/WhitelistCharFilter.java +++ b/src/mightypork/util/string/filtering/WhitelistCharFilter.java @@ -6,7 +6,8 @@ public class WhitelistCharFilter implements CharFilter { private final String whitelist; - public WhitelistCharFilter(String allowed) { + public WhitelistCharFilter(String allowed) + { this.whitelist = allowed; }