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);
}
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();
}
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();
}
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();
}
}
}
}
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;
}
Aggregations