Search in sources :

Example 26 with Layer

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

the class TunnelLayerDialog method setControlStates.

private void setControlStates() {
    spinnerFloorMin.setEnabled(!radioButtonFloorFixedLevel.isSelected());
    spinnerFloorMax.setEnabled(!radioButtonFloorFixedLevel.isSelected());
    spinnerRoofMin.setEnabled(!radioButtonRoofFixedLevel.isSelected());
    spinnerRoofMax.setEnabled(!radioButtonRoofFixedLevel.isSelected());
    spinnerFloodLevel.setEnabled(checkBoxFlood.isSelected());
    checkBoxFloodWithLava.setEnabled(checkBoxFlood.isSelected());
    int selectedFloorRow = tableFloorLayers.getSelectedRow();
    if (selectedFloorRow != -1) {
        buttonRemoveFloorLayer.setEnabled(tableFloorLayers.getSelectedRowCount() > 0);
        Layer selectedLayer = floorLayersTableModel.getLayer(selectedFloorRow);
        buttonEditFloorLayer.setEnabled(selectedLayer instanceof CustomLayer);
    } else {
        buttonRemoveFloorLayer.setEnabled(false);
        buttonEditFloorLayer.setEnabled(false);
    }
}
Also used : CustomLayer(org.pepsoft.worldpainter.layers.CustomLayer) Bo2Layer(org.pepsoft.worldpainter.layers.Bo2Layer) CustomLayer(org.pepsoft.worldpainter.layers.CustomLayer) PlantLayer(org.pepsoft.worldpainter.layers.plants.PlantLayer) Layer(org.pepsoft.worldpainter.layers.Layer) GroundCoverLayer(org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer)

Example 27 with Layer

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

the class TunnelLayerDialog method loadSettings.

private void loadSettings() {
    programmaticChange = true;
    try {
        spinnerFloorLevel.setValue(layer.getFloorLevel());
        spinnerFloorMin.setValue(layer.getFloorMin());
        spinnerFloorMax.setValue(Math.min(layer.getFloorMax(), maxHeight - 1));
        mixedMaterialSelectorFloor.setMaterial(layer.getFloorMaterial());
        switch(layer.getFloorMode()) {
            case CONSTANT_DEPTH:
                radioButtonFloorFixedDepth.setSelected(true);
                break;
            case FIXED_HEIGHT:
                radioButtonFloorFixedLevel.setSelected(true);
                break;
            case INVERTED_DEPTH:
                radioButtonFloorInverse.setSelected(true);
                break;
        }
        NoiseSettings floorNoise = layer.getFloorNoise();
        if (floorNoise == null) {
            floorNoise = new NoiseSettings();
        }
        noiseSettingsEditorFloor.setNoiseSettings(floorNoise);
        spinnerRoofLevel.setValue(layer.getRoofLevel());
        spinnerRoofMin.setValue(layer.getRoofMin());
        spinnerRoofMax.setValue(Math.min(layer.getRoofMax(), maxHeight - 1));
        mixedMaterialSelectorRoof.setMaterial(layer.getRoofMaterial());
        switch(layer.getRoofMode()) {
            case CONSTANT_DEPTH:
                radioButtonRoofFixedDepth.setSelected(true);
                break;
            case FIXED_HEIGHT:
                radioButtonRoofFixedLevel.setSelected(true);
                break;
            case INVERTED_DEPTH:
                radioButtonRoofInverse.setSelected(true);
                break;
        }
        NoiseSettings roofNoise = layer.getRoofNoise();
        if (roofNoise == null) {
            roofNoise = new NoiseSettings();
        }
        noiseSettingsEditorRoof.setNoiseSettings(roofNoise);
        spinnerWallFloorDepth.setValue(layer.getFloorWallDepth());
        spinnerWallRoofDepth.setValue(layer.getRoofWallDepth());
        mixedMaterialSelectorWall.setMaterial(layer.getWallMaterial());
        textFieldName.setText(layer.getName());
        colourEditor1.setColour(layer.getColour());
        checkBoxRemoveWater.setSelected(layer.isRemoveWater());
        checkBoxFlood.setSelected(layer.getFloodLevel() > 0);
        spinnerFloodLevel.setValue((layer.getFloodLevel() > 0) ? layer.getFloodLevel() : waterLevel);
        checkBoxFloodWithLava.setSelected(layer.isFloodWithLava());
        Map<Layer, TunnelLayer.LayerSettings> floorLayers = layer.getFloorLayers();
        floorLayersTableModel = new TunnelFloorLayersTableModel(floorLayers, maxHeight);
        tableFloorLayers.setModel(floorLayersTableModel);
        tableFloorLayers.getColumnModel().getColumn(TunnelFloorLayersTableModel.COLUMN_NAME).setCellRenderer(new LayerTableCellRenderer());
    } finally {
        programmaticChange = false;
    }
    setControlStates();
}
Also used : NoiseSettings(org.pepsoft.worldpainter.NoiseSettings) LayerTableCellRenderer(org.pepsoft.worldpainter.layers.LayerTableCellRenderer) Bo2Layer(org.pepsoft.worldpainter.layers.Bo2Layer) CustomLayer(org.pepsoft.worldpainter.layers.CustomLayer) PlantLayer(org.pepsoft.worldpainter.layers.plants.PlantLayer) Layer(org.pepsoft.worldpainter.layers.Layer) GroundCoverLayer(org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer)

