some changes, nothing much
This commit is contained in:
@@ -27,7 +27,6 @@ import mightypork.rogue.world.World;
|
||||
import mightypork.rogue.world.WorldPos;
|
||||
import mightypork.rogue.world.item.Item;
|
||||
import mightypork.rogue.world.map.Level;
|
||||
import mightypork.rogue.world.structs.LevelList;
|
||||
import mightypork.rogue.world.tile.Tile;
|
||||
import mightypork.util.control.eventbus.EventBus;
|
||||
import mightypork.util.control.eventbus.events.Event;
|
||||
@@ -112,7 +111,6 @@ public final class App extends BaseApp {
|
||||
{
|
||||
Ion.registerIonizable(Item.ION_MARK, Item.class);
|
||||
Ion.registerIonizable(Level.ION_MARK, Level.class);
|
||||
Ion.registerIonizable(LevelList.ION_MARK, LevelList.class);
|
||||
Ion.registerIonizable(PlayerInfo.ION_MARK, PlayerInfo.class);
|
||||
Ion.registerIonizable(Tile.ION_MARK, Tile.class);
|
||||
Ion.registerIonizable(World.ION_MARK, World.class);
|
||||
|
||||
@@ -9,23 +9,22 @@ import java.util.Set;
|
||||
|
||||
import mightypork.rogue.world.map.Level;
|
||||
import mightypork.rogue.world.map.TileRenderContext;
|
||||
import mightypork.rogue.world.structs.LevelList;
|
||||
import mightypork.util.constraints.rect.Rect;
|
||||
import mightypork.util.constraints.rect.RectConst;
|
||||
import mightypork.util.constraints.rect.proxy.RectBound;
|
||||
import mightypork.util.constraints.vect.VectConst;
|
||||
import mightypork.util.control.timing.Updateable;
|
||||
import mightypork.util.error.CorruptedDataException;
|
||||
import mightypork.util.files.ion.Ion;
|
||||
import mightypork.util.files.ion.IonBundle;
|
||||
import mightypork.util.files.ion.Ionizable;
|
||||
import mightypork.util.files.ion.templates.StreamableArrayList;
|
||||
|
||||
|
||||
public class World implements Ionizable, Updateable {
|
||||
|
||||
public static final short ION_MARK = 706;
|
||||
|
||||
private LevelList levels = new LevelList();
|
||||
private StreamableArrayList<Level> levels = new StreamableArrayList<>();
|
||||
|
||||
private PlayerInfo player = new PlayerInfo();
|
||||
|
||||
@@ -42,12 +41,8 @@ public class World implements Ionizable, Updateable {
|
||||
final IonBundle ib = (IonBundle) Ion.readObject(in);
|
||||
player = ib.get("player", player);
|
||||
seed = ib.get("seed", seed);
|
||||
levels = ib.get("levels", levels);
|
||||
|
||||
// levels
|
||||
Ion.readSequence(in, levels);
|
||||
|
||||
if (player == null) throw new CorruptedDataException("Null player in world.");
|
||||
}
|
||||
|
||||
|
||||
@@ -57,8 +52,9 @@ public class World implements Ionizable, Updateable {
|
||||
final IonBundle ib = new IonBundle();
|
||||
ib.put("player", player);
|
||||
ib.put("seed", seed);
|
||||
ib.put("levels", levels);
|
||||
Ion.writeObject(out, ib);
|
||||
|
||||
Ion.writeSequence(out, levels);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,31 +5,20 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import mightypork.rogue.world.map.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 class Item implements Updateable, Ionizable {
|
||||
public class Item implements 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(int id)
|
||||
{
|
||||
@@ -47,7 +36,6 @@ public class Item implements Updateable, Ionizable {
|
||||
{
|
||||
this.model = model;
|
||||
this.id = model.id;
|
||||
this.anim = new AnimatorBounce(2, Easing.SINE_BOTH);
|
||||
}
|
||||
|
||||
|
||||
@@ -60,28 +48,17 @@ public class Item implements Updateable, Ionizable {
|
||||
@Override
|
||||
public void save(OutputStream out) throws IOException
|
||||
{
|
||||
final IonBundle ib = new IonBundle();
|
||||
|
||||
ib.put("id", id);
|
||||
ib.put("flags", flags);
|
||||
ib.put("numbers", numbers);
|
||||
|
||||
Ion.writeObject(out, ib);
|
||||
Ion.writeShort(out, (short) id);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void load(InputStream in) throws IOException
|
||||
{
|
||||
final IonBundle ib = (IonBundle) Ion.readObject(in);
|
||||
id = Ion.readShort(in);
|
||||
|
||||
id = ib.get("id", 0);
|
||||
flags = ib.get("flags", null);
|
||||
numbers = ib.get("numbers", null);
|
||||
|
||||
if (id != model.id) {
|
||||
model = Items.get(id);
|
||||
}
|
||||
// if id changed, get new model
|
||||
if (model == null || id != model.id) model = Items.get(id);
|
||||
}
|
||||
|
||||
|
||||
@@ -91,20 +68,4 @@ public class Item implements Updateable, Ionizable {
|
||||
return ION_MARK;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(double delta)
|
||||
{
|
||||
if (anim != null) {
|
||||
anim.update(delta);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void renderOnTile(TileRenderContext context)
|
||||
{
|
||||
model.renderOnTile(this, context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,11 +13,6 @@ 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)
|
||||
{
|
||||
@@ -38,13 +33,4 @@ public abstract class ItemModel {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Level implements MapAccess, Ionizable {
|
||||
|
||||
/** Level seed (used for generation and tile variation) */
|
||||
public long seed;
|
||||
|
||||
|
||||
private NoiseGen noiseGen;
|
||||
|
||||
|
||||
@@ -193,6 +193,7 @@ public class Level implements MapAccess, Ionizable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NoiseGen getNoiseGen()
|
||||
{
|
||||
|
||||
@@ -38,8 +38,8 @@ public interface MapAccess {
|
||||
* @return map seed
|
||||
*/
|
||||
long getSeed();
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return level-specific noise generator
|
||||
*/
|
||||
|
||||
@@ -28,7 +28,7 @@ public final class TileRenderContext implements RectBound {
|
||||
this.map = map;
|
||||
this.tiler = drawArea.tiles(map.getWidth(), map.getHeight());
|
||||
|
||||
this.tiler.setOverlap(0.001);
|
||||
this.tiler.setOverlap(0.001); // avoid gaps (rounding error?)
|
||||
|
||||
this.noise = map.getNoiseGen();
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package mightypork.rogue.world.structs;
|
||||
|
||||
|
||||
import mightypork.rogue.world.item.Item;
|
||||
import mightypork.util.files.ion.templates.IonizableStack;
|
||||
|
||||
|
||||
public class ItemStack extends IonizableStack<Item> {
|
||||
|
||||
private static final short ION_MARK = 710;
|
||||
|
||||
|
||||
@Override
|
||||
public short getIonMark()
|
||||
{
|
||||
return ION_MARK;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package mightypork.rogue.world.structs;
|
||||
|
||||
|
||||
import mightypork.rogue.world.map.Level;
|
||||
import mightypork.util.files.ion.templates.IonizableArrayList;
|
||||
|
||||
|
||||
public class LevelList extends IonizableArrayList<Level> {
|
||||
|
||||
public static final short ION_MARK = 709;
|
||||
|
||||
|
||||
@Override
|
||||
public short getIonMark()
|
||||
{
|
||||
return ION_MARK;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package mightypork.rogue.world.tile;
|
||||
|
||||
|
||||
import mightypork.rogue.world.item.Item;
|
||||
import mightypork.rogue.world.map.TileRenderContext;
|
||||
import mightypork.util.constraints.rect.Rect;
|
||||
import mightypork.util.constraints.rect.proxy.RectBoundAdapter;
|
||||
import mightypork.util.control.timing.Animator;
|
||||
import mightypork.util.control.timing.AnimatorBounce;
|
||||
import mightypork.util.control.timing.Updateable;
|
||||
import mightypork.util.math.Easing;
|
||||
|
||||
|
||||
public class DroppedItemRenderer implements Updateable {
|
||||
|
||||
private Animator itemAnim = new AnimatorBounce(2, Easing.SINE_BOTH);
|
||||
|
||||
// prepared constraints, to avoid re-building each frame
|
||||
private final RectBoundAdapter tileRectAdapter = new RectBoundAdapter();
|
||||
private final Rect itemRect = tileRectAdapter.shrink(tileRectAdapter.height().perc(10)).moveY(itemAnim.neg());
|
||||
|
||||
|
||||
public Animator getItemAnim()
|
||||
{
|
||||
if (itemAnim == null) {
|
||||
itemAnim = new AnimatorBounce(2, Easing.SINE_BOTH);
|
||||
}
|
||||
|
||||
return itemAnim;
|
||||
}
|
||||
|
||||
|
||||
public void render(Item item, TileRenderContext context)
|
||||
{
|
||||
tileRectAdapter.setRect(context);
|
||||
item.render(itemRect);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(double delta)
|
||||
{
|
||||
itemAnim.update(delta);
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,17 @@ 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.rogue.world.map.TileRenderContext;
|
||||
import mightypork.rogue.world.structs.ItemStack;
|
||||
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;
|
||||
import mightypork.util.files.ion.Streamable;
|
||||
|
||||
|
||||
public final class Tile implements Ionizable, Updateable {
|
||||
@@ -19,15 +22,19 @@ public final class Tile implements Ionizable, Updateable {
|
||||
public static final short ION_MARK = 700;
|
||||
|
||||
private transient TileModel model;
|
||||
|
||||
/**
|
||||
* Temporary storage for the model (unlocked door state, lever switched etc)
|
||||
*/
|
||||
public transient Object modelData;
|
||||
|
||||
/** Animator field for the model to use, if needed */
|
||||
public transient Animator anim;
|
||||
|
||||
private transient DroppedItemRenderer itemRenderer; // lazy
|
||||
|
||||
public int id;
|
||||
|
||||
public ItemStack items = new ItemStack();
|
||||
|
||||
public boolean[] flags;
|
||||
public int[] numbers;
|
||||
private final Stack<Item> items = new Stack<>();
|
||||
|
||||
|
||||
public Tile(int id)
|
||||
@@ -36,12 +43,6 @@ public final class Tile implements Ionizable, Updateable {
|
||||
}
|
||||
|
||||
|
||||
@IonConstructor
|
||||
public Tile()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public Tile(TileModel model)
|
||||
{
|
||||
this.model = model;
|
||||
@@ -49,12 +50,18 @@ public final class Tile implements Ionizable, Updateable {
|
||||
}
|
||||
|
||||
|
||||
@IonConstructor
|
||||
public Tile()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public void render(TileRenderContext context)
|
||||
{
|
||||
model.render(context);
|
||||
|
||||
if (!items.isEmpty()) {
|
||||
items.peek().renderOnTile(context);
|
||||
getItemRenderer().render(items.peek(), context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,17 +71,15 @@ public final class Tile implements Ionizable, Updateable {
|
||||
{
|
||||
if (model.isNullTile()) throw new RuntimeException("Cannot save null tile.");
|
||||
|
||||
Ion.writeShort(out, (short) id);
|
||||
Ion.writeShort(out, (short) id); // tile ID
|
||||
Ion.writeSequence(out, items); // if empty, writes single END mark
|
||||
|
||||
byte written = 0;
|
||||
if (flags != null) written |= 1;
|
||||
if (numbers != null) written |= 2;
|
||||
if (items != null && !items.isEmpty()) written |= 4;
|
||||
Ion.writeByte(out, written);
|
||||
|
||||
if ((written & 1) != 0) Ion.writeBooleanArray(out, flags);
|
||||
if ((written & 2) != 0) Ion.writeIntArray(out, numbers);
|
||||
if ((written & 4) != 0) Ion.writeObject(out, items);
|
||||
// models with metadata can save their stuff
|
||||
if (model.hasMetadata()) {
|
||||
IonBundle ib = new IonBundle();
|
||||
model.saveMetadata(this, ib);
|
||||
Ion.writeObject(out, ib);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,23 +88,18 @@ public final class Tile implements Ionizable, Updateable {
|
||||
{
|
||||
id = Ion.readShort(in);
|
||||
|
||||
final byte written = Ion.readByte(in);
|
||||
|
||||
if ((written & 1) != 0) flags = Ion.readBooleanArray(in);
|
||||
if ((written & 2) != 0) numbers = Ion.readIntArray(in);
|
||||
if ((written & 4) != 0) items = (ItemStack) Ion.readObject(in);
|
||||
|
||||
// renew model
|
||||
// check if model is changed (can happen)
|
||||
if (model == null || id != model.id) {
|
||||
model = Tiles.get(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public short getIonMark()
|
||||
{
|
||||
return ION_MARK;
|
||||
|
||||
Ion.readSequence(in, items); // if END is found, nothing is read.
|
||||
|
||||
// load model's stuff
|
||||
if (model.hasMetadata()) {
|
||||
IonBundle ib = (IonBundle) Ion.readObject(in);
|
||||
model.loadMetadata(this, ib);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -108,14 +108,36 @@ public final class Tile implements Ionizable, Updateable {
|
||||
{
|
||||
model.update(this, delta);
|
||||
if (!items.isEmpty()) {
|
||||
items.peek().update(delta);
|
||||
getItemRenderer().update(delta);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private DroppedItemRenderer getItemRenderer()
|
||||
{
|
||||
if (itemRenderer == null) {
|
||||
itemRenderer = new DroppedItemRenderer();
|
||||
}
|
||||
|
||||
return itemRenderer;
|
||||
}
|
||||
|
||||
|
||||
public TileModel getModel()
|
||||
{
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasItems()
|
||||
{
|
||||
return !items.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public short getIonMark()
|
||||
{
|
||||
return ION_MARK;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package mightypork.rogue.world.tile;
|
||||
|
||||
import mightypork.rogue.world.map.TileRenderContext;
|
||||
import mightypork.util.annotations.DefaultImpl;
|
||||
import mightypork.util.files.ion.IonBundle;
|
||||
|
||||
|
||||
/**
|
||||
@@ -76,4 +77,31 @@ public abstract class TileModel {
|
||||
*/
|
||||
public abstract void update(Tile tile, double delta);
|
||||
|
||||
|
||||
/**
|
||||
* Store tile metadata (door lock state etc)
|
||||
*
|
||||
* @param tile stored tile
|
||||
* @param ib written data bundle
|
||||
*/
|
||||
public abstract void saveMetadata(Tile tile, IonBundle ib);
|
||||
|
||||
|
||||
/**
|
||||
* Load from an IonBundle. The bundle is guaranteed to not be null, but
|
||||
* could be empty.
|
||||
*
|
||||
* @param tile loaded tile
|
||||
* @param ib item data bundle
|
||||
*/
|
||||
public abstract void loadMetadata(Tile tile, IonBundle ib);
|
||||
|
||||
|
||||
/**
|
||||
* True if this tile's data should be saved/loaded.<br>
|
||||
* Must be a constant value.
|
||||
*
|
||||
* @return has data
|
||||
*/
|
||||
public abstract boolean hasMetadata();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package mightypork.rogue.world.tile.models;
|
||||
import mightypork.rogue.world.map.TileRenderContext;
|
||||
import mightypork.rogue.world.tile.Tile;
|
||||
import mightypork.rogue.world.tile.TileModel;
|
||||
import mightypork.util.files.ion.IonBundle;
|
||||
|
||||
|
||||
/**
|
||||
@@ -58,4 +59,20 @@ public abstract class AbstractNullTile extends TileModel {
|
||||
return inst;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMetadata()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadMetadata(Tile tile, IonBundle ib)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveMetadata(Tile tile, IonBundle ib)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package mightypork.rogue.world.tile.models;
|
||||
|
||||
|
||||
/**
|
||||
* Template for floor tiles with no metadata
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class Floor extends SimpleTile {
|
||||
|
||||
public Floor(int id, String sheetKey)
|
||||
|
||||
@@ -8,8 +8,14 @@ import mightypork.rogue.world.map.TileRenderContext;
|
||||
import mightypork.rogue.world.tile.Tile;
|
||||
import mightypork.rogue.world.tile.TileModel;
|
||||
import mightypork.util.annotations.DefaultImpl;
|
||||
import mightypork.util.files.ion.IonBundle;
|
||||
|
||||
|
||||
/**
|
||||
* Basic implementation of a tile with coord-random texture and no animation.
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public abstract class SimpleTile extends TileModel {
|
||||
|
||||
protected final TxSheet sheet;
|
||||
@@ -36,8 +42,10 @@ public abstract class SimpleTile extends TileModel {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Items can override this if their walkability changes based on something
|
||||
*/
|
||||
@Override
|
||||
@DefaultImpl
|
||||
public boolean isWalkable(Tile tile)
|
||||
{
|
||||
return isPotentiallyWalkable();
|
||||
@@ -47,4 +55,25 @@ public abstract class SimpleTile extends TileModel {
|
||||
@Override
|
||||
public abstract boolean isPotentiallyWalkable();
|
||||
|
||||
|
||||
@Override
|
||||
@DefaultImpl
|
||||
public boolean hasMetadata()
|
||||
{
|
||||
return false; // it's a SIMPLE tile
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@DefaultImpl
|
||||
public void loadMetadata(Tile tile, IonBundle ib)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@DefaultImpl
|
||||
public void saveMetadata(Tile tile, IonBundle ib)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package mightypork.rogue.world.tile.models;
|
||||
|
||||
|
||||
/**
|
||||
* Template for wall tiles with no metadata
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class Wall extends SimpleTile {
|
||||
|
||||
public Wall(int id, String sheetKey)
|
||||
|
||||
Reference in New Issue
Block a user