Search in sources :

Example 6 with Tile

use of org.pepsoft.worldpainter.Tile in project WorldPainter by Captain-Chaos.

the class InfoPanel method updateInfo.

void updateInfo() {
    setTextIfDifferent(labelCoords, worldCoords.x + "," + worldCoords.y);
    Dimension dim = view.getDimension();
    if (dim == null) {
        clearFields();
        return;
    }
    Tile tile = dim.getTile(worldCoords.x >> TILE_SIZE_BITS, worldCoords.y >> TILE_SIZE_BITS);
    if (tile == null) {
        clearFields();
        return;
    }
    final int x = worldCoords.x & TILE_SIZE_MASK, y = worldCoords.y & TILE_SIZE_MASK;
    if (tile.getBitLayerValue(NotPresent.INSTANCE, x, y)) {
        clearFields();
        return;
    }
    fieldsClear = false;
    float height = tile.getHeight(x, y);
    setTextIfDifferent(labelHeight, heightFormatter.format(height));
    int intHeight = (int) (height + 0.5f);
    int waterLevel = tile.getWaterLevel(x, y);
    setTextIfDifferent(labelWaterLevel, Integer.toString(waterLevel));
    if (waterLevel > intHeight) {
        setTextIfDifferent(labelWaterDepth, Integer.toString(waterLevel - intHeight));
    } else {
        setTextIfDifferent(labelWaterDepth, null);
    }
    float slope;
    if ((x > 0) && (x < TILE_SIZE - 1) && (y > 0) && (y < TILE_SIZE - 1)) {
        slope = tile.getSlope(x, y);
    } else {
        slope = dim.getSlope(worldCoords.x, worldCoords.y);
    }
    setTextIfDifferent(labelSlope, ((int) (Math.atan(slope) * 180 / Math.PI + 0.5)) + "°");
    Terrain terrain = tile.getTerrain(x, y);
    if (terrain != currentTerrain) {
        labelTerrain.setText(terrain.getName());
        labelTerrain.setIcon(new ImageIcon(terrain.getIcon(view.getColourScheme())));
        currentTerrain = terrain;
    }
    int biome = tile.getLayerValue(Biome.INSTANCE, x, y);
    boolean automaticBiome = false;
    if (biome == 255) {
        automaticBiome = true;
        biome = dim.getAutoBiome(tile, x, y);
    }
    if (biome < 0) {
        biome = Minecraft1_7Biomes.BIOME_PLAINS;
    }
    if ((automaticBiome != currentAutomaticBiome) || (biome != currentBiome)) {
        labelBiome.setText(biomeHelper.getBiomeName(biome) + " (" + biome + ")");
        labelBiome.setIcon(biomeHelper.getBiomeIcon(biome));
        checkBoxAutomaticBiome.setSelected(automaticBiome);
        currentAutomaticBiome = automaticBiome;
        currentBiome = biome;
    }
    Map<Layer, Integer> layerValues = tile.getLayersAt(x, y);
    if (layerValues != null) {
        checkBoxInSelection.setSelected(layerValues.containsKey(SelectionChunk.INSTANCE) || layerValues.containsKey(SelectionBlock.INSTANCE));
        layerValues.keySet().removeAll(HIDDEN_LAYERS);
        if (!layerValues.isEmpty()) {
            tableModel.update(layerValues);
        } else {
            tableModel.clear();
        }
    } else {
        checkBoxInSelection.setSelected(false);
        tableModel.clear();
    }
}
Also used : Terrain(org.pepsoft.worldpainter.Terrain) Tile(org.pepsoft.worldpainter.Tile) Dimension(org.pepsoft.worldpainter.Dimension)

Example 7 with Tile

use of org.pepsoft.worldpainter.Tile in project WorldPainter by Captain-Chaos.

the class BitLayerPaint method apply.

