Search in sources :

Example 1 with CavernsSettings

use of org.pepsoft.worldpainter.layers.exporters.CavernsExporter.CavernsSettings in project WorldPainter by Captain-Chaos.

the class DimensionPropertiesEditor method loadSettings.

private void loadSettings() {
    int maxHeight = dimension.getMaxHeight() - 1;
    // general
    ((SpinnerNumberModel) spinnerMinSurfaceDepth.getModel()).setMaximum(maxHeight);
    spinnerMinSurfaceDepth.setValue(dimension.getTopLayerMinDepth());
    ((SpinnerNumberModel) spinnerMaxSurfaceDepth.getModel()).setMaximum(maxHeight);
    spinnerMaxSurfaceDepth.setValue(dimension.getTopLayerMinDepth() + dimension.getTopLayerVariation());
    if (dimension.getBorder() != null) {
        switch(dimension.getBorder()) {
            case LAVA:
                radioButtonLavaBorder.setSelected(true);
                radioButtonFixedBorder.setSelected(true);
                break;
            case WATER:
                radioButtonWaterBorder.setSelected(true);
                radioButtonFixedBorder.setSelected(true);
                break;
            case VOID:
                radioButtonVoidBorder.setSelected(true);
                radioButtonFixedBorder.setSelected(true);
                break;
            case ENDLESS_LAVA:
                radioButtonLavaBorder.setSelected(true);
                radioButtonEndlessBorder.setSelected(true);
                break;
            case ENDLESS_WATER:
                radioButtonWaterBorder.setSelected(true);
                radioButtonEndlessBorder.setSelected(true);
                break;
            case ENDLESS_VOID:
                radioButtonVoidBorder.setSelected(true);
                radioButtonEndlessBorder.setSelected(true);
                break;
            default:
                throw new InternalError();
        }
    } else {
        radioButtonNoBorder.setSelected(true);
    }
    ((SpinnerNumberModel) spinnerBorderLevel.getModel()).setMaximum(maxHeight);
    spinnerBorderLevel.setValue(dimension.getBorderLevel());
    spinnerBorderSize.setValue(dimension.getBorderSize() * 128);
    checkBoxBedrockWall.setSelected(dimension.isBedrockWall());
    spinnerMinecraftSeed.setValue(dimension.getMinecraftSeed());
    checkBoxBottomless.setSelected(dimension.isBottomless());
    checkBoxCoverSteepTerrain.setSelected(dimension.isCoverSteepTerrain());
    ((SpinnerNumberModel) spinnerCeilingHeight.getModel()).setMaximum(maxHeight + 1);
    spinnerCeilingHeight.setValue(dimension.getCeilingHeight());
    // Minecraft world border
    World2 world = dimension.getWorld();
    if (world != null) {
        World2.BorderSettings borderSettings = world.getBorderSettings();
        spinnerMcBorderCentreX.setValue(borderSettings.getCentreX());
        spinnerMcBorderCentreY.setValue(borderSettings.getCentreY());
        spinnerMcBorderSize.setValue(borderSettings.getSize());
    // spinnerMcBorderBuffer.setValue(borderSettings.getSafeZone());
    // spinnerMcBorderDamage.setValue(borderSettings.getDamagePerBlock());
    // spinnerMcBorderWarningTime.setValue(borderSettings.getWarningTime());
    // spinnerMcBorderWarningDistance.setValue(borderSettings.getWarningBlocks());
    } else {
        spinnerMcBorderCentreX.setEnabled(false);
        spinnerMcBorderCentreY.setEnabled(false);
        spinnerMcBorderSize.setEnabled(false);
    // spinnerMcBorderBuffer.setEnabled(false);
    // spinnerMcBorderDamage.setEnabled(false);
    // spinnerMcBorderWarningTime.setEnabled(false);
    // spinnerMcBorderWarningDistance.setEnabled(false);
    }
    List<Terrain> materialList = new ArrayList<>(Arrays.asList(Terrain.VALUES));
    for (Iterator<Terrain> i = materialList.iterator(); i.hasNext(); ) {
        Terrain terrain = i.next();
        if ((terrain.isCustom() && (!terrain.isConfigured())) || (terrain == Terrain.GRASS) || (terrain == Terrain.DESERT) || (terrain == Terrain.RED_DESERT)) {
            i.remove();
        }
    }
    comboBoxSubsurfaceMaterial.setModel(new DefaultComboBoxModel(materialList.toArray()));
    comboBoxSubsurfaceMaterial.setSelectedItem(dimension.getSubsurfaceMaterial());
    // caverns
    CavernsSettings cavernsSettings = (CavernsSettings) dimension.getLayerSettings(Caverns.INSTANCE);
    if (cavernsSettings == null) {
        cavernsSettings = new CavernsSettings();
    }
    if (cavernsSettings.getCavernsEverywhereLevel() > 0) {
        checkBoxCavernsEverywhere.setSelected(true);
        sliderCavernsEverywhereLevel.setValue(cavernsSettings.getCavernsEverywhereLevel());
    } else {
        checkBoxCavernsEverywhere.setSelected(false);
        sliderCavernsEverywhereLevel.setValue(8);
    }
    ((SpinnerNumberModel) spinnerCavernsFloodLevel.getModel()).setMaximum(maxHeight);
    if (cavernsSettings.getWaterLevel() > 0) {
        checkBoxFloodCaverns.setSelected(true);
        spinnerCavernsFloodLevel.setValue(cavernsSettings.getWaterLevel());
    } else {
        checkBoxFloodCaverns.setSelected(false);
        spinnerCavernsFloodLevel.setValue(8);
    }
    checkBoxCavernsFloodWithLava.setSelected(cavernsSettings.isFloodWithLava());
    checkBoxCavernsBreakSurface.setSelected(cavernsSettings.isSurfaceBreaking());
    checkBoxCavernsRemoveWater.setSelected(!cavernsSettings.isLeaveWater());
    ((SpinnerNumberModel) spinnerCavernsMinLevel.getModel()).setMaximum(maxHeight);
    spinnerCavernsMinLevel.setValue(cavernsSettings.getMinimumLevel());
    ((SpinnerNumberModel) spinnerCavernsMaxLevel.getModel()).setMaximum(maxHeight);
    spinnerCavernsMaxLevel.setValue(Math.min(cavernsSettings.getMaximumLevel(), maxHeight));
    // chasms
    ChasmsSettings chasmsSettings = (ChasmsSettings) dimension.getLayerSettings(Chasms.INSTANCE);
    if (chasmsSettings == null) {
        chasmsSettings = new ChasmsSettings();
    }
    if (chasmsSettings.getChasmsEverywhereLevel() > 0) {
        checkBoxChasmsEverywhere.setSelected(true);
        sliderChasmsEverywhereLevel.setValue(chasmsSettings.getChasmsEverywhereLevel());
    } else {
        checkBoxChasmsEverywhere.setSelected(false);
        sliderChasmsEverywhereLevel.setValue(8);
    }
    checkBoxChasmsBreakSurface.setSelected(chasmsSettings.isSurfaceBreaking());
    ((SpinnerNumberModel) spinnerChasmsMinLevel.getModel()).setMaximum(maxHeight);
    spinnerChasmsMinLevel.setValue(chasmsSettings.getMinimumLevel());
    ((SpinnerNumberModel) spinnerChasmsMaxLevel.getModel()).setMaximum(maxHeight);
    spinnerChasmsMaxLevel.setValue(Math.min(chasmsSettings.getMaximumLevel(), maxHeight));
    // populate
    checkBoxPopulate.setSelected(dimension.isPopulate());
    // deciduous
    TreeLayerSettings<DeciduousForest> deciduousSettings = (TreeLayerSettings<DeciduousForest>) dimension.getLayerSettings(DeciduousForest.INSTANCE);
    if (deciduousSettings == null) {
        deciduousSettings = new TreeLayerSettings<>(DeciduousForest.INSTANCE);
    }
    if (deciduousSettings.getMinimumLevel() > 0) {
        checkBoxDeciduousEverywhere.setSelected(true);
        sliderDeciduousLevel.setValue(deciduousSettings.getMinimumLevel());
    } else {
        checkBoxDeciduousEverywhere.setSelected(false);
        sliderDeciduousLevel.setValue(8);
    }
    // pine
    TreeLayerSettings<PineForest> pineSettings = (TreeLayerSettings<PineForest>) dimension.getLayerSettings(PineForest.INSTANCE);
    if (pineSettings == null) {
        pineSettings = new TreeLayerSettings<>(PineForest.INSTANCE);
    }
    if (pineSettings.getMinimumLevel() > 0) {
        checkBoxPineEverywhere.setSelected(true);
        sliderPineLevel.setValue(pineSettings.getMinimumLevel());
    } else {
        checkBoxPineEverywhere.setSelected(false);
        sliderPineLevel.setValue(8);
    }
    // jungle
    TreeLayerSettings<Jungle> jungleSettings = (TreeLayerSettings<Jungle>) dimension.getLayerSettings(Jungle.INSTANCE);
    if (jungleSettings == null) {
        jungleSettings = new TreeLayerSettings<>(Jungle.INSTANCE);
    }
    if (jungleSettings.getMinimumLevel() > 0) {
        checkBoxJungleEverywhere.setSelected(true);
        sliderJungleLevel.setValue(jungleSettings.getMinimumLevel());
    } else {
        checkBoxJungleEverywhere.setSelected(false);
        sliderJungleLevel.setValue(8);
    }
    // swamp
    TreeLayerSettings<SwampLand> swampLandSettings = (TreeLayerSettings<SwampLand>) dimension.getLayerSettings(SwampLand.INSTANCE);
    if (swampLandSettings == null) {
        swampLandSettings = new TreeLayerSettings<>(SwampLand.INSTANCE);
    }
    if (swampLandSettings.getMinimumLevel() > 0) {
        checkBoxSwamplandEverywhere.setSelected(true);
        jSlider6.setValue(swampLandSettings.getMinimumLevel());
    } else {
        checkBoxSwamplandEverywhere.setSelected(false);
        jSlider6.setValue(8);
    }
    // frost
    FrostSettings frostSettings = (FrostSettings) dimension.getLayerSettings(Frost.INSTANCE);
    if (frostSettings == null) {
        frostSettings = new FrostSettings();
    }
    checkBoxFrostEverywhere.setSelected(frostSettings.isFrostEverywhere());
    checkBoxSmoothSnow.setSelected((frostSettings.getMode() == 2) || (frostSettings.getMode() == 3));
    checkBoxSnowUnderTrees.setSelected(frostSettings.isSnowUnderTrees());
    // resources
    ResourcesExporterSettings resourcesSettings = (ResourcesExporterSettings) dimension.getLayerSettings(Resources.INSTANCE);
    if (resourcesSettings == null) {
        resourcesSettings = new ResourcesExporterSettings(dimension.getMaxHeight());
        resourcesSettings.setMinimumLevel(0);
    }
    jCheckBox8.setSelected(resourcesSettings.isApplyEverywhere());
    if (resourcesSettings.isApplyEverywhere()) {
        jSlider4.setValue(resourcesSettings.getMinimumLevel());
    } else {
        jSlider4.setValue(8);
    }
    spinnerGoldChance.setValue(resourcesSettings.getChance(BLK_GOLD_ORE));
    ((SpinnerNumberModel) spinnerGoldMinLevel.getModel()).setMaximum(maxHeight);
    spinnerGoldMinLevel.setValue(clamp(resourcesSettings.getMinLevel(BLK_GOLD_ORE), maxHeight));
    ((SpinnerNumberModel) spinnerGoldMaxLevel.getModel()).setMaximum(maxHeight);
    spinnerGoldMaxLevel.setValue(clamp(resourcesSettings.getMaxLevel(BLK_GOLD_ORE), maxHeight));
    spinnerIronChance.setValue(resourcesSettings.getChance(BLK_IRON_ORE));
    ((SpinnerNumberModel) spinnerIronMinLevel.getModel()).setMaximum(maxHeight);
    spinnerIronMinLevel.setValue(clamp(resourcesSettings.getMinLevel(BLK_IRON_ORE), maxHeight));
    ((SpinnerNumberModel) spinnerIronMaxLevel.getModel()).setMaximum(maxHeight);
    spinnerIronMaxLevel.setValue(clamp(resourcesSettings.getMaxLevel(BLK_IRON_ORE), maxHeight));
    spinnerCoalChance.setValue(resourcesSettings.getChance(BLK_COAL));
    ((SpinnerNumberModel) spinnerCoalMinLevel.getModel()).setMaximum(maxHeight);
    spinnerCoalMinLevel.setValue(clamp(resourcesSettings.getMinLevel(BLK_COAL), maxHeight));
    ((SpinnerNumberModel) spinnerCoalMaxLevel.getModel()).setMaximum(maxHeight);
    spinnerCoalMaxLevel.setValue(clamp(resourcesSettings.getMaxLevel(BLK_COAL), maxHeight));
    spinnerLapisChance.setValue(resourcesSettings.getChance(BLK_LAPIS_LAZULI_ORE));
    ((SpinnerNumberModel) spinnerLapisMinLevel.getModel()).setMaximum(maxHeight);
    spinnerLapisMinLevel.setValue(clamp(resourcesSettings.getMinLevel(BLK_LAPIS_LAZULI_ORE), maxHeight));
    ((SpinnerNumberModel) spinnerLapisMaxLevel.getModel()).setMaximum(maxHeight);
    spinnerLapisMaxLevel.setValue(clamp(resourcesSettings.getMaxLevel(BLK_LAPIS_LAZULI_ORE), maxHeight));
    spinnerDiamondChance.setValue(resourcesSettings.getChance(BLK_DIAMOND_ORE));
    ((SpinnerNumberModel) spinnerDiamondMinLevel.getModel()).setMaximum(maxHeight);
    spinnerDiamondMinLevel.setValue(clamp(resourcesSettings.getMinLevel(BLK_DIAMOND_ORE), maxHeight));
    ((SpinnerNumberModel) spinnerDiamondMaxLevel.getModel()).setMaximum(maxHeight);
    spinnerDiamondMaxLevel.setValue(clamp(resourcesSettings.getMaxLevel(BLK_DIAMOND_ORE), maxHeight));
    spinnerRedstoneChance.setValue(resourcesSettings.getChance(BLK_REDSTONE_ORE));
    ((SpinnerNumberModel) spinnerRedstoneMinLevel.getModel()).setMaximum(maxHeight);
    spinnerRedstoneMinLevel.setValue(clamp(resourcesSettings.getMinLevel(BLK_REDSTONE_ORE), maxHeight));
    ((SpinnerNumberModel) spinnerRedstoneMaxLevel.getModel()).setMaximum(maxHeight);
    spinnerRedstoneMaxLevel.setValue(clamp(resourcesSettings.getMaxLevel(BLK_REDSTONE_ORE), maxHeight));
    spinnerWaterChance.setValue(resourcesSettings.getChance(BLK_WATER));
    ((SpinnerNumberModel) spinnerWaterMinLevel.getModel()).setMaximum(maxHeight);
    spinnerWaterMinLevel.setValue(clamp(resourcesSettings.getMinLevel(BLK_WATER), maxHeight));
    ((SpinnerNumberModel) spinnerWaterMaxLevel.getModel()).setMaximum(maxHeight);
    spinnerWaterMaxLevel.setValue(clamp(resourcesSettings.getMaxLevel(BLK_WATER), maxHeight));
    spinnerLavaChance.setValue(resourcesSettings.getChance(BLK_LAVA));
    ((SpinnerNumberModel) spinnerLavaMinLevel.getModel()).setMaximum(maxHeight);
    spinnerLavaMinLevel.setValue(clamp(resourcesSettings.getMinLevel(BLK_LAVA), maxHeight));
    ((SpinnerNumberModel) spinnerLavaMaxLevel.getModel()).setMaximum(maxHeight);
    spinnerLavaMaxLevel.setValue(clamp(resourcesSettings.getMaxLevel(BLK_LAVA), maxHeight));
    spinnerDirtChance.setValue(resourcesSettings.getChance(BLK_DIRT));
    ((SpinnerNumberModel) spinnerDirtMinLevel.getModel()).setMaximum(maxHeight);
    spinnerDirtMinLevel.setValue(clamp(resourcesSettings.getMinLevel(BLK_DIRT), maxHeight));
    ((SpinnerNumberModel) spinnerDirtMaxLevel.getModel()).setMaximum(maxHeight);
    spinnerDirtMaxLevel.setValue(clamp(resourcesSettings.getMaxLevel(BLK_DIRT), maxHeight));
    spinnerGravelChance.setValue(resourcesSettings.getChance(BLK_GRAVEL));
    ((SpinnerNumberModel) spinnerGravelMinLevel.getModel()).setMaximum(maxHeight);
    spinnerGravelMinLevel.setValue(clamp(resourcesSettings.getMinLevel(BLK_GRAVEL), maxHeight));
    ((SpinnerNumberModel) spinnerGravelMaxLevel.getModel()).setMaximum(maxHeight);
    spinnerGravelMaxLevel.setValue(clamp(resourcesSettings.getMaxLevel(BLK_GRAVEL), maxHeight));
    spinnerEmeraldChance.setValue(resourcesSettings.getChance(BLK_EMERALD_ORE));
    ((SpinnerNumberModel) spinnerEmeraldMinLevel.getModel()).setMaximum(maxHeight);
    spinnerEmeraldMinLevel.setValue(clamp(resourcesSettings.getMinLevel(BLK_EMERALD_ORE), maxHeight));
    ((SpinnerNumberModel) spinnerEmeraldMaxLevel.getModel()).setMaximum(maxHeight);
    spinnerEmeraldMaxLevel.setValue(clamp(resourcesSettings.getMaxLevel(BLK_EMERALD_ORE), maxHeight));
    spinnerQuartzChance.setValue(resourcesSettings.getChance(BLK_QUARTZ_ORE));
    ((SpinnerNumberModel) spinnerQuartzMinLevel.getModel()).setMaximum(maxHeight);
    spinnerQuartzMinLevel.setValue(clamp(resourcesSettings.getMinLevel(BLK_QUARTZ_ORE), maxHeight));
    ((SpinnerNumberModel) spinnerQuartzMaxLevel.getModel()).setMaximum(maxHeight);
    spinnerQuartzMaxLevel.setValue(clamp(resourcesSettings.getMaxLevel(BLK_QUARTZ_ORE), maxHeight));
    // terrain ranges
    if (mode != Mode.EXPORT) {
        if ((dimension.getTileFactory() instanceof HeightMapTileFactory) && (((HeightMapTileFactory) dimension.getTileFactory()).getTheme() instanceof SimpleTheme) && (((SimpleTheme) ((HeightMapTileFactory) dimension.getTileFactory()).getTheme()).getTerrainRanges() != null)) {
            themeEditor.setTheme((SimpleTheme) ((HeightMapTileFactory) dimension.getTileFactory()).getTheme());
        } else {
            jTabbedPane1.setEnabledAt(1, false);
        }
    }
    // annotations
    AnnotationsSettings annotationsSettings = (AnnotationsSettings) dimension.getLayerSettings(Annotations.INSTANCE);
    if (annotationsSettings == null) {
        annotationsSettings = new AnnotationsSettings();
    }
    checkBoxExportAnnotations.setSelected(annotationsSettings.isExport());
    // custom layers
    if (mode == Mode.EXPORT) {
        Set<CustomLayer> customLayers = App.getInstance().getCustomLayers();
        // if (! customLayers.isEmpty()) {
        customLayersTableModel = new CustomLayersTableModel(customLayers);
        tableCustomLayers.setModel(customLayersTableModel);
    // } else {
    // jTabbedPane1.setEnabledAt(5, false);
    // }
    }
    setControlStates();
}
Also used : FrostSettings(org.pepsoft.worldpainter.layers.exporters.FrostExporter.FrostSettings) ChasmsSettings(org.pepsoft.worldpainter.layers.exporters.ChasmsExporter.ChasmsSettings) TreeLayerSettings(org.pepsoft.worldpainter.layers.exporters.TreesExporter.TreeLayerSettings) CavernsSettings(org.pepsoft.worldpainter.layers.exporters.CavernsExporter.CavernsSettings) SimpleTheme(org.pepsoft.worldpainter.themes.SimpleTheme) ResourcesExporterSettings(org.pepsoft.worldpainter.layers.exporters.ResourcesExporter.ResourcesExporterSettings) AnnotationsSettings(org.pepsoft.worldpainter.layers.exporters.AnnotationsExporter.AnnotationsSettings)