Example 28 with Layer

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

the class DumpWorld method dumpDimension.

private static void dumpDimension(Dimension dimension) {
    System.out.println("Dimension: " + dimension.getName() + " (index: " + dimension.getDim() + ")");
    System.out.println("    Size: " + dimension.getWidth() + "x" + dimension.getHeight() + " tiles");
    System.out.println("    Westernmost tile: " + dimension.getLowestX() + "; easternmost tile: " + dimension.getHighestX());
    System.out.println("    Northernmost tile: " + dimension.getLowestY() + "; southernmost tile: " + dimension.getHighestY());
    System.out.println("    Total number of tiles: " + dimension.getTileCount());
    System.out.println("    WorldPainter seed: " + dimension.getSeed() + "; Minecraft seed: " + dimension.getMinecraftSeed());
    if (dimension.getBorder() != null) {
        switch(dimension.getBorder()) {
            case LAVA:
            case WATER:
                System.out.println("    Border: " + dimension.getBorder() + " (size: " + dimension.getBorderSize() + "; level; " + dimension.getBorderLevel() + ")");
                break;
            case VOID:
                System.out.println("    Border: VOID (size: " + dimension.getBorderSize() + ")");
                break;
        }
    } else {
        System.out.println("    Border: none");
    }
    if ((dimension.getDim() == Constants.DIM_NORMAL_CEILING) || (dimension.getDim() == Constants.DIM_NETHER_CEILING) || (dimension.getDim() == Constants.DIM_END_CEILING)) {
        System.out.println("    Ceiling height: " + dimension.getCeilingHeight());
    }
    System.out.println("    Max height: " + dimension.getMaxHeight());
    System.out.println("    Contour separation: " + dimension.getContourSeparation());
    System.out.println("    Grid size: " + dimension.getGridSize());
    System.out.println("    Last view position: " + dimension.getLastViewPosition().x + "," + dimension.getLastViewPosition().y);
    if (dimension.getOverlay() != null) {
        System.out.println("    Overlay image: " + dimension.getOverlay());
        System.out.println("        Offset: " + dimension.getOverlayOffsetX() + "," + dimension.getOverlayOffsetY());
        System.out.println("        Scale:" + dimension.getOverlayScale());
        System.out.println("        Transparency: " + dimension.getOverlayTransparency());
    } else {
        System.out.println("    Overlay image: none");
    }
    System.out.println("    Subfurface material: " + dimension.getSubsurfaceMaterial());
    System.out.println("    Top layer depth: " + dimension.getTopLayerMinDepth() + " - " + (dimension.getTopLayerMinDepth() + dimension.getTopLayerVariation()));
    Map<Layer, Integer> usedLayers = new HashMap<>();
    EnumSet<Terrain> terrainsUsed = EnumSet.noneOf(Terrain.class);
    float lowestSurface = Float.MAX_VALUE, highestSurface = Float.MIN_VALUE;
    int lowestWaterlevel = Integer.MAX_VALUE, highestWaterlevel = Integer.MIN_VALUE;
    for (Tile tile : dimension.getTiles()) {
        for (Layer layer : tile.getLayers()) {
            Integer count = usedLayers.get(layer);
            if (count == null) {
                usedLayers.put(layer, 1);
            } else {
                usedLayers.put(layer, count + 1);
            }
        }
        for (int x = 0; x < Constants.TILE_SIZE; x++) {
            for (int y = 0; y < Constants.TILE_SIZE; y++) {
                terrainsUsed.add(tile.getTerrain(x, y));
                float height = tile.getHeight(x, y);
                if (height < lowestSurface) {
                    lowestSurface = height;
                }
                if (height > highestSurface) {
                    highestSurface = height;
                }
                int waterLevel = tile.getWaterLevel(x, y);
                if (waterLevel < lowestWaterlevel) {
                    lowestWaterlevel = waterLevel;
                }
                if (waterLevel > highestWaterlevel) {
                    highestWaterlevel = waterLevel;
                }
            }
        }
    }
    System.out.println("    Terrain heights: " + lowestSurface + " - " + highestSurface);
    System.out.println("    Water levels: " + lowestWaterlevel + " - " + highestWaterlevel);
    if ((dimension.getCustomBiomes() != null) && (!dimension.getCustomBiomes().isEmpty())) {
        System.out.println("    Custom biomes installed:");
        dimension.getCustomBiomes().forEach(customBiome -> System.out.println("        " + customBiome.getName() + " (" + customBiome.getId() + ")"));
    } else {
        System.out.println("    No custom biomes installed");
    }
    System.out.println("    Layers used:");
    usedLayers.entrySet().forEach(entry -> {
        Layer layer = entry.getKey();
        System.out.println("        Name: " + layer.getName());
        System.out.println("            Type: " + layer.getClass().getSimpleName());
        System.out.println("            Data size: " + layer.getDataSize());
        System.out.println("            Tile count: " + entry.getValue());
    });
    Set<Layer> unusedLayers = new HashSet<>(dimension.getCustomLayers());
    unusedLayers.removeAll(usedLayers.keySet());
    if (!unusedLayers.isEmpty()) {
        System.out.println("    Layers stored but not in use:");
        unusedLayers.forEach(layer -> {
            System.out.println("        Name: " + layer.getName());
            System.out.println("            Type: " + layer.getClass().getSimpleName());
            System.out.println("            Data size: " + layer.getDataSize());
        });
    }
    System.out.println("    Terrain types used:");
    terrainsUsed.forEach(terrain -> System.out.println("        " + terrain.getName() + " (index: " + terrain.ordinal() + ")"));
    List<String> problems = new ArrayList<>();
    if (dimension.getMaxHeight() != dimension.getWorld().getMaxHeight()) {
        problems.add("Dimension max height (" + dimension.getMaxHeight() + ") does not equal the world max height (" + dimension.getWorld().getMaxHeight() + ")");
    }
    for (Terrain terrain : terrainsUsed) {
        if (terrain.isCustom() && (!terrain.isConfigured())) {
            problems.add("Unconfigured custom terrain type " + terrain.getName() + " (index: " + terrain.ordinal() + ") encountered");
        }
    }
    if (!problems.isEmpty()) {
        System.out.println("    PROBLEMS:");
        problems.forEach(problem -> System.out.println("        " + problem));
    }
// TODO: layer settings
// TODO: tile factory
}
Also used : Layer(org.pepsoft.worldpainter.layers.Layer)