@Override
public void apply(Dimension dimension, int centreX, int centreY, float dynamicLevel) {
    if (brush.getRadius() == 0) {
        // Special case: if the radius is 0, assume that the user wants to paint complete pixels instead of trying
        // to apply the brush
        applyPixel(dimension, centreX, centreY);
        return;
    }
    final int effectiveRadius = brush.getEffectiveRadius();
    final int x1 = centreX - effectiveRadius, y1 = centreY - effectiveRadius, x2 = centreX + effectiveRadius, y2 = centreY + effectiveRadius;
    final int tileX1 = x1 >> TILE_SIZE_BITS, tileY1 = y1 >> TILE_SIZE_BITS, tileX2 = x2 >> TILE_SIZE_BITS, tileY2 = y2 >> TILE_SIZE_BITS;
    if ((tileX1 == tileX2) && (tileY1 == tileY2)) {
        // The bounding box of the brush is entirely on one tile; optimize by painting directly to the tile
        final Tile tile = dimension.getTileForEditing(tileX1, tileY1);
        if (tile == null) {
            return;
        }
        final int x1InTile = x1 & TILE_SIZE_MASK, y1InTile = y1 & TILE_SIZE_MASK, x2InTile = x2 & TILE_SIZE_MASK, y2InTile = y2 & TILE_SIZE_MASK;
        final int tileXInWorld = tileX1 << TILE_SIZE_BITS, tileYInWorld = tileY1 << TILE_SIZE_BITS;
        if (dither) {
            for (int y = y1InTile; y <= y2InTile; y++) {
                for (int x = x1InTile; x <= x2InTile; x++) {
                    final float strength = dynamicLevel * getStrength(centreX, centreY, tileXInWorld + x, tileYInWorld + y);
                    if ((strength > 0.95f) || (Math.random() < strength)) {
                        tile.setBitLayerValue(layer, x, y, true);
                    }
                }
            }
        } else {
            for (int y = y1InTile; y <= y2InTile; y++) {
                for (int x = x1InTile; x <= x2InTile; x++) {
                    final float strength = dynamicLevel * getFullStrength(centreX, centreY, tileXInWorld + x, tileYInWorld + y);
                    if (strength > 0.75f) {
                        tile.setBitLayerValue(layer, x, y, true);
                    }
                }
            }
        }
    } else {
        // The bounding box of the brush straddles more than one tile; paint to the dimension
        if (dither) {
            for (int y = y1; y <= y2; y++) {
                for (int x = x1; x <= x2; x++) {
                    final float strength = dynamicLevel * getStrength(centreX, centreY, x, y);
                    if ((strength > 0.95f) || (Math.random() < strength)) {
                        dimension.setBitLayerValueAt(layer, x, y, true);
                    }
                }
            }
        } else {
            for (int y = y1; y <= y2; y++) {
                for (int x = x1; x <= x2; x++) {
                    final float strength = dynamicLevel * getFullStrength(centreX, centreY, x, y);
                    if (strength > 0.75f) {
                        dimension.setBitLayerValueAt(layer, x, y, true);
                    }
                }
            }
        }
    }
}
Also used : Tile(org.pepsoft.worldpainter.Tile)

Example 8 with Tile

use of org.pepsoft.worldpainter.Tile in project WorldPainter by Captain-Chaos.

the class BitLayerPaint method remove.

@Override
public void remove(Dimension dimension, int centreX, int centreY, float dynamicLevel) {
    if (brush.getRadius() == 0) {
        // Special case: if the radius is 0, assume that the user wants to remove complete pixels instead of trying
        // to apply the brush
        removePixel(dimension, centreX, centreY);
        return;
    }
    final int effectiveRadius = brush.getEffectiveRadius();
    final int x1 = centreX - effectiveRadius, y1 = centreY - effectiveRadius, x2 = centreX + effectiveRadius, y2 = centreY + effectiveRadius;
    final int tileX1 = x1 >> TILE_SIZE_BITS, tileY1 = y1 >> TILE_SIZE_BITS, tileX2 = x2 >> TILE_SIZE_BITS, tileY2 = y2 >> TILE_SIZE_BITS;
    if ((tileX1 == tileX2) && (tileY1 == tileY2)) {
        // The bounding box of the brush is entirely on one tile; optimize by painting directly to the tile
        final Tile tile = dimension.getTileForEditing(tileX1, tileY1);
        if (tile == null) {
            return;
        }
        final int x1InTile = x1 & TILE_SIZE_MASK, y1InTile = y1 & TILE_SIZE_MASK, x2InTile = x2 & TILE_SIZE_MASK, y2InTile = y2 & TILE_SIZE_MASK;
        final int tileXInWorld = tileX1 << TILE_SIZE_BITS, tileYInWorld = tileY1 << TILE_SIZE_BITS;
        if (dither) {
            for (int y = y1InTile; y <= y2InTile; y++) {
                for (int x = x1InTile; x <= x2InTile; x++) {
                    final float strength = dynamicLevel * getFullStrength(centreX, centreY, tileXInWorld + x, tileYInWorld + y);
                    if ((strength > 0.95f) || (Math.random() < strength)) {
                        tile.setBitLayerValue(layer, x, y, false);
                    }
                }
            }
        } else {
            for (int y = y1InTile; y <= y2InTile; y++) {
                for (int x = x1InTile; x <= x2InTile; x++) {
                    final float strength = dynamicLevel * getFullStrength(centreX, centreY, tileXInWorld + x, tileYInWorld + y);
                    if (strength > 0.75f) {
                        tile.setBitLayerValue(layer, x, y, false);
                    }
                }
            }
        }
    } else {
        // The bounding box of the brush straddles more than one tile; paint to the dimension
        if (dither) {
            for (int y = y1; y <= y2; y++) {
                for (int x = x1; x <= x2; x++) {
                    final float strength = dynamicLevel * getFullStrength(centreX, centreY, x, y);
                    if ((strength > 0.95f) || (Math.random() < strength)) {
                        dimension.setBitLayerValueAt(layer, x, y, false);
                    }
                }
            }
        } else {
            for (int y = y1; y <= y2; y++) {
                for (int x = x1; x <= x2; x++) {
                    final float strength = dynamicLevel * getFullStrength(centreX, centreY, x, y);
                    if (strength > 0.75f) {
                        dimension.setBitLayerValueAt(layer, x, y, false);
                    }
                }
            }
        }
    }
}
Also used : Tile(org.pepsoft.worldpainter.Tile)

