parent
							
								
									b70279acd5
								
							
						
					
					
						commit
						db3da1554d
					
				
									
										Binary file not shown.
									
								
							
						@ -0,0 +1,84 @@ | 
				
			||||
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 isPotentiallyWalkable() | 
				
			||||
	{ | 
				
			||||
		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) | 
				
			||||
	{ | 
				
			||||
		//
 | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
} | 
				
			||||
@ -0,0 +1,46 @@ | 
				
			||||
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(); | 
				
			||||
		} | 
				
			||||
	} | 
				
			||||
} | 
				
			||||
					Loading…
					
					
				
		Reference in new issue