parent
							
								
									65ad97994b
								
							
						
					
					
						commit
						8872fd3f5f
					
				| @ -0,0 +1,32 @@ | |||||||
|  | package mightypork.rogue.screens.ingame; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | import java.util.Random; | ||||||
|  | 
 | ||||||
|  | import mightypork.gamecore.gui.screens.Screen; | ||||||
|  | import mightypork.gamecore.gui.screens.ScreenLayer; | ||||||
|  | import mightypork.rogue.world.MapGenerator; | ||||||
|  | import mightypork.rogue.world.World; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | public class WorldLayer extends ScreenLayer { | ||||||
|  | 	 | ||||||
|  | 	public WorldLayer(Screen screen) | ||||||
|  | 	{ | ||||||
|  | 		super(screen); | ||||||
|  | 		 | ||||||
|  | 		Random rand = new Random(); | ||||||
|  | 		World w = MapGenerator.createWorld(rand.nextLong()); | ||||||
|  | 		 | ||||||
|  | 		WorldRenderer wr = new WorldRenderer(w); | ||||||
|  | 		wr.setRect(root); | ||||||
|  | 		root.add(wr); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public int getPriority() | ||||||
|  | 	{ | ||||||
|  | 		return -1; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | } | ||||||
| @ -0,0 +1,68 @@ | |||||||
|  | package mightypork.rogue.screens.ingame; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | import mightypork.gamecore.control.events.MouseButtonEvent; | ||||||
|  | import mightypork.gamecore.gui.components.InputComponent; | ||||||
|  | import mightypork.gamecore.render.Render; | ||||||
|  | import mightypork.rogue.world.World; | ||||||
|  | import mightypork.util.constraints.num.Num; | ||||||
|  | import mightypork.util.constraints.rect.Rect; | ||||||
|  | import mightypork.util.control.timing.Updateable; | ||||||
|  | import mightypork.util.math.color.PAL16; | ||||||
|  | import mightypork.util.math.color.RGB; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | public class WorldRenderer extends InputComponent implements Updateable { | ||||||
|  | 	 | ||||||
|  | 	private final World world; | ||||||
|  | 	private final Rect rightShadow; | ||||||
|  | 	private final Rect leftShadow; | ||||||
|  | 	private final Rect topShadow; | ||||||
|  | 	private final Rect bottomShadow; | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	public WorldRenderer(World world) | ||||||
|  | 	{ | ||||||
|  | 		this.world = world; | ||||||
|  | 		 | ||||||
|  | 		final Num h = height(); | ||||||
|  | 		final Num w = width(); | ||||||
|  | 		final Num minWH = w.min(h).max(700); | ||||||
|  | 				 | ||||||
|  | 		Num grX = w.perc(30); | ||||||
|  | 		Num grY = h.perc(20); | ||||||
|  | 		 | ||||||
|  | 		leftShadow = leftEdge().growRight(grX); | ||||||
|  | 		rightShadow = rightEdge().growLeft(grX); | ||||||
|  | 		topShadow = topEdge().growDown(grY); | ||||||
|  | 		bottomShadow = bottomEdge().growUp(grY).moveY(minWH.perc(-6)); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public void receive(MouseButtonEvent event) | ||||||
|  | 	{ | ||||||
|  | 		System.out.println("world clciked, yo"); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	protected void renderComponent() | ||||||
|  | 	{		 | ||||||
|  | 		world.render(this, 8, 6, 64); | ||||||
|  | 		 | ||||||
|  | 		Render.quadGradH(leftShadow, RGB.BLACK, RGB.NONE); | ||||||
|  | 		Render.quadGradH(rightShadow, RGB.NONE, RGB.BLACK); | ||||||
|  | 		 | ||||||
|  | 		Render.quadGradV(topShadow, RGB.BLACK, RGB.NONE); | ||||||
|  | 		Render.quadGradV(bottomShadow, RGB.NONE, RGB.BLACK); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public void update(double delta) | ||||||
|  | 	{ | ||||||
|  | 		world.update(delta); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | } | ||||||
| @ -0,0 +1,83 @@ | |||||||
|  | package mightypork.rogue.world; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | import java.io.IOException; | ||||||
|  | import java.io.InputStream; | ||||||
|  | import java.io.OutputStream; | ||||||
|  | 
 | ||||||
|  | import mightypork.util.files.ion.Ion; | ||||||
|  | import mightypork.util.files.ion.IonBundle; | ||||||
|  | import mightypork.util.files.ion.IonConstructor; | ||||||
|  | import mightypork.util.files.ion.Ionizable; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Player info | ||||||
|  |  *  | ||||||
|  |  * @author MightyPork | ||||||
|  |  */ | ||||||
|  | public class LocalPlayer implements Ionizable, MapObserver { | ||||||
|  | 	 | ||||||
|  | 	public static final short ION_MARK = 708; | ||||||
|  | 	 | ||||||
|  | 	public WorldPos position = new WorldPos(); | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@IonConstructor | ||||||
|  | 	public LocalPlayer() | ||||||
|  | 	{ | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	public LocalPlayer(int x, int y, int floor) | ||||||
|  | 	{ | ||||||
|  | 		this.position.setTo(x, y, floor); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	public LocalPlayer(WorldPos pos) | ||||||
|  | 	{ | ||||||
|  | 		this.position = pos; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public void load(InputStream in) throws IOException | ||||||
|  | 	{ | ||||||
|  | 		IonBundle ib = (IonBundle) Ion.readObject(in); | ||||||
|  | 		 | ||||||
|  | 		position = ib.get("pos", position); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public void save(OutputStream out) throws IOException | ||||||
|  | 	{ | ||||||
|  | 		IonBundle ib = new IonBundle(); | ||||||
|  | 		 | ||||||
|  | 		ib.put("pos", position); | ||||||
|  | 		 | ||||||
|  | 		Ion.writeObject(out, ib); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public short getIonMark() | ||||||
|  | 	{ | ||||||
|  | 		return ION_MARK; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public WorldPos getPosition() | ||||||
|  | 	{ | ||||||
|  | 		return position; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public int getViewRange() | ||||||
|  | 	{ | ||||||
|  | 		return 15; | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @ -0,0 +1,54 @@ | |||||||
|  | package mightypork.rogue.world; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | import java.util.Random; | ||||||
|  | 
 | ||||||
|  | import mightypork.rogue.world.map.LevelMap; | ||||||
|  | import mightypork.rogue.world.tile.Tiles; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | public class MapGenerator { | ||||||
|  | 	 | ||||||
|  | 	public static final Random rand = new Random(); | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	public static World createWorld(long seed) | ||||||
|  | 	{ | ||||||
|  | 		synchronized (rand) { | ||||||
|  | 			rand.setSeed(seed); | ||||||
|  | 			 | ||||||
|  | 			World w = new World(); | ||||||
|  | 			w.setSeed(seed); | ||||||
|  | 			 | ||||||
|  | 			int levels = 4 + rand.nextInt(6); | ||||||
|  | 			 | ||||||
|  | 			for (int i = 0; i < levels; i++) { | ||||||
|  | 				w.addLevel(createLevel(rand.nextLong())); | ||||||
|  | 			} | ||||||
|  | 			 | ||||||
|  | 			// TODO place on start position
 | ||||||
|  | 			w.setPlayer(new LocalPlayer(10, 10, 0)); | ||||||
|  | 			return w;	 | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	private static LevelMap createLevel(long seed) | ||||||
|  | 	{ | ||||||
|  | 		// TODO
 | ||||||
|  | 		 | ||||||
|  | 		LevelMap lm = new LevelMap(20, 20); | ||||||
|  | 		 | ||||||
|  | 		lm.fill(Tiles.CRYSTAL_FLOOR); | ||||||
|  | 		 | ||||||
|  | 		Random rand = new Random(); | ||||||
|  | 		rand.setSeed(seed); | ||||||
|  | 		 | ||||||
|  | 		for (int i = 0; i < 150; i++) { | ||||||
|  | 			lm.setTile(Tiles.CRYSTAL_WALL, rand.nextInt(20), rand.nextInt(20)); | ||||||
|  | 		} | ||||||
|  | 		 | ||||||
|  | 		return lm; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | } | ||||||
| @ -0,0 +1,22 @@ | |||||||
|  | package mightypork.rogue.world; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Player observing a map represented by an observer. | ||||||
|  |  *  | ||||||
|  |  * @author MightyPork | ||||||
|  |  */ | ||||||
|  | public interface MapObserver { | ||||||
|  | 	 | ||||||
|  | 	/** | ||||||
|  | 	 * @return observer's position | ||||||
|  | 	 */ | ||||||
|  | 	public WorldPos getPosition(); | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	/** | ||||||
|  | 	 * @return observed range (in tiles) | ||||||
|  | 	 */ | ||||||
|  | 	public int getViewRange(); | ||||||
|  | 	 | ||||||
|  | } | ||||||
| @ -0,0 +1,185 @@ | |||||||
|  | package mightypork.rogue.world; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | import java.io.IOException; | ||||||
|  | import java.io.InputStream; | ||||||
|  | import java.io.OutputStream; | ||||||
|  | import java.util.HashSet; | ||||||
|  | import java.util.Set; | ||||||
|  | 
 | ||||||
|  | import mightypork.gamecore.render.Render; | ||||||
|  | import mightypork.rogue.world.map.LevelMap; | ||||||
|  | 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.Vect; | ||||||
|  | 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.math.color.RGB; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | public class World implements Ionizable, Updateable { | ||||||
|  | 	 | ||||||
|  | 	public static final short ION_MARK = 706; | ||||||
|  | 	 | ||||||
|  | 	private LevelList levels = new LevelList(); | ||||||
|  | 	 | ||||||
|  | 	private LocalPlayer player = new LocalPlayer(); | ||||||
|  | 	 | ||||||
|  | 	private transient final Set<MapObserver> observers = new HashSet<>(); | ||||||
|  | 	 | ||||||
|  | 	private long seed; | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public void load(InputStream in) throws IOException | ||||||
|  | 	{ | ||||||
|  | 		// world data
 | ||||||
|  | 		IonBundle ib = (IonBundle) Ion.readObject(in); | ||||||
|  | 		player = ib.get("player", player); | ||||||
|  | 		levels = ib.get("levels", levels); | ||||||
|  | 		seed = ib.get("seed", seed); | ||||||
|  | 		 | ||||||
|  | 		// levels
 | ||||||
|  | 		Ion.readSequence(in, levels); | ||||||
|  | 		 | ||||||
|  | 		if (player == null) throw new CorruptedDataException("Null player in world."); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public void save(OutputStream out) throws IOException | ||||||
|  | 	{ | ||||||
|  | 		IonBundle ib = new IonBundle(); | ||||||
|  | 		ib.put("player", player); | ||||||
|  | 		ib.put("levels", levels); | ||||||
|  | 		ib.put("seed", seed); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	public void setPlayer(LocalPlayer player) | ||||||
|  | 	{ | ||||||
|  | 		removeObserver(this.player); | ||||||
|  | 		 | ||||||
|  | 		this.player = player; | ||||||
|  | 		 | ||||||
|  | 		addObserver(player); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	public void removeObserver(MapObserver observer) | ||||||
|  | 	{ | ||||||
|  | 		observers.remove(observer); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	public void addObserver(MapObserver observer) | ||||||
|  | 	{ | ||||||
|  | 		observers.add(observer); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	public void addLevel(LevelMap level) | ||||||
|  | 	{ | ||||||
|  | 		levels.add(level); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public short getIonMark() | ||||||
|  | 	{ | ||||||
|  | 		return ION_MARK; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public void update(double delta) | ||||||
|  | 	{ | ||||||
|  | 		for (int level = 0; level < levels.size(); level++) { | ||||||
|  | 			for (MapObserver observer : observers) { | ||||||
|  | 				if (observer.getPosition().floor == level) { | ||||||
|  | 					levels.get(level).update(observer, delta); | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	public LevelMap getLevelForObserver(MapObserver observer) | ||||||
|  | 	{ | ||||||
|  | 		return levels.get(observer.getPosition().floor); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	/** | ||||||
|  | 	 * Draw on screen | ||||||
|  | 	 *  | ||||||
|  | 	 * @param viewport rendering area on screen | ||||||
|  | 	 * @param xTiles Desired nr of tiles horizontally | ||||||
|  | 	 * @param yTiles Desired nr of tiles vertically | ||||||
|  | 	 * @param minSize minimum tile size | ||||||
|  | 	 */ | ||||||
|  | 	public void render(final RectBound viewport, final int yTiles, final int xTiles, final int minSize) | ||||||
|  | 	{ | ||||||
|  | 		LevelMap floor = getLevelForObserver(player); // TODO fractional movement
 | ||||||
|  | 		 | ||||||
|  | 		Rect r = viewport.getRect(); | ||||||
|  | 		double vpH = r.height().value(); | ||||||
|  | 		double vpW = r.width().value(); | ||||||
|  | 		 | ||||||
|  | 		// adjust tile size to fit desired amount of tiles
 | ||||||
|  | 		 | ||||||
|  | 		double allowedSizeW = vpW / xTiles; | ||||||
|  | 		double allowedSizeH = vpH / yTiles; | ||||||
|  | 		int tileSize = (int) Math.round(Math.max(Math.min(allowedSizeH, allowedSizeW), minSize)); | ||||||
|  | 		 | ||||||
|  | 		tileSize -= tileSize % 16; | ||||||
|  | 		 | ||||||
|  | 		VectConst vpCenter = r.center().sub(tileSize * 0.5, tileSize).freeze(); // 0.5 to center, 1 to move up (down is teh navbar)
 | ||||||
|  | 		 | ||||||
|  | 		int playerX = player.getPosition().x; | ||||||
|  | 		int playerY = player.getPosition().y; | ||||||
|  | 		 | ||||||
|  | 		// total map area
 | ||||||
|  | 		//@formatter:off
 | ||||||
|  | 		RectConst mapRect = vpCenter.startRect().grow( | ||||||
|  | 				playerX*tileSize, | ||||||
|  | 				playerY*tileSize,//
 | ||||||
|  | 				(floor.getWidth() - playerX) * tileSize, | ||||||
|  | 				(floor.getHeight() - playerY) * tileSize | ||||||
|  | 		).freeze(); | ||||||
|  | 		//@formatter:on
 | ||||||
|  | 		 | ||||||
|  | 		// tiles to render
 | ||||||
|  | 		int x1 = (int) Math.floor(playerX - (vpW / tileSize)); | ||||||
|  | 		int y1 = (int) Math.floor(playerY - (vpH / tileSize)); | ||||||
|  | 		int x2 = (int) Math.ceil(playerX + (vpW / tileSize)); | ||||||
|  | 		int y2 = (int) Math.ceil(playerY + (vpH / tileSize)); | ||||||
|  | 		 | ||||||
|  | 		TileRenderContext trc = new TileRenderContext(floor, mapRect); //-tileSize*0.5
 | ||||||
|  | 		for (trc.y = y1; trc.y <= y2; trc.y++) { | ||||||
|  | 			for (trc.x = x1; trc.x <= x2; trc.x++) { | ||||||
|  | 				trc.render(); | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	public void setSeed(long seed) | ||||||
|  | 	{ | ||||||
|  | 		this.seed = seed; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	public long getSeed() | ||||||
|  | 	{ | ||||||
|  | 		return seed; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | } | ||||||
| @ -0,0 +1,71 @@ | |||||||
|  | package mightypork.rogue.world; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | import java.io.IOException; | ||||||
|  | import java.io.InputStream; | ||||||
|  | import java.io.OutputStream; | ||||||
|  | 
 | ||||||
|  | import mightypork.util.files.ion.Ion; | ||||||
|  | import mightypork.util.files.ion.IonConstructor; | ||||||
|  | import mightypork.util.files.ion.Ionizable; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * A simple dimension data object | ||||||
|  |  *  | ||||||
|  |  * @author MightyPork | ||||||
|  |  */ | ||||||
|  | public class WorldPos implements Ionizable { | ||||||
|  | 	 | ||||||
|  | 	public static final short ION_MARK = 707; | ||||||
|  | 	 | ||||||
|  | 	public int x, y, floor; | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	public WorldPos(int x, int y, int z) | ||||||
|  | 	{ | ||||||
|  | 		super(); | ||||||
|  | 		this.x = x; | ||||||
|  | 		this.y = y; | ||||||
|  | 		this.floor = z; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@IonConstructor | ||||||
|  | 	public WorldPos() | ||||||
|  | 	{ | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public void load(InputStream in) throws IOException | ||||||
|  | 	{ | ||||||
|  | 		x = Ion.readInt(in); | ||||||
|  | 		y = Ion.readInt(in); | ||||||
|  | 		floor = Ion.readInt(in); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public void save(OutputStream out) throws IOException | ||||||
|  | 	{ | ||||||
|  | 		Ion.writeInt(out, x); | ||||||
|  | 		Ion.writeInt(out, y); | ||||||
|  | 		Ion.writeInt(out, floor); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public short getIonMark() | ||||||
|  | 	{ | ||||||
|  | 		return ION_MARK; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	public void setTo(int x, int y, int z) | ||||||
|  | 	{ | ||||||
|  | 		this.x = x; | ||||||
|  | 		this.y = y; | ||||||
|  | 		this.floor = z; | ||||||
|  | 	} | ||||||
|  | } | ||||||
| @ -0,0 +1,40 @@ | |||||||
|  | package mightypork.rogue.world.map; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | import mightypork.rogue.world.tile.Tile; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Access interface for a level map. | ||||||
|  |  *  | ||||||
|  |  * @author MightyPork | ||||||
|  |  */ | ||||||
|  | public interface MapAccess { | ||||||
|  | 	 | ||||||
|  | 	/** | ||||||
|  | 	 * Ge tile at X,Y | ||||||
|  | 	 *  | ||||||
|  | 	 * @param x | ||||||
|  | 	 * @param y | ||||||
|  | 	 * @return tile | ||||||
|  | 	 */ | ||||||
|  | 	Tile getTile(int x, int y); | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	/** | ||||||
|  | 	 * @return map width in tiles | ||||||
|  | 	 */ | ||||||
|  | 	int getWidth(); | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	/** | ||||||
|  | 	 * @return map height in tiles | ||||||
|  | 	 */ | ||||||
|  | 	int getHeight(); | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	/** | ||||||
|  | 	 * @return map seed | ||||||
|  | 	 */ | ||||||
|  | 	long getSeed(); | ||||||
|  | } | ||||||
| @ -0,0 +1,19 @@ | |||||||
|  | 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; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | } | ||||||
| @ -0,0 +1,18 @@ | |||||||
|  | package mightypork.rogue.world.structs; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | import mightypork.rogue.world.map.LevelMap; | ||||||
|  | import mightypork.util.files.ion.templates.IonizableArrayList; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | public class LevelList extends IonizableArrayList<LevelMap> { | ||||||
|  | 	 | ||||||
|  | 	public static final short ION_MARK = 709; | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public short getIonMark() | ||||||
|  | 	{ | ||||||
|  | 		return ION_MARK; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | } | ||||||
| @ -1,13 +0,0 @@ | |||||||
| package mightypork.rogue.world.tile; |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| public interface TileGrid { |  | ||||||
| 	 |  | ||||||
| 	Tile getTile(int x, int y); |  | ||||||
| 	 |  | ||||||
| 	 |  | ||||||
| 	int getWidth(); |  | ||||||
| 	 |  | ||||||
| 	 |  | ||||||
| 	int getHeight(); |  | ||||||
| } |  | ||||||
| @ -0,0 +1,18 @@ | |||||||
|  | package mightypork.rogue.world.tile.models; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | public class NullFloor extends AbstractNullTile { | ||||||
|  | 	 | ||||||
|  | 	public NullFloor(int id) | ||||||
|  | 	{ | ||||||
|  | 		super(id); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public boolean isPotentiallyWalkable() | ||||||
|  | 	{ | ||||||
|  | 		return true; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | } | ||||||
| @ -0,0 +1,18 @@ | |||||||
|  | package mightypork.rogue.world.tile.models; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | public class NullWall extends AbstractNullTile { | ||||||
|  | 	 | ||||||
|  | 	public NullWall(int id) | ||||||
|  | 	{ | ||||||
|  | 		super(id); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public boolean isPotentiallyWalkable() | ||||||
|  | 	{ | ||||||
|  | 		return false; | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | } | ||||||
| @ -0,0 +1,6 @@ | |||||||
|  | package mightypork.test; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | public class testworldtofile { | ||||||
|  | 	 | ||||||
|  | } | ||||||
| @ -0,0 +1,36 @@ | |||||||
|  | package mightypork.util.error; | ||||||
|  | 
 | ||||||
|  | import java.io.IOException; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * To be used when a data could not be read successfully. | ||||||
|  |  *  | ||||||
|  |  * @author MightyPork | ||||||
|  |  */ | ||||||
|  | public class CorruptedDataException extends IOException { | ||||||
|  | 	 | ||||||
|  | 	public CorruptedDataException() | ||||||
|  | 	{ | ||||||
|  | 		super(); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	public CorruptedDataException(String message, Throwable cause) | ||||||
|  | 	{ | ||||||
|  | 		super(message, cause); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	public CorruptedDataException(String message) | ||||||
|  | 	{ | ||||||
|  | 		super(message); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	public CorruptedDataException(Throwable cause) | ||||||
|  | 	{ | ||||||
|  | 		super(cause); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | } | ||||||
| @ -0,0 +1,28 @@ | |||||||
|  | package mightypork.util.files.ion.templates; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | import java.io.IOException; | ||||||
|  | import java.io.InputStream; | ||||||
|  | import java.io.OutputStream; | ||||||
|  | import java.util.ArrayList; | ||||||
|  | 
 | ||||||
|  | import mightypork.util.files.ion.Ion; | ||||||
|  | import mightypork.util.files.ion.Ionizable; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | public abstract class IonizableArrayList<E> extends ArrayList<E> implements Ionizable { | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public void load(InputStream in) throws IOException | ||||||
|  | 	{ | ||||||
|  | 		Ion.readSequence(in, this); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public void save(OutputStream out) throws IOException | ||||||
|  | 	{ | ||||||
|  | 		Ion.writeSequence(out, this); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | } | ||||||
| @ -0,0 +1,28 @@ | |||||||
|  | package mightypork.util.files.ion.templates; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | import java.io.IOException; | ||||||
|  | import java.io.InputStream; | ||||||
|  | import java.io.OutputStream; | ||||||
|  | import java.util.HashMap; | ||||||
|  | 
 | ||||||
|  | import mightypork.util.files.ion.Ion; | ||||||
|  | import mightypork.util.files.ion.Ionizable; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | public abstract class IonizableHashMap<K, V> extends HashMap<K, V> implements Ionizable { | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public void load(InputStream in) throws IOException | ||||||
|  | 	{ | ||||||
|  | 		Ion.readMap(in, this); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public void save(OutputStream out) throws IOException | ||||||
|  | 	{ | ||||||
|  | 		Ion.writeMap(out, this); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | } | ||||||
| @ -0,0 +1,28 @@ | |||||||
|  | package mightypork.util.files.ion.templates; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | import java.io.IOException; | ||||||
|  | import java.io.InputStream; | ||||||
|  | import java.io.OutputStream; | ||||||
|  | import java.util.HashSet; | ||||||
|  | 
 | ||||||
|  | import mightypork.util.files.ion.Ion; | ||||||
|  | import mightypork.util.files.ion.Ionizable; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | public abstract class IonizableHashSet<E> extends HashSet<E> implements Ionizable { | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public void load(InputStream in) throws IOException | ||||||
|  | 	{ | ||||||
|  | 		Ion.readSequence(in, this); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public void save(OutputStream out) throws IOException | ||||||
|  | 	{ | ||||||
|  | 		Ion.writeSequence(out, this); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | } | ||||||
| @ -0,0 +1,28 @@ | |||||||
|  | package mightypork.util.files.ion.templates; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | import java.io.IOException; | ||||||
|  | import java.io.InputStream; | ||||||
|  | import java.io.OutputStream; | ||||||
|  | import java.util.LinkedHashMap; | ||||||
|  | 
 | ||||||
|  | import mightypork.util.files.ion.Ion; | ||||||
|  | import mightypork.util.files.ion.Ionizable; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | public abstract class IonizableLinkedHashMap<K, V> extends LinkedHashMap<K, V> implements Ionizable { | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public void load(InputStream in) throws IOException | ||||||
|  | 	{ | ||||||
|  | 		Ion.readMap(in, this); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public void save(OutputStream out) throws IOException | ||||||
|  | 	{ | ||||||
|  | 		Ion.writeMap(out, this); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | } | ||||||
| @ -0,0 +1,28 @@ | |||||||
|  | package mightypork.util.files.ion.templates; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | import java.io.IOException; | ||||||
|  | import java.io.InputStream; | ||||||
|  | import java.io.OutputStream; | ||||||
|  | import java.util.LinkedList; | ||||||
|  | 
 | ||||||
|  | import mightypork.util.files.ion.Ion; | ||||||
|  | import mightypork.util.files.ion.Ionizable; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | public abstract class IonizableLinkedList<E> extends LinkedList<E> implements Ionizable { | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public void load(InputStream in) throws IOException | ||||||
|  | 	{ | ||||||
|  | 		Ion.readSequence(in, this); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public void save(OutputStream out) throws IOException | ||||||
|  | 	{ | ||||||
|  | 		Ion.writeSequence(out, this); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | } | ||||||
| @ -0,0 +1,28 @@ | |||||||
|  | package mightypork.util.files.ion.templates; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | import java.io.IOException; | ||||||
|  | import java.io.InputStream; | ||||||
|  | import java.io.OutputStream; | ||||||
|  | import java.util.TreeSet; | ||||||
|  | 
 | ||||||
|  | import mightypork.util.files.ion.Ion; | ||||||
|  | import mightypork.util.files.ion.Ionizable; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | public abstract class IonizableTreeSet<E> extends TreeSet<E> implements Ionizable { | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public void load(InputStream in) throws IOException | ||||||
|  | 	{ | ||||||
|  | 		Ion.readSequence(in, this); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | 	 | ||||||
|  | 	@Override | ||||||
|  | 	public void save(OutputStream out) throws IOException | ||||||
|  | 	{ | ||||||
|  | 		Ion.writeSequence(out, this); | ||||||
|  | 	} | ||||||
|  | 	 | ||||||
|  | } | ||||||
					Loading…
					
					
				
		Reference in new issue