Search in sources :

Example 1 with HeightFilter

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

the class Configuration method readObject.

@SuppressWarnings("deprecation")
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();
    // Legacy config
    if ((border != null) && (border2 == null)) {
        border2 = Border.valueOf(border.name());
        border = null;
    }
    if (customMaterials == null) {
        customMaterials = new Material[] { Material.DIRT, Material.DIRT, Material.DIRT, Material.DIRT, Material.DIRT };
    }
    if (minecraftJars == null) {
        minecraftJars = new HashMap<>();
        minecraft1_9_p3Jar = null;
    }
    if (uuid == null) {
        uuid = UUID.randomUUID();
    }
    if (undoLevels == 0) {
        checkForUpdates = true;
        undoEnabled = true;
        defaultContoursEnabled = true;
        undoLevels = 100;
        defaultGridSize = 128;
        defaultContourSeparation = 10;
        defaultWidth = 5;
        defaultHeight = 5;
        defaultMaxHeight = DEFAULT_MAX_HEIGHT_2;
    }
    if (defaultTerrainAndLayerSettings == null) {
        defaultTerrainAndLayerSettings = new Dimension(World2.DEFAULT_OCEAN_SEED, TileFactoryFactory.createNoiseTileFactory(new Random().nextLong(), surface, defaultMaxHeight, level, waterLevel, lava, beaches, 20, 1.0), Constants.DIM_NORMAL, defaultMaxHeight);
    }
    // New legacy mechanism with version number
    if (version < 1) {
        worldFileBackups = 3;
    }
    if (version < 2) {
        defaultRange = 20;
        defaultScale = 1.0;
        defaultLightOrigin = LightOrigin.NORTHWEST;
    }
    if (version < 3) {
        String maxRadiusStr = System.getProperty("org.pepsoft.worldpainter.maxRadius");
        if ((maxRadiusStr != null) && (!maxRadiusStr.trim().isEmpty())) {
            try {
                maximumBrushSize = Integer.parseInt(maxRadiusStr);
            } catch (NumberFormatException e) {
                maximumBrushSize = 300;
            }
        } else {
            maximumBrushSize = 300;
        }
    }
    if (version < 4) {
        // Turn on smooth snow for everyone once
        FrostSettings frostSettings = (FrostSettings) defaultTerrainAndLayerSettings.getLayerSettings(Frost.INSTANCE);
        if (frostSettings != null) {
            frostSettings.setMode(FrostSettings.MODE_SMOOTH);
        }
    }
    if (version < 5) {
        // Reset the Resource setting preferences once, which might have
        // been unintentionally altered due to a bug
        defaultTerrainAndLayerSettings.setLayerSettings(Resources.INSTANCE, new ResourcesExporterSettings(defaultMaxHeight));
    }
    if (version < 6) {
        if (!Boolean.FALSE.equals(pingAllowed)) {
            eventLog = new LinkedList<>();
        }
    }
    if (version < 7) {
        customLayers = new ArrayList<>();
        mixedMaterials = new ArrayList<>();
    }
    if (version < 8) {
        // continue to the top of the map
        if ((defaultTerrainAndLayerSettings.getTileFactory() instanceof HeightMapTileFactory) && (((HeightMapTileFactory) defaultTerrainAndLayerSettings.getTileFactory()).getTheme() instanceof SimpleTheme)) {
            SimpleTheme theme = (SimpleTheme) ((HeightMapTileFactory) defaultTerrainAndLayerSettings.getTileFactory()).getTheme();
            // luck; it's not worth migrating them as well
            if (theme.getTerrainRanges() != null) {
                SortedMap<Integer, Terrain> terrainRanges = theme.getTerrainRanges();
                Map<Filter, Layer> layerMap = new HashMap<>();
                boolean frostAdded = false;
                for (Map.Entry<Integer, Terrain> entry : terrainRanges.entrySet()) {
                    if (entry.getValue() == Terrain.SNOW) {
                        if (!frostAdded) {
                            layerMap.put(new HeightFilter(defaultMaxHeight, entry.getKey(), defaultMaxHeight - 1, theme.isRandomise()), Frost.INSTANCE);
                            frostAdded = true;
                        }
                        entry.setValue(Terrain.ROCK);
                    }
                }
                if (!layerMap.isEmpty()) {
                    theme.setLayerMap(layerMap);
                }
            }
        }
    }
    if (version < 9) {
        // Set default export settings
        defaultCreateGoodiesChest = true;
        defaultGenerator = Generator.DEFAULT;
        defaultMapFeatures = true;
        defaultGameType = 0;
    }
    if (version < 10) {
        if (defaultTerrainAndLayerSettings.getSubsurfaceMaterial() == Terrain.STONE) {
            defaultTerrainAndLayerSettings.setSubsurfaceMaterial(Terrain.STONE_MIX);
        }
    }
    if (version < 11) {
        switch(SystemUtils.getOS()) {
            case WINDOWS:
                accelerationType = AccelerationType.DIRECT3D;
                break;
            case MAC:
                accelerationType = AccelerationType.DEFAULT;
                break;
            case LINUX:
                accelerationType = AccelerationType.XRENDER;
                break;
            default:
                accelerationType = AccelerationType.DEFAULT;
                break;
        }
        // Previous default; principle of least surprise:
        overlayType = OverlayType.SCALE_ON_LOAD;
    }
    if (version < 12) {
        defaultJideLayoutData = null;
        jideLayoutData = null;
        showCalloutCount = 3;
    }
    if (version < 13) {
        backgroundImageMode = TiledImageViewer.BackgroundImageMode.REPEAT;
        backgroundColour = -1;
        showBiomes = showBorders = true;
    }
    if (version < 14) {
        if (defaultGameType >= 0) {
            defaultGameTypeObj = GameType.values()[defaultGameType];
            defaultGameType = -1;
        } else {
            // Not sure how this could have happened, but it has been
            // observed
            defaultGameTypeObj = GameType.SURVIVAL;
            defaultGameType = -1;
        }
    }
    if (version < 15) {
        defaultPlatform = DefaultPlugin.JAVA_ANVIL;
        exportDirectories = new HashMap<>();
        if (exportDirectory != null) {
            exportDirectories.put(DefaultPlugin.JAVA_ANVIL, exportDirectory);
            exportDirectories.put(DefaultPlugin.JAVA_MCREGION, exportDirectory);
            exportDirectory = null;
        }
    }
    version = CURRENT_VERSION;
    // Bug fix: make sure terrain ranges map conforms to surface material setting
    TileFactory tileFactory = defaultTerrainAndLayerSettings.getTileFactory();
    if ((tileFactory instanceof HeightMapTileFactory) && (((HeightMapTileFactory) tileFactory).getTheme() instanceof SimpleTheme)) {
        SortedMap<Integer, Terrain> defaultTerrainRanges = ((SimpleTheme) ((HeightMapTileFactory) tileFactory).getTheme()).getTerrainRanges();
        // Find what is probably meant to be the surface material. With the
        // default settings this should be -1, but if someone configured a
        // default underwater material, try not to change that
        int surfaceLevel = defaultTerrainRanges.headMap(waterLevel + 3).lastKey();
        defaultTerrainRanges.put(surfaceLevel, surface);
    }
}
Also used : SimpleTheme(org.pepsoft.worldpainter.themes.SimpleTheme) ResourcesExporterSettings(org.pepsoft.worldpainter.layers.exporters.ResourcesExporter.ResourcesExporterSettings) HeightFilter(org.pepsoft.worldpainter.themes.HeightFilter) CustomLayer(org.pepsoft.worldpainter.layers.CustomLayer) Layer(org.pepsoft.worldpainter.layers.Layer) FrostSettings(org.pepsoft.worldpainter.layers.exporters.FrostExporter.FrostSettings) HeightFilter(org.pepsoft.worldpainter.themes.HeightFilter) Filter(org.pepsoft.worldpainter.themes.Filter)