Example 29 with Layer

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

the class ErrorDialog method setException.

public void setException(Throwable exception) {
    logger.error(exception.getClass().getSimpleName() + ": " + exception.getMessage(), exception);
    Throwable rootCause = exception;
    while (rootCause.getCause() != null) {
        rootCause = rootCause.getCause();
    }
    if (rootCause instanceof OutOfMemoryError) {
        setTitle("Out of Memory");
        jTextArea1.setText("Not enough memory available for that operation!\n\n" + "WorldPainter is already using the recommended maximum\n" + "amount of memory, so it is not recommended to give it\n" + "more. To be able to perform the operation you should\n" + "install more memory.");
        jButton1.setEnabled(false);
        jButton1.setToolTipText("Not necessary to mail details of out of memory errors");
        jButton3.setEnabled(false);
    } else {
        String message = rootCause.getMessage();
        if ((message != null) && (message.length() > 250)) {
            message = message.substring(0, 247) + "...";
        }
        String text = "An unexpected error has occurred.\n\n" + "Type: " + rootCause.getClass().getName() + "\n" + "Message: " + message + "\n\n" + "Please help debug the problem by using the button below to email the details of this error to the creator of this program.\n\n" + "The program may now be in an unstable state. It is recommended to restart it as soon as possible.";
        jTextArea1.setText(text);
    }
    pack();
    StringBuilder sb = new StringBuilder();
    String eol = System.getProperty("line.separator");
    sb.append(exception.getClass().getName());
    sb.append(": ");
    sb.append(exception.getMessage());
    sb.append(eol);
    StackTraceElement[] stackTrace = exception.getStackTrace();
    for (int i = 0; i < Math.min(stackTrace.length, 5); i++) {
        sb.append("\tat ");
        sb.append(stackTrace[i].getClassName());
        sb.append('.');
        sb.append(stackTrace[i].getMethodName());
        sb.append('(');
        sb.append(stackTrace[i].getFileName());
        sb.append(':');
        sb.append(stackTrace[i].getLineNumber());
        sb.append(')');
        sb.append(eol);
    }
    sb.append(eol);
    if (rootCause != exception) {
        sb.append("Root cause:");
        sb.append(eol);
        sb.append(rootCause.getClass().getName());
        sb.append(": ");
        sb.append(rootCause.getMessage());
        sb.append(eol);
        stackTrace = rootCause.getStackTrace();
        for (int i = 0; i < Math.min(stackTrace.length, 5); i++) {
            sb.append("\tat ");
            sb.append(stackTrace[i].getClassName());
            sb.append('.');
            sb.append(stackTrace[i].getMethodName());
            sb.append('(');
            sb.append(stackTrace[i].getFileName());
            sb.append(':');
            sb.append(stackTrace[i].getLineNumber());
            sb.append(')');
            sb.append(eol);
        }
        sb.append(eol);
    }
    sb.append("WorldPainter version: " + Version.VERSION + " (" + Version.BUILD + ")" + eol);
    sb.append(eol);
    for (String propertyName : SYSTEM_PROPERTIES) {
        sb.append(propertyName);
        sb.append(": ");
        sb.append(System.getProperty(propertyName));
        sb.append(eol);
    }
    sb.append(eol);
    Runtime runtime = Runtime.getRuntime();
    sb.append("Free memory: " + runtime.freeMemory() + " bytes" + eol);
    sb.append("Total memory size: " + runtime.totalMemory() + " bytes" + eol);
    sb.append("Max memory size: " + runtime.maxMemory() + " bytes" + eol);
    // interrogating it, swallow it to prevent endless loops
    try {
        App app = App.getInstanceIfExists();
        World2 world = (app != null) ? app.getWorld() : null;
        Dimension dimension = (app != null) ? app.getDimension() : null;
        if ((world != null) && (dimension != null)) {
            sb.append(eol);
            sb.append("World name: " + world.getName() + eol);
            sb.append("Seed: " + dimension.getSeed() + eol);
            sb.append("Bounds: " + dimension.getLowestX() + ", " + dimension.getLowestY() + " => " + dimension.getHighestX() + ", " + dimension.getHighestY() + eol);
            sb.append("Height: " + world.getMaxHeight() + eol);
            sb.append("Number of tiles: " + dimension.getTiles().size() + eol);
            Set<Layer> layers = new HashSet<>();
            for (Tile tile : dimension.getTiles()) {
                layers.addAll(tile.getLayers());
            }
            sb.append("Layers in use: ");
            boolean first = true;
            for (Layer layer : layers) {
                if (first) {
                    first = false;
                } else {
                    sb.append(", ");
                }
                sb.append(layer.getName());
            }
            sb.append(eol);
            sb.append("Border: " + dimension.getBorder() + " @ " + dimension.getBorderLevel() + eol);
            sb.append("Sub surface material: " + dimension.getSubsurfaceMaterial() + eol);
            TileFactory tileFactory = dimension.getTileFactory();
            if (tileFactory instanceof HeightMapTileFactory) {
                HeightMapTileFactory heightMapTileFactory = (HeightMapTileFactory) tileFactory;
                sb.append("Water height: " + heightMapTileFactory.getWaterHeight() + eol);
            }
            if (world.getImportedFrom() != null) {
                sb.append("World imported from " + world.getImportedFrom() + eol);
            }
            if (!world.isAllowMerging()) {
                sb.append("World created in old coordinate system" + eol);
            }
        }
        if (app != null) {
            sb.append(eol);
            sb.append("Operation: " + app.getActiveOperation() + eol);
            sb.append("Radius: " + app.getRadius() + eol);
            // sb.append("Brush shape: " + app.getBrushShape() + "/" + app.getToolBrushShape() + eol);
            sb.append("Brush: " + app.getBrush() + "/" + app.getToolBrush() + eol);
            sb.append("Level: " + app.getLevel() + "/" + app.getToolLevel() + eol);
            sb.append("Zoom: " + app.getZoom() + eol);
            sb.append("Hidden layers: " + app.getHiddenLayers());
        }
    } catch (Throwable t) {
        logger.error("Secondary exception occurred while interrogating app for exception report", t);
    }
    body = sb.toString();
    if (!"true".equals(System.getProperty("org.pepsoft.worldpainter.devMode"))) {
        logger.error(body);
    }
}
Also used : Layer(org.pepsoft.worldpainter.layers.Layer) HashSet(java.util.HashSet)