Example 9 with Tile

use of org.pepsoft.worldpainter.Tile in project WorldPainter by Captain-Chaos.

the class NibbleLayerPaint method applyPixel.

@Override
public void applyPixel(Dimension dimension, int x, int y) {
    final Tile tile = dimension.getTileForEditing(x >> TILE_SIZE_BITS, y >> TILE_SIZE_BITS);
    if (tile != null) {
        final int xInTile = x & TILE_SIZE_MASK, yInTile = y & TILE_SIZE_MASK;
        final int value = 1 + (int) (brush.getLevel() * 14 + 0.5f);
        if (tile.getLayerValue(layer, xInTile, yInTile) < value) {
            tile.setLayerValue(layer, xInTile, yInTile, value);
        }
    }
}
Also used : Tile(org.pepsoft.worldpainter.Tile)

Example 10 with Tile

use of org.pepsoft.worldpainter.Tile in project WorldPainter by Captain-Chaos.

the class NibbleLayerPaint method apply.

@Override
public void apply(Dimension dimension, int centreX, int centreY, float dynamicLevel) {
    if (brush.getRadius() == 0) {
        // Special case: if the radius is 0, assume that the user wants to paint complete pixels instead of trying
        // to apply the brush
        applyPixel(dimension, centreX, centreY);
        return;
    }
    final int effectiveRadius = brush.getEffectiveRadius();
    final int x1 = centreX - effectiveRadius, y1 = centreY - effectiveRadius, x2 = centreX + effectiveRadius, y2 = centreY + effectiveRadius;
    final int tileX1 = x1 >> TILE_SIZE_BITS, tileY1 = y1 >> TILE_SIZE_BITS, tileX2 = x2 >> TILE_SIZE_BITS, tileY2 = y2 >> TILE_SIZE_BITS;
    if ((tileX1 == tileX2) && (tileY1 == tileY2)) {
        // The bounding box of the brush is entirely on one tile; optimize by painting directly to the tile
        final Tile tile = dimension.getTileForEditing(tileX1, tileY1);
        if (tile == null) {
            return;
        }
        final int x1InTile = x1 & TILE_SIZE_MASK, y1InTile = y1 & TILE_SIZE_MASK, x2InTile = x2 & TILE_SIZE_MASK, y2InTile = y2 & TILE_SIZE_MASK;
        final int tileXInWorld = tileX1 << TILE_SIZE_BITS, tileYInWorld = tileY1 << TILE_SIZE_BITS;
        for (int y = y1InTile; y <= y2InTile; y++) {
            for (int x = x1InTile; x <= x2InTile; x++) {
                final int currentValue = tile.getLayerValue(layer, x, y);
                final float strength = dynamicLevel * getStrength(centreX, centreY, tileXInWorld + x, tileYInWorld + y);
                if (strength != 0f) {
                    int targetValue = 1 + (int) (strength * 14 + 0.5f);
                    if (targetValue > currentValue) {
                        tile.setLayerValue(layer, x, y, targetValue);
                    }
                }
            }
        }
    } else {
        // The bounding box of the brush straddles more than one tile; paint to the dimension
        for (int y = y1; y <= y2; y++) {
            for (int x = x1; x <= x2; x++) {
                final int currentValue = dimension.getLayerValueAt(layer, x, y);
                final float strength = dynamicLevel * getStrength(centreX, centreY, x, y);
                if (strength != 0f) {
                    int targetValue = 1 + (int) (strength * 14 + 0.5f);
                    if (targetValue > currentValue) {
                        dimension.setLayerValueAt(layer, x, y, targetValue);
                    }
                }
            }
        }
    }
}
Also used : Tile(org.pepsoft.worldpainter.Tile)

Aggregations

Tile (org.pepsoft.worldpainter.Tile)31 Dimension (org.pepsoft.worldpainter.Dimension)6 CombinedLayer (org.pepsoft.worldpainter.layers.CombinedLayer)5 Point (java.awt.Point)4 FileOutputStream (java.io.FileOutputStream)4 Terrain (org.pepsoft.worldpainter.Terrain)4 World2 (org.pepsoft.worldpainter.World2)4 Rectangle (java.awt.Rectangle)3 BufferedImage (java.awt.image.BufferedImage)3 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 ObjectInputStream (java.io.ObjectInputStream)3 GZIPInputStream (java.util.zip.GZIPInputStream)3 SubProgressReceiver (org.pepsoft.util.SubProgressReceiver)3 Layer (org.pepsoft.worldpainter.layers.Layer)3 Graphics2D (java.awt.Graphics2D)2 ObjectOutputStream (java.io.ObjectOutputStream)2 PrintWriter (java.io.PrintWriter)2 java.util (java.util)2 List (java.util.List)2