Example 2 with CavernsSettings

use of org.pepsoft.worldpainter.layers.exporters.CavernsExporter.CavernsSettings in project WorldPainter by Captain-Chaos.

the class DimensionPropertiesEditor method saveSettings.

public boolean saveSettings() {
    int maxHeight = dimension.getMaxHeight() - 1;
    // terrain ranges
    if ((mode != Mode.EXPORT) && (!themeEditor.save())) {
        jTabbedPane1.setSelectedIndex(1);
        return false;
    }
    // general
    int topLayerMinDepth = (Integer) spinnerMinSurfaceDepth.getValue();
    dimension.setTopLayerMinDepth(topLayerMinDepth);
    dimension.setTopLayerVariation((Integer) spinnerMaxSurfaceDepth.getValue() - topLayerMinDepth);
    dimension.setSubsurfaceMaterial((Terrain) comboBoxSubsurfaceMaterial.getSelectedItem());
    dimension.setBorder(getSelectedBorder());
    dimension.setBorderLevel((Integer) spinnerBorderLevel.getValue());
    dimension.setBorderSize((Integer) spinnerBorderSize.getValue() / 128);
    dimension.setBedrockWall(checkBoxBedrockWall.isSelected());
    long previousSeed = dimension.getMinecraftSeed();
    long newSeed = ((Number) spinnerMinecraftSeed.getValue()).longValue();
    if (newSeed != previousSeed) {
        dimension.setMinecraftSeed(newSeed);
    }
    dimension.setBottomless(checkBoxBottomless.isSelected());
    dimension.setCoverSteepTerrain(checkBoxCoverSteepTerrain.isSelected());
    dimension.setCeilingHeight((Integer) spinnerCeilingHeight.getValue());
    // Minecraft world border
    World2 world = dimension.getWorld();
    if (world != null) {
        World2.BorderSettings borderSettings = world.getBorderSettings();
        borderSettings.setCentreX((Integer) spinnerMcBorderCentreX.getValue());
        borderSettings.setCentreY((Integer) spinnerMcBorderCentreY.getValue());
        borderSettings.setSize((Integer) spinnerMcBorderSize.getValue());
    // borderSettings.setSafeZone((Integer) spinnerMcBorderBuffer.getValue());
    // borderSettings.setDamagePerBlock((Float) spinnerMcBorderDamage.getValue());
    // borderSettings.setWarningTime((Integer) spinnerMcBorderWarningTime.getValue());
    // borderSettings.setWarningBlocks((Integer) spinnerMcBorderWarningDistance.getValue());
    }
    // caverns
    CavernsSettings cavernsSettings = (CavernsSettings) dimension.getLayerSettings(Caverns.INSTANCE);
    if (cavernsSettings == null) {
        cavernsSettings = new CavernsSettings();
    }
    if (checkBoxCavernsEverywhere.isSelected()) {
        int cavernsEverywhereLevel = sliderCavernsEverywhereLevel.getValue();
        cavernsSettings.setCavernsEverywhereLevel(cavernsEverywhereLevel);
    } else {
        cavernsSettings.setCavernsEverywhereLevel(0);
    }
    if (checkBoxFloodCaverns.isSelected()) {
        cavernsSettings.setWaterLevel((Integer) spinnerCavernsFloodLevel.getValue());
    } else {
        cavernsSettings.setWaterLevel(0);
    }
    cavernsSettings.setFloodWithLava(checkBoxCavernsFloodWithLava.isSelected());
    cavernsSettings.setSurfaceBreaking(checkBoxCavernsBreakSurface.isSelected());
    cavernsSettings.setLeaveWater(!checkBoxCavernsRemoveWater.isSelected());
    cavernsSettings.setMinimumLevel((Integer) spinnerCavernsMinLevel.getValue());
    int cavernsMaxLevel = (Integer) spinnerCavernsMaxLevel.getValue();
    cavernsSettings.setMaximumLevel((cavernsMaxLevel >= maxHeight) ? Integer.MAX_VALUE : cavernsMaxLevel);
    dimension.setLayerSettings(Caverns.INSTANCE, cavernsSettings);
    // chasms
    ChasmsSettings chasmsSettings = (ChasmsSettings) dimension.getLayerSettings(Chasms.INSTANCE);
    if (chasmsSettings == null) {
        chasmsSettings = new ChasmsSettings();
    }
    if (checkBoxChasmsEverywhere.isSelected()) {
        int chasmsEverywhereLevel = sliderChasmsEverywhereLevel.getValue();
        chasmsSettings.setChasmsEverywhereLevel(chasmsEverywhereLevel);
    } else {
        chasmsSettings.setChasmsEverywhereLevel(0);
    }
    chasmsSettings.setSurfaceBreaking(checkBoxChasmsBreakSurface.isSelected());
    // Other settings copied from Caverns layer
    if (checkBoxFloodCaverns.isSelected()) {
        chasmsSettings.setWaterLevel((Integer) spinnerCavernsFloodLevel.getValue());
    } else {
        chasmsSettings.setWaterLevel(0);
    }
    chasmsSettings.setFloodWithLava(checkBoxCavernsFloodWithLava.isSelected());
    chasmsSettings.setLeaveWater(!checkBoxCavernsRemoveWater.isSelected());
    chasmsSettings.setMinimumLevel((Integer) spinnerChasmsMinLevel.getValue());
    chasmsSettings.setMaximumLevel((Integer) spinnerChasmsMaxLevel.getValue());
    dimension.setLayerSettings(Chasms.INSTANCE, chasmsSettings);
    // populate
    dimension.setPopulate(checkBoxPopulate.isSelected());
    // deciduous
    TreeLayerSettings<DeciduousForest> deciduousSettings = (TreeLayerSettings<DeciduousForest>) dimension.getLayerSettings(DeciduousForest.INSTANCE);
    if (deciduousSettings == null) {
        deciduousSettings = new TreeLayerSettings<>(DeciduousForest.INSTANCE);
    }
    if (checkBoxDeciduousEverywhere.isSelected()) {
        int minimumLevel = sliderDeciduousLevel.getValue();
        deciduousSettings.setMinimumLevel(minimumLevel);
    } else {
        deciduousSettings.setMinimumLevel(0);
    }
    dimension.setLayerSettings(DeciduousForest.INSTANCE, deciduousSettings);
    // pine
    TreeLayerSettings<PineForest> pineSettings = (TreeLayerSettings<PineForest>) dimension.getLayerSettings(PineForest.INSTANCE);
    if (pineSettings == null) {
        pineSettings = new TreeLayerSettings<>(PineForest.INSTANCE);
    }
    if (checkBoxPineEverywhere.isSelected()) {
        int minimumLevel = sliderPineLevel.getValue();
        pineSettings.setMinimumLevel(minimumLevel);
    } else {
        pineSettings.setMinimumLevel(0);
    }
    dimension.setLayerSettings(PineForest.INSTANCE, pineSettings);
    // jungle
    TreeLayerSettings<Jungle> jungleSettings = (TreeLayerSettings<Jungle>) dimension.getLayerSettings(Jungle.INSTANCE);
    if (jungleSettings == null) {
        jungleSettings = new TreeLayerSettings<>(Jungle.INSTANCE);
    }
    if (checkBoxJungleEverywhere.isSelected()) {
        int minimumLevel = sliderJungleLevel.getValue();
        jungleSettings.setMinimumLevel(minimumLevel);
    } else {
        jungleSettings.setMinimumLevel(0);
    }
    dimension.setLayerSettings(Jungle.INSTANCE, jungleSettings);
    // swampland
    TreeLayerSettings<SwampLand> swampLandSettings = (TreeLayerSettings<SwampLand>) dimension.getLayerSettings(SwampLand.INSTANCE);
    if (swampLandSettings == null) {
        swampLandSettings = new TreeLayerSettings<>(SwampLand.INSTANCE);
    }
    if (checkBoxSwamplandEverywhere.isSelected()) {
        int minimumLevel = jSlider6.getValue();
        swampLandSettings.setMinimumLevel(minimumLevel);
    } else {
        swampLandSettings.setMinimumLevel(0);
    }
    dimension.setLayerSettings(SwampLand.INSTANCE, swampLandSettings);
    // frost
    FrostSettings frostSettings = (FrostSettings) dimension.getLayerSettings(Frost.INSTANCE);
    if (frostSettings == null) {
        frostSettings = new FrostSettings();
    }
    frostSettings.setFrostEverywhere(checkBoxFrostEverywhere.isSelected());
    if ((!checkBoxSmoothSnow.isSelected()) || (frostSettings.getMode() != 3)) {
        frostSettings.setMode(checkBoxSmoothSnow.isSelected() ? 2 : 0);
    }
    frostSettings.setSnowUnderTrees(checkBoxSnowUnderTrees.isSelected());
    dimension.setLayerSettings(Frost.INSTANCE, frostSettings);
    // resources
    ResourcesExporterSettings resourcesSettings = (ResourcesExporterSettings) dimension.getLayerSettings(Resources.INSTANCE);
    if (resourcesSettings == null) {
        resourcesSettings = new ResourcesExporterSettings(dimension.getMaxHeight());
    }
    if (jCheckBox8.isSelected()) {
        int minimumLevel = jSlider4.getValue();
        resourcesSettings.setMinimumLevel(minimumLevel);
    } else {
        resourcesSettings.setMinimumLevel(0);
    }
    resourcesSettings.setChance(BLK_GOLD_ORE, (Integer) spinnerGoldChance.getValue());
    resourcesSettings.setMinLevel(BLK_GOLD_ORE, (Integer) spinnerGoldMinLevel.getValue());
    resourcesSettings.setMaxLevel(BLK_GOLD_ORE, (Integer) spinnerGoldMaxLevel.getValue());
    resourcesSettings.setChance(BLK_IRON_ORE, (Integer) spinnerIronChance.getValue());
    resourcesSettings.setMinLevel(BLK_IRON_ORE, (Integer) spinnerIronMinLevel.getValue());
    resourcesSettings.setMaxLevel(BLK_IRON_ORE, (Integer) spinnerIronMaxLevel.getValue());
    resourcesSettings.setChance(BLK_COAL, (Integer) spinnerCoalChance.getValue());
    resourcesSettings.setMinLevel(BLK_COAL, (Integer) spinnerCoalMinLevel.getValue());
    resourcesSettings.setMaxLevel(BLK_COAL, (Integer) spinnerCoalMaxLevel.getValue());
    resourcesSettings.setChance(BLK_LAPIS_LAZULI_ORE, (Integer) spinnerLapisChance.getValue());
    resourcesSettings.setMinLevel(BLK_LAPIS_LAZULI_ORE, (Integer) spinnerLapisMinLevel.getValue());
    resourcesSettings.setMaxLevel(BLK_LAPIS_LAZULI_ORE, (Integer) spinnerLapisMaxLevel.getValue());
    resourcesSettings.setChance(BLK_DIAMOND_ORE, (Integer) spinnerDiamondChance.getValue());
    resourcesSettings.setMinLevel(BLK_DIAMOND_ORE, (Integer) spinnerDiamondMinLevel.getValue());
    resourcesSettings.setMaxLevel(BLK_DIAMOND_ORE, (Integer) spinnerDiamondMaxLevel.getValue());
    resourcesSettings.setChance(BLK_REDSTONE_ORE, (Integer) spinnerRedstoneChance.getValue());
    resourcesSettings.setMinLevel(BLK_REDSTONE_ORE, (Integer) spinnerRedstoneMinLevel.getValue());
    resourcesSettings.setMaxLevel(BLK_REDSTONE_ORE, (Integer) spinnerRedstoneMaxLevel.getValue());
    resourcesSettings.setChance(BLK_WATER, (Integer) spinnerWaterChance.getValue());
    resourcesSettings.setMinLevel(BLK_WATER, (Integer) spinnerWaterMinLevel.getValue());
    resourcesSettings.setMaxLevel(BLK_WATER, (Integer) spinnerWaterMaxLevel.getValue());
    resourcesSettings.setChance(BLK_LAVA, (Integer) spinnerLavaChance.getValue());
    resourcesSettings.setMinLevel(BLK_LAVA, (Integer) spinnerLavaMinLevel.getValue());
    resourcesSettings.setMaxLevel(BLK_LAVA, (Integer) spinnerLavaMaxLevel.getValue());
    resourcesSettings.setChance(BLK_DIRT, (Integer) spinnerDirtChance.getValue());
    resourcesSettings.setMinLevel(BLK_DIRT, (Integer) spinnerDirtMinLevel.getValue());
    resourcesSettings.setMaxLevel(BLK_DIRT, (Integer) spinnerDirtMaxLevel.getValue());
    resourcesSettings.setChance(BLK_GRAVEL, (Integer) spinnerGravelChance.getValue());
    resourcesSettings.setMinLevel(BLK_GRAVEL, (Integer) spinnerGravelMinLevel.getValue());
    resourcesSettings.setMaxLevel(BLK_GRAVEL, (Integer) spinnerGravelMaxLevel.getValue());
    resourcesSettings.setChance(BLK_EMERALD_ORE, (Integer) spinnerEmeraldChance.getValue());
    resourcesSettings.setMinLevel(BLK_EMERALD_ORE, (Integer) spinnerEmeraldMinLevel.getValue());
    resourcesSettings.setMaxLevel(BLK_EMERALD_ORE, (Integer) spinnerEmeraldMaxLevel.getValue());
    resourcesSettings.setChance(BLK_QUARTZ_ORE, (Integer) spinnerQuartzChance.getValue());
    resourcesSettings.setMinLevel(BLK_QUARTZ_ORE, (Integer) spinnerQuartzMinLevel.getValue());
    resourcesSettings.setMaxLevel(BLK_QUARTZ_ORE, (Integer) spinnerQuartzMaxLevel.getValue());
    dimension.setLayerSettings(Resources.INSTANCE, resourcesSettings);
    // annotations
    AnnotationsSettings annotationsSettings = (AnnotationsSettings) dimension.getLayerSettings(Annotations.INSTANCE);
    if (annotationsSettings == null) {
        annotationsSettings = new AnnotationsSettings();
    }
    annotationsSettings.setExport(checkBoxExportAnnotations.isSelected());
    dimension.setLayerSettings(Annotations.INSTANCE, annotationsSettings);
    // custom layers
    if ((mode == Mode.EXPORT) && (!customLayersTableModel.isPristine())) {
        customLayersTableModel.save();
        dimension.setDirty(true);
    }
    return true;
}
Also used : ResourcesExporterSettings(org.pepsoft.worldpainter.layers.exporters.ResourcesExporter.ResourcesExporterSettings) FrostSettings(org.pepsoft.worldpainter.layers.exporters.FrostExporter.FrostSettings) ChasmsSettings(org.pepsoft.worldpainter.layers.exporters.ChasmsExporter.ChasmsSettings) AnnotationsSettings(org.pepsoft.worldpainter.layers.exporters.AnnotationsExporter.AnnotationsSettings) TreeLayerSettings(org.pepsoft.worldpainter.layers.exporters.TreesExporter.TreeLayerSettings) CavernsSettings(org.pepsoft.worldpainter.layers.exporters.CavernsExporter.CavernsSettings)