Example 30 with Layer

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

the class FillDialog method fillWithLayer.

private void fillWithLayer(ProgressReceiver progressReceiver) throws UnsupportedOperationException, OperationCancelled {
    Layer layer = (Layer) comboBoxSetLayer.getSelectedItem();
    if (layer.getDataSize() == Layer.DataSize.NIBBLE) {
        int baseLayerValue = Math.round((sliderLayerValue.getValue() + 2) / 6.667f);
        dimension.visitTiles().forFilter(filter).andDo(tile -> {
            final int worldTileX = tile.getX() << TILE_SIZE_BITS;
            final int worldTileY = tile.getY() << TILE_SIZE_BITS;
            for (int x = 0; x < TILE_SIZE; x++) {
                for (int y = 0; y < TILE_SIZE; y++) {
                    int layerValue;
                    if (filter == null) {
                        layerValue = baseLayerValue;
                    } else {
                        layerValue = (int) (filter.modifyStrength(worldTileX | x, worldTileY | y, 1.0f) * baseLayerValue);
                    }
                    if (tile.getLayerValue(layer, x, y) < layerValue) {
                        tile.setLayerValue(layer, x, y, layerValue);
                    }
                }
            }
        }, progressReceiver);
    } else if (layer.getDataSize() == Layer.DataSize.BIT) {
        dimension.visitTiles().forFilter(filter).andDo(tile -> {
            final int worldTileX = tile.getX() << TILE_SIZE_BITS;
            final int worldTileY = tile.getY() << TILE_SIZE_BITS;
            for (int x = 0; x < TILE_SIZE; x++) {
                for (int y = 0; y < TILE_SIZE; y++) {
                    boolean set;
                    if (filter == null) {
                        set = true;
                    } else {
                        float strength = filter.modifyStrength(worldTileX | x, worldTileY | y, 1.0f);
                        set = (strength > 0.95f) || (Math.random() < strength);
                    }
                    if (set && (!tile.getBitLayerValue(layer, x, y))) {
                        tile.setBitLayerValue(layer, x, y, true);
                    }
                }
            }
        }, progressReceiver);
    } else if (layer.getDataSize() == Layer.DataSize.BIT_PER_CHUNK) {
        dimension.visitTiles().forFilter(filter).andDo(tile -> {
            final int worldTileX = tile.getX() << TILE_SIZE_BITS;
            final int worldTileY = tile.getY() << TILE_SIZE_BITS;
            for (int x = 0; x < TILE_SIZE; x += 16) {
                for (int y = 0; y < TILE_SIZE; y += 16) {
                    boolean set;
                    if (filter == null) {
                        set = true;
                    } else {
                        float strength = filter.modifyStrength(worldTileX | x, worldTileY | y, 1.0f);
                        set = (strength > 0.95f) || (Math.random() < strength);
                    }
                    if (set && (!tile.getBitLayerValue(layer, x, y))) {
                        tile.setBitLayerValue(layer, x, y, true);
                    }
                }
            }
        }, progressReceiver);
    } else {
        throw new UnsupportedOperationException();
    }
}
Also used : CustomBiomeManager(org.pepsoft.worldpainter.biomeschemes.CustomBiomeManager) BiomeHelper(org.pepsoft.worldpainter.biomeschemes.BiomeHelper) Arrays(java.util.Arrays) AutoBiomeScheme(org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme) Collection(java.util.Collection) Biome(org.pepsoft.worldpainter.layers.Biome) ProgressDialog(org.pepsoft.util.swing.ProgressDialog) Listener(org.pepsoft.worldpainter.panels.BrushOptions.Listener) Set(java.util.Set) DefaultFilter(org.pepsoft.worldpainter.panels.DefaultFilter) TILE_SIZE(org.pepsoft.worldpainter.Constants.TILE_SIZE) Layer(org.pepsoft.worldpainter.layers.Layer) TerrainListCellRenderer(org.pepsoft.worldpainter.themes.TerrainListCellRenderer) ProgressTask(org.pepsoft.util.swing.ProgressTask) FloodWithLava(org.pepsoft.worldpainter.layers.FloodWithLava) ObservableBoolean(org.pepsoft.util.ObservableBoolean) ProgressReceiver(org.pepsoft.util.ProgressReceiver) SelectionBlock(org.pepsoft.worldpainter.selection.SelectionBlock) OperationCancelled(org.pepsoft.util.ProgressReceiver.OperationCancelled) SelectionChunk(org.pepsoft.worldpainter.selection.SelectionChunk) SelectionHelper(org.pepsoft.worldpainter.selection.SelectionHelper) TILE_SIZE_BITS(org.pepsoft.worldpainter.Constants.TILE_SIZE_BITS) Filter(org.pepsoft.worldpainter.operations.Filter) javax.swing(javax.swing) Layer(org.pepsoft.worldpainter.layers.Layer)

Aggregations

Layer (org.pepsoft.worldpainter.layers.Layer)34 CustomLayer (org.pepsoft.worldpainter.layers.CustomLayer)9 Map (java.util.Map)8 ProgressReceiver (org.pepsoft.util.ProgressReceiver)7 HashMap (java.util.HashMap)6 OperationCancelled (org.pepsoft.util.ProgressReceiver.OperationCancelled)5 ExporterSettings (org.pepsoft.worldpainter.layers.exporters.ExporterSettings)5 Point (java.awt.Point)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 SubProgressReceiver (org.pepsoft.util.SubProgressReceiver)4 TILE_SIZE (org.pepsoft.worldpainter.Constants.TILE_SIZE)4 Biome (org.pepsoft.worldpainter.layers.Biome)4 Bo2Layer (org.pepsoft.worldpainter.layers.Bo2Layer)4 CombinedLayer (org.pepsoft.worldpainter.layers.CombinedLayer)4 GroundCoverLayer (org.pepsoft.worldpainter.layers.groundcover.GroundCoverLayer)4 PlantLayer (org.pepsoft.worldpainter.layers.plants.PlantLayer)4 File (java.io.File)3 Arrays (java.util.Arrays)3 BitSet (java.util.BitSet)3