WorldMap now successfully IONIZABLE!
This commit is contained in:
@@ -22,6 +22,7 @@ import mightypork.rogue.screens.main_menu.ScreenMainMenu;
|
||||
import mightypork.rogue.screens.test_bouncyboxes.ScreenTestBouncy;
|
||||
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.tile.Tile;
|
||||
import mightypork.util.control.eventbus.EventBus;
|
||||
@@ -107,8 +108,10 @@ public final class App extends BaseApp {
|
||||
{
|
||||
Ion.registerIonizable(Tile.ION_MARK, Tile.class);
|
||||
Ion.registerIonizable(Item.ION_MARK, Item.class);
|
||||
Ion.registerIonizable(WorldMap.ION_MARK, WorldMap.class);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected File getLockFile()
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@ public class CrossfadeOverlay extends Overlay implements CrossfadeRequest.Listen
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
if(requestedScreenName == null) shutdown();
|
||||
if (requestedScreenName == null) shutdown();
|
||||
getEventBus().send(new ScreenRequestEvent(requestedScreenName));
|
||||
}
|
||||
};
|
||||
@@ -45,7 +45,7 @@ public class CrossfadeOverlay extends Overlay implements CrossfadeRequest.Listen
|
||||
public CrossfadeOverlay(AppAccess app) {
|
||||
super(app);
|
||||
|
||||
QuadPainter qp = new QuadPainter(color);
|
||||
final QuadPainter qp = new QuadPainter(color);
|
||||
qp.setRect(root);
|
||||
root.add(qp);
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import mightypork.util.control.eventbus.events.Event;
|
||||
*/
|
||||
public class CrossfadeRequest implements Event<CrossfadeRequest.Listener> {
|
||||
|
||||
private String screen;
|
||||
private final String screen;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,35 +19,35 @@ public class GameGui extends ScreenLayer {
|
||||
public GameGui(Screen screen) {
|
||||
super(screen);
|
||||
|
||||
Num h = root.height();
|
||||
Num w = root.width();
|
||||
Num minWH = w.min(h).max(700); // avoid too small shrinking
|
||||
final Num h = root.height();
|
||||
final Num w = root.width();
|
||||
final Num minWH = w.min(h).max(700); // avoid too small shrinking
|
||||
|
||||
Component qp = new QuadPainter(PAL16.VOID);
|
||||
final Component qp = new QuadPainter(PAL16.VOID);
|
||||
qp.setRect(root);
|
||||
root.add(qp);
|
||||
|
||||
ImagePainter nav = new ImagePainter(Res.getTxQuad("panel"));
|
||||
final ImagePainter nav = new ImagePainter(Res.getTxQuad("panel"));
|
||||
nav.setRect(root.bottomEdge().growUp(minWH.perc(7)));
|
||||
root.add(nav);
|
||||
|
||||
HorizontalFixedFlowLayout itemSlots = new HorizontalFixedFlowLayout(root, nav.height().mul(1.8), AlignX.LEFT);
|
||||
final HorizontalFixedFlowLayout itemSlots = new HorizontalFixedFlowLayout(root, nav.height().mul(1.8), AlignX.LEFT);
|
||||
itemSlots.setRect(nav.growUp(nav.height()).move(nav.height().mul(0.2), nav.height().mul(-0.2)));
|
||||
root.add(itemSlots);
|
||||
|
||||
itemSlots.add(new NavItemSlot(Res.getTxQuad("meat")));
|
||||
itemSlots.add(new NavItemSlot(Res.getTxQuad("sword")));
|
||||
|
||||
Rect shrunk = root.shrink(minWH.perc(3));
|
||||
Num displays_height = minWH.perc(6);
|
||||
final Rect shrunk = root.shrink(minWH.perc(3));
|
||||
final Num displays_height = minWH.perc(6);
|
||||
|
||||
HeartBar hearts = new HeartBar(6, 3, Res.getTxQuad("heart_on"), Res.getTxQuad("heart_off"), AlignX.LEFT);
|
||||
Rect hearts_box = shrunk.topLeft().startRect().growDown(displays_height);
|
||||
final HeartBar hearts = new HeartBar(6, 3, Res.getTxQuad("heart_on"), Res.getTxQuad("heart_off"), AlignX.LEFT);
|
||||
final Rect hearts_box = shrunk.topLeft().startRect().growDown(displays_height);
|
||||
hearts.setRect(hearts_box);
|
||||
root.add(hearts);
|
||||
|
||||
HeartBar experience = new HeartBar(6, 2, Res.getTxQuad("xp_on"), Res.getTxQuad("xp_off"), AlignX.RIGHT);
|
||||
Rect xp_box = shrunk.topRight().startRect().growDown(displays_height);
|
||||
final HeartBar experience = new HeartBar(6, 2, Res.getTxQuad("xp_on"), Res.getTxQuad("xp_off"), AlignX.RIGHT);
|
||||
final Rect xp_box = shrunk.topRight().startRect().growDown(displays_height);
|
||||
experience.setRect(xp_box);
|
||||
root.add(experience);
|
||||
}
|
||||
|
||||
@@ -12,10 +12,10 @@ import mightypork.util.constraints.rect.Rect;
|
||||
|
||||
public class HeartBar extends VisualComponent {
|
||||
|
||||
private TxQuad img_on;
|
||||
private TxQuad img_off;
|
||||
private int total;
|
||||
private int active;
|
||||
private final TxQuad img_on;
|
||||
private final TxQuad img_off;
|
||||
private final int total;
|
||||
private final int active;
|
||||
|
||||
NumVar index = new NumVar(0);
|
||||
Rect heart;
|
||||
@@ -26,7 +26,7 @@ public class HeartBar extends VisualComponent {
|
||||
* @param active
|
||||
* @param img_on
|
||||
* @param img_off
|
||||
* @param align
|
||||
* @param align
|
||||
*/
|
||||
public HeartBar(int total, int active, TxQuad img_on, TxQuad img_off, AlignX align) {
|
||||
super();
|
||||
@@ -35,18 +35,18 @@ public class HeartBar extends VisualComponent {
|
||||
this.img_on = img_on;
|
||||
this.img_off = img_off;
|
||||
|
||||
Num h = height();
|
||||
Num w = width();
|
||||
final Num h = height();
|
||||
final Num w = width();
|
||||
|
||||
switch (align) {
|
||||
case LEFT:
|
||||
heart = leftEdge().growRight(h).moveX(index.mul(h));
|
||||
break;
|
||||
case RIGHT:
|
||||
heart = rightEdge().growLeft(h).moveX(h.mul(-total+1).add(index.mul(h)));
|
||||
heart = rightEdge().growLeft(h).moveX(h.mul(-total + 1).add(index.mul(h)));
|
||||
break;
|
||||
case CENTER:
|
||||
heart = leftEdge().moveX(w.half().add(h.mul(-total/2D))).growRight(h).moveX(index.mul(h));
|
||||
heart = leftEdge().moveX(w.half().add(h.mul(-total / 2D))).growRight(h).moveX(index.mul(h));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package mightypork.rogue.screens.ingame;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.events.MouseMotionEvent;
|
||||
import mightypork.gamecore.gui.components.ClickableComponent;
|
||||
import mightypork.gamecore.gui.components.InputComponent;
|
||||
import mightypork.gamecore.render.Render;
|
||||
import mightypork.gamecore.render.textures.TxQuad;
|
||||
import mightypork.rogue.Res;
|
||||
@@ -13,15 +13,14 @@ import mightypork.util.constraints.rect.caching.RectCache;
|
||||
import mightypork.util.constraints.vect.Vect;
|
||||
import mightypork.util.control.timing.Updateable;
|
||||
import mightypork.util.math.Easing;
|
||||
import mightypork.gamecore.control.events.MouseMotionEvent;
|
||||
|
||||
|
||||
public class NavItemSlot extends ClickableComponent implements MouseMotionEvent.Listener, Updateable {
|
||||
|
||||
private TxQuad image;
|
||||
private TxQuad frame;
|
||||
private RectCache paintBox;
|
||||
private NumAnimated yOffset;
|
||||
private final TxQuad image;
|
||||
private final TxQuad frame;
|
||||
private final RectCache paintBox;
|
||||
private final NumAnimated yOffset;
|
||||
private boolean wasInside = false;
|
||||
|
||||
|
||||
@@ -29,11 +28,11 @@ public class NavItemSlot extends ClickableComponent implements MouseMotionEvent.
|
||||
this.image = image;
|
||||
this.frame = Res.getTxQuad("item_frame");
|
||||
|
||||
Rect ref = shrink(height().perc(8));
|
||||
final Rect ref = shrink(height().perc(8));
|
||||
yOffset = new NumAnimated(0, Easing.LINEAR);
|
||||
yOffset.setDefaultDuration(0.05);
|
||||
|
||||
Num h = ref.width().min(ref.height());
|
||||
final Num h = ref.width().min(ref.height());
|
||||
this.paintBox = ref.bottomLeft().startRect().grow(Num.ZERO, h, h, Num.ZERO).moveY(yOffset.mul(h.perc(-5))).cached();
|
||||
}
|
||||
|
||||
@@ -61,7 +60,7 @@ public class NavItemSlot extends ClickableComponent implements MouseMotionEvent.
|
||||
|
||||
@Override
|
||||
public void receive(MouseMotionEvent event)
|
||||
{
|
||||
{
|
||||
if (event.getPos().isInside(this) != wasInside) {
|
||||
if (wasInside) {
|
||||
// left
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
package mightypork.rogue.screens.ingame;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.gamecore.gui.screens.LayeredScreen;
|
||||
|
||||
|
||||
public class ScreenGame extends LayeredScreen {
|
||||
|
||||
|
||||
public ScreenGame(AppAccess app) {
|
||||
super(app);
|
||||
|
||||
addLayer(new GameGui(this));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package mightypork.rogue.screens.main_menu;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.events.ScreenRequestEvent;
|
||||
import mightypork.gamecore.gui.AlignX;
|
||||
import mightypork.gamecore.gui.components.layout.GridLayout;
|
||||
import mightypork.gamecore.gui.components.painters.QuadPainter;
|
||||
@@ -9,8 +8,6 @@ import mightypork.gamecore.gui.components.painters.TextPainter;
|
||||
import mightypork.gamecore.gui.screens.BaseScreen;
|
||||
import mightypork.gamecore.gui.screens.ScreenLayer;
|
||||
import mightypork.rogue.Res;
|
||||
import mightypork.rogue.events.ActionRequest;
|
||||
import mightypork.rogue.events.ActionRequest.RequestType;
|
||||
import mightypork.rogue.screens.CrossfadeRequest;
|
||||
import mightypork.util.constraints.num.Num;
|
||||
import mightypork.util.constraints.rect.Rect;
|
||||
@@ -49,13 +46,18 @@ class MenuLayer extends ScreenLayer {
|
||||
b3 = new MenuButton("Flying Cat", PAL16.PIGMEAT);
|
||||
b4 = new MenuButton("Bye!", PAL16.BLOODRED);
|
||||
|
||||
int r=0;
|
||||
int r = 0;
|
||||
|
||||
layout.put(tp, r, 0, 4, 1); r += 5;
|
||||
layout.put(b0, r, 0, 2, 1); r += 3;
|
||||
layout.put(b1, r, 0, 2, 1); r += 2;
|
||||
layout.put(b2, r, 0, 2, 1); r += 2;
|
||||
layout.put(b3, r, 0, 2, 1); r += 3;
|
||||
layout.put(tp, r, 0, 4, 1);
|
||||
r += 5;
|
||||
layout.put(b0, r, 0, 2, 1);
|
||||
r += 3;
|
||||
layout.put(b1, r, 0, 2, 1);
|
||||
r += 2;
|
||||
layout.put(b2, r, 0, 2, 1);
|
||||
r += 2;
|
||||
layout.put(b3, r, 0, 2, 1);
|
||||
r += 3;
|
||||
layout.put(b4, r, 0, 2, 1);
|
||||
|
||||
root.add(layout);
|
||||
|
||||
@@ -57,6 +57,15 @@ public abstract class Entity<D, M extends EntityModel<D, R>, R extends RectBound
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return data
|
||||
*/
|
||||
public final D getData()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return entity model
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package mightypork.rogue.world;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
@@ -57,8 +58,9 @@ public abstract class EntityModel<D, R extends RectBound> {
|
||||
*
|
||||
* @param data data to load
|
||||
* @param in input stream
|
||||
* @throws IOException
|
||||
*/
|
||||
public abstract void load(D data, InputStream in);
|
||||
public abstract void load(D data, InputStream in) throws IOException;
|
||||
|
||||
|
||||
/**
|
||||
@@ -66,9 +68,10 @@ public abstract class EntityModel<D, R extends RectBound> {
|
||||
*
|
||||
* @param data data to save
|
||||
* @param out output stream
|
||||
* @throws IOException
|
||||
*/
|
||||
@DefaultImpl
|
||||
public abstract void save(D data, OutputStream out);
|
||||
public abstract void save(D data, OutputStream out) throws IOException;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,12 +13,19 @@ import mightypork.util.files.ion.Ionizable;
|
||||
|
||||
public class WorldMap implements TileHolder, Ionizable {
|
||||
|
||||
public static final int ION_MARK = 702;
|
||||
|
||||
private int width, height;
|
||||
|
||||
/** Array of tiles [y][x] */
|
||||
private Tile[][] tiles;
|
||||
|
||||
|
||||
public WorldMap() {
|
||||
// constructor for ION
|
||||
}
|
||||
|
||||
|
||||
public WorldMap(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
@@ -33,27 +40,33 @@ public class WorldMap implements TileHolder, Ionizable {
|
||||
|
||||
|
||||
@Override
|
||||
public Tile getTile(int x, int y)
|
||||
public final Tile getTile(int x, int y)
|
||||
{
|
||||
return tiles[y][x];
|
||||
}
|
||||
|
||||
|
||||
public void setTile(Tile tile, int x, int y)
|
||||
public final void setTile(int tileId, int x, int y)
|
||||
{
|
||||
setTile(new Tile(tileId), x, y);
|
||||
}
|
||||
|
||||
|
||||
public final void setTile(Tile tile, int x, int y)
|
||||
{
|
||||
tiles[y][x] = tile;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getWidth()
|
||||
public final int getWidth()
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getHeight()
|
||||
public final int getHeight()
|
||||
{
|
||||
return height;
|
||||
}
|
||||
@@ -67,23 +80,52 @@ public class WorldMap implements TileHolder, Ionizable {
|
||||
|
||||
buildArray();
|
||||
|
||||
short mark;
|
||||
|
||||
mark = Ion.readMark(in);
|
||||
if(mark == Ion.START);
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void saveTo(OutputStream out) throws IOException
|
||||
{
|
||||
Ion.writeInt(out, width);
|
||||
Ion.writeInt(out, height);
|
||||
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
final Tile t = getTile(x, y);
|
||||
if (t != null) {
|
||||
Ion.writeMark(out, Ion.ENTRY);
|
||||
Ion.writeInt(out, x);
|
||||
Ion.writeInt(out, y);
|
||||
Ion.writeObject(out, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ion.writeMark(out, Ion.END);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public short getIonMark()
|
||||
{
|
||||
return 0;
|
||||
return ION_MARK;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package mightypork.rogue.world.item;
|
||||
|
||||
|
||||
/**
|
||||
* Item data object. Can be extended for particular models' needs.
|
||||
* Item data object.
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
|
||||
@@ -10,7 +10,7 @@ public final class Items {
|
||||
private static final Map<Integer, ItemModel> registered = new HashMap<>();
|
||||
|
||||
|
||||
public static void register(int id, ItemModel model)
|
||||
static void register(int id, ItemModel model)
|
||||
{
|
||||
if (registered.containsKey(id)) throw new IllegalArgumentException("Item ID " + id + " already in use.");
|
||||
registered.put(id, model);
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package mightypork.rogue.world.tile;
|
||||
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
import mightypork.rogue.world.Entity;
|
||||
import mightypork.rogue.world.item.Item;
|
||||
|
||||
@@ -16,12 +14,6 @@ public final class Tile extends Entity<TileData, TileModel, TileRenderContext> {
|
||||
|
||||
public static final short ION_MARK = 700;
|
||||
|
||||
/** Items dropped onto this tile */
|
||||
public final Stack<Item> items = new Stack<>();
|
||||
|
||||
/** Whether the tile is occupied by an entity */
|
||||
public boolean occupied;
|
||||
|
||||
|
||||
public Tile() {
|
||||
super();
|
||||
@@ -58,8 +50,8 @@ public final class Tile extends Entity<TileData, TileModel, TileRenderContext> {
|
||||
super.render(context);
|
||||
|
||||
// render laying-on-top item
|
||||
if (!items.isEmpty()) {
|
||||
Item item = items.peek();
|
||||
if (!data.items.isEmpty()) {
|
||||
final Item item = data.items.peek();
|
||||
|
||||
item.render(context.getRect());
|
||||
}
|
||||
@@ -72,8 +64,8 @@ public final class Tile extends Entity<TileData, TileModel, TileRenderContext> {
|
||||
super.update(delta);
|
||||
|
||||
// update laying-on-top item
|
||||
if (!items.isEmpty()) {
|
||||
Item item = items.peek();
|
||||
if (!data.items.isEmpty()) {
|
||||
final Item item = data.items.peek();
|
||||
item.update(delta);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,9 @@ import java.util.Stack;
|
||||
|
||||
import mightypork.rogue.world.item.Item;
|
||||
|
||||
|
||||
/**
|
||||
* Tile data object. Can be extended for particular models' needs.
|
||||
* Tile data object.
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
@@ -15,4 +16,7 @@ public abstract class TileData {
|
||||
/** Items dropped onto this tile */
|
||||
public final Stack<Item> items = new Stack<>();
|
||||
|
||||
/** Whether the tile is occupied by an entity */
|
||||
public boolean occupied;
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ public final class Tiles {
|
||||
private static final Map<Integer, TileModel> registered = new HashMap<>();
|
||||
|
||||
|
||||
public static void register(int id, TileModel model)
|
||||
static void register(int id, TileModel model)
|
||||
{
|
||||
if (registered.containsKey(id)) throw new IllegalArgumentException("Tile ID " + id + " already in use.");
|
||||
registered.put(id, model);
|
||||
|
||||
Reference in New Issue
Block a user