Example 3 with CavernsSettings

use of org.pepsoft.worldpainter.layers.exporters.CavernsExporter.CavernsSettings in project WorldPainter by Captain-Chaos.

the class NewWorldDialog method getSelectedDimension.

public Dimension getSelectedDimension(final ProgressReceiver progressReceiver) throws ProgressReceiver.OperationCancelled {
    long minecraftSeed;
    try {
        minecraftSeed = Long.parseLong(fieldSeed.getText());
    } catch (NumberFormatException e) {
        minecraftSeed = fieldSeed.getText().hashCode();
    }
    if (radioButtonCustomSeed.isSelected()) {
        worldpainterSeed = minecraftSeed;
    }
    int waterHeight = (Integer) spinnerWaterLevel.getValue();
    final TileFactory tileFactory = createTileFactory(worldpainterSeed);
    int maxHeight = (Integer) comboBoxMaxHeight.getSelectedItem();
    final Dimension dimension = new Dimension(minecraftSeed, tileFactory, dim, maxHeight);
    dimension.setEventsInhibited(true);
    try {
        ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
        final AtomicBoolean cancelled = new AtomicBoolean();
        if (tiles != null) {
            logger.info("Creating new dimension with " + tiles.size() + " preselected tiles");
            final int[] tileCount = new int[1];
            final int totalTiles = tiles.size();
            for (final Point tileCoords : tiles) {
                executorService.execute(() -> {
                    if (cancelled.get()) {
                        // Operation cancelled by user
                        return;
                    }
                    Tile tile = tileFactory.createTile(tileCoords.x, tileCoords.y);
                    dimension.addTile(tile);
                    if (progressReceiver != null) {
                        synchronized (tileCount) {
                            tileCount[0]++;
                            try {
                                progressReceiver.setProgress((float) tileCount[0] / totalTiles);
                            } catch (ProgressReceiver.OperationCancelled e) {
                                cancelled.set(true);
                            }
                        }
                    }
                });
            }
        } else if (checkBoxCircular.isSelected()) {
            final int radius = (Integer) spinnerWidth.getValue() / 2;
            int diameter = radius * 2;
            logger.info("Creating new circular dimension with diameter " + diameter + " blocks");
            int tileRadius = (radius + 127) / 128;
            final int[] tileCount = new int[1];
            final int approximateTotalTiles = (int) Math.ceil(Math.PI * tileRadius * tileRadius);
            for (int x = -tileRadius; x < tileRadius; x++) {
                for (int y = -tileRadius; y < tileRadius; y++) {
                    if (org.pepsoft.worldpainter.util.MathUtils.getSmallestDistanceFromOrigin(x, y) < radius) {
                        // At least one corner is inside the circle; include
                        // the tile. Note that this is always correct in
                        // this case only because the centre of the circle
                        // is always at a tile intersection so the circle
                        // can never "bulge" into a tile without any of the
                        // the tile's corners being inside the circle
                        final int tileX = x, tileY = y;
                        executorService.execute(() -> {
                            if (cancelled.get()) {
                                // Operation cancelled by user
                                return;
                            }
                            Tile tile = tileFactory.createTile(tileX, tileY);
                            dimension.addTile(tile);
                            if (org.pepsoft.worldpainter.util.MathUtils.getLargestDistanceFromOrigin(tileX, tileY) >= radius) {
                                // the edge
                                for (int xx = 0; xx < TILE_SIZE; xx++) {
                                    for (int yy = 0; yy < TILE_SIZE; yy++) {
                                        float distance = MathUtils.getDistance(tileX * TILE_SIZE + xx + 0.5f, tileY * TILE_SIZE + yy + 0.5f);
                                        if (distance > radius) {
                                            tile.setBitLayerValue(org.pepsoft.worldpainter.layers.Void.INSTANCE, xx, yy, true);
                                        }
                                    }
                                }
                            }
                            if (progressReceiver != null) {
                                synchronized (tileCount) {
                                    tileCount[0]++;
                                    try {
                                        // System.out.println("Progress: " + tileCount[0] + " of " + approximateTotalTiles + " (" + ((float) tileCount[0] / approximateTotalTiles) + ")");
                                        progressReceiver.setProgress(Math.min((float) tileCount[0] / approximateTotalTiles, 1.0f));
                                    } catch (ProgressReceiver.OperationCancelled e) {
                                        cancelled.set(true);
                                    }
                                }
                            }
                        });
                    }
                }
            }
            // Assume the user will want an endless void border by default;
            // override the preferences
            dimension.setBorder(Border.ENDLESS_VOID);
        } else {
            int width = ((Integer) spinnerWidth.getValue()) / 128;
            int height = ((Integer) spinnerLength.getValue()) / 128;
            logger.info("Creating new dimension of size " + width + "x" + height + " for a total of " + width * height + " tiles");
            final int[] tileCount = new int[1];
            final int totalTiles = width * height;
            int startX = -width / 2;
            int startY = -height / 2;
            for (int x = startX; x < startX + width; x++) {
                for (int y = startY; y < startY + height; y++) {
                    final int tileX = x, tileY = y;
                    executorService.execute(() -> {
                        if (cancelled.get()) {
                            // Operation cancelled by user
                            return;
                        }
                        Tile tile = tileFactory.createTile(tileX, tileY);
                        dimension.addTile(tile);
                        if (progressReceiver != null) {
                            synchronized (tileCount) {
                                tileCount[0]++;
                                try {
                                    progressReceiver.setProgress((float) tileCount[0] / totalTiles);
                                } catch (ProgressReceiver.OperationCancelled e) {
                                    cancelled.set(true);
                                }
                            }
                        }
                    });
                }
            }
        }
        // Wait for all tiles to be created
        executorService.shutdown();
        try {
            executorService.awaitTermination(1, TimeUnit.DAYS);
        } catch (InterruptedException e) {
            throw new RuntimeException("Thread interrupted", e);
        }
        if (cancelled.get()) {
            // The operation was cancelled by the user
            return null;
        }
        if (dim == DIM_NORMAL_CEILING) {
            ResourcesExporter.ResourcesExporterSettings resourcesSettings = new ResourcesExporter.ResourcesExporterSettings(maxHeight);
            // Invert min and max levels:
            int maxZ = maxHeight - 1;
            for (int blockType : resourcesSettings.getBlockTypes()) {
                int low = resourcesSettings.getMinLevel(blockType);
                int high = resourcesSettings.getMaxLevel(blockType);
                resourcesSettings.setMinLevel(blockType, maxZ - high);
                resourcesSettings.setMaxLevel(blockType, maxZ - low);
            }
            // Remove lava and water:
            resourcesSettings.setChance(BLK_WATER, 0);
            resourcesSettings.setChance(BLK_LAVA, 0);
            dimension.setLayerSettings(Resources.INSTANCE, resourcesSettings);
        } else if (dim == DIM_NETHER) {
            dimension.setSubsurfaceMaterial(NETHERLIKE);
            CavernsSettings cavernsSettings = new CavernsSettings();
            cavernsSettings.setCavernsEverywhereLevel(16);
            cavernsSettings.setSurfaceBreaking(true);
            cavernsSettings.setFloodWithLava(true);
            cavernsSettings.setWaterLevel(16);
            dimension.setLayerSettings(Caverns.INSTANCE, cavernsSettings);
        } else if (dim == DIM_NETHER_CEILING) {
            dimension.setSubsurfaceMaterial(NETHERLIKE);
        } else if ((dim == DIM_END) || (dim == DIM_END_CEILING)) {
            dimension.setSubsurfaceMaterial(END_STONE);
        }
        Configuration config = Configuration.getInstance();
        Dimension defaults = config.getDefaultTerrainAndLayerSettings();
        if (dim == DIM_NORMAL) {
            if (!checkBoxCircular.isSelected()) {
                dimension.setBorder(defaults.getBorder());
                dimension.setBorderSize(defaults.getBorderSize());
            }
            dimension.setBedrockWall(defaults.isBedrockWall());
            dimension.setSubsurfaceMaterial(defaults.getSubsurfaceMaterial());
            dimension.setPopulate(defaults.isPopulate());
            dimension.setTopLayerMinDepth(defaults.getTopLayerMinDepth());
            dimension.setTopLayerVariation(defaults.getTopLayerVariation());
            dimension.setBottomless(defaults.isBottomless());
            for (Map.Entry<Layer, ExporterSettings> entry : defaults.getAllLayerSettings().entrySet()) {
                dimension.setLayerSettings(entry.getKey(), entry.getValue().clone());
            }
        }
        dimension.setBorderLevel(waterHeight);
        dimension.setCoverSteepTerrain(defaults.isCoverSteepTerrain());
        dimension.setGridEnabled(config.isDefaultGridEnabled());
        dimension.setGridSize(config.getDefaultGridSize());
        dimension.setContoursEnabled(config.isDefaultContoursEnabled());
        dimension.setContourSeparation(config.getDefaultContourSeparation());
    } finally {
        dimension.setEventsInhibited(false);
    }
    dimension.setDirty(false);
    return dimension;
}
Also used : ExporterSettings(org.pepsoft.worldpainter.layers.exporters.ExporterSettings) CavernsSettings(org.pepsoft.worldpainter.layers.exporters.CavernsExporter.CavernsSettings) ResourcesExporter(org.pepsoft.worldpainter.layers.exporters.ResourcesExporter) Layer(org.pepsoft.worldpainter.layers.Layer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExecutorService(java.util.concurrent.ExecutorService) ProgressReceiver(org.pepsoft.util.ProgressReceiver)

Aggregations

CavernsSettings (org.pepsoft.worldpainter.layers.exporters.CavernsExporter.CavernsSettings)3 AnnotationsSettings (org.pepsoft.worldpainter.layers.exporters.AnnotationsExporter.AnnotationsSettings)2 ChasmsSettings (org.pepsoft.worldpainter.layers.exporters.ChasmsExporter.ChasmsSettings)2 FrostSettings (org.pepsoft.worldpainter.layers.exporters.FrostExporter.FrostSettings)2 ResourcesExporterSettings (org.pepsoft.worldpainter.layers.exporters.ResourcesExporter.ResourcesExporterSettings)2 TreeLayerSettings (org.pepsoft.worldpainter.layers.exporters.TreesExporter.TreeLayerSettings)2 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ProgressReceiver (org.pepsoft.util.ProgressReceiver)1 Layer (org.pepsoft.worldpainter.layers.Layer)1 ExporterSettings (org.pepsoft.worldpainter.layers.exporters.ExporterSettings)1 ResourcesExporter (org.pepsoft.worldpainter.layers.exporters.ResourcesExporter)1 SimpleTheme (org.pepsoft.worldpainter.themes.SimpleTheme)1