use of org.pepsoft.util.swing.TiledImageViewer in project WorldPainter by Captain-Chaos.
the class TileFactoryPreviewer method main.
public static void main(String[] args) {
final long seed;
if (args.length > 0) {
seed = Long.parseLong(args[0]);
} else {
seed = new Random().nextLong();
}
// final ExperimentalTileFactory tileFactory = new ExperimentalTileFactory(DEFAULT_MAX_HEIGHT_2);
// final HeightMapTileFactory tileFactory = TileFactoryFactory.createNoiseTileFactory(Terrain.GRASS, World2.DEFAULT_MAX_HEIGHT, 58, 62, false, true, 20.0f, 1.0);
// HeightMap oceanFloor = new ConstantHeightMap(40f);
// HeightMap continent;
// // continent = new NinePatchHeightMap(200, 100, 50, 58f);
// continent = new NinePatchHeightMap(0, 1000, 50, 22f);
// HeightMap hills = new ProductHeightMap(
// new NoiseHeightMap(1.0f, 10f, 1),
// new SumHeightMap(
// new NoiseHeightMap(20.0f, 1.0f, 2),
// new ConstantHeightMap(-5f)));
// continent = new SumHeightMap(
// new SumHeightMap(
// oceanFloor,
// continent),
// hills);
// HeightMap mountainsLimit = new NinePatchHeightMap(0, 1000, 200, 1f);
// HeightMap mountains = new ProductHeightMap(
// new ProductHeightMap(
// new NoiseHeightMap(1.0f, 10f, 1),
// mountainsLimit),
// new NoiseHeightMap(256f, 5f, 4));
// HeightMap heightMap = new MaximisingHeightMap(continent, mountains);
// final HeightMapTileFactory tileFactory = new HeightMapTileFactory(seed, heightMap, 256, false, new FancyTheme(256, 62, heightMap));
final HeightMapTileFactory tileFactory = TileFactoryFactory.createFancyTileFactory(seed, Terrain.GRASS, Constants.DEFAULT_MAX_HEIGHT_2, 62, 58, false, 20f, 1.0);
// SortedMap<Integer, Terrain> terrainRanges = tileFactory.getTerrainRanges();
// terrainRanges.clear();
// terrainRanges.put( -1, Terrain.DIRT);
// terrainRanges.put( 64, Terrain.GRASS);
// terrainRanges.put(128, Terrain.ROCK);
// terrainRanges.put(192, Terrain.DEEP_SNOW);
// tileFactory.setTerrainRanges(terrainRanges);
final org.pepsoft.worldpainter.TileProvider tileProvider = new org.pepsoft.worldpainter.TileProvider() {
@Override
public Rectangle getExtent() {
// Tile factories are endless
return null;
}
@Override
public boolean isTilePresent(int x, int y) {
// Tile factories are endless and have no holes
return true;
}
@Override
public Tile getTile(int x, int y) {
Point coords = new Point(x, y);
synchronized (cache) {
Tile tile = cache.get(coords);
if (tile == null) {
tile = tileFactory.createTile(x, y);
cache.put(coords, tile);
}
return tile;
}
}
private final Map<Point, Tile> cache = new HashMap<>();
};
Terrain.setCustomMaterial(0, new MixedMaterial("Dirt/Gravel", new Row[] { new Row(Material.DIRT, 750, 1.0f), new Row(Material.GRAVEL, 250, 1.0f) }, Minecraft1_2BiomeScheme.BIOME_PLAINS, null, 1.0f));
Terrain.setCustomMaterial(1, new MixedMaterial("Stone/Gravel", new Row[] { new Row(Material.STONE, 750, 1.0f), new Row(Material.GRAVEL, 250, 1.0f) }, Minecraft1_2BiomeScheme.BIOME_PLAINS, null, 1.0f));
TiledImageViewer viewer = new TiledImageViewer();
JFrame frame = new JFrame("TileFactory Previewer");
viewer.setTileProvider(new WPTileProvider(tileProvider, new DynMapColourScheme("default", true), new AutoBiomeScheme(null), null, Collections.singleton((Layer) Biome.INSTANCE), true, 10, TileRenderer.LightOrigin.NORTHWEST, false, null));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(viewer, BorderLayout.CENTER);
frame.setSize(1000, 800);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
use of org.pepsoft.util.swing.TiledImageViewer in project WorldPainter by Captain-Chaos.
the class MapViewer method main.
public static void main(String[] args) throws IOException {
File mySavesDir = null;
File minecraftDir = MinecraftUtil.findMinecraftDir();
if (minecraftDir != null) {
mySavesDir = new File(minecraftDir, "saves");
}
File levelDatFile = FileUtils.selectFileForOpen(null, "Select Minecraft map level.dat file", mySavesDir, new FileFilter() {
@Override
public boolean accept(File f) {
return f.isDirectory() || f.getName().equalsIgnoreCase("level.dat");
}
@Override
public String getDescription() {
return "Minecraft levels (level.dat)";
}
});
if (levelDatFile != null) {
final File worldDir = levelDatFile.getParentFile();
TileProvider tileProvider = new MinecraftMapTileProvider(worldDir);
JFrame frame = new JFrame("Map Viewer");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final TiledImageViewer viewer = new TiledImageViewer(true, Math.max(Runtime.getRuntime().availableProcessors() - 1, 1), true);
viewer.setTileProvider(tileProvider);
viewer.addMouseWheelListener(e -> {
int zoom = viewer.getZoom();
zoom -= e.getWheelRotation();
// System.out.println("Setting zoom to " + zoom);
viewer.setZoom(zoom);
});
frame.getContentPane().add(viewer, BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
Aggregations