Search in sources :

Example 1 with TILE_SIZE_BITS

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

the class FillDialog method clearLayer.

private void clearLayer(ProgressReceiver progressReceiver) throws OperationCancelled {
    Layer layer = (Layer) comboBoxClearLayer.getSelectedItem();
    if (filter == null) {
        dimension.clearLayerData(layer);
    } else {
        if (layer.getDataSize() == Layer.DataSize.NIBBLE) {
            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 oldLayervalue = tile.getLayerValue(layer, x, y);
                        int layerValue;
                        if (filter == null) {
                            layerValue = 0;
                        } else {
                            layerValue = Math.min(oldLayervalue, 15 - (int) (filter.modifyStrength(worldTileX | x, worldTileY | y, 1.0f) * 15));
                        }
                        if (oldLayervalue != 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, false);
                        }
                    }
                }
            }, 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, false);
                        }
                    }
                }
            }, 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)

Example 2 with TILE_SIZE_BITS

use of org.pepsoft.worldpainter.Constants.TILE_SIZE_BITS 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)

Example 3 with TILE_SIZE_BITS

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

the class FillDialog method invertLayer.

private void invertLayer(ProgressReceiver progressReceiver) throws UnsupportedOperationException, OperationCancelled {
    Layer layer = (Layer) comboBoxInvertLayer.getSelectedItem();
    if (layer.getDataSize() == Layer.DataSize.NIBBLE) {
        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.setLayerValue(layer, x, y, 15 - tile.getLayerValue(layer, x, y));
                    }
                }
            }
        }, 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.setBitLayerValue(layer, x, y, !tile.getBitLayerValue(layer, x, y));
                    }
                }
            }
        }, 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.setBitLayerValue(layer, x, y, !tile.getBitLayerValue(layer, x, y));
                    }
                }
            }
        }, 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

Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 Set (java.util.Set)3 javax.swing (javax.swing)3 ObservableBoolean (org.pepsoft.util.ObservableBoolean)3 ProgressReceiver (org.pepsoft.util.ProgressReceiver)3 OperationCancelled (org.pepsoft.util.ProgressReceiver.OperationCancelled)3 ProgressDialog (org.pepsoft.util.swing.ProgressDialog)3 ProgressTask (org.pepsoft.util.swing.ProgressTask)3 TILE_SIZE (org.pepsoft.worldpainter.Constants.TILE_SIZE)3 TILE_SIZE_BITS (org.pepsoft.worldpainter.Constants.TILE_SIZE_BITS)3 AutoBiomeScheme (org.pepsoft.worldpainter.biomeschemes.AutoBiomeScheme)3 BiomeHelper (org.pepsoft.worldpainter.biomeschemes.BiomeHelper)3 CustomBiomeManager (org.pepsoft.worldpainter.biomeschemes.CustomBiomeManager)3 Biome (org.pepsoft.worldpainter.layers.Biome)3 FloodWithLava (org.pepsoft.worldpainter.layers.FloodWithLava)3 Layer (org.pepsoft.worldpainter.layers.Layer)3 Filter (org.pepsoft.worldpainter.operations.Filter)3 Listener (org.pepsoft.worldpainter.panels.BrushOptions.Listener)3 DefaultFilter (org.pepsoft.worldpainter.panels.DefaultFilter)3