Example 2 with HeightFilter

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

the class LayerMapTableModel method setValueAt.

@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    switch(columnIndex) {
        case COLUMN_LAYER:
            layers.set(rowIndex, (Layer) aValue);
            break;
        case COLUMN_FROM:
            HeightFilter oldFilter = filters.get(rowIndex);
            filters.set(rowIndex, new HeightFilter(maxHeight, (Integer) aValue, oldFilter.getStopHeight(), oldFilter.isFeather()));
            break;
        case COLUMN_TO:
            oldFilter = filters.get(rowIndex);
            filters.set(rowIndex, new HeightFilter(maxHeight, oldFilter.getStartHeight(), (Integer) aValue, oldFilter.isFeather()));
            break;
        case COLUMN_FEATHER:
            oldFilter = filters.get(rowIndex);
            filters.set(rowIndex, new HeightFilter(maxHeight, oldFilter.getStartHeight(), oldFilter.getStopHeight(), (Boolean) aValue));
            break;
        default:
            throw new IndexOutOfBoundsException("columnIndex " + columnIndex);
    }
    TableModelEvent event = new TableModelEvent(this, rowIndex, rowIndex, columnIndex);
    for (TableModelListener listener : listeners) {
        listener.tableChanged(event);
    }
}
Also used : TableModelEvent(javax.swing.event.TableModelEvent) TableModelListener(javax.swing.event.TableModelListener) HeightFilter(org.pepsoft.worldpainter.themes.HeightFilter)

Example 3 with HeightFilter

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

the class LayerRangesTableModel method setValueAt.

@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    switch(columnIndex) {
        case COLUMN_FROM:
            HeightFilter old = (HeightFilter) filters.get(rowIndex);
            filters.set(rowIndex, new HeightFilter(maxHeight, (int) aValue, old.getStopHeight(), old.isFeather()));
            break;
        case COLUMN_TO:
            old = (HeightFilter) filters.get(rowIndex);
            filters.set(rowIndex, new HeightFilter(maxHeight, old.getStartHeight(), (int) aValue, old.isFeather()));
            break;
        case COLUMN_FEATHER:
            old = (HeightFilter) filters.get(rowIndex);
            filters.set(rowIndex, new HeightFilter(maxHeight, old.getStartHeight(), old.getStopHeight(), (boolean) aValue));
            break;
        case COLUMN_LAYER:
            throw new IllegalArgumentException("columnIndex " + columnIndex + " not editable");
        case COLUMN_ACTIONS:
            // Do nothing
            break;
        default:
            throw new IndexOutOfBoundsException("columnIndex " + columnIndex);
    }
}
Also used : HeightFilter(org.pepsoft.worldpainter.themes.HeightFilter)

Aggregations

HeightFilter (org.pepsoft.worldpainter.themes.HeightFilter)3 TableModelEvent (javax.swing.event.TableModelEvent)1 TableModelListener (javax.swing.event.TableModelListener)1 CustomLayer (org.pepsoft.worldpainter.layers.CustomLayer)1 Layer (org.pepsoft.worldpainter.layers.Layer)1 FrostSettings (org.pepsoft.worldpainter.layers.exporters.FrostExporter.FrostSettings)1 ResourcesExporterSettings (org.pepsoft.worldpainter.layers.exporters.ResourcesExporter.ResourcesExporterSettings)1 Filter (org.pepsoft.worldpainter.themes.Filter)1 SimpleTheme (org.pepsoft.worldpainter.themes.SimpleTheme)1