Search in sources :

Example 1 with WPObject

use of org.pepsoft.worldpainter.objects.WPObject in project WorldPainter by Captain-Chaos.

the class DynMapPreviewer method main.

public static void main(String[] args) throws IOException, ClassNotFoundException {
    // Install java.util.logging -> slf4j bridge:
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();
    // Load or initialise configuration
    // This will migrate the configuration directory if necessary
    Configuration config = Configuration.load();
    if (config == null) {
        if (!logger.isDebugEnabled()) {
            // If debug logging is on, the Configuration constructor will
            // already log this
            logger.info("Creating new configuration");
        }
        config = new Configuration();
    }
    Configuration.setInstance(config);
    logger.info("Installation ID: " + config.getUuid());
    // Load and install trusted WorldPainter root certificate
    X509Certificate trustedCert = null;
    try {
        CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
        trustedCert = (X509Certificate) certificateFactory.generateCertificate(DynMapPreviewer.class.getResourceAsStream("/wproot.pem"));
    } catch (CertificateException e) {
        logger.error("Certificate exception while loading trusted root certificate", e);
    }
    // Load the plugins
    if (trustedCert != null) {
        PluginManager.loadPlugins(new File(Configuration.getConfigDir(), "plugins"), trustedCert.getPublicKey());
    } else {
        logger.error("Trusted root certificate not available; not loading plugins");
    }
    WPPluginManager.initialise(config.getUuid());
    JFrame frame = new JFrame("DynMapPreviewerTest");
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    DynMapPreviewer viewer = new DynMapPreviewer();
    WPObject object = CustomObjectManager.getInstance().loadObject(new File(args[0]));
    TileFactory tileFactory = TileFactoryFactory.createNoiseTileFactory(0L, Terrain.GRASS, DEFAULT_MAX_HEIGHT_2, 58, 62, false, true, 20.0f, 1.0);
    Dimension dimension = new Dimension(0L, tileFactory, DIM_NORMAL, DEFAULT_MAX_HEIGHT_2);
    viewer.setObject(object, dimension);
    frame.getContentPane().add(viewer, BorderLayout.CENTER);
    frame.setSize(800, 600);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
Also used : WPObject(org.pepsoft.worldpainter.objects.WPObject) CertificateException(java.security.cert.CertificateException) Dimension(org.pepsoft.worldpainter.Dimension) CertificateFactory(java.security.cert.CertificateFactory) File(java.io.File) X509Certificate(java.security.cert.X509Certificate)

Example 2 with WPObject

use of org.pepsoft.worldpainter.objects.WPObject in project WorldPainter by Captain-Chaos.

the class Bo2ObjectTube method getObject.

@Override
public WPObject getObject() {
    if (weightedObjects == null) {
        weightedObjects = new TreeMap<>();
        totalObjectWeight = 0;
        for (WPObject object : objects) {
            int frequency = object.getAttribute(ATTRIBUTE_FREQUENCY);
            totalObjectWeight += frequency;
            weightedObjects.put(totalObjectWeight, object);
        }
    }
    return weightedObjects.tailMap(random.nextInt(totalObjectWeight)).values().iterator().next();
}
Also used : WPObject(org.pepsoft.worldpainter.objects.WPObject)

Example 3 with WPObject

use of org.pepsoft.worldpainter.objects.WPObject in project WorldPainter by Captain-Chaos.

the class Bo2LayerEditor method setLeavesDecay.

private void setLeavesDecay() {
    for (Enumeration<WPObject> e = (Enumeration<WPObject>) listModel.elements(); e.hasMoreElements(); ) {
        WPObject object = e.nextElement();
        object.setAttribute(ATTRIBUTE_LEAF_DECAY_MODE, LEAF_DECAY_ON);
    }
    refreshLeafDecaySettings();
}
Also used : WPObject(org.pepsoft.worldpainter.objects.WPObject)

Example 4 with WPObject

use of org.pepsoft.worldpainter.objects.WPObject in project WorldPainter by Captain-Chaos.

the class Bo2LayerEditor method listObjectsMouseClicked.

// GEN-LAST:event_buttonResetActionPerformed
private void listObjectsMouseClicked(java.awt.event.MouseEvent evt) {
    // GEN-FIRST:event_listObjectsMouseClicked
    if (evt.getClickCount() == 2) {
        int row = listObjects.getSelectedIndex();
        if (row != -1) {
            WPObject object = (WPObject) listModel.getElementAt(row);
            EditObjectAttributes dialog = new EditObjectAttributes(SwingUtilities.getWindowAncestor(this), object, colourScheme);
            dialog.setVisible(true);
            if (!dialog.isCancelled()) {
                refreshLeafDecaySettings();
            }
        }
    }
}
Also used : WPObject(org.pepsoft.worldpainter.objects.WPObject)

Example 5 with WPObject

use of org.pepsoft.worldpainter.objects.WPObject in project WorldPainter by Captain-Chaos.

the class Bo2LayerEditor method saveSettings.

private Bo2Layer saveSettings(Bo2Layer layer) {
    String name = fieldName.getText();
    List<WPObject> objects = new ArrayList<>(listModel.getSize());
    for (int i = 0; i < listModel.getSize(); i++) {
        objects.add((WPObject) listModel.getElementAt(i));
    }
    Bo2ObjectProvider objectProvider = new Bo2ObjectTube(name, objects);
    if (layer == null) {
        layer = new Bo2Layer(objectProvider, "Custom (e.g. bo2, bo3 and/or schematic) objects", selectedColour);
    } else {
        layer.setObjectProvider(objectProvider);
        layer.setColour(selectedColour);
    }
    layer.setDensity((Integer) spinnerBlocksPerAttempt.getValue());
    return layer;
}
Also used : WPObject(org.pepsoft.worldpainter.objects.WPObject) Bo2Layer(org.pepsoft.worldpainter.layers.Bo2Layer)

Aggregations

WPObject (org.pepsoft.worldpainter.objects.WPObject)17 File (java.io.File)4 Point3i (javax.vecmath.Point3i)3 CustomObjectManager (org.pepsoft.worldpainter.plugins.CustomObjectManager)3 IOException (java.io.IOException)2 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 MirroredObject (org.pepsoft.worldpainter.objects.MirroredObject)2 RotatedObject (org.pepsoft.worldpainter.objects.RotatedObject)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 CertificateException (java.security.cert.CertificateException)1 CertificateFactory (java.security.cert.CertificateFactory)1 X509Certificate (java.security.cert.X509Certificate)1 Dimension (org.pepsoft.worldpainter.Dimension)1 Fixup (org.pepsoft.worldpainter.exporting.Fixup)1 Bo2Layer (org.pepsoft.worldpainter.layers.Bo2Layer)1 Bo2ObjectProvider (org.pepsoft.worldpainter.layers.bo2.Bo2ObjectProvider)1