Search in sources :

Example 1 with Filter

use of org.pepsoft.worldpainter.themes.Filter 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 Filter

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

the class LayerRangesTableModel method getLayerMap.

public Map<Filter, Layer> getLayerMap() {
    if (!layers.isEmpty()) {
        Map<Filter, Layer> layerMap = new HashMap<>();
        Iterator<Filter> filterIterator = filters.iterator();
        for (Layer layer : layers) {
            Filter filter = filterIterator.next();
            layerMap.put(filter, layer);
        }
        return layerMap;
    } else {
        return null;
    }
}
Also used : HeightFilter(org.pepsoft.worldpainter.themes.HeightFilter) Filter(org.pepsoft.worldpainter.themes.Filter) HashMap(java.util.HashMap) Layer(org.pepsoft.worldpainter.layers.Layer)

Aggregations

Layer (org.pepsoft.worldpainter.layers.Layer)2 Filter (org.pepsoft.worldpainter.themes.Filter)2 HeightFilter (org.pepsoft.worldpainter.themes.HeightFilter)2 HashMap (java.util.HashMap)1 CustomLayer (org.pepsoft.worldpainter.layers.CustomLayer)1 FrostSettings (org.pepsoft.worldpainter.layers.exporters.FrostExporter.FrostSettings)1 ResourcesExporterSettings (org.pepsoft.worldpainter.layers.exporters.ResourcesExporter.ResourcesExporterSettings)1 SimpleTheme (org.pepsoft.worldpainter.themes.SimpleTheme)1